Skip to content

Commit ae0e40b

Browse files
committed
Run Fantomas + fix build
1 parent ccffefe commit ae0e40b

10 files changed

Lines changed: 98 additions & 82 deletions

File tree

src/Compiler/Driver/CompilerConfig.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ type TypeCheckingMode =
209209
| Sequential
210210
/// Signature files and implementation files without backing files are processed sequentially, then backed implementation files are processed in parallel.
211211
| ParallelCheckingOfBackedImplFiles
212-
/// Parallel type-checking that uses automated file-to-file dependency detection to construct a highly-parallelisable file graph.
212+
/// Parallel type-checking that uses automated file-to-file dependency detection to construct a highly-parallelisable file graph.
213213
| Graph
214214

215215
[<RequireQualifiedAccess>]

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,15 @@ let ParseInputFilesInParallel (tcConfig: TcConfig, lexResourceManager, sourceFil
759759
for fileName in sourceFiles do
760760
checkInputFile tcConfig fileName
761761

762-
763762
// Order files to be parsed by size (descending). The idea is to process big files first,
764763
// so that near the end when only some nodes are still processing items, it's the smallest items,
765764
// which should reduce the period of time where only some nodes are busy.
766-
// This requires some empirical evidence.
765+
// This requires some empirical evidence.
767766
let sourceFiles =
768767
sourceFiles
769768
|> List.mapi (fun i f -> i, f)
770769
|> List.sortBy (fun (_i, f) -> -FileInfo(f).Length)
771-
770+
772771
let sourceFiles = List.zip sourceFiles isLastCompiland
773772

774773
UseMultipleDiagnosticLoggers (sourceFiles, delayLogger, None) (fun sourceFilesWithDelayLoggers ->
@@ -782,8 +781,7 @@ let ParseInputFilesInParallel (tcConfig: TcConfig, lexResourceManager, sourceFil
782781
idx, (input, directoryName))
783782
// Bring back index-based order
784783
|> List.sortBy fst
785-
|> List.map snd
786-
)
784+
|> List.map snd)
787785

788786
let ParseInputFilesSequential (tcConfig: TcConfig, lexResourceManager, sourceFiles, diagnosticsLogger: DiagnosticsLogger, retryLocked) =
789787
let isLastCompiland, isExe = sourceFiles |> tcConfig.ComputeCanContainEntryPoint

tests/ParallelTypeCheckingTests/Code/ASTVisit.fs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,20 +1254,18 @@ module TopModulesExtraction =
12541254
synAccessOption,
12551255
range,
12561256
synModuleOrNamespaceTrivia) ->
1257-
if
1258-
mightHaveAutoOpen synAttributeLists && synModuleOrNamespaceKind.IsModule
1259-
then
1257+
if mightHaveAutoOpen synAttributeLists && synModuleOrNamespaceKind.IsModule then
12601258
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
12611259
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
12621260
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
12631261
else
1264-
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
1265-
if
1266-
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1267-
then
1268-
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
1269-
else
1270-
[| longId |]
1262+
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
1263+
if
1264+
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1265+
then
1266+
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
1267+
else
1268+
[| longId |]
12711269
// TODO Temporarily disabled digging into the file's structure to avoid edge cases where another file depends on this file's namespace existing (but nothing else)
12721270
// synModuleDecls
12731271
// |> moduleDecls
@@ -1330,20 +1328,18 @@ module TopModulesExtraction =
13301328
synAccessOption,
13311329
range,
13321330
synModuleOrNamespaceTrivia) ->
1333-
if
1334-
mightHaveAutoOpen synAttributeLists && synModuleOrNamespaceKind.IsModule
1335-
then
1331+
if mightHaveAutoOpen synAttributeLists && synModuleOrNamespaceKind.IsModule then
13361332
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
13371333
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
13381334
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
13391335
else
1340-
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
1341-
if
1342-
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1343-
then
1344-
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
1345-
else
1346-
[| longId |]
1336+
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
1337+
if
1338+
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1339+
then
1340+
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
1341+
else
1342+
[| longId |]
13471343

13481344
and moduleSigDecls (x: SynModuleSigDecl list) : Eit =
13491345
let emptyState = Eit.Nested [||]

tests/ParallelTypeCheckingTests/Code/Graph.fs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ module Graph =
4242
graph.Values |> Seq.toArray |> Array.concat |> Array.except graph.Keys
4343

4444
addIfMissing missingNodes graph
45-
45+
4646
/// Create a transitive closure of the graph
4747
let transitiveOpt<'Node when 'Node: equality> (graph: Graph<'Node>) : Graph<'Node> =
4848
let go (node: 'Node) =
4949
let visited = HashSet<'Node>()
50+
5051
let rec dfs (node: 'Node) =
51-
graph[node]
52-
|> Array.filter visited.Add
53-
|> Array.iter dfs
52+
graph[node] |> Array.filter visited.Add |> Array.iter dfs
53+
5454
dfs node
55-
visited
56-
|> Seq.toArray
57-
55+
visited |> Seq.toArray
56+
5857
graph.Keys
5958
|> Seq.toArray
6059
|> Array.Parallel.map (fun node -> node, go node)

tests/ParallelTypeCheckingTests/Code/Parallel.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let processInParallel
1616
(parallelism: int)
1717
(shouldStop: int -> bool)
1818
(ct: CancellationToken)
19-
(_itemToString : 'Item -> string)
19+
(_itemToString: 'Item -> string)
2020
: unit =
2121
let bc = new BlockingCollection<'Item>()
2222
firstItems |> Array.iter bc.Add
@@ -31,10 +31,10 @@ let processInParallel
3131
lock processedCountLock (fun () ->
3232
processedCount <- processedCount + 1
3333
processedCount)
34+
3435
let toScheduleString =
35-
toSchedule
36-
|> Array.map _itemToString
37-
|> fun names -> String.Join(", ", names)
36+
toSchedule |> Array.map _itemToString |> (fun names -> String.Join(", ", names))
37+
3838
printfn $"Scheduling {toSchedule.Length} items: {toScheduleString}"
3939
toSchedule |> Array.iter bc.Add
4040
processedCount
@@ -44,6 +44,7 @@ let processInParallel
4444
for node in bc.GetConsumingEnumerable(ct) do
4545
if not ct.IsCancellationRequested then // improve
4646
let processedCount = processItem node
47+
4748
if shouldStop processedCount then
4849
bc.CompleteAdding()
4950

tests/ParallelTypeCheckingTests/Tests/AssemblySetUp.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type AssemblySetUp() =
1010

1111
[<OneTimeSetUp>]
1212
member this.SetUp() =
13-
FSharp.Compiler.ParseAndCheckInputs.CheckMultipleInputsUsingGraphMode <- ParallelTypeCheckingTests.ParallelTypeChecking.CheckMultipleInputsInParallel
13+
FSharp.Compiler.ParseAndCheckInputs.CheckMultipleInputsUsingGraphMode <-
14+
ParallelTypeCheckingTests.ParallelTypeChecking.CheckMultipleInputsInParallel
15+
1416
tracerProvider <- ParallelTypeCheckingTests.TestUtils.setupOtel () |> Some
1517

1618
[<OneTimeTearDown>]

tests/ParallelTypeCheckingTests/Tests/TestCompilation.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,16 @@ type Case =
213213
let methodOptions (method: Method) =
214214
match method with
215215
| Method.Sequential -> []
216-
| Method.ParallelCheckingOfBackedImplFiles -> ["--test:ParallelCheckingWithSignatureFilesOn"]
217-
| Method.Graph -> ["--test:GraphBasedChecking"]
216+
| Method.ParallelCheckingOfBackedImplFiles -> [ "--test:ParallelCheckingWithSignatureFilesOn" ]
217+
| Method.Graph -> [ "--test:GraphBasedChecking" ]
218218

219-
let withMethod (method: Method) (cu : CompilationUnit) : CompilationUnit =
219+
let withMethod (method: Method) (cu: CompilationUnit) : CompilationUnit =
220220
match cu with
221221
| CompilationUnit.FS cs ->
222-
FS {cs with Options = cs.Options @ (methodOptions method)}
222+
FS
223+
{ cs with
224+
Options = cs.Options @ (methodOptions method)
225+
}
223226
| cu -> cu
224227

225228
let compileAValidProject (x: Case) =

tests/ParallelTypeCheckingTests/Tests/TestCompilationFromCmdlineArgs.fs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ let internal setupParsed config =
4949
setupCompilationMethod method
5050

5151
printfn $"Method: {method}"
52+
5253
let args =
5354
match method with
5455
| Method.Sequential -> args
55-
| Method.ParallelCheckingOfBackedImplFiles ->
56-
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
57-
| Method.Graph ->
58-
Array.append args [|"--test:GraphBasedChecking"|]
59-
56+
| Method.ParallelCheckingOfBackedImplFiles -> Array.append args [| "--test:ParallelCheckingWithSignatureFilesOn" |]
57+
| Method.Graph -> Array.append args [| "--test:GraphBasedChecking" |]
58+
6059
printfn $"WorkingDir = {workingDir}"
6160
workingDir |> Option.iter (fun dir -> Environment.CurrentDirectory <- dir)
6261
args
@@ -101,10 +100,9 @@ let ``1. Test sequential type-checking`` (code: Codebase) =
101100
let ``2. Test parallelfs type-checking`` (code: Codebase) =
102101
let config = codebaseToConfig code Method.ParallelCheckingOfBackedImplFiles
103102
TestCompilerFromArgs config
104-
103+
105104
/// Before running this test, you must prepare the codebase by running the script 'FCS.prepare.ps1'
106105
[<TestCaseSource(nameof (codebases))>]
107106
let ``3. Test graph-based type-checking`` (code: Codebase) =
108107
let config = codebaseToConfig code Method.Graph
109108
TestCompilerFromArgs config
110-

tests/ParallelTypeCheckingTests/Tests/TestDependencyResolution.fs

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,104 +49,123 @@ open A
4949
let expectedEdges = [ "B.fs", [ "A.fs" ] ]
5050
assertGraphEqual deps expectedEdges
5151

52-
5352
[<Test>]
5453
let ``A top-level module with an attribute, belonging to a namespace, depends on another file that uses the same namespace`` () =
5554
let files =
5655
[|
57-
"A.fsi", """
56+
"A.fsi",
57+
"""
5858
namespace A.B.C
5959
type X = X of int
6060
"""
61-
"B.fsi", """
61+
"B.fsi",
62+
"""
6263
[<System.Obsolete("This is enough for the algorithm to consider this module AutoOpen")>]
6364
module public A.B.C.D
6465
val x: X
6566
"""
66-
|] |> buildFiles
67+
|]
68+
|> buildFiles
6769

6870
let deps = DependencyResolution.detectFileDependencies files
6971

70-
let expectedEdges = ["B.fsi", ["A.fsi"]]
72+
let expectedEdges = [ "B.fsi", [ "A.fsi" ] ]
7173
assertGraphEqual deps expectedEdges
7274

73-
7475
[<Test>]
75-
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi pair`` () =
76+
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi pair``
77+
()
78+
=
7679
let files =
7780
[|
78-
"A.fsi", """
81+
"A.fsi",
82+
"""
7983
module A.B.C1
8084
type X = X of int
8185
"""
82-
"B.fsi", """
86+
"B.fsi",
87+
"""
8388
module A.B.C2
8489
val x : C1.X -> unit
8590
"""
86-
|] |> buildFiles
91+
|]
92+
|> buildFiles
8793

8894
let deps = DependencyResolution.detectFileDependencies files
8995

90-
let expectedEdges = ["B.fsi", ["A.fsi"]]
96+
let expectedEdges = [ "B.fsi", [ "A.fsi" ] ]
9197
assertGraphEqual deps expectedEdges
9298

93-
9499
[<Test>]
95-
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fs, .fsi pair`` () =
100+
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fs, .fsi pair``
101+
()
102+
=
96103
let files =
97104
[|
98-
"A.fs", """
105+
"A.fs",
106+
"""
99107
module A.B.C1
100108
type X = X of int
101109
"""
102-
"B.fsi", """
110+
"B.fsi",
111+
"""
103112
module A.B.C2
104113
val x : C1.X -> unit
105114
"""
106-
|] |> buildFiles
115+
|]
116+
|> buildFiles
107117

108118
let deps = DependencyResolution.detectFileDependencies files
109119

110-
let expectedEdges = ["B.fsi", ["A.fs"]]
120+
let expectedEdges = [ "B.fsi", [ "A.fs" ] ]
111121
assertGraphEqual deps expectedEdges
112122

113-
114123
[<Test>]
115-
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi, .fs pair`` () =
124+
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi, .fs pair``
125+
()
126+
=
116127
let files =
117128
[|
118-
"A.fsi", """
129+
"A.fsi",
130+
"""
119131
module A.B.C1
120132
type X = X of int
121133
"""
122-
"B.fs", """
134+
"B.fs",
135+
"""
123136
module A.B.C2
124137
let x : C1.X -> unit = failwith ""
125138
"""
126-
|] |> buildFiles
139+
|]
140+
|> buildFiles
127141

128142
let deps = DependencyResolution.detectFileDependencies files
129143

130-
let expectedEdges = ["B.fs", ["A.fsi"]]
144+
let expectedEdges = [ "B.fs", [ "A.fsi" ] ]
131145
assertGraphEqual deps expectedEdges
132146

133147
[<Test>]
134-
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fs, .fs pair`` () =
148+
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fs, .fs pair``
149+
()
150+
=
135151
let files =
136152
[|
137-
"A.fs", """
153+
"A.fs",
154+
"""
138155
module A.B.C1
139156
type X = X of int
140157
"""
141-
"B.fs", """
158+
"B.fs",
159+
"""
142160
module A.B.C2
143161
let x : C1.X -> unit = failwith ""
144162
"""
145-
|] |> buildFiles
163+
|]
164+
|> buildFiles
146165

147166
let deps = DependencyResolution.detectFileDependencies files
148167

149-
let expectedEdges = ["B.fs", ["A.fs"]]
168+
let expectedEdges = [ "B.fs", [ "A.fs" ] ]
150169
assertGraphEqual deps expectedEdges
151170

152171
[<Test>]
@@ -343,7 +362,7 @@ let analyseResult (result: DepsResult) =
343362
// let makeDotFile (path : string) (graph : Graph<File>) : unit =
344363
// let g = DotGraph(directed=true)
345364
// g.Layout.Direction <- DotLayoutDirection.LeftToRight
346-
// let name (f : File) = $"{f.QualifiedName}.{Path.GetExtension(f.Name)}"
365+
// let name (f : File) = $"{f.QualifiedName}.{Path.GetExtension(f.Name)}"
347366
// graph
348367
// |> Graph.collectEdges
349368
// |> Array.iter (fun (a, b) -> g.Edges.Add(name a, name b) |> ignore)
@@ -356,7 +375,7 @@ let ``Analyse hardcoded files`` () =
356375
let deps = DependencyResolution.detectFileDependencies sampleFiles
357376
printfn "Detected file dependencies:"
358377
deps.Graph |> Graph.print
359-
// makeDotFile "graph.dot" deps.Graph
378+
// makeDotFile "graph.dot" deps.Graph
360379

361380
let private parseProjectAndGetSourceFiles (projectFile: string) =
362381
//let cacheDir = "."
@@ -420,5 +439,5 @@ let ``Analyse whole projects and print statistics`` (projectFile: string) =
420439
v |> Array.map (fun d -> graph.Graph[d].Length) |> Array.max)
421440

422441
printfn $"TotalDeps: {totalDeps}, topFirstDeps: {topFirstDeps}, diff: {totalDeps - topFirstDeps}"
423-
424-
// makeDotFile "FCS.deps.dot" graph.Graph
442+
443+
// makeDotFile "FCS.deps.dot" graph.Graph

0 commit comments

Comments
 (0)