Skip to content
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Preserve constraint inference order when explicit generic arguments share a caller type parameter, avoiding spurious FS0001 errors with multiply implemented generic interfaces. ([PR #20491](https://github.com/dotnet/fsharp/pull/20491))
* Build parser diagnostic messages without runtime printf specialization or reflective function construction, so Native AOT hosts report indentation and invalid-character diagnostics instead of failing during formatting. Preserve `#r` reference tooltips while script project options remain alive, including after garbage collection or cache eviction. ([PR #20658](https://github.com/dotnet/fsharp/pull/20658))
* Preserve tupled lambda argument groups when reducing state-machine applications, avoiding invalid argument substitutions and runtime failures with inline formatters. ([Issue #20675](https://github.com/dotnet/fsharp/issues/20675), [PR #20700](https://github.com/dotnet/fsharp/pull/20700))
* Transparent compiler: `ParseFile` no longer imports the references of the project, which also type checked the projects it references. Parsing only needs the compiler options of the project. ([PR #20704](https://github.com/dotnet/fsharp/pull/20704))
* Preserve SRTP extension scopes across source files and competing witnesses through imported inline calls. Compile generic extension forwarding, including quotations, in unoptimized builds. Preserve applicable built-in operator priority in imported inline quotations. Do not reuse SRTP specializations across different selected witnesses. ([Issue #20683](https://github.com/dotnet/fsharp/issues/20683), [Issue #20684](https://github.com/dotnet/fsharp/issues/20684), [Issue #20685](https://github.com/dotnet/fsharp/issues/20685), [PR #20717](https://github.com/dotnet/fsharp/pull/20717))

### Changed
Expand Down
44 changes: 40 additions & 4 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ type internal CompilerCaches(cacheSizes: CacheSizes) =

member val BootstrapInfo = AsyncMemoize(cs.BootstrapInfoKeepStrongly, cs.BootstrapInfoKeepWeakly, name = "BootstrapInfo")

member val ParsingTcConfig = AsyncMemoize(cs.BootstrapInfoKeepStrongly, cs.BootstrapInfoKeepWeakly, name = "ParsingTcConfig")

member val TcLastFile = AsyncMemoizeDisabled(cs.TcLastFileKeepStrongly, cs.TcLastFileKeepWeakly, name = "TcLastFile")

member val TcIntermediate = AsyncMemoize(cs.TcIntermediateKeepStrongly, cs.TcIntermediateKeepWeakly, name = "TcIntermediate")
Expand All @@ -401,6 +403,7 @@ type internal CompilerCaches(cacheSizes: CacheSizes) =
this.ParseAndCheckProject.Clear(shouldClear)
this.BootstrapInfoStatic.Clear(shouldClear)
this.BootstrapInfo.Clear(shouldClear)
this.ParsingTcConfig.Clear(shouldClear)
this.TcIntermediate.Clear(snd >> shouldClear)
this.AssemblyData.Clear(shouldClear)
this.SemanticClassification.Clear(snd >> shouldClear)
Expand Down Expand Up @@ -1173,6 +1176,41 @@ type internal TransparentCompiler
}
)

/// The TcConfig of a project, without importing its references. That is all that parsing a file needs,
/// while the bootstrap info also imports the referenced assemblies and type checks the referenced projects.
let ComputeParsingTcConfig (projectSnapshot: ProjectSnapshot) =
caches.ParsingTcConfig.Get(
projectSnapshot.NoFileVersionsKey,
async {
use _ =
Activity.start
"ComputeParsingTcConfig"
[|
Activity.Tags.project, projectSnapshot.ProjectFileName |> Path.GetFileName |> (!!)
|]

let delayedLogger = CapturingDiagnosticsLogger("ParsingTcConfig")
use _ = new CompilationGlobalsScope(delayedLogger, BuildPhase.Parameter)

let! tcConfigOpt =
async {
try
let! tcConfigB, _, _ = ComputeTcConfigBuilder projectSnapshot
return Some(TcConfig.Create(tcConfigB, validate = false))
with exn ->
errorRecoveryNoRange exn
return None
}

let diagnostics =
delayedLogger.Diagnostics
|> List.map (fun diagnostic -> FSharpDiagnostic.CreateFromException(diagnostic, suggestNamesForErrors, false, None))
|> Array.ofList

return tcConfigOpt, diagnostics
}
)

// TODO: Not sure if we should cache this. For VS probably not. Maybe it can be configurable by FCS user.
let LoadSource (file: FSharpFileSnapshot) isExe isLastCompiland =
async {
Expand Down Expand Up @@ -2121,11 +2159,9 @@ type internal TransparentCompiler
// TODO: might need to deal with exceptions here:
use _ = new CompilationGlobalsScope(DiscardErrorsLogger, BuildPhase.Parse)

match! ComputeBootstrapInfo projectSnapshot with
match! ComputeParsingTcConfig projectSnapshot with
| None, creationDiags -> return emptyParseResult fileName creationDiags
| Some bootstrapInfo, _ ->
let tcConfig = bootstrapInfo.TcConfig

| Some tcConfig, _ ->
let fileSnapshot =
projectSnapshot.SourceFiles |> List.find (fun f -> f.FileName = fileName)

Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Service/TransparentCompiler.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ type internal CompilerCaches =

member BootstrapInfo: AsyncMemoize<FSharpProjectIdentifier, string, BootstrapInfo option * FSharpDiagnostic array>

member ParsingTcConfig: AsyncMemoize<FSharpProjectIdentifier, string, TcConfig option * FSharpDiagnostic array>

member BootstrapInfoStatic:
AsyncMemoize<FSharpProjectIdentifier, string * string, int * TcImports * TcGlobals * TcInfo * Event<unit>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,30 @@ let ``What happens if bootstrapInfoStatic needs to be recomputed`` _ =
}


[<Fact>]
let ``Parsing a file does not type check the referenced projects`` () =
let library = SyntheticProject.Create("library", sourceFile "Library" [])

let project =
{ SyntheticProject.Create(sourceFile "First" []) with DependsOn = [library] }
|> updateFile "First" (addDependency "Library")

// A private checker because we subscribe to FileChecked.
let checker = FSharpChecker.Create(useTransparentCompiler = true)
let checkedFiles = ConcurrentQueue<string>()
checker.FileChecked.Add(fun (fileName, _) -> checkedFiles.Enqueue fileName)

async {
do! saveProject project false checker
let options = project.GetProjectOptions checker
let! snapshot = FSharpProjectSnapshot.FromOptions(options, DocumentSource.FileSystem)
let! parseResults = checker.ParseFile(getFilePath project (project.Find "First"), snapshot)
Assert.False parseResults.ParseHadErrors
}
|> Async.RunSynchronously

Assert.Empty checkedFiles

module ParsedInputHashing =

let source = """
Expand Down
Loading