Skip to content

Commit c3d84f1

Browse files
committed
Merge remote-tracking branch 'origin/parallel-project-analysis' into otel_parallel
2 parents 0702fc1 + 4431af5 commit c3d84f1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/Compiler/Driver/CompilerImports.fs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,20 @@ and [<Sealed>] TcImports
21412141
node {
21422142
CheckDisposed()
21432143

2144+
// TODO inject top-down from FSharpChecker
2145+
let runInParallel =
2146+
Environment.GetEnvironmentVariable("FCS_PARALLEL_PROJECTS_ANALYSIS")
2147+
|> bool.TryParse
2148+
|> function
2149+
| true, runInParallel -> runInParallel
2150+
| false, _ -> false
2151+
2152+
let runMethod =
2153+
if runInParallel then
2154+
NodeCode.Parallel
2155+
else
2156+
NodeCode.Sequential
2157+
21442158
let! results =
21452159
nms
21462160
|> List.map (fun nm ->
@@ -2151,7 +2165,7 @@ and [<Sealed>] TcImports
21512165
errorR (Error(FSComp.SR.buildProblemReadingAssembly (nm.resolvedPath, e.Message), nm.originalReference.Range))
21522166
return None
21532167
})
2154-
|> NodeCode.Sequential
2168+
|> runMethod
21552169

21562170
let dllinfos, phase2s = results |> Array.choose id |> List.ofArray |> List.unzip
21572171
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)