Skip to content

Commit

Permalink
given that we need to clear and resize the ScriptClosureCache under a…
Browse files Browse the repository at this point in the history
… lock, it might be a better approach to just use the one from the BackgroundCompiler
  • Loading branch information
dawedawe committed Jan 31, 2024
1 parent 1570223 commit adfe730
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/Compiler/Service/BackgroundCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ type internal IBackgroundCompiler =

abstract member ProjectChecked: IEvent<FSharpProjectOptions>

abstract member ScriptClosureCache: MruCache<AnyCallerThreadToken, FSharpProjectOptions, LoadClosure>

type internal ParseCacheLockToken() =
interface LockToken

Expand Down Expand Up @@ -1678,3 +1680,5 @@ type internal BackgroundCompiler
userOpName: string
) : (FSharpParseFileResults * FSharpCheckFileResults * SourceTextHash) option =
self.TryGetRecentCheckResultsForFile(fileName, options, sourceText, userOpName)

member _.ScriptClosureCache = scriptClosureCache
5 changes: 5 additions & 0 deletions src/Compiler/Service/BackgroundCompiler.fsi
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace FSharp.Compiler.CodeAnalysis

open FSharp.Compiler.ScriptClosure
open FSharp.Compiler.Text
open FSharp.Compiler.BuildGraph

open System.Reflection
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.CompilerConfig
open FSharp.Compiler.Diagnostics
open Internal.Utilities.Collections
open Internal.Utilities.Library

type SourceTextHash = int64

Expand Down Expand Up @@ -163,6 +166,8 @@ type internal IBackgroundCompiler =

abstract ProjectChecked: IEvent<FSharpProjectOptions>

abstract ScriptClosureCache: MruCache<AnyCallerThreadToken, FSharpProjectOptions, LoadClosure>

[<AutoOpen>]
module internal EnvMisc =

Expand Down
14 changes: 4 additions & 10 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,6 @@ type internal TransparentCompiler
let fileChecked = Event<string * FSharpProjectOptions>()
let projectChecked = Event<FSharpProjectOptions>()

/// Information about the derived script closure.
let scriptClosureCache =
MruCache<AnyCallerThreadToken, FSharpProjectOptions, LoadClosure>(
projectCacheSize,
areSame = FSharpProjectOptions.AreSameForChecking,
areSimilar = FSharpProjectOptions.UseSameProject
)

// use this to process not-yet-implemented tasks
let backgroundCompiler =
BackgroundCompiler(
Expand Down Expand Up @@ -560,7 +552,7 @@ type internal TransparentCompiler
getProjectReferences projectSnapshot "ComputeTcConfigBuilder"

let loadClosureOpt: LoadClosure option =
scriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())
backgroundCompiler.ScriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())

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

let loadClosure =
scriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())
backgroundCompiler.ScriptClosureCache.TryGet(AnyCallerThread, projectSnapshot.ToOptions())

let typedResults =
FSharpCheckFileResults.Make(
Expand Down Expand Up @@ -2078,3 +2070,5 @@ type internal TransparentCompiler
userOpName: string
) : (FSharpParseFileResults * FSharpCheckFileResults * SourceTextHash) option =
backgroundCompiler.TryGetRecentCheckResultsForFile(fileName, options, sourceText, userOpName)

member _.ScriptClosureCache = backgroundCompiler.ScriptClosureCache

0 comments on commit adfe730

Please sign in to comment.