Skip to content

Commit b461abb

Browse files
committed
WIP
1 parent b1ebfdb commit b461abb

4 files changed

Lines changed: 53 additions & 6 deletions

File tree

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
module FSharp.Compiler.Service.Tests.DepResolving
22

3+
open System
34
open System.Collections.Generic
5+
open Buildalyzer
46
open FSharp.Compiler.Service.Tests2.SyntaxTreeTests.TypeTests
57
open FSharp.Compiler.Syntax
68
open NUnit.Framework
79

10+
let log (msg : string) =
11+
let d = DateTime.Now.ToString("HH:mm:ss.fff")
12+
printfn $"{d} {msg}"
13+
814
/// File * AST
915
type FileAST = string * ParsedInput
1016

@@ -122,12 +128,13 @@ let rec searchInTrie (trie : TrieNode) (path : LongIdent) : TrieNode option =
122128
| false, _ ->
123129
None
124130

125-
let detectFileDependencies (nodes : FileAST list) : Graph =
131+
let detectFileDependencies (nodes : FileAST[]) : Graph =
126132
// Create ASTs, extract module refs
127133
let nodes =
128134
nodes
129-
|> List.mapi (fun i (name, ast) ->
130-
let typeAndModuleRefs = visit ast
135+
|> Array.mapi (fun i (name, ast) ->
136+
printfn $"Visiting {name}"
137+
let typeAndModuleRefs = visit ast
131138
let top = topModuleOrNamespace ast
132139
let moduleRefs = extractModuleSegments typeAndModuleRefs
133140
{
@@ -138,7 +145,6 @@ let detectFileDependencies (nodes : FileAST list) : Graph =
138145
Idx = i
139146
}
140147
)
141-
|> List.toArray
142148

143149
let trie = buildTrie nodes
144150

@@ -282,9 +288,47 @@ type B = int
282288
let nodes =
283289
files
284290
|> List.map (fun (name, code) -> name, getParseResults code)
291+
|> List.toArray
285292

286293
let graph = detectFileDependencies nodes
287294

288295
printfn "Detected file dependencies:"
289296
graph
290297
|> Array.iter (fun (file, deps) -> printfn $"{file} -> %+A{deps}")
298+
299+
[<Test>]
300+
let Test () =
301+
log "start"
302+
let m = AnalyzerManager()
303+
let analyzer = m.GetProject(@"C:\projekty\fsharp\fsharp_main\src\Compiler\FSharp.Compiler.Service.fsproj")
304+
let results = analyzer.Build()
305+
log "built"
306+
307+
let res = results.Results |> Seq.head
308+
let files = res.SourceFiles
309+
let files =
310+
files
311+
|> Array.take 3
312+
|> Array.Parallel.map (fun f -> f, System.IO.File.ReadAllText(f))
313+
|> Array.chunkBySize 5
314+
|> Array.map (fun chunk ->
315+
chunk
316+
|> Array.Parallel.map (fun (f, code) ->
317+
printfn $"Parsing {f}"
318+
let ast = getParseResults code
319+
f, ast
320+
)
321+
)
322+
|> Array.concat
323+
let N = files.Length
324+
log $"{N} files read"
325+
326+
let graph = detectFileDependencies files
327+
log "deps detected"
328+
329+
let totalDeps = graph |> Array.sumBy (fun (f, deps) -> deps.Length)
330+
let maxPossibleDeps = (N * (N-1)) / 2
331+
printfn $"Analysed {N} files, detected {totalDeps}/{maxPossibleDeps} file dependencies:"
332+
graph
333+
|> Array.iter (fun (file, deps) -> printfn $"{file} -> %+A{deps}")
334+
()

tests/FSharp.Compiler.Service.Tests2/FSharp.Compiler.Service.Tests2.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
4242
<!-- Force a newer Newtonsoft.Json version to avoid conflicts. -->
4343
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
44+
<PackageReference Include="Buildalyzer" Version="4.1.2" />
4445
<ProjectReference Include="..\..\src\Compiler\FSharp.Compiler.Service.fsproj" />
4546
<ProjectReference Include="..\..\tests\FSharp.Test.Utilities\FSharp.Test.Utilities.fsproj" />
4647
</ItemGroup>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,12 +1018,13 @@ and visitSynModuleOrNamespace (x : SynModuleOrNamespace) : Stuff =
10181018
yield! visitSynAttributeLists synAttributeLists
10191019
}
10201020

1021-
and visit (input : ParsedInput) : Stuff =
1021+
and visit (input : ParsedInput) =
10221022
match input with
10231023
| ParsedInput.SigFile _ -> failwith "Signature files are not currently supported"
10241024
| ParsedInput.ImplFile(ParsedImplFileInput(fileName, isScript, qualifiedNameOfFile, scopedPragmas, parsedHashDirectives, synModuleOrNamespaces, flags, parsedImplFileInputTrivia)) ->
10251025
synModuleOrNamespaces
10261026
|> Seq.collect visitSynModuleOrNamespace
1027+
|> Seq.toArray
10271028

10281029
let topModuleOrNamespace (input : ParsedInput) =
10291030
match input with

tests/service/Program.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2+
23
[<EntryPoint>]
34
let main argv =
4-
printfn "Dotnet Core NUnit Tests..."
5+
FSharp.Compiler.Service.Tests.DepResolving.Test()
56
0

0 commit comments

Comments
 (0)