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

[Explicit Module Builds] Add an instance of InterModuleDependencyGraph to the DriverExecutorWorkload #1530

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public struct Driver {
/// Set during planning because needs the jobs to look at outputs.
@_spi(Testing) public private(set) var incrementalCompilationState: IncrementalCompilationState? = nil

/// Nil if not running in explicit module build mode.
/// Set during planning.
var interModuleDependencyGraph: InterModuleDependencyGraph? = nil

/// The path of the SDK.
public var absoluteSDKPath: AbsolutePath? {
guard let path = frontendTargetInfo.sdkPath?.path else {
Expand Down Expand Up @@ -1664,6 +1668,7 @@ extension Driver {
try executor.execute(
workload: .init(allJobs,
incrementalCompilationState,
interModuleDependencyGraph,
continueBuildingAfterErrors: continueBuildingAfterErrors),
delegate: jobExecutionDelegate,
numParallelJobs: numParallelJobs ?? 1,
Expand Down
25 changes: 15 additions & 10 deletions Sources/SwiftDriver/Execution/DriverExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public protocol DriverExecutor {

/// Execute multiple jobs, tracking job status using the provided execution delegate.
/// Pass in the `IncrementalCompilationState` to allow for incremental compilation.
/// Pass in the `InterModuleDependencyGraph` to allow for module dependency tracking.
func execute(workload: DriverExecutorWorkload,
delegate: JobExecutionDelegate,
numParallelJobs: Int,
Expand Down Expand Up @@ -58,20 +59,24 @@ public struct DriverExecutorWorkload {
case all([Job])
case incremental(IncrementalCompilationState)
}

public let kind: Kind
public let interModuleDependencyGraph: InterModuleDependencyGraph?

public init(_ allJobs: [Job],
_ incrementalCompilationState: IncrementalCompilationState?,
continueBuildingAfterErrors: Bool
) {
self.continueBuildingAfterErrors = continueBuildingAfterErrors
self.kind = incrementalCompilationState
.map {.incremental($0)}
?? .all(allJobs)
_ incrementalCompilationState: IncrementalCompilationState?,
_ interModuleDependencyGraph: InterModuleDependencyGraph?,
continueBuildingAfterErrors: Bool) {
self.continueBuildingAfterErrors = continueBuildingAfterErrors
self.kind = incrementalCompilationState
.map {.incremental($0)}
?? .all(allJobs)
self.interModuleDependencyGraph = interModuleDependencyGraph
}

static public func all(_ jobs: [Job]) -> Self {
.init(jobs, nil, continueBuildingAfterErrors: false)
static public func all(_ jobs: [Job],
_ interModuleDependencyGraph: InterModuleDependencyGraph? = nil) -> Self {
.init(jobs, nil, interModuleDependencyGraph, continueBuildingAfterErrors: false)
}
}

Expand Down Expand Up @@ -114,7 +119,7 @@ extension DriverExecutor {
recordedInputModificationDates: [TypedVirtualPath: TimePoint]
) throws {
try execute(
workload: .all(jobs),
workload: .all(jobs, nil),
delegate: delegate,
numParallelJobs: numParallelJobs,
forceResponseFiles: forceResponseFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public final class IncrementalCompilationState {
internal init(
driver: inout Driver,
jobsInPhases: JobsInPhases,
initialState: InitialStateForPlanning,
interModuleDependencyGraph: InterModuleDependencyGraph?
initialState: InitialStateForPlanning
) throws {
let reporter = initialState.incrementalOptions.contains(.showIncremental)
? Reporter(diagnosticEngine: driver.diagnosticEngine,
Expand All @@ -68,12 +67,12 @@ public final class IncrementalCompilationState {
initialState: initialState,
jobsInPhases: jobsInPhases,
driver: driver,
interModuleDependencyGraph: interModuleDependencyGraph,
interModuleDependencyGraph: driver.interModuleDependencyGraph,
reporter: reporter)
.compute(batchJobFormer: &driver)

self.info = initialState.graph.info
self.upToDateInterModuleDependencyGraph = interModuleDependencyGraph
self.upToDateInterModuleDependencyGraph = driver.interModuleDependencyGraph
self.protectedState = ProtectedState(
skippedCompileGroups: firstWave.initiallySkippedCompileGroups,
initialState.graph,
Expand Down
11 changes: 4 additions & 7 deletions Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension Driver {
try IncrementalCompilationState.computeIncrementalStateForPlanning(driver: &self)

// For an explicit build, compute the inter-module dependency graph
let interModuleDependencyGraph = try computeInterModuleDependencyGraph(with: initialIncrementalState)
interModuleDependencyGraph = try computeInterModuleDependencyGraph(with: initialIncrementalState)

// Compute the set of all jobs required to build this module
let jobsInPhases = try computeJobsForPhasedStandardBuild(with: interModuleDependencyGraph)
Expand All @@ -115,8 +115,7 @@ extension Driver {
incrementalCompilationState =
try IncrementalCompilationState(driver: &self,
jobsInPhases: jobsInPhases,
initialState: initialState,
interModuleDependencyGraph: interModuleDependencyGraph)
initialState: initialState)
} else {
incrementalCompilationState = nil
}
Expand All @@ -139,19 +138,17 @@ extension Driver {
private mutating func computeInterModuleDependencyGraph(with initialIncrementalState:
IncrementalCompilationState.InitialStateForPlanning?)
throws -> InterModuleDependencyGraph? {
let interModuleDependencyGraph: InterModuleDependencyGraph?
if (parsedOptions.contains(.driverExplicitModuleBuild) ||
parsedOptions.contains(.explainModuleDependency)) &&
inputFiles.contains(where: { $0.type.isPartOfSwiftCompilation }) {
// If the incremental build record's module dependency graph is up-to-date, we
// can skip dependency scanning entirely.
interModuleDependencyGraph =
return
try initialIncrementalState?.upToDatePriorInterModuleDependencyGraph ??
gatherModuleDependencies()
} else {
interModuleDependencyGraph = nil
return nil
}
return interModuleDependencyGraph
}

/// Construct a build plan consisting of *all* jobs required for building the current module (non-incrementally).
Expand Down
4 changes: 2 additions & 2 deletions Sources/swift-build-sdk-interfaces/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ do {
}
}
do {
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, continueBuildingAfterErrors: true),
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, nil, continueBuildingAfterErrors: true),
delegate: delegate, numParallelJobs: 128)
} catch {
// Only fail when critical failures happened.
Expand All @@ -191,7 +191,7 @@ do {
}
do {
if !danglingJobs.isEmpty && delegate.shouldRunDanglingJobs {
try executor.execute(workload: DriverExecutorWorkload.init(danglingJobs, nil, continueBuildingAfterErrors: true), delegate: delegate, numParallelJobs: 128)
try executor.execute(workload: DriverExecutorWorkload.init(danglingJobs, nil, nil, continueBuildingAfterErrors: true), delegate: delegate, numParallelJobs: 128)
}
} catch {
// Failing of dangling jobs don't fail the process.
Expand Down