Skip to content

Commit 3a8eeaa

Browse files
committed
Updated System.Collections
1 parent a09b214 commit 3a8eeaa

File tree

9 files changed

+147
-43
lines changed

9 files changed

+147
-43
lines changed

fcs/fcs-fable/Fable.Core.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Fable.Core
2+
3+
module JS =
4+
5+
type Map<'K, 'V> =
6+
abstract size: int
7+
abstract clear: unit -> unit
8+
abstract delete: key: 'K -> bool
9+
abstract entries: unit -> seq<'K * 'V>
10+
11+
abstract forEach: callbackfn: ('V -> 'K -> Map<'K, 'V> -> unit) * ?thisArg: obj -> unit
12+
13+
abstract get: key: 'K -> 'V
14+
abstract has: key: 'K -> bool
15+
abstract keys: unit -> seq<'K>
16+
abstract set: key: 'K * value: 'V -> Map<'K, 'V>
17+
abstract values: unit -> seq<'V>

fcs/fcs-fable/System.Collections.Concurrent.fs

Lines changed: 111 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ type ConcurrentStack<'T>() =
2424
(xs.GetEnumerator() :> System.Collections.IEnumerator)
2525

2626
// not thread safe, just a Dictionary // TODO: threaded implementation
27-
[<AllowNullLiteral>]
2827
type ConcurrentDictionary<'K, 'V>(comparer: IEqualityComparer<'K>) =
29-
inherit Dictionary<'K, 'V>(comparer)
28+
let xs = Dictionary<'K, 'V>(comparer)
3029

3130
new () =
3231
ConcurrentDictionary<'K, 'V>(EqualityComparer.Default)
@@ -37,47 +36,127 @@ type ConcurrentDictionary<'K, 'V>(comparer: IEqualityComparer<'K>) =
3736
new (_concurrencyLevel: int, _capacity: int, comparer: IEqualityComparer<'K>) =
3837
ConcurrentDictionary<'K, 'V>(comparer)
3938

40-
member x.TryAdd (key: 'K, value: 'V): bool =
41-
if x.ContainsKey(key)
39+
member _.Keys = xs.Keys
40+
member _.Values = xs.Values
41+
42+
member _.Item
43+
with get (key: 'K): 'V = xs[key]
44+
and set (key: 'K) (value: 'V) = xs[key] <- value
45+
46+
member _.Clear () = xs.Clear()
47+
member _.ContainsKey (key: 'K) = xs.ContainsKey(key)
48+
49+
member _.TryGetValue (key: 'K): bool * 'V =
50+
match xs.TryGetValue(key) with
51+
| true, v -> (true, v)
52+
| false, v -> (false, v)
53+
54+
member _.TryAdd (key: 'K, value: 'V): bool =
55+
if xs.ContainsKey(key)
4256
then false
43-
else x.Add(key, value); true
57+
else xs.Add(key, value); true
4458

45-
member x.TryRemove (key: 'K): bool * 'V =
46-
match x.TryGetValue(key) with
47-
| true, v -> (x.Remove(key), v)
59+
member _.TryRemove (key: 'K): bool * 'V =
60+
match xs.TryGetValue(key) with
61+
| true, v -> (xs.Remove(key), v)
4862
| _ as res -> res
4963

50-
member x.GetOrAdd (key: 'K, value: 'V): 'V =
51-
match x.TryGetValue(key) with
64+
member _.GetOrAdd (key: 'K, value: 'V): 'V =
65+
match xs.TryGetValue(key) with
5266
| true, v -> v
53-
| _ -> let v = value in x.Add(key, v); v
67+
| _ -> let v = value in xs.Add(key, v); v
5468

55-
member x.GetOrAdd (key: 'K, valueFactory: System.Func<'K, 'V>): 'V =
56-
match x.TryGetValue(key) with
69+
member _.GetOrAdd (key: 'K, valueFactory: System.Func<'K, 'V>): 'V =
70+
match xs.TryGetValue(key) with
5771
| true, v -> v
58-
| _ -> let v = valueFactory.Invoke(key) in x.Add(key, v); v
72+
| _ -> let v = valueFactory.Invoke(key) in xs.Add(key, v); v
5973

60-
// member x.GetOrAdd<'Arg> (key: 'K, valueFactory: 'K * 'Arg -> 'V, arg: 'Arg): 'V =
61-
// match x.TryGetValue(key) with
74+
// member _.GetOrAdd<'Arg> (key: 'K, valueFactory: 'K * 'Arg -> 'V, arg: 'Arg): 'V =
75+
// match xs.TryGetValue(key) with
6276
// | true, v -> v
63-
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v
77+
// | _ -> let v = valueFactory(key, arg) in xs.Add(key, v); v
6478

65-
member x.TryUpdate (key: 'K, value: 'V, comparisonValue: 'V): bool =
66-
match x.TryGetValue(key) with
67-
| true, v when Unchecked.equals v comparisonValue -> x[key] <- value; true
79+
member _.TryUpdate (key: 'K, value: 'V, comparisonValue: 'V): bool =
80+
match xs.TryGetValue(key) with
81+
| true, v when Unchecked.equals v comparisonValue -> xs[key] <- value; true
6882
| _ -> false
6983

70-
member x.AddOrUpdate (key: 'K, value: 'V, updateFactory: System.Func<'K, 'V, 'V>): 'V =
71-
match x.TryGetValue(key) with
72-
| true, v -> let v = updateFactory.Invoke(key, v) in x[key] <- v; v
73-
| _ -> let v = value in x.Add(key, v); v
84+
member _.AddOrUpdate (key: 'K, value: 'V, updateFactory: System.Func<'K, 'V, 'V>): 'V =
85+
match xs.TryGetValue(key) with
86+
| true, v -> let v = updateFactory.Invoke(key, v) in xs[key] <- v; v
87+
| _ -> let v = value in xs.Add(key, v); v
88+
89+
// member _.AddOrUpdate (key: 'K, valueFactory: 'K -> 'V, updateFactory: 'K * 'V -> 'V): 'V =
90+
// match xs.TryGetValue(key) with
91+
// | true, v -> let v = updateFactory(key, v) in xs[key] <- v; v
92+
// | _ -> let v = valueFactory(key) in xs.Add(key, v); v
93+
94+
// member _.AddOrUpdate (key: 'K, valueFactory: 'K * 'Arg -> 'V, updateFactory: 'K * 'Arg * 'V -> 'V, arg: 'Arg): 'V =
95+
// match xs.TryGetValue(key) with
96+
// | true, v -> let v = updateFactory(key, arg, v) in xs[key] <- v; v
97+
// | _ -> let v = valueFactory(key, arg) in xs.Add(key, v); v
98+
99+
interface System.Collections.IEnumerable with
100+
member _.GetEnumerator(): System.Collections.IEnumerator =
101+
(xs.GetEnumerator() :> System.Collections.IEnumerator)
102+
103+
interface IEnumerable<KeyValuePair<'K, 'V>> with
104+
member _.GetEnumerator(): IEnumerator<KeyValuePair<'K, 'V>> =
105+
xs.GetEnumerator()
106+
107+
interface ICollection<KeyValuePair<'K, 'V>> with
108+
member _.Add(item: KeyValuePair<'K, 'V>) : unit =
109+
xs.Add(item.Key, item.Value)
110+
111+
member _.Clear() : unit = xs.Clear()
112+
113+
member _.Contains(item: KeyValuePair<'K, 'V>) : bool =
114+
match xs.TryGetValue(item.Key) with
115+
| true, value when Unchecked.equals value item.Value -> true
116+
| _ -> false
117+
118+
member _.CopyTo(array: KeyValuePair<'K, 'V>[], arrayIndex: int) : unit =
119+
xs |> Seq.iteri (fun i e -> array[arrayIndex + i] <- e)
120+
121+
member _.Count: int = xs.Count
122+
member _.IsReadOnly: bool = false
123+
124+
member _.Remove(item: KeyValuePair<'K, 'V>) : bool =
125+
match xs.TryGetValue(item.Key) with
126+
| true, value when Unchecked.equals value item.Value -> xs.Remove(item.Key)
127+
| _ -> false
128+
129+
interface IDictionary<'K, 'V> with
130+
member _.Add(key: 'K, value: 'V) : unit = xs.Add(key, value)
131+
member _.ContainsKey(key: 'K) : bool = xs.ContainsKey(key)
132+
133+
member _.Item
134+
with get (key: 'K): 'V = xs[key]
135+
and set (key: 'K) (v: 'V): unit = xs[key] <- v
136+
137+
member _.Keys: ICollection<'K> = xs.Keys
138+
139+
member _.Remove(key: 'K) : bool = xs.Remove(key)
140+
141+
member _.TryGetValue(key: 'K, value: byref<'V>) : bool = xs.TryGetValue(key, &value)
142+
member _.Values: ICollection<'V> = xs.Values
143+
144+
interface Fable.Core.JS.Map<'K, 'V> with
145+
member _.size = xs.Count
146+
member _.clear() = xs.Clear()
147+
member _.delete(k) = xs.Remove(k)
148+
149+
member _.entries() =
150+
xs |> Seq.map (fun p -> p.Key, p.Value)
151+
152+
member _.get(k) = xs[k]
153+
member _.has(k) = xs.ContainsKey(k)
154+
member _.keys() = xs.Keys
155+
member _.values() = xs.Values
74156

75-
// member x.AddOrUpdate (key: 'K, valueFactory: 'K -> 'V, updateFactory: 'K * 'V -> 'V): 'V =
76-
// match x.TryGetValue(key) with
77-
// | true, v -> let v = updateFactory(key, v) in x[key] <- v; v
78-
// | _ -> let v = valueFactory(key) in x.Add(key, v); v
157+
member this.set(k, v) =
158+
xs[k] <- v
159+
this
79160

80-
// member x.AddOrUpdate (key: 'K, valueFactory: 'K * 'Arg -> 'V, updateFactory: 'K * 'Arg * 'V -> 'V, arg: 'Arg): 'V =
81-
// match x.TryGetValue(key) with
82-
// | true, v -> let v = updateFactory(key, arg, v) in x[key] <- v; v
83-
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v
161+
member this.forEach(f, ?thisArg) =
162+
this |> Seq.iter (fun p -> f p.Value p.Key this)

fcs/fcs-fable/fcs-fable.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
<DefineConstants>$(DefineConstants);NO_INLINE_IL_PARSER</DefineConstants>
1515
<DefineConstants>$(DefineConstants);FSHARPCORE_USE_PACKAGE</DefineConstants>
1616
<OtherFlags>$(OtherFlags) --nowarn:57</OtherFlags>
17+
<!-- <Nullable>enable</Nullable> -->
18+
<!-- <WarningsAsErrors>FS3261</WarningsAsErrors> -->
19+
<!-- <WarningsAsErrors>FS3559</WarningsAsErrors> -->
1720
<!-- <DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference> -->
1821
</PropertyGroup>
1922

2023
<ItemGroup>
24+
<Compile Include="Fable.Core.fs" />
2125
<!-- BCL shims -->
2226
<Compile Include="System.fs" />
2327
<Compile Include="System.Collections.Immutable.fs" />

src/Compiler/AbstractIL/il.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ type ILFieldInit =
15821582
| ILFieldInit.UInt64 u64 -> box u64
15831583
| ILFieldInit.Single ieee32 -> box ieee32
15841584
| ILFieldInit.Double ieee64 -> box ieee64
1585-
| ILFieldInit.Null -> (null :> objnull)
1585+
| ILFieldInit.Null -> (null: objnull)
15861586

15871587
// --------------------------------------------------------------------
15881588
// Native Types, for marshalling to the native C interface.

src/Compiler/Facilities/DiagnosticResolutionHints.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ type SuggestionBuffer(idText: string) =
119119
interface IEnumerable with
120120
member this.GetEnumerator() =
121121
if this.IsEmpty then
122-
Seq.empty.GetEnumerator() :> IEnumerator
122+
Seq.empty<objnull>.GetEnumerator() :> IEnumerator
123123
else
124124
new SuggestionBufferEnumerator(tail, data) :> IEnumerator

src/Compiler/Facilities/DiagnosticsLogger.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ type StopProcessingExiter() =
220220
interface Exiter with
221221
member exiter.Exit n =
222222
exiter.ExitCode <- n
223-
raise StopProcessing
223+
raise StopProcessing<unit>
224224

225225
/// Closed enumeration of build phases.
226226
[<RequireQualifiedAccess>]

src/Compiler/Utilities/Activity.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,15 @@ module internal Activity =
122122
let start (name: string) (tags: (string * string) seq) : IDisposable =
123123
ignore name
124124
ignore tags
125-
null
125+
{ new IDisposable with
126+
member _.Dispose() = ()
127+
}
126128

127129
let startNoTags (name: string) : IDisposable =
128130
ignore name
129-
null
131+
{ new IDisposable with
132+
member _.Dispose() = ()
133+
}
130134

131135
let addEvent (name: string) =
132136
ignore name

src/Compiler/Utilities/FileSystem.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ type FileSystem =
496496
String.IsNullOrEmpty p || p.IndexOfAny(Path.GetInvalidPathChars()) <> -1
497497
let isInvalidFilename(p: string) =
498498
String.IsNullOrEmpty p || p.IndexOfAny(Path.GetInvalidFileNameChars()) <> -1
499-
let isInvalidDirectory(d: string) =
500-
d=null || d.IndexOfAny(Path.GetInvalidPathChars()) <> -1
499+
let isInvalidDirectory(p: string) =
500+
String.IsNullOrEmpty p || p.IndexOfAny(Path.GetInvalidPathChars()) <> -1
501501
isInvalidPath path ||
502502
let directory = Path.GetDirectoryName path
503503
let filename = Path.GetFileName path

src/Compiler/Utilities/illib.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type InterruptibleLazy<'T> private (value, valueFactory: unit -> 'T) =
4242
| _ ->
4343

4444
value <- (valueFactory |> unbox<unit -> 'T>) ()
45-
valueFactory <- Unchecked.defaultof<_>
45+
valueFactory <- Unchecked.defaultof<'T>
4646
finally
4747
Monitor.Exit(syncObj)
4848

@@ -1051,7 +1051,7 @@ type LazyWithContext<'T, 'Ctxt> =
10511051
static member NotLazy(x: 'T) : LazyWithContext<'T, 'Ctxt> =
10521052
{
10531053
value = x
1054-
funcOrException = null
1054+
funcOrException = (null: objnull)
10551055
findOriginalException = id
10561056
}
10571057

@@ -1094,7 +1094,7 @@ type LazyWithContext<'T, 'Ctxt> =
10941094
try
10951095
let res = f ctxt
10961096
x.value <- res
1097-
x.funcOrException <- null
1097+
x.funcOrException <- (null: objnull)
10981098
res
10991099
with RecoverableException exn ->
11001100
x.funcOrException <- box (LazyWithContextFailure(exn))
@@ -1153,7 +1153,7 @@ module IPartialEqualityComparer =
11531153
if dict.ContainsKey key then
11541154
false
11551155
else
1156-
(dict[key] <- null
1156+
(dict[key] <- (null: objnull)
11571157
true)
11581158
else
11591159
true)

0 commit comments

Comments
 (0)