Skip to content

Commit ed78898

Browse files
author
David Ungar
committed
Print out details of version mismatch.
1 parent 889da74 commit ed78898

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

Sources/SwiftDriver/IncrementalCompilation/IncrementalDependencyAndInputSetup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
218218
do {
219219
graphIfPresent = try ModuleDependencyGraph.read( from: dependencyGraphPath, info: self)
220220
}
221-
catch ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion {
221+
catch let ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion(expected, read) {
222222
diagnosticEngine.emit(
223-
warning: "Will not do cross-module incremental builds, wrong version of priors at '\(dependencyGraphPath)'")
223+
warning: "Will not do cross-module incremental builds, wrong version of priors; expected \(expected) but read \(read) at '\(dependencyGraphPath)'")
224224
graphIfPresent = nil
225225
}
226226
catch {

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ extension ModuleDependencyGraph {
487487
case badMagic
488488
case noRecordBlock
489489
case malformedMetadataRecord
490-
case mismatchedSerializedGraphVersion
490+
case mismatchedSerializedGraphVersion(expected: Version, read: Version)
491491
case unexpectedMetadataRecord
492492
case malformedFingerprintRecord
493493
case malformedIdentifierRecord
@@ -668,10 +668,15 @@ extension ModuleDependencyGraph {
668668
try Bitcode.read(bytes: data, using: &visitor)
669669
guard let major = visitor.majorVersion,
670670
let minor = visitor.minorVersion,
671-
visitor.compilerVersionString != nil,
672-
Version(Int(major), Int(minor), 0) == Self.serializedGraphVersion
671+
visitor.compilerVersionString != nil
673672
else {
674-
throw ReadError.mismatchedSerializedGraphVersion
673+
throw ReadError.malformedMetadataRecord
674+
}
675+
let readVersion = Version(Int(major), Int(minor), 0)
676+
guard readVersion == Self.serializedGraphVersion
677+
else {
678+
throw ReadError.mismatchedSerializedGraphVersion(
679+
expected: Self.serializedGraphVersion, read: readVersion)
675680
}
676681
let graph = visitor.finalizeGraph()
677682
info.reporter?.report("Read dependency graph", path)

Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker
2626
let fs = InMemoryFileSystem()
2727
let graph = Self.mockGraphCreator.mockUpAGraph()
2828
let currentVersion = ModuleDependencyGraph.serializedGraphVersion
29+
let alteredVersion = currentVersion.withAlteredMinor
2930
try graph.write(
3031
to: mockPath,
3132
on: fs,
3233
compilerVersion: "Swift 99",
33-
mockSerializedGraphVersion: currentVersion.withAlteredMinor)
34+
mockSerializedGraphVersion: alteredVersion)
3435
do {
3536
_ = try ModuleDependencyGraph.read(from: mockPath,
3637
info: .mock(fileSystem: fs))
3738
XCTFail("Should have thrown an exception")
3839
}
39-
catch ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion {
40+
catch let ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion(expected, read) {
41+
XCTAssertEqual(expected, currentVersion)
42+
XCTAssertEqual(read, alteredVersion)
4043
}
4144
catch {
4245
XCTFail("Threw an unexpected exception: \(error.localizedDescription)")

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ extension DiagVerifiable {
11901190
"Incremental compilation: Read dependency graph"
11911191
}
11921192
@DiagsBuilder var couldNotReadPriors: [Diagnostic.Message] {
1193-
.warning("Will not do cross-module incremental builds, wrong version of priors at '")
1193+
.warning("Will not do cross-module incremental builds, wrong version of priors; expected")
11941194
}
11951195
// MARK: - dependencies
11961196
@DiagsBuilder func fingerprintChanged(_ aspect: DependencyKey.DeclAspect, _ input: String) -> [Diagnostic.Message] {

0 commit comments

Comments
 (0)