Skip to content

Commit

Permalink
IL: don't keep ILPreTypeDefImpl storage after it was evaluated (#16151)
Browse files Browse the repository at this point in the history
* IL: don't keep ILPreTypeDefImpl storage after it was evaluated

* Fantomas
  • Loading branch information
auduchinok authored Oct 23, 2023
1 parent bd66d54 commit 7382e6f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,7 @@ and [<NoEquality; NoComparison>] ILPreTypeDef =
/// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies.
and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
let mutable store: ILTypeDef = Unchecked.defaultof<_>
let mutable storage = storage

interface ILPreTypeDef with
member _.Namespace = nameSpace
Expand All @@ -2884,12 +2885,24 @@ and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIn
member x.GetTypeDef() =
match box store with
| null ->
match storage with
| ILTypeDefStored.Given td ->
store <- td
td
| ILTypeDefStored.Computed f -> LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f ()))
| ILTypeDefStored.Reader f -> LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f metadataIndex))
let syncObj = storage
Monitor.Enter(syncObj)

try
match box store with
| null ->
let value =
match storage with
| ILTypeDefStored.Given td -> td
| ILTypeDefStored.Computed f -> f ()
| ILTypeDefStored.Reader f -> f metadataIndex

store <- value
storage <- Unchecked.defaultof<_>
value
| _ -> store
finally
Monitor.Exit(syncObj)
| _ -> store

and ILTypeDefStored =
Expand Down

0 comments on commit 7382e6f

Please sign in to comment.