Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TransparentCompiler cache for GetProjectOptionsFromScript #16889

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Compiler/Facilities/AsyncMemoize.fs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ type internal AsyncMemoize<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'T

member this.OnEvent = this.Event.Add

member this.Count = cache.Count

member _.Locked = lock.Semaphore.CurrentCount < 1

member _.Running =
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Facilities/AsyncMemoize.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type internal AsyncMemoize<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'T

member OnEvent: ((JobEvent * (string * 'TKey * 'TVersion) -> unit) -> unit)

member Count: int

/// A drop-in replacement for AsyncMemoize that disables caching and just runs the computation every time.
type internal AsyncMemoizeDisabled<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'TVersion: equality> =

Expand Down
34 changes: 21 additions & 13 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,19 +2151,27 @@ type internal TransparentCompiler
optionsStamp: int64 option,
userOpName: string
) : Async<FSharpProjectOptions * FSharpDiagnostic list> =
backgroundCompiler.GetProjectOptionsFromScript(
fileName,
sourceText,
previewEnabled,
loadedTimeStamp,
otherFlags,
useFsiAuxLib,
useSdkRefs,
sdkDirOverride,
assumeDotNetFramework,
optionsStamp,
userOpName
)
async {
let bc = this :> IBackgroundCompiler

let! snapshot, diagnostics =
bc.GetProjectSnapshotFromScript(
fileName,
SourceTextNew.ofISourceText sourceText,
previewEnabled,
loadedTimeStamp,
otherFlags,
useFsiAuxLib,
useSdkRefs,
sdkDirOverride,
assumeDotNetFramework,
optionsStamp,
userOpName
)

let projectOptions = snapshot.ToOptions()
return projectOptions, diagnostics
}

member this.GetProjectSnapshotFromScript
(
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Utilities/LruCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,5 @@ type internal LruCache<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'TVers
match w.TryGetTarget() with
| true, value -> Some(label, version, value)
| _ -> None)

member this.Count = Seq.length (this.GetValues())
3 changes: 3 additions & 0 deletions src/Compiler/Utilities/LruCache.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type internal LruCache<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'TVers

member GetValues: unit -> (string * 'TVersion * 'TValue) seq

/// Gets the number of items in the cache
member Count: int

member Remove: key: 'TKey -> unit

member Remove: key: 'TKey * version: 'TVersion -> unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,13 @@ printfn "Hello from F#"
ProjectWorkflowBuilder(project, useTransparentCompiler = useTransparentCompiler) {
checkFile "As 01" expectTwoWarnings
}

[<Fact>]
let ``Transparent Compiler ScriptClosure cache is populated after GetProjectOptionsFromScript`` () =
async {
let transparentChecker = FSharpChecker.Create(useTransparentCompiler = true)
let scriptName = Path.Combine(__SOURCE_DIRECTORY__, "script.fsx")
let content = SourceTextNew.ofString ""
let! _ = transparentChecker.GetProjectOptionsFromScript(scriptName, content)
Assert.Equal(1, transparentChecker.Caches.ScriptClosure.Count)
}
Loading