Skip to content

Commit 716db8e

Browse files
committed
Start cleanup for sharing the branch
1 parent 6df43e9 commit 716db8e

5 files changed

Lines changed: 29 additions & 20 deletions

File tree

tests/ParallelTypeCheckingTests/Code/DependencyResolution.fs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,16 @@ module internal DependencyResolution =
232232
// Force .fsi files to depend on all other (previous) .fsi files - avoids the issue of TcEnv being overriden
233233
let additionalFsiDeps =
234234
if node.File.Name.EndsWith ".fsi" then
235-
fsiFiles
235+
nodes
236236
else
237237
[||]
238238

239239
// Collect files from all reachable TrieNodes
240240
let deps =
241241
reachable
242242
|> Seq.collect (fun node -> node.Files)
243-
// TODO Temporary - Add all nodes
244-
// |> Seq.append nodes
245-
// If not, then the below is not necessary.
246-
// Assume that this file depends on all files that have any module abbreviations
243+
// Assume that this file depends on all files that have any module abbreviations - this is probably unnecessary.
247244
// TODO Handle module abbreviations in a better way
248-
// For starters: can module abbreviations affect other files?
249245
|> Seq.append filesWithModuleAbbreviations
250246
|> Seq.append additionalFsiDeps
251247
|> Seq.append fsiDep

tests/ParallelTypeCheckingTests/Code/FileInfoGathering.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ let internal gatherBackingInfo (files : SourceFiles) : Files =
2929

3030
type ExtractedData =
3131
{
32-
/// Order of the file in the project. Files with lower number cannot depend on files with higher number
3332
Tops : SimpleId[]
3433
Abbreviations : Abbreviation[]
3534
/// All partial module references found in this file's AST

tests/ParallelTypeCheckingTests/Code/Graph.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
#nowarn "40"
44

55
open System.Collections.Generic
6+
open System.IO
7+
open Newtonsoft.Json
68
open ParallelTypeCheckingTests.Utils
79

810
/// <summary> DAG of files </summary>
911
type Graph<'Node> = IReadOnlyDictionary<'Node, 'Node[]>
1012

1113
module Graph =
1214

15+
let make (nodeDeps : ('Node * 'Node[]) seq) =
16+
nodeDeps
17+
|> readOnlyDict
18+
19+
let map (f : 'a -> 'b) (graph : Graph<'a>) : Graph<'b> =
20+
graph
21+
|> Seq.map (fun (KeyValue(node, deps)) -> f node, deps |> Array.map f)
22+
|> make
23+
1324
let collectEdges<'Node when 'Node : equality> (graph : Graph<'Node>) : ('Node * 'Node)[] =
1425
let graph : IReadOnlyDictionary<'Node, 'Node[]> = graph
1526
graph
@@ -78,4 +89,8 @@ module Graph =
7889
|> Seq.iter (fun (KeyValue(file, deps)) -> printfn $"{file} -> {deps |> Array.map printer |> join}")
7990

8091
let print (graph : Graph<'Node>) : unit = printCustom graph (fun node -> node.ToString())
81-
92+
93+
let serialiseToJson (path : string) (graph : Graph<'Node>) : unit =
94+
let json = JsonConvert.SerializeObject(graph, Formatting.Indented)
95+
printfn $"Serialising graph as JSON in {path}"
96+
File.WriteAllText(path, json)

tests/ParallelTypeCheckingTests/Code/ParallelTypeChecking.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#nowarn "1182"
33
open System.Collections.Concurrent
44
open System.Collections.Generic
5+
open System.IO
56
open System.Threading
67
open FSharp.Compiler
78
open FSharp.Compiler.CheckBasics
@@ -22,7 +23,6 @@ open FSharp.Compiler.Text
2223
open FSharp.Compiler.TypedTree
2324
open Internal.Utilities.Library
2425
open Internal.Utilities.Library.Extras
25-
open Newtonsoft.Json
2626

2727
type FileGraph = Graph<File>
2828

@@ -118,12 +118,14 @@ let CheckMultipleInputsInParallel
118118
} : DepsResult
119119
else
120120
graph
121+
121122
graph.Graph |> Graph.print
122123

123-
let graphJson = graph.Graph |> Seq.map (fun (KeyValue(file, deps)) -> file.Name, deps |> Array.map (fun d -> d.Name)) |> dict
124-
let json = JsonConvert.SerializeObject(graphJson, Formatting.Indented)
125-
let path = $"c:/projekty/fsharp/heuristic/FCS.deps.json"
126-
System.IO.File.WriteAllText(path, json)
124+
let graphDumpPath =
125+
let graphDumpName = tcConfig.outputFile |> Option.map Path.GetFileName |> Option.defaultValue "project"
126+
$"{graphDumpName}.deps.json"
127+
graph.Graph
128+
|> Graph.serialiseToJson graphDumpPath
127129

128130
let _ = ctok // TODO Use
129131
let diagnosticsLogger = DiagnosticsThreadStatics.DiagnosticsLogger

tests/ParallelTypeCheckingTests/Tests/TestDependencyResolution.fs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,16 @@ let ``Analyse whole projects and print statistics`` (projectFile : string) =
274274
log $"{N} files read and parsed"
275275

276276
let graph = DependencyResolution.detectFileDependencies files
277-
log "Deps detected"
277+
log "Dependency graph calculated"
278278

279279
let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(_file, deps)) -> deps.Length)
280280
let maxPossibleDeps = (N * (N-1)) / 2
281281

282-
let graphJson = graph.Graph |> Seq.map (fun (KeyValue(file, deps)) -> file.Name, deps |> Array.map (fun _d -> file.Name)) |> dict
283-
let json = JsonConvert.SerializeObject(graphJson, Formatting.Indented)
284-
let path = $"{System.IO.Path.GetFileName(projectFile)}.deps.json"
285-
System.IO.File.WriteAllText(path, json)
282+
let path = $"{Path.GetFileName(projectFile)}.deps.json"
283+
graph.Graph
284+
|> Graph.serialiseToJson path
286285

287286
log $"Analysed {N} files, detected {totalDeps}/{maxPossibleDeps} file dependencies (%.1f{100.0 * double(totalDeps) / double(maxPossibleDeps)}%%)."
288-
log $"Wrote graph in {path}"
289-
290287
analyseEfficiency graph
291288

292289
let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(_k, v)) -> v.Length)

0 commit comments

Comments
 (0)