Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel project analysis behind a feature flag #13521

Merged
merged 18 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Compiler/Driver/CompilerImports.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,20 @@ and [<Sealed>] TcImports
node {
CheckDisposed()

// TODO inject top-down from FSharpChecker
let runInParallel =
Environment.GetEnvironmentVariable("FCS_PARALLEL_PROJECTS_ANALYSIS")
|> bool.TryParse
|> function
| true, runInParallel -> runInParallel
| false, _ -> false

let runMethod =
if runInParallel then
NodeCode.Parallel
else
NodeCode.Sequential

let! results =
nms
|> List.map (fun nm ->
Expand All @@ -2162,7 +2176,7 @@ and [<Sealed>] TcImports
errorR (Error(FSComp.SR.buildProblemReadingAssembly (nm.resolvedPath, e.Message), nm.originalReference.Range))
return None
})
|> NodeCode.Sequential
|> runMethod

let dllinfos, phase2s = results |> Array.choose id |> List.ofArray |> List.unzip
fixupOrphanCcus ()
Expand Down
8 changes: 7 additions & 1 deletion src/Compiler/Facilities/BuildGraph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ type NodeCode private () =

return results.ToArray()
}

static member Parallel (computations: NodeCode<'T> seq) =
computations
|> Seq.map (fun (Node x) -> x)
|> Async.Parallel
|> Node

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

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

try
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Facilities/BuildGraph.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type NodeCode =

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

static member Parallel: computations: (NodeCode<'T> seq) -> NodeCode<'T[]>

/// Execute the cancellable computation synchronously using the ambient cancellation token of
/// the NodeCode.
static member FromCancellable: computation: Cancellable<'T> -> NodeCode<'T>
Expand Down