Skip to content

Commit c62e89c

Browse files
committed
Allow parallel project analysis with an environment variable
1 parent c19ebd5 commit c62e89c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Compiler/Driver/CompilerImports.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,13 @@ and [<Sealed>] TcImports
21522152
node {
21532153
CheckDisposed()
21542154

2155+
// TODO inject top-down from FSharpChecker
2156+
let runInParallel =
2157+
Environment.GetEnvironmentVariable("FCS_PARALLEL_PROJECTS_ANALYSIS")
2158+
|> bool.TryParse
2159+
|> function | true, runInParallel -> runInParallel | false, _ -> false
2160+
let runMethod = if runInParallel then NodeCode.Parallel else NodeCode.Sequential
2161+
21552162
let! results =
21562163
nms
21572164
|> List.map (fun nm ->
@@ -2162,7 +2169,7 @@ and [<Sealed>] TcImports
21622169
errorR (Error(FSComp.SR.buildProblemReadingAssembly (nm.resolvedPath, e.Message), nm.originalReference.Range))
21632170
return None
21642171
})
2165-
|> NodeCode.Sequential
2172+
|> runMethod
21662173

21672174
let dllinfos, phase2s = results |> Array.choose id |> List.ofArray |> List.unzip
21682175
fixupOrphanCcus ()

src/Compiler/Facilities/BuildGraph.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ type NodeCode private () =
182182

183183
return results.ToArray()
184184
}
185+
186+
static member Parallel (computations: NodeCode<'T> seq) =
187+
computations
188+
|> Seq.map (fun (Node x) -> x)
189+
|> Async.Parallel
190+
|> Node
185191

186192
type private AgentMessage<'T> = GetValue of AsyncReplyChannel<Result<'T, Exception>> * callerCancellationToken: CancellationToken
187193

@@ -331,7 +337,7 @@ type GraphNode<'T>(retryCompute: bool, computation: NodeCode<'T>) =
331337
// occur, making sure we are under the protection of the 'try'.
332338
// For example, NodeCode's 'try/finally' (TryFinally) uses async.TryFinally which does
333339
// implicit cancellation checks even before the try is entered, as do the
334-
// de-sugaring of 'do!' and other CodeCode constructs.
340+
// de-sugaring of 'do!' and other NodeCode constructs.
335341
let mutable taken = false
336342

337343
try

src/Compiler/Facilities/BuildGraph.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type NodeCode =
6565

6666
static member Sequential: computations: NodeCode<'T> seq -> NodeCode<'T[]>
6767

68+
static member Parallel: computations: (NodeCode<'T> seq) -> NodeCode<'T[]>
69+
6870
/// Execute the cancellable computation synchronously using the ambient cancellation token of
6971
/// the NodeCode.
7072
static member FromCancellable: computation: Cancellable<'T> -> NodeCode<'T>

0 commit comments

Comments
 (0)