Skip to content

Commit f98bc5e

Browse files
committed
IL: don't keep ILPreTypeDefImpl storage after it was evaluated
1 parent 12c2a40 commit f98bc5e

File tree

1 file changed

+17
-6
lines changed
  • src/Compiler/AbstractIL

1 file changed

+17
-6
lines changed

src/Compiler/AbstractIL/il.fs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,6 +2876,7 @@ and [<NoEquality; NoComparison>] ILPreTypeDef =
28762876
/// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies.
28772877
and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
28782878
let mutable store: ILTypeDef = Unchecked.defaultof<_>
2879+
let mutable storage = storage
28792880

28802881
interface ILPreTypeDef with
28812882
member _.Namespace = nameSpace
@@ -2884,12 +2885,22 @@ and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIn
28842885
member x.GetTypeDef() =
28852886
match box store with
28862887
| null ->
2887-
match storage with
2888-
| ILTypeDefStored.Given td ->
2889-
store <- td
2890-
td
2891-
| ILTypeDefStored.Computed f -> LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f ()))
2892-
| ILTypeDefStored.Reader f -> LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f metadataIndex))
2888+
let syncObj = storage
2889+
Monitor.Enter(syncObj)
2890+
try
2891+
match box store with
2892+
| null ->
2893+
let value =
2894+
match storage with
2895+
| ILTypeDefStored.Given td -> td
2896+
| ILTypeDefStored.Computed f -> f ()
2897+
| ILTypeDefStored.Reader f -> f metadataIndex
2898+
store <- value
2899+
storage <- Unchecked.defaultof<_>
2900+
value
2901+
| _ -> store
2902+
finally
2903+
Monitor.Exit(syncObj)
28932904
| _ -> store
28942905

28952906
and ILTypeDefStored =

0 commit comments

Comments
 (0)