-
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
34 changed files
with
437 additions
and
0 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
124 changes: 124 additions & 0 deletions
124
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,124 @@ | ||
module internal FSharp.Compiler.ReuseTcResults | ||
|
||
open System | ||
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 | ||
|
||
open Internal.Utilities.Hashing | ||
|
||
let (++) a b = Path.Combine(a, b) | ||
|
||
[<Sealed>] | ||
type ReuseTcResultsDriver(tcConfig: TcConfig) = | ||
|
||
let outputDir = tcConfig.outputDir |> Option.defaultValue "" | ||
let tcDataFolderName = outputDir ++ FSharpTcDataResourceName | ||
|
||
let cmdLineFilePath = tcDataFolderName ++ "cmdline" | ||
let graphFilePath = tcDataFolderName ++ "graph" | ||
let referencesFilePath = tcDataFolderName ++ "references" | ||
|
||
let writeThisTcData path content = | ||
use tcDataFile = FileSystem.OpenFileForWriteShim path | ||
tcDataFile.WriteAllLines content | ||
|
||
let readPrevTcData path = | ||
if FileSystem.FileExistsShim path then | ||
use tcDataFile = FileSystem.OpenFileForReadShim path | ||
tcDataFile.ReadAllLines() | ||
else | ||
Array.empty | ||
|
||
let getPrevCompilationCmdLine () = readPrevTcData cmdLineFilePath | ||
let getPrevCompilationGraph () = readPrevTcData graphFilePath | ||
let getPrevCompilationReferences () = readPrevTcData referencesFilePath | ||
|
||
let writeThisCompilationCmdLine = writeThisTcData cmdLineFilePath | ||
let writeThisCompilationGraph = writeThisTcData graphFilePath | ||
let writeThisCompilationReferences = writeThisTcData referencesFilePath | ||
|
||
let getContentHash fileName = | ||
use stream = FileSystem.OpenFileForReadShim fileName | ||
stream.ReadAllBytes() |> Md5Hasher.computeHash |> BitConverter.ToString | ||
|
||
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 hash = getContentHash sourceFiles[idx].FileName | ||
list.Add($"%i{idx}[\"{hash}\"]") | ||
|
||
for KeyValue(idx, deps) in graph do | ||
for depIdx in deps do | ||
list.Add($"%i{idx} --> %i{depIdx}") | ||
|
||
list.ToArray() | ||
|
||
let getThisCompilationReferences = | ||
List.map (fun (r: AssemblyReference) -> r.Text, getContentHash r.Text) | ||
>> List.map (fun (name, hash) -> $"{name}: {hash}") | ||
>> List.toArray | ||
|
||
member _.TryReuseTcResults inputs = | ||
if FileSystem.DirectoryExistsShim tcDataFolderName then | ||
use _ = Activity.start Activity.Events.reuseTcResultsCachePresent [] | ||
|
||
let prevCompilationCmdLine = getPrevCompilationCmdLine () | ||
let thisCompilationCmdLine = getThisCompilationCmdLine tcConfig.cmdLineArgs | ||
|
||
if prevCompilationCmdLine = thisCompilationCmdLine then | ||
|
||
let prevCompilationReferences = getPrevCompilationReferences () | ||
let thisCompilationReferences = getThisCompilationReferences tcConfig.referencedDLLs | ||
|
||
if prevCompilationReferences = thisCompilationReferences then | ||
|
||
let prevCompilationGraph = getPrevCompilationGraph () | ||
let thisCompilationGraph = getThisCompilationGraph inputs | ||
|
||
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 tcConfig.cmdLineArgs) | ||
writeThisCompilationGraph (getThisCompilationGraph inputs) | ||
writeThisCompilationReferences (getThisCompilationReferences tcConfig.referencedDLLs) |
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
module internal FSharp.Compiler.ReuseTcResults | ||
|
||
open FSharp.Compiler.CompilerConfig | ||
open FSharp.Compiler.Syntax | ||
|
||
[<Sealed>] | ||
type ReuseTcResultsDriver = | ||
|
||
new: tcConfig: TcConfig -> ReuseTcResultsDriver | ||
|
||
member TryReuseTcResults: 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
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.