Skip to content

Show version mismatch in -driver-show-incremental #5308

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
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
26 changes: 22 additions & 4 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ using InputInfoMap = Driver::InputInfoMap;

static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,
const InputFileList &inputs,
StringRef buildRecordPath) {
StringRef buildRecordPath,
bool ShowIncrementalBuildDecisions) {
// Treat a missing file as "no previous build".
auto buffer = llvm::MemoryBuffer::getFile(buildRecordPath);
if (!buffer)
Expand Down Expand Up @@ -260,6 +261,7 @@ static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,

// FIXME: LLVM's YAML support does incremental parsing in such a way that
// for-range loops break.
SmallString<64> CompilationRecordSwiftVersion;
for (auto i = topLevelMap->begin(), e = topLevelMap->end(); i != e; ++i) {
auto *key = cast<yaml::ScalarNode>(i->getKey());
StringRef keyStr = key->getValue(scratch);
Expand All @@ -274,7 +276,8 @@ static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,
// swift::version::Version::getCurrentLanguageVersion() here because any
// -swift-version argument is handled in the argsHashStr check that
// follows.
versionValid = (value->getValue(scratch)
CompilationRecordSwiftVersion = value->getValue(scratch);
versionValid = (CompilationRecordSwiftVersion
== version::getSwiftFullVersion(
version::Version::getCurrentLanguageVersion()));

Expand Down Expand Up @@ -325,8 +328,22 @@ static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,
}
}

if (!versionValid || !optionsMatch)
if (!versionValid) {
if (ShowIncrementalBuildDecisions) {
auto v = version::getSwiftFullVersion(
version::Version::getCurrentLanguageVersion());
llvm::outs() << "Incremental compilation has been disabled, due to a "
<< "compiler version mismatch.\n"
<< "\tCompiling with: " << v << "\n"
<< "\tPreviously compiled with: "
<< CompilationRecordSwiftVersion << "\n";
}
return true;
}

if (!optionsMatch) {
return true;
}

size_t numInputsFromPrevious = 0;
for (auto &inputPair : inputs) {
Expand Down Expand Up @@ -460,7 +477,8 @@ std::unique_ptr<Compilation> Driver::buildCompilation(

} else {
if (populateOutOfDateMap(outOfDateMap, ArgsHash, Inputs,
buildRecordPath)) {
buildRecordPath,
ShowIncrementalBuildDecisions)) {
// FIXME: Distinguish errors from "file removed", which is benign.
} else {
rebuildEverything = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Test that when:
//
// 1. Using -incremental -v -driver-show-incremental, and...
// 2. ...the Swift compiler version used to perform the incremental
// compilation differs the original compilation...
//
// ...then the driver prints a message indicating that incremental compilation
// is disabled.


// RUN: rm -rf %t && cp -r %S/Inputs/one-way/ %t
// RUN: %S/Inputs/touch.py 443865900 %t/*

// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
// RUN: cd %t && %swiftc_driver -driver-use-frontend-path %S/Inputs/update-dependencies.py -c ./main.swift ./other.swift -module-name main -incremental -v -driver-show-incremental -output-file-map %t/output.json | %FileCheck --check-prefix CHECK-INCREMENTAL %s
// CHECK-INCREMENTAL-NOT: Incremental compilation has been disabled
// CHECK-INCREMENTAL: Queuing main.swift (initial)

// RUN: echo '{version: "bogus", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
// RUN: cd %t && %swiftc_driver -driver-use-frontend-path %S/Inputs/update-dependencies.py -c ./main.swift ./other.swift -module-name main -incremental -v -driver-show-incremental -output-file-map %t/output.json | %FileCheck --check-prefix CHECK-VERSION-MISMATCH %s
// CHECK-VERSION-MISMATCH: Incremental compilation has been disabled
// CHECK-VERSION-MISMATCH: Compiling with:
// CHECK-VERSION-MISMATCH: Previously compiled with: bogus
// CHECK-VERSION-MISMATCH-NOT: Queuing main.swift (initial)