Skip to content

Commit 7a7f2b6

Browse files
committed
Revert "[Incremental Builds] Separately check whether we can skip 'emit-modul…"
This reverts commit 04e7999.
1 parent 04e7999 commit 7a7f2b6

File tree

3 files changed

+9
-106
lines changed

3 files changed

+9
-106
lines changed

Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,11 @@ extension IncrementalCompilationState.FirstWaveComputer {
134134
jobCreatingPch: jobCreatingPch)
135135

136136
// In the case where there are no compilation jobs to run on this build (no source-files were changed),
137-
// and the emit-module task does not need to be re-run, we can skip running `beforeCompiles` jobs if we
138-
// also ensure that none of the `afterCompiles` jobs have any dependencies on them.
139-
let skippingAllCompileJobs = batchedCompilationJobs.isEmpty
140-
let skipEmitModuleJobs = try skippingAllCompileJobs && computeCanSkipEmitModuleTasks(buildRecord)
141-
let skipAllJobs = skippingAllCompileJobs && skipEmitModuleJobs && !nonVerifyAfterCompileJobsDependOnBeforeCompileJobs()
142-
143-
let beforeCompileJobs: [Job]
144-
var skippedNonCompileJobs: [Job] = []
145-
if skipAllJobs {
146-
beforeCompileJobs = []
147-
skippedNonCompileJobs = jobsInPhases.beforeCompiles
148-
} else if skipEmitModuleJobs {
149-
beforeCompileJobs = jobsInPhases.beforeCompiles.filter { $0.kind != .emitModule }
150-
skippedNonCompileJobs.append(contentsOf: jobsInPhases.beforeCompiles.filter { $0.kind == .emitModule })
151-
} else {
152-
beforeCompileJobs = jobsInPhases.beforeCompiles
153-
}
137+
// we can skip running `beforeCompiles` jobs if we also ensure that none of the `afterCompiles` jobs
138+
// have any dependencies on them.
139+
let skipAllJobs = batchedCompilationJobs.isEmpty ? !nonVerifyAfterCompileJobsDependOnBeforeCompileJobs() : false
140+
let beforeCompileJobs = skipAllJobs ? [] : jobsInPhases.beforeCompiles
141+
var skippedNonCompileJobs = skipAllJobs ? jobsInPhases.beforeCompiles : []
154142

155143
// Schedule emitModule job together with verify module interface job.
156144
let afterCompileJobs = jobsInPhases.afterCompiles.compactMap { job -> Job? in
@@ -182,27 +170,6 @@ extension IncrementalCompilationState.FirstWaveComputer {
182170
}
183171
}
184172

185-
/// Figure out if the emit-module tasks are *not* mandatory. This functionality only runs if there are not actual
186-
/// compilation tasks to be run in this build, for example on an emit-module-only build.
187-
private func computeCanSkipEmitModuleTasks(_ buildRecord: BuildRecord) throws -> Bool {
188-
guard let emitModuleJob = jobsInPhases.beforeCompiles.first(where: { $0.kind == .emitModule }) else {
189-
return false // Nothing to skip, so no special handling is required
190-
}
191-
// If a non-emit-module task exists in 'beforeCompiles', it may be another kind of
192-
// changed dependency so we should re-run the module task as well
193-
guard jobsInPhases.beforeCompiles.allSatisfy({ $0.kind == .emitModule }) else {
194-
return false
195-
}
196-
// If any of the outputs do not exist, they must be re-computed
197-
guard try emitModuleJob.outputs.allSatisfy({ try fileSystem.exists($0.file) }) else {
198-
return false
199-
}
200-
201-
// Ensure that no output is older than any of the inputs
202-
let oldestOutputModTime: TimePoint = try emitModuleJob.outputs.map { try fileSystem.lastModificationTime(for: $0.file) }.min() ?? .distantPast
203-
return try emitModuleJob.inputs.swiftSourceFiles.allSatisfy({ try fileSystem.lastModificationTime(for: $0.typedFile.file) < oldestOutputModTime })
204-
}
205-
206173
/// Figure out which compilation inputs are *not* mandatory at the start
207174
private func computeInitiallySkippedCompilationInputs(
208175
inputsInvalidatedByExternals: TransitivelyInvalidatedSwiftSourceFileSet,
@@ -211,7 +178,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
211178
) -> Set<TypedVirtualPath> {
212179
let allCompileJobs = jobsInPhases.compileJobs
213180
// Input == source file
214-
let changedInputs = computeChangedInputs(buildRecord)
181+
let changedInputs = computeChangedInputs(moduleDependencyGraph, buildRecord)
215182

216183
if let reporter = reporter {
217184
for input in inputsInvalidatedByExternals {
@@ -307,6 +274,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
307274

308275
// Find the inputs that have changed since last compilation, or were marked as needed a build
309276
private func computeChangedInputs(
277+
_ moduleDependencyGraph: ModuleDependencyGraph,
310278
_ outOfDateBuildRecord: BuildRecord
311279
) -> [ChangedInput] {
312280
jobsInPhases.compileJobs.compactMap { job in

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
913913
try incrementalDriver.run(jobs: incrementalJobs)
914914
XCTAssertFalse(incrementalDriver.diagnosticEngine.hasErrors)
915915
let state = try XCTUnwrap(incrementalDriver.incrementalCompilationState)
916+
XCTAssertTrue(state.mandatoryJobsInOrder.contains { $0.kind == .emitModule })
916917
XCTAssertTrue(state.jobsAfterCompiles.contains { $0.kind == .verifyModuleInterface })
917918

918919
// TODO: emitModule job should run again if interface is deleted.
@@ -922,6 +923,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
922923
var reDriver = try Driver(args: invocationArguments + ["-color-diagnostics"])
923924
let _ = try reDriver.planBuild()
924925
let reState = try XCTUnwrap(reDriver.incrementalCompilationState)
926+
XCTAssertFalse(reState.mandatoryJobsInOrder.contains { $0.kind == .emitModule })
925927
XCTAssertFalse(reState.jobsAfterCompiles.contains { $0.kind == .verifyModuleInterface })
926928
}
927929
}

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -645,55 +645,6 @@ extension IncrementalCompilationTests {
645645
linking
646646
}
647647
}
648-
649-
func testExplicitIncrementalEmitModuleOnly() throws {
650-
guard let sdkArgumentsForTesting = try Driver.sdkArgumentsForTesting()
651-
else {
652-
throw XCTSkip("Cannot perform this test on this host")
653-
}
654-
655-
let args = [
656-
"swiftc",
657-
"-module-name", module,
658-
"-emit-module", "-emit-module-path",
659-
derivedDataPath.appending(component: module + ".swiftmodule").pathString,
660-
"-incremental",
661-
"-driver-show-incremental",
662-
"-driver-show-job-lifecycle",
663-
"-save-temps",
664-
"-output-file-map", OFM.pathString,
665-
"-no-color-diagnostics"
666-
] + inputPathsAndContents.map {$0.0.pathString}.sorted() + explicitBuildArgs + sdkArgumentsForTesting
667-
668-
// Initial build
669-
_ = try doABuildWithoutExpectations(arguments: args)
670-
671-
// Subsequent build, ensure module does not get re-emitted since inputs have not changed
672-
_ = try doABuild(
673-
whenAutolinking: autolinkLifecycleExpectedDiags,
674-
arguments: args
675-
) {
676-
readGraph
677-
explicitIncrementalScanReuseCache(serializedDepScanCachePath.pathString)
678-
explicitIncrementalScanCacheSerialized(serializedDepScanCachePath.pathString)
679-
queuingInitial("main", "other")
680-
}
681-
682-
touch("main")
683-
touch("other")
684-
// Subsequent build, ensure module re-emitted since inputs changed
685-
_ = try doABuild(
686-
whenAutolinking: autolinkLifecycleExpectedDiags,
687-
arguments: args
688-
) {
689-
readGraph
690-
explicitIncrementalScanReuseCache(serializedDepScanCachePath.pathString)
691-
explicitIncrementalScanCacheSerialized(serializedDepScanCachePath.pathString)
692-
queuingInitial("main", "other")
693-
emittingModule(module)
694-
schedulingPostCompileJobs
695-
}
696-
}
697648
}
698649

699650
extension IncrementalCompilationTests {
@@ -1819,14 +1770,6 @@ extension IncrementalCompilationTests {
18191770
}
18201771
}
18211772

1822-
private func doABuild(
1823-
whenAutolinking autolinkExpectedDiags: [Diagnostic.Message],
1824-
arguments: [String],
1825-
@DiagsBuilder expecting expectedDiags: () -> [Diagnostic.Message]
1826-
) throws -> Driver {
1827-
try doABuild(whenAutolinking: autolinkExpectedDiags, expecting: expectedDiags(), arguments: arguments)
1828-
}
1829-
18301773
private func doABuildWithoutExpectations(arguments: [String]) throws -> Driver {
18311774
// If not checking, print out the diagnostics
18321775
let diagnosticEngine = DiagnosticsEngine(handlers: [
@@ -1916,16 +1859,6 @@ extension DiagVerifiable {
19161859
@DiagsBuilder func explicitDependencyModuleOlderThanInput(_ dependencyModuleName: String) -> [Diagnostic.Message] {
19171860
"Dependency module \(dependencyModuleName) is older than input file"
19181861
}
1919-
@DiagsBuilder func startEmitModule(_ moduleName: String) -> [Diagnostic.Message] {
1920-
"Starting Emitting module for \(moduleName)"
1921-
}
1922-
@DiagsBuilder func finishEmitModule(_ moduleName: String) -> [Diagnostic.Message] {
1923-
"Finished Emitting module for \(moduleName)"
1924-
}
1925-
@DiagsBuilder func emittingModule(_ moduleName: String) -> [Diagnostic.Message] {
1926-
startEmitModule(moduleName)
1927-
finishEmitModule(moduleName)
1928-
}
19291862
@DiagsBuilder func startCompilingExplicitClangDependency(_ dependencyModuleName: String) -> [Diagnostic.Message] {
19301863
"Starting Compiling Clang module \(dependencyModuleName)"
19311864
}

0 commit comments

Comments
 (0)