Skip to content

Commit cded6a0

Browse files
committed
WIP
1 parent 126c584 commit cded6a0

File tree

3 files changed

+58
-38
lines changed

3 files changed

+58
-38
lines changed

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ type DepsResult =
5252

5353
type References = Reference seq
5454

55+
let calcTransitiveGraph (graph : IDictionary<int, int[]>) : IDictionary<int, int[]> =
56+
let transitiveDeps = Dictionary<int, int[]>()
57+
58+
let rec calcTransitiveDepsInner (idx : int) =
59+
match transitiveDeps.TryGetValue idx with
60+
| true, deps -> deps
61+
| false, _ ->
62+
let directDeps = graph[idx]
63+
let deps =
64+
directDeps
65+
|> Array.collect (
66+
fun dep ->
67+
calcTransitiveDepsInner dep
68+
|> Array.append [|dep|]
69+
)
70+
|> Array.distinct
71+
transitiveDeps[idx] <- deps
72+
deps
73+
74+
graph.Keys
75+
|> Seq.map (fun idx -> idx, calcTransitiveDepsInner idx)
76+
|> dict
77+
78+
5579
/// Extract partial module references from partial module or type references
5680
let extractModuleSegments (stuff : ReferenceOrAbbreviation seq) : LongIdent[] * bool =
5781

@@ -307,29 +331,8 @@ module internal AutomatedDependencyResolving =
307331
)
308332
|> dict
309333

310-
let transitiveDeps = Dictionary<int, int[]>()
311-
312-
let rec calcTransitiveDeps (idx : int) =
313-
match transitiveDeps.TryGetValue idx with
314-
| true, deps -> deps
315-
| false, _ ->
316-
let directDeps = graph[idx]
317-
let deps =
318-
directDeps
319-
|> Array.collect (
320-
fun dep ->
321-
calcTransitiveDeps dep
322-
|> Array.append [|dep|]
323-
)
324-
|> Array.distinct
325-
transitiveDeps[idx] <- deps
326-
deps
327-
328334
// Calculate transitive closure of the graph
329-
let graph =
330-
graph.Keys
331-
|> Seq.map (fun idx -> idx, calcTransitiveDeps idx)
332-
|> dict
335+
let graph = calcTransitiveGraph graph
333336

334337
let res =
335338
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ open System
44

55
let runCompiler () =
66
Environment.CurrentDirectory <- "c:/projekty/fsharp/heuristic/src/Compiler"
7-
FSharp.Compiler.Service.Tests.RunCompiler.runCompiler()
7+
RunCompiler.runCompiler()
88

99
[<EntryPoint>]
1010
let main _ =
1111
//TestDepResolving.TestProject(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")
1212
//runCompiler ()
1313
//TestDepResolving.TestHardcodedFiles()
14-
TestDepResolving.TestProject(@"C:\projekty\fsharp\fsharp_main\src\Compiler\FSharp.Compiler.Service.fsproj")
14+
//TestDepResolving.TestProject(@"C:\projekty\fsharp\fsharp_main\src\Compiler\FSharp.Compiler.Service.fsproj")
15+
RunCompiler.runGrapher()
1516
0

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
module FSharp.Compiler.Service.Tests.RunCompiler
1+
module FSharp.Compiler.Service.Tests2.RunCompiler
22

33
open System
44
open System.Collections.Concurrent
55
open System.Threading
66
open System.Threading.Tasks
7+
open FSharp.Compiler.Service.Tests2
78
open NUnit.Framework
89

910
type Node =
1011
{
1112
Idx : int
1213
Deps : int[]
1314
Dependants : int[]
14-
mutable Result : string option
15+
mutable PartialResult : string option
1516
mutable UnprocessedDepsCount : int
1617
_lock : Object
1718
}
@@ -37,6 +38,10 @@ let runGrapher () =
3738
4, [|3|] // C2 -> C1
3839
5, [|2; 4|] // D -> B2, C2
3940
|]
41+
|> dict
42+
|> DepResolving.calcTransitiveGraph
43+
|> Seq.map (fun (KeyValue(k, v)) -> k, v)
44+
|> Seq.toArray
4045

4146
let fileDependants =
4247
fileDeps
@@ -48,18 +53,18 @@ let runGrapher () =
4853
|> Array.map (fun (dep, edges) -> dep, edges |> Array.map fst)
4954
|> dict
5055
// Add nodes that are missing due to having no dependants
51-
|> fun g ->
56+
|> fun graph ->
5257
fileDeps
53-
|> Array.map fst
54-
|> Array.map (fun idx ->
55-
match g.TryGetValue idx with
56-
| true, dependants -> dependants
57-
| false, _ -> [||]
58+
|> Array.map (fun (idx, deps) ->
59+
match graph.TryGetValue idx with
60+
| true, dependants -> idx, dependants
61+
| false, _ -> idx, [||]
5862
)
63+
|> dict
5964

6065
let graph =
6166
fileDeps
62-
|> Seq.map (fun (idx, deps) -> idx, {Idx = idx; Deps = deps; Dependants = fileDependants[idx]; Result = None; UnprocessedDepsCount = deps.Length; _lock = Object()})
67+
|> Seq.map (fun (idx, deps) -> idx, {Idx = idx; Deps = deps; Dependants = fileDependants[idx]; PartialResult = None; UnprocessedDepsCount = deps.Length; _lock = Object()})
6368
|> dict
6469

6570
printfn "start"
@@ -83,16 +88,22 @@ let runGrapher () =
8388
)
8489

8590
let actualWork (idx : int) =
86-
idx.ToString()
91+
let node = graph[idx]
92+
let depsResult =
93+
node.Deps
94+
|> Array.map (fun dep -> match graph[dep].PartialResult with Some result -> result | None -> failwith $"Unexpected lack of result for a dependency {idx} -> {dep}")
95+
|> Array.fold (fun state item -> state + item) ""
96+
let thisResult = idx.ToString()
97+
$"{thisResult}"
8798

8899
// Processing of a single node/file - gives a result
89100
let go (idx : int) =
90101
let node = graph[idx]
91102
printfn $"Start {idx} -> %+A{node.Deps}"
92103
Thread.Sleep(500)
93104
let res = actualWork idx
94-
node.Result <- Some res
95-
printfn $" Stop {idx} work"
105+
node.PartialResult <- Some res
106+
printfn $" Stop {idx} work - result {res}"
96107

97108
// Increment processed deps count for all dependants and schedule those who are now unblocked
98109
node.Dependants
@@ -133,5 +144,10 @@ let runGrapher () =
133144
q.CompleteAdding()
134145
printfn "waitall"
135146
Task.WaitAll workers
136-
printfn "End"
137-
()
147+
148+
let fullResult =
149+
graph
150+
|> Seq.map (fun (KeyValue(idx, node)) -> node.PartialResult |> Option.get) // TODO Oops
151+
|> Seq.fold (fun state item -> state + item) ""
152+
153+
printfn $"End result: {fullResult}"

0 commit comments

Comments
 (0)