Skip to content

Commit 617605c

Browse files
authored
Merge pull request #5308 from modocache/sr-2855-driver-show-incremental-version
2 parents dfca714 + 88ac618 commit 617605c

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

lib/Driver/Driver.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ using InputInfoMap = Driver::InputInfoMap;
196196

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

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

@@ -325,8 +328,22 @@ static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,
325328
}
326329
}
327330

328-
if (!versionValid || !optionsMatch)
331+
if (!versionValid) {
332+
if (ShowIncrementalBuildDecisions) {
333+
auto v = version::getSwiftFullVersion(
334+
version::Version::getCurrentLanguageVersion());
335+
llvm::outs() << "Incremental compilation has been disabled, due to a "
336+
<< "compiler version mismatch.\n"
337+
<< "\tCompiling with: " << v << "\n"
338+
<< "\tPreviously compiled with: "
339+
<< CompilationRecordSwiftVersion << "\n";
340+
}
329341
return true;
342+
}
343+
344+
if (!optionsMatch) {
345+
return true;
346+
}
330347

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

461478
} else {
462479
if (populateOutOfDateMap(outOfDateMap, ArgsHash, Inputs,
463-
buildRecordPath)) {
480+
buildRecordPath,
481+
ShowIncrementalBuildDecisions)) {
464482
// FIXME: Distinguish errors from "file removed", which is benign.
465483
} else {
466484
rebuildEverything = false;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test that when:
2+
//
3+
// 1. Using -incremental -v -driver-show-incremental, and...
4+
// 2. ...the Swift compiler version used to perform the incremental
5+
// compilation differs the original compilation...
6+
//
7+
// ...then the driver prints a message indicating that incremental compilation
8+
// is disabled.
9+
10+
11+
// RUN: rm -rf %t && cp -r %S/Inputs/one-way/ %t
12+
// RUN: %S/Inputs/touch.py 443865900 %t/*
13+
14+
// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
15+
// 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
16+
// CHECK-INCREMENTAL-NOT: Incremental compilation has been disabled
17+
// CHECK-INCREMENTAL: Queuing main.swift (initial)
18+
19+
// RUN: echo '{version: "bogus", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
20+
// 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
21+
// CHECK-VERSION-MISMATCH: Incremental compilation has been disabled
22+
// CHECK-VERSION-MISMATCH: Compiling with:
23+
// CHECK-VERSION-MISMATCH: Previously compiled with: bogus
24+
// CHECK-VERSION-MISMATCH-NOT: Queuing main.swift (initial)
25+

0 commit comments

Comments
 (0)