Skip to content

Commit a5be24f

Browse files
authored
Merge pull request #1239 from artemcm/IncrementalSkipExplicitDependencies
[Explicit Module Builds] On an incremental build, skip re-building module dependencies when they are up-to-date
2 parents f0efe6c + 0250198 commit a5be24f

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension IncrementalCompilationState {
2727
let fileSystem: FileSystem
2828
let showJobLifecycle: Bool
2929
let alwaysRebuildDependents: Bool
30+
let rebuildExplicitModuleDependencies: Bool
3031
/// If non-null outputs information for `-driver-show-incremental` for input path
3132
private let reporter: Reporter?
3233

@@ -49,6 +50,8 @@ extension IncrementalCompilationState {
4950
self.showJobLifecycle = driver.showJobLifecycle
5051
self.alwaysRebuildDependents = initialState.incrementalOptions.contains(
5152
.alwaysRebuildDependents)
53+
self.rebuildExplicitModuleDependencies =
54+
initialState.maybeUpToDatePriorInterModuleDependencyGraph != nil ? false : true
5255
self.reporter = reporter
5356
}
5457

@@ -122,6 +125,11 @@ extension IncrementalCompilationState.FirstWaveComputer {
122125
: compileGroups[input]
123126
}
124127

128+
// If module dependencies are known to be up-to-date, do not rebuild them
129+
let mandatoryBeforeCompilesJobs = self.rebuildExplicitModuleDependencies ?
130+
jobsInPhases.beforeCompiles :
131+
jobsInPhases.beforeCompiles.filter { $0.kind != .generatePCM && $0.kind != .compileModuleFromInterface }
132+
125133
let batchedCompilationJobs = try batchJobFormer.formBatchedJobs(
126134
mandatoryCompileGroupsInOrder.flatMap {$0.allJobs()},
127135
showJobLifecycle: showJobLifecycle)
@@ -130,7 +138,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
130138
// we can skip running `beforeCompiles` jobs if we also ensure that none of the `afterCompiles` jobs
131139
// have any dependencies on them.
132140
let skipAllJobs = batchedCompilationJobs.isEmpty ? !nonVerifyAfterCompileJobsDependOnBeforeCompileJobs() : false
133-
let mandatoryJobsInOrder = skipAllJobs ? [] : jobsInPhases.beforeCompiles + batchedCompilationJobs
141+
let mandatoryJobsInOrder = skipAllJobs ? [] : mandatoryBeforeCompilesJobs + batchedCompilationJobs
134142
return (initiallySkippedCompileGroups: initiallySkippedCompileGroups,
135143
mandatoryJobsInOrder: mandatoryJobsInOrder)
136144
}

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension IncrementalCompilationState {
5353
/// Record about existence and time of the last compile.
5454
let maybeBuildRecord: BuildRecord?
5555
/// Record about the compiled module's module dependencies from the last compile.
56-
let maybeInterModuleDependencyGraph: InterModuleDependencyGraph?
56+
let maybeUpToDatePriorInterModuleDependencyGraph: InterModuleDependencyGraph?
5757
/// A set of inputs invalidated by external changes.
5858
let inputsInvalidatedByExternals: TransitivelyInvalidatedSwiftSourceFileSet
5959
/// Compiler options related to incremental builds.

Sources/SwiftDriver/IncrementalCompilation/IncrementalDependencyAndInputSetup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ extension IncrementalCompilationState {
330330
return InitialStateForPlanning(
331331
graph: graph, buildRecordInfo: buildRecordInfo,
332332
maybeBuildRecord: maybeBuildRecord,
333-
maybeInterModuleDependencyGraph: maybeInterModuleDependencyGraph,
333+
maybeUpToDatePriorInterModuleDependencyGraph: maybeInterModuleDependencyGraph,
334334
inputsInvalidatedByExternals: inputsInvalidatedByExternals,
335335
incrementalOptions: options, buildStartTime: buildStartTime,
336336
buildEndTime: buildEndTime)

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ extension Driver {
142142
let interModuleDependencyGraph: InterModuleDependencyGraph?
143143
if parsedOptions.contains(.driverExplicitModuleBuild) {
144144
interModuleDependencyGraph =
145-
try initialIncrementalState?.maybeInterModuleDependencyGraph ??
145+
try initialIncrementalState?.maybeUpToDatePriorInterModuleDependencyGraph ??
146146
gatherModuleDependencies()
147147
} else {
148148
interModuleDependencyGraph = nil

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,6 @@ extension IncrementalCompilationTests {
887887
implicitBuildRemarks
888888
readInterModuleGraph
889889
interModuleDependencyGraphUpToDate
890-
// TODO: We can do better, but for now make sure the jobs are still run
891-
// even if the graph is up-to-date
892-
compilingExplicitClangDependency("SwiftShims")
893-
compilingExplicitSwiftDependency("Swift")
894-
compilingExplicitSwiftDependency("SwiftOnoneSupport")
895890
}
896891

897892
touch("main")

0 commit comments

Comments
 (0)