-
Notifications
You must be signed in to change notification settings - Fork 846
Reuse typechecking results - stage 1 #17898
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
Merged
psfinaki
merged 1 commit into
dotnet:feature/reuse-typechecking-results
from
psfinaki:reuse-typecheck-a
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| module internal FSharp.Compiler.ReuseTcResults | ||
|
|
||
| open System.Collections.Generic | ||
| open System.IO | ||
|
|
||
| open FSharp.Compiler.CompilerConfig | ||
| open FSharp.Compiler.Diagnostics | ||
| open FSharp.Compiler.GraphChecking | ||
| open FSharp.Compiler.IO | ||
| open FSharp.Compiler.Syntax | ||
| open FSharp.Compiler.Syntax.PrettyNaming | ||
|
|
||
| type TcData = | ||
| { | ||
| CmdLine: string array | ||
| Graph: string array | ||
| References: string array | ||
| } | ||
|
|
||
| [<Sealed>] | ||
| type CachingDriver(tcConfig: TcConfig) = | ||
|
|
||
| let outputDir = tcConfig.outputDir |> Option.defaultValue "" | ||
| let tcDataFilePath = Path.Combine(outputDir, FSharpTcDataResourceName) | ||
|
|
||
| [<Literal>] | ||
| let CmdLineHeader = "CMDLINE" | ||
|
|
||
| [<Literal>] | ||
| let GraphHeader = "GRAPH" | ||
|
|
||
| [<Literal>] | ||
| let ReferencesHeader = "REFERENCES" | ||
|
|
||
| let writeThisTcData (tcData: TcData) = | ||
| use tcDataFile = FileSystem.OpenFileForWriteShim tcDataFilePath | ||
|
|
||
| let lines = ResizeArray<string>() | ||
| lines.Add $"BEGIN {CmdLineHeader}" | ||
| lines.AddRange tcData.CmdLine | ||
| lines.Add $"BEGIN {GraphHeader}" | ||
| lines.AddRange tcData.Graph | ||
| lines.Add $"BEGIN {ReferencesHeader}" | ||
| lines.AddRange tcData.References | ||
|
|
||
| tcDataFile.WriteAllLines lines | ||
|
|
||
| let readPrevTcData () = | ||
| if FileSystem.FileExistsShim tcDataFilePath then | ||
| use tcDataFile = FileSystem.OpenFileForReadShim tcDataFilePath | ||
|
|
||
| let cmdLine = ResizeArray<string>() | ||
| let graph = ResizeArray<string>() | ||
| let refs = ResizeArray<string>() | ||
|
|
||
| let mutable currentHeader = "" | ||
|
|
||
| tcDataFile.ReadLines() | ||
| |> Seq.iter (fun line -> | ||
| match line with | ||
| | line when line.StartsWith "BEGIN" -> currentHeader <- line.Split ' ' |> Array.last | ||
| | line -> | ||
| match currentHeader with | ||
| | CmdLineHeader -> cmdLine.Add line | ||
| | GraphHeader -> graph.Add line | ||
| | ReferencesHeader -> refs.Add line | ||
| | _ -> invalidOp "broken tc cache") | ||
|
|
||
| Some | ||
| { | ||
| CmdLine = cmdLine.ToArray() | ||
| Graph = graph.ToArray() | ||
| References = refs.ToArray() | ||
| } | ||
|
|
||
| else | ||
| None | ||
|
|
||
| let formatAssemblyReference (r: AssemblyReference) = | ||
| let fileName = r.Text | ||
| let lastWriteTime = FileSystem.GetLastWriteTimeShim fileName | ||
| sprintf "%s,%i" fileName lastWriteTime.Ticks | ||
|
|
||
| let getThisCompilationCmdLine args = args | ||
|
|
||
| // maybe split into two things? | ||
| let getThisCompilationGraph inputs = | ||
| let sourceFiles = | ||
| inputs | ||
| |> Seq.toArray | ||
| |> Array.mapi (fun idx (input: ParsedInput) -> | ||
| { | ||
| Idx = idx | ||
| FileName = input.FileName | ||
| ParsedInput = input | ||
| }) | ||
|
|
||
| let filePairs = FilePairMap sourceFiles | ||
| let graph, _ = DependencyResolution.mkGraph filePairs sourceFiles | ||
|
|
||
| let list = List<string>() | ||
|
|
||
| for KeyValue(idx, _) in graph do | ||
| let fileName = sourceFiles[idx].FileName | ||
| let lastWriteTime = FileSystem.GetLastWriteTimeShim fileName | ||
| list.Add(sprintf "%i,%s,%i" idx fileName lastWriteTime.Ticks) | ||
|
|
||
| for KeyValue(idx, deps) in graph do | ||
| for depIdx in deps do | ||
| list.Add $"%i{idx} --> %i{depIdx}" | ||
|
|
||
| list.ToArray() | ||
|
|
||
| let getThisCompilationReferences = Seq.map formatAssemblyReference >> Seq.toArray | ||
|
|
||
| member _.TryReuseTcResults inputs = | ||
| let prevTcDataOpt = readPrevTcData () | ||
|
|
||
| let thisTcData = | ||
| { | ||
| CmdLine = getThisCompilationCmdLine tcConfig.cmdLineArgs | ||
| Graph = getThisCompilationGraph inputs | ||
| References = getThisCompilationReferences tcConfig.referencedDLLs | ||
| } | ||
|
|
||
| match prevTcDataOpt with | ||
| | Some prevTcData -> | ||
| use _ = Activity.start Activity.Events.reuseTcResultsCachePresent [] | ||
|
|
||
| if prevTcData = thisTcData then | ||
| use _ = Activity.start Activity.Events.reuseTcResultsCacheHit [] | ||
|
|
||
| () // do nothing, yet | ||
| else | ||
| use _ = Activity.start Activity.Events.reuseTcResultsCacheMissed [] | ||
|
|
||
| writeThisTcData thisTcData | ||
|
|
||
| | None -> | ||
| use _ = Activity.start Activity.Events.reuseTcResultsCacheAbsent [] | ||
|
|
||
| writeThisTcData thisTcData |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module internal FSharp.Compiler.ReuseTcResults | ||
|
|
||
| open FSharp.Compiler.CompilerConfig | ||
| open FSharp.Compiler.Syntax | ||
|
|
||
| [<Sealed>] | ||
| type CachingDriver = | ||
|
|
||
| new: tcConfig: TcConfig -> CachingDriver | ||
|
|
||
| member TryReuseTcResults: inputs: ParsedInput seq -> unit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.