Skip to content

Commit fd67ddb

Browse files
committed
changes
1 parent 2ec476d commit fd67ddb

File tree

10 files changed

+218
-439
lines changed

10 files changed

+218
-439
lines changed

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

Lines changed: 126 additions & 217 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@
2727
<Link>Common.fs</Link>
2828
</Compile>
2929
<Compile Include="Utils.fs" />
30+
<Compile Include="Types.fs" />
3031
<Compile Include="ASTVisit.fs" />
31-
<Compile Include="TestASTVisit.fs" />
32-
<Compile Include="DepResolving.fs" />
33-
<Compile Include="TestDepResolving.fs" />
32+
<Compile Include="FileInfoGathering.fs" />
3433
<Compile Include="Graph.fs" />
35-
<Compile Include="RunCompiler.fs" />
34+
<Compile Include="DepResolving.fs" />
3635
<None Include="Big.fs">
3736
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3837
</None>
39-
<Compile Include="Types.fs" />
40-
<Compile Include="Program.fs" />
4138
<Compile Include="Parallel.fs" />
4239
<Compile Include="GraphProcessing.fs" />
43-
<Compile Include="FileInfoGathering.fs" />
44-
<Compile Include="code2.fs" />
40+
<Compile Include="ParallelTypeChecking.fs" />
4541
<Content Include="Docs.md" />
42+
<Compile Include="Tests\TestASTVisit.fs" />
43+
<Compile Include="Tests\TestDepResolving.fs" />
44+
<Compile Include="Tests\RunCompiler.fs" />
45+
<Compile Include="Program.fs" />
4646
</ItemGroup>
4747

4848
<ItemGroup>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ let private gatherBackingInfo (files : SourceFiles) : Files =
3030

3131
type ExtractedData =
3232
{
33-
ModuleRefs : LongIdent[]
33+
/// Order of the file in the project. Files with lower number cannot depend on files with higher number
3434
Tops : LongIdent[]
3535
ContainsModuleAbbreviations : bool
36+
/// All partial module references found in this file's AST
37+
ModuleRefs : LongIdent[]
3638
}
3739

40+
/// All the data about a single file needed for the dependency resolution algorithm
3841
type FileData =
3942
{
4043
File : File
4144
Data : ExtractedData
4245
}
46+
with member this.CodeSize = this.File.CodeSize
4347

4448
let private gatherFileData (file : File) : ExtractedData =
4549
let moduleRefs, containsModuleAbbreviations = ASTVisit.findModuleRefs file.AST

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ let combineResults
6969
// TODO Could be replaced with a simpler recursive approach with memoised per-item results
7070
let processGraph<'Item, 'State, 'Result when 'Item : equality>
7171
(graph : Graph<'Item>)
72-
(doWork : 'Item -> 'State -> 'State * 'Result)
72+
(doWork : 'Item -> 'State -> 'Result)
7373
(folder : 'State -> 'Result -> 'State)
7474
(parallelism : int)
7575
: 'State
@@ -109,8 +109,10 @@ let processGraph<'Item, 'State, 'Result when 'Item : equality>
109109
let deps = lookupMany node.Info.Deps
110110
let transitiveDeps = lookupMany node.Info.TransitiveDeps
111111
let inputState = combineResults deps transitiveDeps folder
112-
let res = doWork node.Info.Item inputState
113-
node.Result <- Some res
112+
let singleRes = doWork node.Info.Item inputState
113+
let state = folder inputState singleRes
114+
node.Result <- Some (state, singleRes)
115+
114116
// Need to double-check that only one dependency schedules this dependant
115117
let unblocked =
116118
node.Info.Dependants
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
module FSharp.Compiler.Service.Tests.code
1+
module FSharp.Compiler.Service.Tests.ParallelTypeChecking
22

3-
open FSharp.Compiler.ParseAndCheckInputs
43
open FSharp.Compiler.Service.Tests.Graph
54
open FSharp.Compiler.Service.Tests.Types
65

@@ -9,27 +8,31 @@ type FileGraph = Graph<File>
98
let calcFileGraph (files : SourceFiles) : FileGraph =
109
failwith ""
1110

11+
// TODO Use real things
1212
type State = string
1313
type SingleResult = int
1414

15+
// TODO Use the real thing
1516
let typeCheckFile (file : File) (state : State) : SingleResult
1617
=
1718
file.Idx.Idx
1819

20+
// TODO Use the real thing
1921
let folder (state : string) (result : int) =
20-
$"{state}+{result}"
22+
$"{state}+{result}"
2123

22-
let typeCheckGraph (graph : FileGraph) : TcState =
24+
// TODO We probably need to return partial results as well
25+
let typeCheckGraph (graph : FileGraph) : State =
2326
let parallelism = 4 // cpu count?
2427
let state =
2528
GraphProcessing.processGraph
2629
graph
2730
typeCheckFile
2831
folder
2932
parallelism
30-
state
33+
state
3134

32-
let typeCheck (files : SourceFiles) : TcState =
35+
let typeCheck (files : SourceFiles) : State =
3336
let graph = calcFileGraph files
3437
let state = typeCheckGraph graph
3538
state

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

Lines changed: 0 additions & 199 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module FSharp.Compiler.Service.Tests2.RunCompiler
2+
3+
open System
4+
open System.Collections.Concurrent
5+
open System.Collections.Generic
6+
open System.Threading
7+
open System.Threading.Tasks
8+
open FSharp.Compiler.Service.Tests
9+
open FSharp.Compiler.Service.Tests.Graph
10+
open NUnit.Framework
11+
12+
[<Test>]
13+
let runCompiler () =
14+
let args =
15+
System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\args.txt") |> Array.skip 1
16+
FSharp.Compiler.CommandLineMain.main args |> ignore
17+
18+
[<Test>]
19+
let runGrapher () =
20+
// let args =
21+
// System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\args.txt") |> Array.skip 1
22+
// FSharp.Compiler.CommandLineMain.main args |> ignore
23+
24+
let deps : Graph<int> =
25+
[|
26+
0, [||] // A
27+
1, [|0|] // B1 -> A
28+
2, [|1|] // B2 -> B1
29+
3, [|0|] // C1 -> A
30+
4, [|3|] // C2 -> C1
31+
5, [|2; 4|] // D -> B2, C2
32+
|]
33+
|> readOnlyDict
34+
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

0 commit comments

Comments
 (0)