From 0a8fd182f47b3eb6af7740aaa04ab67ef918eaf2 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:23:18 +0200 Subject: [PATCH 1/2] use standard lazy --- src/Compiler/AbstractIL/il.fs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/Compiler/AbstractIL/il.fs b/src/Compiler/AbstractIL/il.fs index b10a119fced..e7b6c3b7709 100644 --- a/src/Compiler/AbstractIL/il.fs +++ b/src/Compiler/AbstractIL/il.fs @@ -2913,35 +2913,17 @@ and [] ILPreTypeDef = /// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies. and [] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) = - let mutable store: ILTypeDef = Unchecked.defaultof<_> - let mutable storage = storage + let stored = + lazy + match storage with + | ILTypeDefStored.Given td -> td + | ILTypeDefStored.Computed f -> f () + | ILTypeDefStored.Reader f -> f metadataIndex interface ILPreTypeDef with member _.Namespace = nameSpace member _.Name = name - - member x.GetTypeDef() = - match box store with - | null -> - 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 + member x.GetTypeDef() = stored.Value and ILTypeDefStored = | Given of ILTypeDef From e51d9df33a64fe1d7018c9fbc6a3c94c530ac7d3 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:23:47 +0200 Subject: [PATCH 2/2] rn --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 24b85706238..ba81d52ccee 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -1,6 +1,7 @@ ### Fixed * Fix extension methods support for non-reference system assemblies ([PR #17799](https://github.com/dotnet/fsharp/pull/17799)) -* Ensure `frameworkTcImportsCache` mutations are threadsafe. ([PR #17795](https://github.com/dotnet/fsharp/pull/17795)) +* Ensure `frameworkTcImportsCache` mutations are thread-safe. ([PR #17795](https://github.com/dotnet/fsharp/pull/17795)) +* Fix concurrency issue in `ILPreTypeDefImpl` ([PR #17812](https://github.com/dotnet/fsharp/pull/17812)) ### Added