Skip to content

Commit 221f650

Browse files
committed
WIP
1 parent a343a59 commit 221f650

3 files changed

Lines changed: 54 additions & 6 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ module internal AutomatedDependencyResolving =
225225
ContainsModuleAbbreviations = containsModuleAbbreviations
226226
}
227227
)
228+
229+
let nodesByName =
230+
nodes
231+
|> Seq.map (fun f -> f.Name, f)
232+
|> dict
228233

229234
log "ASTs traversed"
230235

@@ -325,14 +330,37 @@ module internal AutomatedDependencyResolving =
325330
deps
326331
// We know a file can't depend on a file further down in the project definition (or on itself)
327332
|> Array.filter (fun depIdx -> depIdx < node.Idx)
333+
// Filter out deps onto .fs files that have backing .fsi files
334+
// TODO This isn't fully correct - need to take into account the order of files
335+
|> Array.filter (fun depIdx ->
336+
let dep = nodes[depIdx]
337+
// If it's an impl file
338+
if dep.Name.EndsWith(".fs") then
339+
// See if it has an .fsi file (for now don't consider order)
340+
let depFsiName = dep.Name + "i"
341+
match nodesByName.TryGetValue depFsiName with
342+
| true, _ ->
343+
// There is an .fsi file - remove a dependency onto the .fs file
344+
false
345+
| false, _ ->
346+
// There is no .fsi file - keep the dependency
347+
true
348+
else
349+
// It's a sign file - keep the dependency
350+
true
351+
)
328352

329353
// Return the node and its dependencies
330354
node.Idx, deps
331355
)
332356
|> dict
333357

358+
let totalSize1 = graph |> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
334359
// Calculate transitive closure of the graph
335360
let graph = calcTransitiveGraph graph
361+
let totalSize2 = graph |> Seq.sumBy (fun (KeyValue(k,v)) -> v.Length)
362+
363+
printfn $"Non-transitive size: {totalSize1}, transitive size: {totalSize2}"
336364

337365
let res =
338366
{

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ let runCompiler () =
88

99
[<EntryPoint>]
1010
let main _ =
11-
TestDepResolving.TestProject(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")
1211
//runCompiler ()
1312
//TestDepResolving.TestHardcodedFiles()
14-
printfn ""
13+
//TestDepResolving.TestProject(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")
1514
TestDepResolving.TestProject(@"C:\projekty\fsharp\fsharp_main\src\Compiler\FSharp.Compiler.Service.fsproj")
1615
//RunCompiler.runGrapher()
1716
0

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ let TestHardcodedFiles() =
105105
|> Seq.iter (fun (KeyValue(idx, deps)) -> printfn $"{graph.Files[idx].Name} -> %+A{deps |> Array.map(fun d -> graph.Files[d].Name)}")
106106

107107
analyseEfficiency graph
108+
109+
let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(k, v)) -> v.Length)
110+
let topFirstDeps =
111+
graph.Graph
112+
|> Seq.sumBy (
113+
fun (KeyValue(k, v)) ->
114+
if v.Length = 0 then 0
115+
else v |> Array.map (fun d -> graph.Graph[d].Length) |> Array.max
116+
)
117+
printfn $"TotalDeps: {totalDeps}, topFirstDeps: {topFirstDeps}"
108118

109119
let private parseProjectAndGetSourceFiles (projectFile : string) =
110120
let m = AnalyzerManager()
@@ -129,9 +139,9 @@ let TestProject (projectFile : string) =
129139
{Name = f; Code = code; AST = ast}
130140
)
131141
|> Array.filter (fun x ->
132-
true
133-
//ASTVisit.extractModuleRefs x.AST
134-
//|> Array.forall (function | ReferenceOrAbbreviation.Reference _ -> true | ReferenceOrAbbreviation.Abbreviation _ -> false)
142+
// true
143+
ASTVisit.extractModuleRefs x.AST
144+
|> Array.forall (function | ReferenceOrAbbreviation.Reference _ -> true | ReferenceOrAbbreviation.Abbreviation _ -> false)
135145
)
136146
let N = files.Length
137147
log $"{N} files read and parsed"
@@ -149,4 +159,15 @@ let TestProject (projectFile : string) =
149159

150160
log $"Analysed {N} files, detected {totalDeps}/{maxPossibleDeps} file dependencies (%.1f{100.0 * double(totalDeps) / double(maxPossibleDeps)}%%)."
151161
log $"Wrote graph in {path}"
152-
analyseEfficiency graph
162+
163+
analyseEfficiency graph
164+
165+
let totalDeps = graph.Graph |> Seq.sumBy (fun (KeyValue(k, v)) -> v.Length)
166+
let topFirstDeps =
167+
graph.Graph
168+
|> Seq.sumBy (
169+
fun (KeyValue(k, v)) ->
170+
if v.Length = 0 then 0
171+
else v |> Array.map (fun d -> graph.Graph[d].Length) |> Array.max
172+
)
173+
printfn $"TotalDeps: {totalDeps}, topFirstDeps: {topFirstDeps}, diff: {totalDeps - topFirstDeps}"

0 commit comments

Comments
 (0)