Skip to content

[Explicit Module Builds] On an incremental build, skip re-building module dependencies when they are up-to-date #1239

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

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extension IncrementalCompilationState {
let fileSystem: FileSystem
let showJobLifecycle: Bool
let alwaysRebuildDependents: Bool
let rebuildExplicitModuleDependencies: Bool
/// If non-null outputs information for `-driver-show-incremental` for input path
private let reporter: Reporter?

Expand All @@ -49,6 +50,8 @@ extension IncrementalCompilationState {
self.showJobLifecycle = driver.showJobLifecycle
self.alwaysRebuildDependents = initialState.incrementalOptions.contains(
.alwaysRebuildDependents)
self.rebuildExplicitModuleDependencies =
initialState.maybeUpToDatePriorInterModuleDependencyGraph != nil ? false : true
self.reporter = reporter
}

Expand Down Expand Up @@ -122,6 +125,11 @@ extension IncrementalCompilationState.FirstWaveComputer {
: compileGroups[input]
}

// If module dependencies are known to be up-to-date, do not rebuild them
let mandatoryBeforeCompilesJobs = self.rebuildExplicitModuleDependencies ?
jobsInPhases.beforeCompiles :
jobsInPhases.beforeCompiles.filter { $0.kind != .generatePCM && $0.kind != .compileModuleFromInterface }

let batchedCompilationJobs = try batchJobFormer.formBatchedJobs(
mandatoryCompileGroupsInOrder.flatMap {$0.allJobs()},
showJobLifecycle: showJobLifecycle)
Expand All @@ -130,7 +138,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
// we can skip running `beforeCompiles` jobs if we also ensure that none of the `afterCompiles` jobs
// have any dependencies on them.
let skipAllJobs = batchedCompilationJobs.isEmpty ? !nonVerifyAfterCompileJobsDependOnBeforeCompileJobs() : false
let mandatoryJobsInOrder = skipAllJobs ? [] : jobsInPhases.beforeCompiles + batchedCompilationJobs
let mandatoryJobsInOrder = skipAllJobs ? [] : mandatoryBeforeCompilesJobs + batchedCompilationJobs
return (initiallySkippedCompileGroups: initiallySkippedCompileGroups,
mandatoryJobsInOrder: mandatoryJobsInOrder)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension IncrementalCompilationState {
/// Record about existence and time of the last compile.
let maybeBuildRecord: BuildRecord?
/// Record about the compiled module's module dependencies from the last compile.
let maybeInterModuleDependencyGraph: InterModuleDependencyGraph?
let maybeUpToDatePriorInterModuleDependencyGraph: InterModuleDependencyGraph?
/// A set of inputs invalidated by external changes.
let inputsInvalidatedByExternals: TransitivelyInvalidatedSwiftSourceFileSet
/// Compiler options related to incremental builds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ extension IncrementalCompilationState {
return InitialStateForPlanning(
graph: graph, buildRecordInfo: buildRecordInfo,
maybeBuildRecord: maybeBuildRecord,
maybeInterModuleDependencyGraph: maybeInterModuleDependencyGraph,
maybeUpToDatePriorInterModuleDependencyGraph: maybeInterModuleDependencyGraph,
inputsInvalidatedByExternals: inputsInvalidatedByExternals,
incrementalOptions: options, buildStartTime: buildStartTime,
buildEndTime: buildEndTime)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension Driver {
let interModuleDependencyGraph: InterModuleDependencyGraph?
if parsedOptions.contains(.driverExplicitModuleBuild) {
interModuleDependencyGraph =
try initialIncrementalState?.maybeInterModuleDependencyGraph ??
try initialIncrementalState?.maybeUpToDatePriorInterModuleDependencyGraph ??
gatherModuleDependencies()
} else {
interModuleDependencyGraph = nil
Expand Down
5 changes: 0 additions & 5 deletions Tests/SwiftDriverTests/IncrementalCompilationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,6 @@ extension IncrementalCompilationTests {
implicitBuildRemarks
readInterModuleGraph
interModuleDependencyGraphUpToDate
// TODO: We can do better, but for now make sure the jobs are still run
// even if the graph is up-to-date
compilingExplicitClangDependency("SwiftShims")
compilingExplicitSwiftDependency("Swift")
compilingExplicitSwiftDependency("SwiftOnoneSupport")
}

touch("main")
Expand Down