Skip to content

Commit a9a55ab

Browse files
committed
[Explicit Module Builds] Treat binary Swift module explicit dependencies as always up-to-date
The driver does not have the capability to rebuild them, so there is no point to invalidating these dependency nodes. Crucially, if these dependencies are newer than some other dependency between the source module and it, it will still cause invalidation of dependencies which can and must be re-built. This change fixes the remaining case left by the initial attempt at this in swiftlang#1674.
1 parent 7e74ff6 commit a9a55ab

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,15 @@ internal extension InterModuleDependencyGraph {
357357
return false
358358
}
359359

360+
// We do not verify the binary module itself being out-of-date if we do not have a textual
361+
// interface it was built from, but we can safely treat it as up-to-date, particularly
362+
// because if it is newer than any of the modules they depend on it, they will
363+
// still get invalidated in the check below for whether a module has
364+
// any dependencies newer than it.
365+
if case .swiftPrebuiltExternal(_) = moduleID {
366+
return true
367+
}
368+
360369
// Check if a dependency of this module has a newer output than this module
361370
for dependencyId in checkedModuleInfo.directDependencies ?? [] {
362371
let dependencyInfo = try moduleInfo(of: dependencyId)
@@ -400,11 +409,6 @@ internal extension InterModuleDependencyGraph {
400409
}
401410
}
402411
case .swiftPrebuiltExternal(_):
403-
// We do not verify the binary module itself being out-of-date if we do not have a textual
404-
// interface it was built from, but we can safely treat it as up-to-date, particularly
405-
// because if it is newer than any of the modules they depend on it, they will
406-
// still get invalidated in the check above for whether a module has
407-
// any dependencies newer than it.
408412
return true;
409413
case .swiftPlaceholder(_):
410414
// TODO: This should never ever happen. Hard error?

TestInputs/ExplicitModuleBuilds/Swift/G.swiftinterface

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
import Swift
66
public func overlayFuncG() { }
77
#endif
8+
import D

Tests/SwiftDriverTests/CachingBuildTests.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ final class CachingBuildTests: XCTestCase {
302302
try checkCachingBuildJob(job: job, moduleId: .clang("G"),
303303
dependencyGraph: dependencyGraph)
304304
}
305+
else if relativeOutputPathFileName.starts(with: "D-") {
306+
try checkCachingBuildJob(job: job, moduleId: .clang("D"),
307+
dependencyGraph: dependencyGraph)
308+
}
305309
else if relativeOutputPathFileName.starts(with: "F-") {
306310
try checkCachingBuildJob(job: job, moduleId: .clang("F"),
307311
dependencyGraph: dependencyGraph)
@@ -555,6 +559,10 @@ final class CachingBuildTests: XCTestCase {
555559
try checkCachingBuildJob(job: job, moduleId: .clang("C"),
556560
dependencyGraph: dependencyGraph)
557561
}
562+
else if relativeOutputPathFileName.starts(with: "D-") {
563+
try checkCachingBuildJob(job: job, moduleId: .clang("D"),
564+
dependencyGraph: dependencyGraph)
565+
}
558566
else if relativeOutputPathFileName.starts(with: "G-") {
559567
try checkCachingBuildJob(job: job, moduleId: .clang("G"),
560568
dependencyGraph: dependencyGraph)
@@ -775,11 +783,11 @@ final class CachingBuildTests: XCTestCase {
775783
let expectedNumberOfDependencies: Int
776784
if driver.hostTriple.isMacOSX,
777785
driver.hostTriple.version(for: .macOS) < Triple.Version(11, 0, 0) {
778-
expectedNumberOfDependencies = 12
786+
expectedNumberOfDependencies = 13
779787
} else if driver.targetTriple.isWindows {
780-
expectedNumberOfDependencies = 14
788+
expectedNumberOfDependencies = 15
781789
} else {
782-
expectedNumberOfDependencies = 11
790+
expectedNumberOfDependencies = 12
783791
}
784792

785793
// Dispatch several iterations in parallel

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

+15-3
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ final class ExplicitModuleBuildTests: XCTestCase {
578578
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("C"),
579579
dependencyGraph: dependencyGraph)
580580
}
581+
else if relativeOutputPathFileName.starts(with: "D-") {
582+
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("D"),
583+
dependencyGraph: dependencyGraph)
584+
}
581585
else if relativeOutputPathFileName.starts(with: "G-") {
582586
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("G"),
583587
dependencyGraph: dependencyGraph)
@@ -719,6 +723,10 @@ final class ExplicitModuleBuildTests: XCTestCase {
719723
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("C"),
720724
dependencyGraph: dependencyGraph)
721725
}
726+
else if relativeOutputPathFileName.starts(with: "D-") {
727+
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("D"),
728+
dependencyGraph: dependencyGraph)
729+
}
722730
else if relativeOutputPathFileName.starts(with: "G-") {
723731
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("G"),
724732
dependencyGraph: dependencyGraph)
@@ -846,6 +854,10 @@ final class ExplicitModuleBuildTests: XCTestCase {
846854
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("C"),
847855
dependencyGraph: dependencyGraph)
848856
}
857+
else if relativeOutputPathFileName.starts(with: "D-") {
858+
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("D"),
859+
dependencyGraph: dependencyGraph)
860+
}
849861
else if relativeOutputPathFileName.starts(with: "G-") {
850862
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("G"),
851863
dependencyGraph: dependencyGraph)
@@ -1736,11 +1748,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
17361748
let expectedNumberOfDependencies: Int
17371749
if hostTriple.isMacOSX,
17381750
hostTriple.version(for: .macOS) < Triple.Version(11, 0, 0) {
1739-
expectedNumberOfDependencies = 12
1751+
expectedNumberOfDependencies = 13
17401752
} else if driver.targetTriple.isWindows {
1741-
expectedNumberOfDependencies = 14
1753+
expectedNumberOfDependencies = 15
17421754
} else {
1743-
expectedNumberOfDependencies = 11
1755+
expectedNumberOfDependencies = 12
17441756
}
17451757

17461758
// Dispatch several iterations in parallel

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,15 @@ extension IncrementalCompilationTests {
533533
try! localFileSystem.removeFileTree(try AbsolutePath(validating: explicitSwiftDependenciesPath.appending(component: "G.swiftinterface").pathString))
534534
try buildInitialState(checkDiagnostics: false, explicitModuleBuild: true)
535535

536-
// Touch one of the inputs to actually trigger the incremental build, so that we can ensure
537-
// no module deps get re-built
536+
// Touch one of the inputs to actually trigger the incremental build
538537
touch(inputPath(basename: "other"))
539538

539+
// Touch the output of a dependency of 'G', to ensure that it is newer than 'G', but 'G' still does not
540+
// get "invalidated",
541+
let nameOfDModule = try XCTUnwrap(modCacheEntries.first { $0.hasPrefix("D") && $0.hasSuffix(".pcm")})
542+
let pathToDModule = explicitModuleCacheDir.appending(component: nameOfDModule)
543+
touch(pathToDModule)
544+
540545
try doABuild(
541546
"Unchanged binary dependency (G)",
542547
checkDiagnostics: true,
@@ -563,7 +568,6 @@ extension IncrementalCompilationTests {
563568
reading(deps: "other")
564569
schedulingPostCompileJobs
565570
linking
566-
567571
}
568572
}
569573
}

0 commit comments

Comments
 (0)