Skip to content

Commit

Permalink
use hash instead?
Browse files Browse the repository at this point in the history
  • Loading branch information
psfinaki committed Nov 1, 2024
1 parent 17ed53d commit fd7c2e6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Compiler/Driver/GraphChecking/Graph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ module internal Graph =

graph |> serialiseToMermaid |> out.WriteAllText

let asString (graph: Graph<FileIndex * DateTime>) =
let asString (graph: Graph<FileIndex * string>) =
let sb = StringBuilder()
let appendLine (line: string) = sb.AppendLine(line) |> ignore

for KeyValue((idx, dateTime), _) in graph do
appendLine $" %i{idx}[\"%A{dateTime}\"]"
for KeyValue((idx, hash), _) in graph do
appendLine $" %i{idx}[\"{hash}\"]"

for KeyValue((idx, _), deps) in graph do
for depIdx, _ in deps do
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/GraphChecking/Graph.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ module internal Graph =
/// Create a simple Mermaid graph and save it under the path specified.
val writeMermaidToFile: path: string -> graph: Graph<FileIndex * string> -> unit
/// Serialize the graph to a string
val asString: graph: Graph<FileIndex * DateTime> -> string
val asString: graph: Graph<FileIndex * string> -> string
11 changes: 8 additions & 3 deletions src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open System.Collections.Generic

open FSharp.Compiler.Parser
open Internal.Utilities.Collections
open Internal.Utilities.Hashing
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open Internal.Utilities.Text.Lexing
Expand Down Expand Up @@ -1967,6 +1968,12 @@ let TryReuseTypecheckingResults (tcConfig: TcConfig) inputs =
let tcDataFileName =
FileSystem.GetFullFilePathInDirectoryShim outputDir FSharpTypecheckingDataResourceName

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 " "

Expand All @@ -1985,9 +1992,7 @@ let TryReuseTypecheckingResults (tcConfig: TcConfig) inputs =

DependencyResolution.mkGraph filePairs sourceFiles
|> fst
|> Graph.map (fun idx ->
let lastModified = FileSystem.GetLastWriteTimeShim(sourceFiles[idx].FileName)
idx, lastModified)
|> Graph.map (fun idx -> idx, getContentHash sourceFiles[idx].FileName)
|> Graph.asString

let writeThisTcData (cmdLine: string) (graph: string) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ type Activities() =

let tempDir = DirectoryInfo (createTemporaryDirectory "temp")
let tempName = getTemporaryFileName()
let cUnit =
Fsx "42"
|> withOutputDirectory (Some tempDir)
|> withName tempName

let actualActivities = List<string>()

Expand All @@ -38,12 +34,22 @@ type Activities() =
Activity.Events.reuseTcResultsCacheMissed
]

let cUnit =
Fsx "42"
|> withOutputDirectory (Some tempDir)
|> withName tempName

cUnit
|> withReuseTypecheckingResults
|> compile
|> shouldSucceed
|> ignore

let cUnit =
Fsx "43"
|> withOutputDirectory (Some tempDir)
|> withName tempName

cUnit
|> withReuseTypecheckingResults
|> compile
Expand All @@ -60,6 +66,11 @@ type Activities() =
Activity.Events.reuseTcResultsCacheMissed
]

let cUnit =
Fsx "42"
|> withOutputDirectory (Some tempDir)
|> withName tempName

cUnit
|> withReuseTypecheckingResults
|> compile
Expand All @@ -69,7 +80,7 @@ type Activities() =
cUnit
|> withReuseTypecheckingResults
|> withNoOptimizationData // random option
|> recompile
|> compile
|> shouldSucceed
|> ignore

Expand All @@ -83,6 +94,11 @@ type Activities() =
Activity.Events.reuseTcResultsCacheHit
]

let cUnit =
Fsx "42"
|> withOutputDirectory (Some tempDir)
|> withName tempName

cUnit
|> withReuseTypecheckingResults
|> compile
Expand All @@ -91,7 +107,7 @@ type Activities() =

cUnit
|> withReuseTypecheckingResults
|> recompile
|> compile
|> shouldSucceed
|> ignore

Expand Down

0 comments on commit fd7c2e6

Please sign in to comment.