Skip to content

Commit c2002ea

Browse files
committed
Show inputs mismatch in -driver-show-incremental
SR-2855 suggests `-driver-show-incremental` not only print information about why certain files are included in incremental compilation, but also print out why incremental compilation may be disabled altogether. Add a message for one such reason: when the inputs passed to the Swift compiler don't match the ones used previously.
1 parent 76b5afc commit c2002ea

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

lib/Driver/Driver.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,34 @@ static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,
356356
map[inputPair.second] = iter->getValue();
357357
}
358358

359-
// If a file was removed, we've lost its dependency info. Rebuild everything.
360-
// FIXME: Can we do better?
361-
return numInputsFromPrevious != previousInputs.size();
359+
if (numInputsFromPrevious == previousInputs.size()) {
360+
return false;
361+
} else {
362+
// If a file was removed, we've lost its dependency info. Rebuild everything.
363+
// FIXME: Can we do better?
364+
if (ShowIncrementalBuildDecisions) {
365+
llvm::StringSet<> inputArgs;
366+
for (auto &inputPair : inputs) {
367+
inputArgs.insert(inputPair.second->getValue());
368+
}
369+
370+
SmallVector<StringRef, 8> missingInputs;
371+
for (auto &previousInput : previousInputs) {
372+
auto previousInputArg = previousInput.getKey();
373+
if (inputArgs.find(previousInputArg) == inputArgs.end()) {
374+
missingInputs.push_back(previousInputArg);
375+
}
376+
}
377+
378+
llvm::outs() << "Incremental compilation has been disabled, because "
379+
<< "the following inputs were used in the previous "
380+
<< "compilation, but not in the current compilation:\n";
381+
for (auto &missing : missingInputs) {
382+
llvm::outs() << "\t" << missing << "\n";
383+
}
384+
}
385+
return true;
386+
}
362387
}
363388

364389
std::unique_ptr<Compilation> Driver::buildCompilation(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test that when:
2+
//
3+
// 1. Using -incremental -v -driver-show-incremental, and...
4+
// 2. ...the inputs passed to the Swift compiler version differ from the ones
5+
// used in 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+
// RUN: echo '{version: "'$(%swiftc_driver_plain -version | head -n1)'", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
14+
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: cd %t && %swiftc_driver -driver-use-frontend-path %S/Inputs/update-dependencies.py -c ./main.swift -module-name main -incremental -v -driver-show-incremental -output-file-map %t/output.json | %FileCheck --check-prefix CHECK-INPUTS-MISMATCH %s
20+
// CHECK-INPUTS-MISMATCH: Incremental compilation has been disabled{{.*}}inputs
21+
// CHECK-INPUTS-MISMATCH: ./other.swift
22+
// CHECK-INPUTS-MISMATCH-NOT: Queuing main.swift (initial)
23+

test/Driver/Dependencies/driver-show-incremental-swift-version.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
// RUN: echo '{version: "bogus", inputs: {"./main.swift": [443865900, 0], "./other.swift": [443865900, 0]}}' > %t/main~buildrecord.swiftdeps
2020
// 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
21+
// CHECK-VERSION-MISMATCH: Incremental compilation has been disabled{{.*}}compiler version mismatch
2222
// CHECK-VERSION-MISMATCH: Compiling with:
2323
// CHECK-VERSION-MISMATCH: Previously compiled with: bogus
2424
// CHECK-VERSION-MISMATCH-NOT: Queuing main.swift (initial)

0 commit comments

Comments
 (0)