Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e754739

Browse files
authoredSep 30, 2024··
Fix concurrency issue in ILPreTypeDefImpl (#17812)
* use standard lazy * rn
1 parent 1bf093f commit e754739

File tree

2 files changed

+9
-26
lines changed
  • docs/release-notes/.FSharp.Compiler.Service
  • src/Compiler/AbstractIL

2 files changed

+9
-26
lines changed
 

‎docs/release-notes/.FSharp.Compiler.Service/9.0.200.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
* Fix internal error when calling 'AddSingleton' and other overloads only differing in generic arity ([PR #17804](https://github.com/dotnet/fsharp/pull/17804))
44
* Fix extension methods support for non-reference system assemblies ([PR #17799](https://github.com/dotnet/fsharp/pull/17799))
5-
* Ensure `frameworkTcImportsCache` mutations are threadsafe. ([PR #17795](https://github.com/dotnet/fsharp/pull/17795))
5+
* Ensure `frameworkTcImportsCache` mutations are thread-safe. ([PR #17795](https://github.com/dotnet/fsharp/pull/17795))
6+
* Fix concurrency issue in `ILPreTypeDefImpl` ([PR #17812](https://github.com/dotnet/fsharp/pull/17812))
67

78

89
### Added

‎src/Compiler/AbstractIL/il.fs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,35 +2913,17 @@ and [<NoEquality; NoComparison>] ILPreTypeDef =
29132913

29142914
/// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies.
29152915
and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
2916-
let mutable store: ILTypeDef = Unchecked.defaultof<_>
2917-
let mutable storage = storage
2916+
let stored =
2917+
lazy
2918+
match storage with
2919+
| ILTypeDefStored.Given td -> td
2920+
| ILTypeDefStored.Computed f -> f ()
2921+
| ILTypeDefStored.Reader f -> f metadataIndex
29182922

29192923
interface ILPreTypeDef with
29202924
member _.Namespace = nameSpace
29212925
member _.Name = name
2922-
2923-
member x.GetTypeDef() =
2924-
match box store with
2925-
| null ->
2926-
let syncObj = storage
2927-
Monitor.Enter(syncObj)
2928-
2929-
try
2930-
match box store with
2931-
| null ->
2932-
let value =
2933-
match storage with
2934-
| ILTypeDefStored.Given td -> td
2935-
| ILTypeDefStored.Computed f -> f ()
2936-
| ILTypeDefStored.Reader f -> f metadataIndex
2937-
2938-
store <- value
2939-
storage <- Unchecked.defaultof<_>
2940-
value
2941-
| _ -> store
2942-
finally
2943-
Monitor.Exit(syncObj)
2944-
| _ -> store
2926+
member x.GetTypeDef() = stored.Value
29452927

29462928
and ILTypeDefStored =
29472929
| Given of ILTypeDef

0 commit comments

Comments
 (0)
Please sign in to comment.