Skip to content

Commit 3e20672

Browse files
committed
[Explicit Module Builds] Add an instance of InterModuleDependencyGraph to the DriverExecutorWorkload
For possible clients to have access to the full module dependnecies info.
1 parent ba1d273 commit 3e20672

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ public struct Driver {
315315
/// Set during planning because needs the jobs to look at outputs.
316316
@_spi(Testing) public private(set) var incrementalCompilationState: IncrementalCompilationState? = nil
317317

318+
/// Nil if not running in explicit module build mode.
319+
/// Set during planning.
320+
var interModuleDependencyGraph: InterModuleDependencyGraph? = nil
321+
318322
/// The path of the SDK.
319323
public var absoluteSDKPath: AbsolutePath? {
320324
guard let path = frontendTargetInfo.sdkPath?.path else {
@@ -1674,6 +1678,7 @@ extension Driver {
16741678
try executor.execute(
16751679
workload: .init(allJobs,
16761680
incrementalCompilationState,
1681+
interModuleDependencyGraph,
16771682
continueBuildingAfterErrors: continueBuildingAfterErrors),
16781683
delegate: jobExecutionDelegate,
16791684
numParallelJobs: numParallelJobs ?? 1,

Sources/SwiftDriver/Execution/DriverExecutor.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public protocol DriverExecutor {
2929

3030
/// Execute multiple jobs, tracking job status using the provided execution delegate.
3131
/// Pass in the `IncrementalCompilationState` to allow for incremental compilation.
32+
/// Pass in the `InterModuleDependencyGraph` to allow for module dependency tracking.
3233
func execute(workload: DriverExecutorWorkload,
3334
delegate: JobExecutionDelegate,
3435
numParallelJobs: Int,
@@ -58,20 +59,24 @@ public struct DriverExecutorWorkload {
5859
case all([Job])
5960
case incremental(IncrementalCompilationState)
6061
}
62+
6163
public let kind: Kind
64+
public let interModuleDependencyGraph: InterModuleDependencyGraph?
6265

6366
public init(_ allJobs: [Job],
64-
_ incrementalCompilationState: IncrementalCompilationState?,
65-
continueBuildingAfterErrors: Bool
66-
) {
67-
self.continueBuildingAfterErrors = continueBuildingAfterErrors
68-
self.kind = incrementalCompilationState
69-
.map {.incremental($0)}
70-
?? .all(allJobs)
67+
_ incrementalCompilationState: IncrementalCompilationState?,
68+
_ interModuleDependencyGraph: InterModuleDependencyGraph?,
69+
continueBuildingAfterErrors: Bool) {
70+
self.continueBuildingAfterErrors = continueBuildingAfterErrors
71+
self.kind = incrementalCompilationState
72+
.map {.incremental($0)}
73+
?? .all(allJobs)
74+
self.interModuleDependencyGraph = interModuleDependencyGraph
7175
}
7276

73-
static public func all(_ jobs: [Job]) -> Self {
74-
.init(jobs, nil, continueBuildingAfterErrors: false)
77+
static public func all(_ jobs: [Job],
78+
_ interModuleDependencyGraph: InterModuleDependencyGraph? = nil) -> Self {
79+
.init(jobs, nil, interModuleDependencyGraph, continueBuildingAfterErrors: false)
7580
}
7681
}
7782

@@ -114,7 +119,7 @@ extension DriverExecutor {
114119
recordedInputModificationDates: [TypedVirtualPath: TimePoint]
115120
) throws {
116121
try execute(
117-
workload: .all(jobs),
122+
workload: .all(jobs, nil),
118123
delegate: delegate,
119124
numParallelJobs: numParallelJobs,
120125
forceResponseFiles: forceResponseFiles,

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public final class IncrementalCompilationState {
5353
internal init(
5454
driver: inout Driver,
5555
jobsInPhases: JobsInPhases,
56-
initialState: InitialStateForPlanning,
57-
interModuleDependencyGraph: InterModuleDependencyGraph?
56+
initialState: InitialStateForPlanning
5857
) throws {
5958
let reporter = initialState.incrementalOptions.contains(.showIncremental)
6059
? Reporter(diagnosticEngine: driver.diagnosticEngine,
@@ -68,12 +67,12 @@ public final class IncrementalCompilationState {
6867
initialState: initialState,
6968
jobsInPhases: jobsInPhases,
7069
driver: driver,
71-
interModuleDependencyGraph: interModuleDependencyGraph,
70+
interModuleDependencyGraph: driver.interModuleDependencyGraph,
7271
reporter: reporter)
7372
.compute(batchJobFormer: &driver)
7473

7574
self.info = initialState.graph.info
76-
self.upToDateInterModuleDependencyGraph = interModuleDependencyGraph
75+
self.upToDateInterModuleDependencyGraph = driver.interModuleDependencyGraph
7776
self.protectedState = ProtectedState(
7877
skippedCompileGroups: firstWave.initiallySkippedCompileGroups,
7978
initialState.graph,

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ extension Driver {
103103
try IncrementalCompilationState.computeIncrementalStateForPlanning(driver: &self)
104104

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

108108
// Compute the set of all jobs required to build this module
109109
let jobsInPhases = try computeJobsForPhasedStandardBuild(with: interModuleDependencyGraph)
@@ -115,8 +115,7 @@ extension Driver {
115115
incrementalCompilationState =
116116
try IncrementalCompilationState(driver: &self,
117117
jobsInPhases: jobsInPhases,
118-
initialState: initialState,
119-
interModuleDependencyGraph: interModuleDependencyGraph)
118+
initialState: initialState)
120119
} else {
121120
incrementalCompilationState = nil
122121
}
@@ -139,19 +138,17 @@ extension Driver {
139138
private mutating func computeInterModuleDependencyGraph(with initialIncrementalState:
140139
IncrementalCompilationState.InitialStateForPlanning?)
141140
throws -> InterModuleDependencyGraph? {
142-
let interModuleDependencyGraph: InterModuleDependencyGraph?
143141
if (parsedOptions.contains(.driverExplicitModuleBuild) ||
144142
parsedOptions.contains(.explainModuleDependency)) &&
145143
inputFiles.contains(where: { $0.type.isPartOfSwiftCompilation }) {
146144
// If the incremental build record's module dependency graph is up-to-date, we
147145
// can skip dependency scanning entirely.
148-
interModuleDependencyGraph =
146+
return
149147
try initialIncrementalState?.upToDatePriorInterModuleDependencyGraph ??
150148
gatherModuleDependencies()
151149
} else {
152-
interModuleDependencyGraph = nil
150+
return nil
153151
}
154-
return interModuleDependencyGraph
155152
}
156153

157154
/// Construct a build plan consisting of *all* jobs required for building the current module (non-incrementally).

Sources/swift-build-sdk-interfaces/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ do {
181181
}
182182
}
183183
do {
184-
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, continueBuildingAfterErrors: true),
184+
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, nil, continueBuildingAfterErrors: true),
185185
delegate: delegate, numParallelJobs: 128)
186186
} catch {
187187
// Only fail when critical failures happened.
@@ -191,7 +191,7 @@ do {
191191
}
192192
do {
193193
if !danglingJobs.isEmpty && delegate.shouldRunDanglingJobs {
194-
try executor.execute(workload: DriverExecutorWorkload.init(danglingJobs, nil, continueBuildingAfterErrors: true), delegate: delegate, numParallelJobs: 128)
194+
try executor.execute(workload: DriverExecutorWorkload.init(danglingJobs, nil, nil, continueBuildingAfterErrors: true), delegate: delegate, numParallelJobs: 128)
195195
}
196196
} catch {
197197
// Failing of dangling jobs don't fail the process.

0 commit comments

Comments
 (0)