Skip to content

Commit

Permalink
Ditch code that was needed because of a runtime bug, that was fixed i…
Browse files Browse the repository at this point in the history
…n the meantime (#14509)
  • Loading branch information
T-Gro authored Jan 5, 2023
1 parent a9b3ea5 commit 73c9074
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 45 deletions.
44 changes: 1 addition & 43 deletions src/FSharp.Core/fslib-extra-pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ module ExtraTopLevelOperators =
makeSafeKey: 'Key -> 'SafeKey,
getKey: 'SafeKey -> 'Key
) =
#if NETSTANDARD
static let emptyEnumerator =
(Array.empty<KeyValuePair<'Key, 'T>> :> seq<_>).GetEnumerator()
#endif

member _.Count = t.Count

// Give a read-only view of the dictionary
Expand Down Expand Up @@ -169,47 +166,8 @@ module ExtraTopLevelOperators =
member _.GetEnumerator() =
// We use an array comprehension here instead of seq {} as otherwise we get incorrect
// IEnumerator.Reset() and IEnumerator.Current semantics.
// Coreclr has a bug with SZGenericEnumerators --- implement a correct enumerator. On desktop use the desktop implementation because it's ngened.
#if !NETSTANDARD
let kvps = [| for (KeyValue (k, v)) in t -> KeyValuePair(getKey k, v) |] :> seq<_>
kvps.GetEnumerator()
#else
let endIndex = t.Count

if endIndex = 0 then
emptyEnumerator
else
let kvps = [| for (KeyValue (k, v)) in t -> KeyValuePair(getKey k, v) |]
let mutable index = -1

let current () =
if index < 0 then
raise <| InvalidOperationException(SR.GetString(SR.enumerationNotStarted))

if index >= endIndex then
raise <| InvalidOperationException(SR.GetString(SR.enumerationAlreadyFinished))

kvps.[index]

{ new IEnumerator<_> with
member _.Current = current ()
interface System.Collections.IEnumerator with
member _.Current = box (current ())

member _.MoveNext() =
if index < endIndex then
index <- index + 1
index < endIndex
else
false

member _.Reset() =
index <- -1
interface System.IDisposable with
member _.Dispose() =
()
}
#endif

interface System.Collections.IEnumerable with
member _.GetEnumerator() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open System.Collections.Generic
type DictTests () =

[<Fact>]
member this.IEnumerable() =
member this.IEnumerableOnDict() =
// Legit IE
let ie = (dict [|(1,1);(2,4);(3,9)|]) :> IEnumerable
let enum = ie.GetEnumerator()
Expand Down Expand Up @@ -38,7 +38,7 @@ type DictTests () =
CheckThrowsInvalidOperationExn(fun () -> enum.Current |> ignore)

[<Fact>]
member this.IEnumerable_T() =
member this.IEnumerable_T_OnDict() =
// Legit IE
let ie = (dict [|(1,1);(2,4);(3,9)|]) :> IEnumerable<KeyValuePair<_,_>>
let enum = ie.GetEnumerator()
Expand Down

0 comments on commit 73c9074

Please sign in to comment.