Skip to content

Commit ae2bdd9

Browse files
authored
Parallel compilation of scripts (#19649)
* add scenario * remove script extra handling * include AnonModules * fix test * release notes
1 parent d977e96 commit ae2bdd9

5 files changed

Lines changed: 27 additions & 32 deletions

File tree

docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* Fix signature generation: SRTP constraints use postfix syntax that fails conformance, now uses explicit type param declarations. ([Issue #19594](https://github.com/dotnet/fsharp/issues/19594), [PR #19609](https://github.com/dotnet/fsharp/pull/19609))
4848
* Fix signature generation: type params with special characters missing backtick escaping. ([Issue #19595](https://github.com/dotnet/fsharp/issues/19595), [PR #19609](https://github.com/dotnet/fsharp/pull/19609))
4949
* Fix internal error when using custom attribute with `[<Optional>]` value type parameter and no `[<DefaultParameterValue>]`. ([Issue #8353](https://github.com/dotnet/fsharp/issues/8353), [PR #19484](https://github.com/dotnet/fsharp/pull/19484))
50+
* Fix parallel compilation of scripts ([PR #19649](https://github.com/dotnet/fsharp/pull/19649))
5051

5152
### Added
5253

src/Compiler/Driver/GraphChecking/DependencyResolution.fs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -254,31 +254,10 @@ let mkGraph (filePairs: FilePairMap) (files: FileInProject array) : Graph<FileIn
254254

255255
allDependencies
256256

257-
// If there is a script in the project, we just process sequentially all the files that may have been added as part of the script closure.
258-
// That means all files up to the last script file.
259-
let scriptCompilationLength =
260-
files
261-
|> Array.tryFindIndexBack (fun f -> f.IsScript)
262-
|> Option.map (fun idx -> idx + 1)
263-
|> Option.defaultValue 0
264-
265-
let sequentialPartForScriptCompilation =
266-
files
267-
|> Array.take scriptCompilationLength
268-
|> Array.map (fun file ->
269-
file.Idx,
270-
[|
271-
if file.Idx > 0 then
272-
file.Idx - 1
273-
|])
274-
275-
let normalPart =
257+
let graph =
276258
files
277-
|> Array.skip scriptCompilationLength
278259
|> Array.Parallel.map (fun file -> file.Idx, findDependencies file)
279-
280-
let graph =
281-
Array.append sequentialPartForScriptCompilation normalPart |> readOnlyDict
260+
|> readOnlyDict
282261

283262
let trie = trie |> Array.last |> snd
284263

src/Compiler/Driver/GraphChecking/TrieMapping.fs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,7 @@ let processSynModuleOrNamespace<'Decl>
158158
mkSingletonDict name { Current = current; Children = node } |> continuation)
159159
tail
160160

161-
if kind = SynModuleOrNamespaceKind.AnonModule then
162-
// We collect the child nodes from the decls
163-
decls
164-
|> List.choose (mkTrieForDeclaration idx)
165-
|> mkImmutableDictFromKeyValuePairs
166-
else
167-
visit id name
161+
visit id name
168162

169163
{
170164
Current = Root(ImmutableHashSet.empty ())

tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/Scenarios.fs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ module LibB
11051105
11061106
let append s i = s + string i
11071107
"""
1108-
(set [| 0 |])
1108+
Set.empty
11091109
sourceFile
11101110
"Run.fsx"
11111111
"""
@@ -1122,7 +1122,7 @@ module ScriptModule =
11221122
let a = inc 41
11231123
append s a
11241124
"""
1125-
(set [| 1 |])
1125+
(set [| 0; 1 |])
11261126
sourceFile
11271127
"Independent.fs"
11281128
"""
@@ -1150,6 +1150,24 @@ let value = Script.ScriptModule.compute "hi"
11501150
"""
11511151
(set [| 2 |])
11521152
]
1153+
scenario
1154+
"Loaded script referenced by full path without open"
1155+
[
1156+
sourceFile
1157+
"A.fsx"
1158+
"""
1159+
let value = 41
1160+
"""
1161+
Set.empty
1162+
sourceFile
1163+
"B.fsx"
1164+
"""
1165+
#load "A.fsx"
1166+
1167+
let result = A.value + 1
1168+
"""
1169+
(set [| 0 |])
1170+
]
11531171
scenario
11541172
"Sub-namespace opens parent namespace with types and modules"
11551173
[

tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/TrieMappingTests.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ module ``module`` =
490490
}
491491
|]
492492

493+
// Dive into the anonymous module created for Program.fs
494+
let trie = trie.Children["Program"]
495+
493496
Assert.Equal(1, trie.Children.Count)
494497
Assert.True(trie.Children.ContainsKey("module"))
495498

0 commit comments

Comments
 (0)