From d3fa2e6730956dd6a58f883345db25d4ec9014bc Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:23:51 +0200 Subject: [PATCH 1/3] ensure all frameworkTcImportsCache mutations are threadsafe --- src/Compiler/Service/IncrementalBuild.fs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index b7560b222c2..0fe74f453ba 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -507,10 +507,12 @@ type FrameworkImportsCache(size) = let frameworkTcImportsCache = AgedLookup>(size, areSimilar=(fun (x, y) -> x = y)) /// Reduce the size of the cache in low-memory scenarios - member _.Downsize() = frameworkTcImportsCache.Resize(AnyCallerThread, newKeepStrongly=0) + member _.Downsize() = lock gate <| fun () -> + frameworkTcImportsCache.Resize(AnyCallerThread, newKeepStrongly=0) /// Clear the cache - member _.Clear() = frameworkTcImportsCache.Clear AnyCallerThread + member _.Clear() = lock gate <| fun () -> + frameworkTcImportsCache.Clear AnyCallerThread /// This function strips the "System" assemblies from the tcConfig and returns a age-cached TcImports for them. member _.GetNode(tcConfig: TcConfig, frameworkDLLs: AssemblyResolution list, nonFrameworkResolutions: AssemblyResolution list) = @@ -541,7 +543,7 @@ type FrameworkImportsCache(size) = let tcConfigP = TcConfigProvider.Constant tcConfig return! TcImports.BuildFrameworkTcImports (tcConfigP, frameworkDLLs, nonFrameworkResolutions) }) - frameworkTcImportsCache.Put(AnyCallerThread, key, lazyWork) + lock gate <| fun () -> frameworkTcImportsCache.Put(AnyCallerThread, key, lazyWork) lazyWork ) node From 07917390ac0b24e034c44268fe7bf89bdc95f25a Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:03:04 +0200 Subject: [PATCH 2/3] rn --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 + 1 file changed, 1 insertion(+) 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 5ef93105656..d681f5aa1b7 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -1,5 +1,6 @@ ### Fixed +* Ensure `frameworkTcImportsCache` mutations are threadsafe. ([PR #17795](https://github.com/dotnet/fsharp/pull/17795)) ### Added From 6ef2adb302794e7388e5df26017273f47277a254 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:37:47 +0200 Subject: [PATCH 3/3] not needed --- src/Compiler/Service/IncrementalBuild.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index 0fe74f453ba..6b7f3c4d24d 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -543,7 +543,7 @@ type FrameworkImportsCache(size) = let tcConfigP = TcConfigProvider.Constant tcConfig return! TcImports.BuildFrameworkTcImports (tcConfigP, frameworkDLLs, nonFrameworkResolutions) }) - lock gate <| fun () -> frameworkTcImportsCache.Put(AnyCallerThread, key, lazyWork) + frameworkTcImportsCache.Put(AnyCallerThread, key, lazyWork) lazyWork ) node