-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse typechecking results - stage 1
- Loading branch information
Showing
36 changed files
with
504 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,141 @@ | ||
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 _.CanReuseTcResults 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 [] | ||
true | ||
else | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheMissed [] | ||
writeThisTcData thisTcData | ||
false | ||
|
||
| None -> | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheAbsent [] | ||
writeThisTcData thisTcData | ||
false |
This file contains 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 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 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 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 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 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 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.
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.