Skip to content

Commit adfe730

Browse files
committed
given that we need to clear and resize the ScriptClosureCache under a lock, it might be a better approach to just use the one from the BackgroundCompiler
1 parent 1570223 commit adfe730

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/Compiler/Service/BackgroundCompiler.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ type internal IBackgroundCompiler =
173173

174174
abstract member ProjectChecked: IEvent<FSharpProjectOptions>
175175

176+
abstract member ScriptClosureCache: MruCache<AnyCallerThreadToken, FSharpProjectOptions, LoadClosure>
177+
176178
type internal ParseCacheLockToken() =
177179
interface LockToken
178180

@@ -1678,3 +1680,5 @@ type internal BackgroundCompiler
16781680
userOpName: string
16791681
) : (FSharpParseFileResults * FSharpCheckFileResults * SourceTextHash) option =
16801682
self.TryGetRecentCheckResultsForFile(fileName, options, sourceText, userOpName)
1683+
1684+
member _.ScriptClosureCache = scriptClosureCache

src/Compiler/Service/BackgroundCompiler.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
namespace FSharp.Compiler.CodeAnalysis
22

3+
open FSharp.Compiler.ScriptClosure
34
open FSharp.Compiler.Text
45
open FSharp.Compiler.BuildGraph
56

67
open System.Reflection
78
open FSharp.Compiler.CodeAnalysis
89
open FSharp.Compiler.CompilerConfig
910
open FSharp.Compiler.Diagnostics
11+
open Internal.Utilities.Collections
12+
open Internal.Utilities.Library
1013

1114
type SourceTextHash = int64
1215

@@ -163,6 +166,8 @@ type internal IBackgroundCompiler =
163166

164167
abstract ProjectChecked: IEvent<FSharpProjectOptions>
165168

169+
abstract ScriptClosureCache: MruCache<AnyCallerThreadToken, FSharpProjectOptions, LoadClosure>
170+
166171
[<AutoOpen>]
167172
module internal EnvMisc =
168173

src/Compiler/Service/TransparentCompiler.fs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,6 @@ type internal TransparentCompiler
346346
let fileChecked = Event<string * FSharpProjectOptions>()
347347
let projectChecked = Event<FSharpProjectOptions>()
348348

349-
/// Information about the derived script closure.
350-
let scriptClosureCache =
351-
MruCache<AnyCallerThreadToken, FSharpProjectOptions, LoadClosure>(
352-
projectCacheSize,
353-
areSame = FSharpProjectOptions.AreSameForChecking,
354-
areSimilar = FSharpProjectOptions.UseSameProject
355-
)
356-
357349
// use this to process not-yet-implemented tasks
358350
let backgroundCompiler =
359351
BackgroundCompiler(
@@ -560,7 +552,7 @@ type internal TransparentCompiler
560552
getProjectReferences projectSnapshot "ComputeTcConfigBuilder"
561553

562554
let loadClosureOpt: LoadClosure option =
563-
scriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())
555+
backgroundCompiler.ScriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())
564556

565557
let getSwitchValue (switchString: string) =
566558
match commandLineArgs |> List.tryFindIndex (fun s -> s.StartsWithOrdinal switchString) with
@@ -1417,7 +1409,7 @@ type internal TransparentCompiler
14171409
[| yield! creationDiags; yield! extraDiagnostics; yield! tcDiagnostics |]
14181410

14191411
let loadClosure =
1420-
scriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())
1412+
backgroundCompiler.ScriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())
14211413

14221414
let typedResults =
14231415
FSharpCheckFileResults.Make(
@@ -2078,3 +2070,5 @@ type internal TransparentCompiler
20782070
userOpName: string
20792071
) : (FSharpParseFileResults * FSharpCheckFileResults * SourceTextHash) option =
20802072
backgroundCompiler.TryGetRecentCheckResultsForFile(fileName, options, sourceText, userOpName)
2073+
2074+
member _.ScriptClosureCache = backgroundCompiler.ScriptClosureCache

0 commit comments

Comments
 (0)