Skip to content

Commit

Permalink
Allow parallel project analysis with an environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Jul 17, 2022
1 parent c19ebd5 commit c62e89c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Compiler/Driver/CompilerImports.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,13 @@ 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 +2169,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

0 comments on commit c62e89c

Please sign in to comment.