Skip to content

Commit 56e2301

Browse files
committed
changes
1 parent fd67ddb commit 56e2301

6 files changed

Lines changed: 40 additions & 61 deletions

File tree

tests/FSharp.Compiler.Service.Tests2/DepResolving.fs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,9 @@ module internal AutomatedDependencyResolving =
138138
/// <param name="nodes">A list of already parsed source files</param>
139139
let detectFileDependencies (files : SourceFiles) : DepsResult =
140140
let nodes = gatherForAllFiles files
141-
let nodesByName =
142-
nodes
143-
|> Seq.map (fun f -> f.File, f)
144-
|> dict
145-
146141
log "ASTs traversed"
147-
142+
let backed = nodes |> Array.filter (fun n -> n.File.FsiBacked)
143+
printfn $"{backed.Length} backed files found"
148144
let filesWithModuleAbbreviations =
149145
nodes
150146
|> Array.filter (fun n -> n.Data.ContainsModuleAbbreviations)
@@ -245,13 +241,17 @@ module internal AutomatedDependencyResolving =
245241
let graph =
246242
nodes
247243
// TODO Async + cancellations
248-
|> Array.Parallel.map processFile
244+
|> Array.map processFile
245+
// |> Array.Parallel.map processFile
249246
|> readOnlyDict
250247

251-
let totalSize1 = graph |> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
252-
// Calculate transitive closure of the graph
253-
let graph = Graph.transitive graph
254-
let totalSize2 = graph |> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
248+
let totalSize1 =
249+
graph
250+
|> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
251+
let totalSize2 =
252+
graph
253+
|> Graph.transitive
254+
|> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
255255

256256
printfn $"Non-transitive size: {totalSize1}, transitive size: {totalSize2}"
257257

tests/FSharp.Compiler.Service.Tests2/FileInfoGathering.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ open FSharp.Compiler.Service.Tests.Utils
77
open FSharp.Compiler.Service.Tests2
88
open FSharp.Compiler.Syntax
99

10-
let private gatherBackingInfo (files : SourceFiles) : Files =
10+
let internal gatherBackingInfo (files : SourceFiles) : Files =
1111
let seenSigFiles = HashSet<string>()
1212
files
1313
|> Array.mapi (fun i f ->
1414
let fsiBacked =
1515
match f.AST with
1616
| ParsedInput.SigFile _ ->
17+
seenSigFiles.Add f.Name |> ignore
1718
false
1819
| ParsedInput.ImplFile _ ->
1920
let fsiName = System.IO.Path.ChangeExtension(f.Name, "fsi")

tests/FSharp.Compiler.Service.Tests2/Graph.fs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ type Graph<'Node> = IReadOnlyDictionary<'Node, 'Node[]>
1111
module Graph =
1212

1313
let transitive<'Node when 'Node : equality> (graph : Graph<'Node>) : Graph<'Node> =
14-
let transitiveGraph = Dictionary<'Node, 'Node[]>()
15-
1614
let rec calcTransitiveEdges =
1715
fun (node : 'Node) ->
1816
let edgeTargets = graph[node]
1917
edgeTargets
2018
|> Array.collect calcTransitiveEdges
2119
|> Array.append edgeTargets
2220
|> Array.distinct
21+
// Dispose of memoisation context
2322
|> memoize
2423

2524
graph.Keys
26-
|> Seq.iter (fun idx -> calcTransitiveEdges idx |> ignore)
27-
28-
transitiveGraph :> IReadOnlyDictionary<_,_>
25+
|> Seq.map (fun node -> node, calcTransitiveEdges node)
26+
|> readOnlyDict
2927

3028
let reverse (graph : Graph<'Node>) : Graph<'Node> =
3129
graph

tests/FSharp.Compiler.Service.Tests2/Parallel.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ let processInParallelUsingMailbox
6161
=
6262
let processedCountLock = Object()
6363
let mutable processedCount = 0
64-
let agent = Parallel.threadingLimitAgent 10 ct
64+
let agent = threadingLimitAgent 10 ct
6565
let rec processItem item =
6666
async {
6767
let! toSchedule = work item
6868
let pc = lock processedCountLock (fun () -> processedCount <- processedCount + 1; processedCount)
6969
notify pc
70-
toSchedule |> Array.iter (fun x -> agent.Post(Parallel.Start(processItem x)))
70+
toSchedule |> Array.iter (fun x -> agent.Post(Start(processItem x)))
7171
}
72-
firstItems |> Array.iter (fun x -> agent.Post(Parallel.Start(processItem x)))
72+
firstItems |> Array.iter (fun x -> agent.Post(Start(processItem x)))
7373
()
7474

7575
// TODO Could replace with MailboxProcessor+Tasks/Asyncs instead of BlockingCollection + Threads
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
module FSharp.Compiler.Service.Tests2.RunCompiler
22

3-
open System
4-
open System.Collections.Concurrent
5-
open System.Collections.Generic
6-
open System.Threading
7-
open System.Threading.Tasks
83
open FSharp.Compiler.Service.Tests
94
open FSharp.Compiler.Service.Tests.Graph
105
open NUnit.Framework
@@ -32,26 +27,4 @@ let runGrapher () =
3227
|]
3328
|> readOnlyDict
3429

35-
let dependants = deps |> Graph.reverse
36-
let transitiveDeps = deps |> Graph.transitive
37-
let transitiveDependants = transitiveDeps |> Graph.reverse
38-
39-
let nodes =
40-
deps.Keys
41-
|> Seq.map (fun idx -> idx, {Idx = idx; Deps = [||]; Dependants = [||]; TransitiveDeps = [||]; Result = None; UnprocessedDepsCount = 0; _lock = Object()})
42-
|> readOnlyDict
43-
44-
let processs deps = deps |> Array.map (fun d -> nodes[d])
45-
46-
let graph =
47-
nodes
48-
|> Seq.iter (fun (KeyValue(idx, node)) ->
49-
node.Deps <- processs deps[idx]
50-
node.TransitiveDeps <- processs transitiveDeps[idx]
51-
node.Dependants <- processs dependants[idx]
52-
node.UnprocessedDepsCount <- node.Deps.Length
53-
)
54-
nodes.Values
55-
|> Seq.toArray
56-
57-
GraphProcessing.processGraph graph
30+
GraphProcessing.processGraph deps

tests/FSharp.Compiler.Service.Tests2/Tests/TestDepResolving.fs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
open Buildalyzer
44
open FSharp.Compiler.Service.Tests
5-
open FSharp.Compiler.Service.Tests2.ASTVisit
5+
open FSharp.Compiler.Service.Tests.Types
6+
open FSharp.Compiler.Service.Tests.Utils
67
open FSharp.Compiler.Service.Tests2.DepResolving
78
open NUnit.Framework
89
open Newtonsoft.Json
@@ -77,7 +78,7 @@ module GH3 =
7778
"""
7879

7980
[
80-
"Abbr.fs", WithAbbreviations
81+
// "Abbr.fs", WithAbbreviations
8182
"A.fsi", A_fsi
8283
"A.fs", A
8384
"B.fs", B
@@ -95,14 +96,20 @@ let TestHardcodedFiles() =
9596

9697
let nodes =
9798
sampleFiles
98-
|> List.map (fun (name, code) -> {FileAST.Name = name; FileAST.Code = code; FileAST.AST = parseSourceCode(name, code)})
99+
|> List.mapi (fun i (name, code) ->
100+
{
101+
Name = name
102+
Idx = FileIdx.make i
103+
Code = code
104+
AST = parseSourceCode(name, code)
105+
} : SourceFile)
99106
|> List.toArray
100107

101108
let graph = AutomatedDependencyResolving.detectFileDependencies nodes
102109

103110
printfn "Detected file dependencies:"
104111
graph.Graph
105-
|> Seq.iter (fun (KeyValue(idx, deps)) -> printfn $"{graph.Files[idx].Name} -> %+A{deps |> Array.map(fun d -> graph.Files[d].Name)}")
112+
|> Seq.iter (fun (KeyValue(file, deps)) -> printfn $"{file.Name} -> %+A{deps |> Array.map(fun d -> d.Name)}")
106113

107114
analyseEfficiency graph
108115

@@ -133,26 +140,26 @@ let TestProject (projectFile : string) =
133140
let files = parseProjectAndGetSourceFiles projectFile
134141
let files =
135142
files
136-
|> Array.Parallel.map (fun f ->
143+
|> Array.Parallel.mapi (fun i f ->
137144
let code = System.IO.File.ReadAllText(f)
138145
let ast = getParseResults code
139-
{Name = f; Code = code; AST = ast}
140-
)
141-
|> Array.filter (fun x ->
142-
// true
143-
ASTVisit.findModuleAndTypeRefs x.AST
144-
|> Array.forall (function | ReferenceOrAbbreviation.Reference _ -> true | ReferenceOrAbbreviation.Abbreviation _ -> false)
146+
{
147+
Name = f
148+
Idx = FileIdx.make i
149+
Code = code
150+
AST = ast
151+
} : SourceFile
145152
)
146153
let N = files.Length
147154
log $"{N} files read and parsed"
148155

149156
let graph = AutomatedDependencyResolving.detectFileDependencies files
150157
log "Deps detected"
151158

152-
let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(idx, deps)) -> deps.Length)
159+
let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(file, deps)) -> deps.Length)
153160
let maxPossibleDeps = (N * (N-1)) / 2
154161

155-
let graphJson = graph.Graph |> Seq.map (fun (KeyValue(idx, deps)) -> graph.Files[idx].Name, deps |> Array.map (fun d -> graph.Files[d].Name)) |> dict
162+
let graphJson = graph.Graph |> Seq.map (fun (KeyValue(file, deps)) -> file.Name, deps |> Array.map (fun d -> file.Name)) |> dict
156163
let json = JsonConvert.SerializeObject(graphJson, Formatting.Indented)
157164
let path = $"{System.IO.Path.GetFileName(projectFile)}.deps.json"
158165
System.IO.File.WriteAllText(path, json)

0 commit comments

Comments
 (0)