Skip to content

Commit 378bde0

Browse files
CopilotT-Gro
andcommitted
Revert changes - lazy replacement causes test failures requiring deeper investigation
Co-authored-by: T-Gro <[email protected]>
1 parent dca16ff commit 378bde0

1 file changed

Lines changed: 4 additions & 20 deletions

File tree

src/FSharp.Core/seqcore.fs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -383,35 +383,19 @@ module RuntimeHelpers =
383383

384384

385385
let EnumerateTryWith (source : seq<'T>) (exceptionFilter:exn -> int) (exceptionHandler:exn -> seq<'T>) =
386-
// Manual thread-safe one-time initialization cell to replace lazy (avoids IL2091 trimming warnings)
387-
let mutable originalSourceValue = None
388-
let originalSourceInitLock = obj()
389-
let getOriginalSource() =
390-
match originalSourceValue with
391-
| Some v -> v
392-
| None ->
393-
// Double-checked locking pattern: first check avoids lock overhead after initialization,
394-
// second check inside lock ensures only one thread initializes the value
395-
lock originalSourceInitLock (fun () ->
396-
match originalSourceValue with
397-
| Some v -> v
398-
| None ->
399-
let v = source.GetEnumerator()
400-
originalSourceValue <- Some v
401-
v)
402-
386+
let originalSource = lazy source.GetEnumerator()
403387
let mutable shouldDisposeOriginalAtTheEnd = true
404388
let mutable exceptionalSource : IEnumerator<'T> option = None
405389

406390
let current() =
407391
match exceptionalSource with
408392
| Some es -> es.Current
409-
| None -> getOriginalSource().Current
393+
| None -> originalSource.Value.Current
410394

411395
let disposeOriginal() =
412396
if shouldDisposeOriginalAtTheEnd then
413397
shouldDisposeOriginalAtTheEnd <- false
414-
getOriginalSource().Dispose()
398+
originalSource.Value.Dispose()
415399

416400
let moveExceptionHandler exn =
417401
exceptionalSource <- Some ((exceptionHandler exn).GetEnumerator())
@@ -437,7 +421,7 @@ module RuntimeHelpers =
437421
| Some es -> es.MoveNext()
438422
| None ->
439423
try
440-
let hasNext = getOriginalSource().MoveNext()
424+
let hasNext = originalSource.Value.MoveNext()
441425
if not hasNext then
442426
// What if Moving does not fail, but Disposing does?
443427
// In that case, the 'when' guards could actually produce new elements to by yielded

0 commit comments

Comments
 (0)