Skip to content

Commit

Permalink
Start cleanup for sharing the branch
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Nov 8, 2022
1 parent 6df43e9 commit 716db8e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
8 changes: 2 additions & 6 deletions tests/ParallelTypeCheckingTests/Code/DependencyResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,16 @@ module internal DependencyResolution =
// Force .fsi files to depend on all other (previous) .fsi files - avoids the issue of TcEnv being overriden
let additionalFsiDeps =
if node.File.Name.EndsWith ".fsi" then
fsiFiles
nodes
else
[||]

// Collect files from all reachable TrieNodes
let deps =
reachable
|> Seq.collect (fun node -> node.Files)
// TODO Temporary - Add all nodes
// |> Seq.append nodes
// If not, then the below is not necessary.
// Assume that this file depends on all files that have any module abbreviations
// Assume that this file depends on all files that have any module abbreviations - this is probably unnecessary.
// TODO Handle module abbreviations in a better way
// For starters: can module abbreviations affect other files?
|> Seq.append filesWithModuleAbbreviations
|> Seq.append additionalFsiDeps
|> Seq.append fsiDep
Expand Down
1 change: 0 additions & 1 deletion tests/ParallelTypeCheckingTests/Code/FileInfoGathering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ let internal gatherBackingInfo (files : SourceFiles) : Files =

type ExtractedData =
{
/// Order of the file in the project. Files with lower number cannot depend on files with higher number
Tops : SimpleId[]
Abbreviations : Abbreviation[]
/// All partial module references found in this file's AST
Expand Down
17 changes: 16 additions & 1 deletion tests/ParallelTypeCheckingTests/Code/Graph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
#nowarn "40"

open System.Collections.Generic
open System.IO
open Newtonsoft.Json
open ParallelTypeCheckingTests.Utils

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

module Graph =

let make (nodeDeps : ('Node * 'Node[]) seq) =
nodeDeps
|> readOnlyDict

let map (f : 'a -> 'b) (graph : Graph<'a>) : Graph<'b> =
graph
|> Seq.map (fun (KeyValue(node, deps)) -> f node, deps |> Array.map f)
|> make

let collectEdges<'Node when 'Node : equality> (graph : Graph<'Node>) : ('Node * 'Node)[] =
let graph : IReadOnlyDictionary<'Node, 'Node[]> = graph
graph
Expand Down Expand Up @@ -78,4 +89,8 @@ module Graph =
|> Seq.iter (fun (KeyValue(file, deps)) -> printfn $"{file} -> {deps |> Array.map printer |> join}")

let print (graph : Graph<'Node>) : unit = printCustom graph (fun node -> node.ToString())


let serialiseToJson (path : string) (graph : Graph<'Node>) : unit =
let json = JsonConvert.SerializeObject(graph, Formatting.Indented)
printfn $"Serialising graph as JSON in {path}"
File.WriteAllText(path, json)
12 changes: 7 additions & 5 deletions tests/ParallelTypeCheckingTests/Code/ParallelTypeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#nowarn "1182"
open System.Collections.Concurrent
open System.Collections.Generic
open System.IO
open System.Threading
open FSharp.Compiler
open FSharp.Compiler.CheckBasics
Expand All @@ -22,7 +23,6 @@ open FSharp.Compiler.Text
open FSharp.Compiler.TypedTree
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open Newtonsoft.Json

type FileGraph = Graph<File>

Expand Down Expand Up @@ -118,12 +118,14 @@ let CheckMultipleInputsInParallel
} : DepsResult
else
graph

graph.Graph |> Graph.print

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

let _ = ctok // TODO Use
let diagnosticsLogger = DiagnosticsThreadStatics.DiagnosticsLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,16 @@ let ``Analyse whole projects and print statistics`` (projectFile : string) =
log $"{N} files read and parsed"

let graph = DependencyResolution.detectFileDependencies files
log "Deps detected"
log "Dependency graph calculated"

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

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

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

analyseEfficiency graph

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

0 comments on commit 716db8e

Please sign in to comment.