-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
198 additions
and
124 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
113 changes: 113 additions & 0 deletions
113
src/Compiler/Driver/ReuseTcResults/ReuseTcResultsDriver.fs
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,113 @@ | ||
module internal FSharp.Compiler.ReuseTcResults.ReuseTcResultsDriver | ||
|
||
open System | ||
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 | ||
|
||
open Internal.Utilities.Hashing | ||
|
||
let TryReuseTypecheckingResults (tcConfig: TcConfig) inputs = | ||
let (++) a b = Path.Combine(a, b) | ||
|
||
let outputDir = tcConfig.outputDir |> Option.defaultValue "" | ||
let tcDataFolderName = outputDir ++ FSharpTypecheckingDataResourceName | ||
let cmdFileName = "cmd" | ||
let graphFileName = "graph" | ||
let referencesFileName = "references" | ||
|
||
let getContentHash fileName = | ||
use stream = FileSystem.OpenFileForReadShim fileName | ||
let bytes = stream.ReadAllBytes() | ||
let contentHash = Md5Hasher.computeHash bytes | ||
contentHash |> BitConverter.ToString | ||
|
||
let getThisCompilationCmdLine () = | ||
tcConfig.cmdLineArgs |> String.concat Environment.NewLine | ||
|
||
let getThisCompilationGraph () = | ||
let sourceFiles = | ||
inputs | ||
|> Seq.toArray | ||
|> Array.mapi (fun idx (input: ParsedInput) -> | ||
{ | ||
Idx = idx | ||
FileName = input.FileName | ||
ParsedInput = input | ||
}) | ||
|
||
let filePairs = FilePairMap sourceFiles | ||
|
||
DependencyResolution.mkGraph filePairs sourceFiles | ||
|> fst | ||
|> Graph.map (fun idx -> idx, getContentHash sourceFiles[idx].FileName) | ||
|> Graph.asString | ||
|
||
let getThisCompilationReferences () = | ||
tcConfig.referencedDLLs | ||
|> List.map (fun r -> r.Text, getContentHash r.Text) | ||
|> List.map (fun (name, hash) -> $"{name}: {hash}") | ||
|> String.concat Environment.NewLine | ||
|
||
let writeThisTcData (content: string) (tcDataFileName: string) = | ||
let path = tcDataFolderName ++ tcDataFileName | ||
use tcDataFile = FileSystem.OpenFileForWriteShim path | ||
tcDataFile.WriteAllText content | ||
|
||
let readPrevTcData (tcDataFileName: string) = | ||
let path = tcDataFolderName ++ tcDataFileName | ||
if FileSystem.FileExistsShim path then | ||
use tcDataFile = FileSystem.OpenFileForReadShim path | ||
tcDataFile.ReadAllText() | ||
else | ||
"" | ||
|
||
let getPrevCompilationCmdLine() = readPrevTcData cmdFileName | ||
let getPrevCompilationGraph() = readPrevTcData graphFileName | ||
let getPrevCompilationReferences() = readPrevTcData referencesFileName | ||
|
||
let writeThisCompilationCmdLine cmdLine = writeThisTcData cmdLine cmdFileName | ||
let writeThisCompilationGraph graph = writeThisTcData graph graphFileName | ||
let writeThisCompilationReferences references = writeThisTcData references referencesFileName | ||
|
||
if FileSystem.DirectoryExistsShim tcDataFolderName then | ||
use _ = Activity.start Activity.Events.reuseTcResultsCachePresent [] | ||
|
||
let prevCompilationCmdLine = getPrevCompilationCmdLine () | ||
let thisCompilationCmdLine = getThisCompilationCmdLine () | ||
if prevCompilationCmdLine = thisCompilationCmdLine then | ||
|
||
let prevCompilationReferences = getPrevCompilationReferences () | ||
let thisCompilationReferences = getThisCompilationReferences () | ||
if prevCompilationReferences = thisCompilationReferences then | ||
|
||
let prevCompilationGraph = getPrevCompilationGraph () | ||
let thisCompilationGraph = getThisCompilationGraph () | ||
if prevCompilationGraph = thisCompilationGraph then | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheHit [] | ||
|
||
() // do nothing, yet | ||
else | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheMissed [] | ||
|
||
writeThisCompilationGraph thisCompilationGraph | ||
else | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheMissed [] | ||
|
||
writeThisCompilationReferences thisCompilationReferences | ||
else | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheMissed [] | ||
|
||
writeThisCompilationCmdLine thisCompilationCmdLine | ||
else | ||
use _ = Activity.start Activity.Events.reuseTcResultsCacheAbsent [] | ||
|
||
let _ = FileSystem.DirectoryCreateShim tcDataFolderName | ||
writeThisCompilationCmdLine (getThisCompilationCmdLine()) | ||
writeThisCompilationGraph (getThisCompilationGraph()) | ||
writeThisCompilationReferences (getThisCompilationReferences()) |
10 changes: 10 additions & 0 deletions
10
src/Compiler/Driver/ReuseTcResults/ReuseTcResultsDriver.fsi
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,10 @@ | ||
module internal FSharp.Compiler.ReuseTcResults.ReuseTcResultsDriver | ||
|
||
open FSharp.Compiler.CompilerConfig | ||
open FSharp.Compiler.Syntax | ||
|
||
|
||
val TryReuseTypecheckingResults: | ||
tcConfig: TcConfig -> | ||
inputs: ParsedInput seq -> | ||
unit |
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
Oops, something went wrong.