Skip to content

Commit 5d25cd8

Browse files
author
David Ungar
committed
Print negative build decisions with -show-incremental
1 parent 38a6559 commit 5d25cd8

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

include/swift/Driver/DriverIncrementalRanges.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,10 @@ class SourceRangeBasedInfo {
9494
// MARK: scheduling jobs
9595
//==============================================================================
9696

97-
public:
98-
/// Return both the jobs to compile if using ranges, and also any jobs that
99-
/// must be compiled to use ranges in the future (because they were lacking
100-
/// supplementary output files).
101-
static std::pair<llvm::SmallPtrSet<const driver::Job *, 16>,
102-
llvm::SmallVector<const driver::Job *, 16>>
103-
neededCompileJobsForRangeBasedIncrementalCompilation(
104-
const llvm::StringMap<SourceRangeBasedInfo> &allInfos,
105-
std::vector<const driver::Job *>,
106-
function_ref<void(const driver::Job *, Twine)> noteBuilding);
107-
10897
public:
10998
static bool shouldScheduleCompileJob(
11099
const llvm::StringMap<SourceRangeBasedInfo> &allInfos,
111-
const driver::Job *, function_ref<void(Twine)>);
100+
const driver::Job *, function_ref<void(bool, Twine)>);
112101

113102
private:
114103
static Optional<bool> isFileNewerThan(StringRef lhs, StringRef rhs,
@@ -119,11 +108,11 @@ class SourceRangeBasedInfo {
119108

120109
bool didPrimaryParseAnyNonlocalNonprimaryChanges(
121110
StringRef primary, const llvm::StringMap<SourceRangeBasedInfo> &,
122-
function_ref<void(Twine)>) const;
111+
function_ref<void(bool, Twine)>) const;
123112

124113
bool wasEveryNonprimaryNonlocalChangeUnparsed(
125114
StringRef primary, const llvm::StringMap<SourceRangeBasedInfo> &,
126-
function_ref<void(Twine)>) const;
115+
function_ref<void(bool, Twine)>) const;
127116

128117
//==============================================================================
129118
// MARK: printing

lib/Driver/Compilation.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,19 @@ namespace driver {
258258
llvm::SmallDenseMap<const Job *, std::unique_ptr<llvm::Timer>, 16>
259259
DriverTimers;
260260

261-
void noteBuilding(const Job *cmd, const bool forRanges, StringRef reason) {
261+
void noteBuilding(const Job *cmd, const bool willBeBuilding,
262+
const bool forRanges, StringRef reason) {
262263
if (!Comp.getShowIncrementalBuildDecisions())
263264
return;
264265
if (ScheduledCommands.count(cmd))
265266
return;
266-
llvm::outs() << "Queuing "
267+
if (!Comp.getEnableSourceRangeDependencies() &&
268+
!Comp.CompareIncrementalSchemes && !willBeBuilding)
269+
return; // preserve legacy behavior
270+
const bool isHypothetical =
271+
Comp.getUseSourceRangeDependencies() == forRanges;
272+
llvm::outs() << (isHypothetical ? "Hypothetically: " : "")
273+
<< (willBeBuilding ? "Queuing " : "Skipping ")
267274
<< (forRanges ? "<Ranges> "
268275
: Comp.getEnableSourceRangeDependencies()
269276
? "<Dependencies> "
@@ -666,7 +673,7 @@ namespace driver {
666673

667674
for (const Job *Cmd : Dependents) {
668675
DeferredCommands.erase(Cmd);
669-
noteBuilding(Cmd, Comp.getUseSourceRangeDependencies(),
676+
noteBuilding(Cmd, true, Comp.getUseSourceRangeDependencies(),
670677
"because of dependencies discovered later");
671678
scheduleCommandIfNecessaryAndPossible(Cmd);
672679
}
@@ -753,8 +760,6 @@ namespace driver {
753760
return {};
754761
// FIXME: crude, could just use dependencies to schedule only those jobs
755762
// depending on the added tops
756-
assert(Comp.getEnableSourceRangeDependencies() &&
757-
"only implementing this for those");
758763
const size_t topsBefore = countTopLevelProvides(FinishedCmd);
759764

760765
SmallVector<const Job *, 16> jobsForDependencies;
@@ -999,17 +1004,23 @@ namespace driver {
9991004
llvm::SmallVector<const Job *, 16> neededJobs;
10001005
for (const Job *Cmd : Comp.getJobs()) {
10011006
if (SourceRangeBasedInfo::shouldScheduleCompileJob(
1002-
allSourceRangeInfo, Cmd,
1003-
[&](Twine why) { noteBuilding(Cmd, true, why.str()); }))
1007+
allSourceRangeInfo, Cmd, [&](const bool willBuild, Twine why) {
1008+
noteBuilding(Cmd, willBuild, true, why.str());
1009+
}))
10041010
neededJobs.push_back(Cmd);
10051011
}
10061012

10071013
llvm::SmallVector<const Job *, 16> jobsLackingSupplementaryOutputs;
10081014
for (const Job *Cmd : Comp.getJobs()) {
10091015
auto pri = Cmd->getFirstSwiftPrimaryInput();
1010-
if (pri.empty() || allSourceRangeInfo.count(pri))
1011-
continue;
1012-
noteBuilding(Cmd, true,
1016+
if (pri.empty())
1017+
if (allSourceRangeInfo.count(pri)) {
1018+
noteBuilding(
1019+
Cmd, false, true,
1020+
"already have source-range and compiled-source files.");
1021+
continue;
1022+
}
1023+
noteBuilding(Cmd, true, true,
10131024
"to create source-range and compiled-source files for the "
10141025
"next time when falling back from source-ranges");
10151026
jobsLackingSupplementaryOutputs.push_back(Cmd);
@@ -1140,9 +1151,10 @@ namespace driver {
11401151
}
11411152
LLVM_FALLTHROUGH;
11421153
case Job::Condition::RunWithoutCascading:
1143-
noteBuilding(Cmd, false, "(initial)");
1154+
noteBuilding(Cmd, true, false, "(initial)");
11441155
return true;
11451156
case Job::Condition::CheckDependencies:
1157+
noteBuilding(Cmd, false, false, "flie is up-to-date and output exists");
11461158
return false;
11471159
}
11481160
}
@@ -1167,7 +1179,8 @@ namespace driver {
11671179

11681180
for (auto *externalCmd :
11691181
llvm::makeArrayRef(AdditionalOutOfDateCommands).slice(firstSize)) {
1170-
noteBuilding(externalCmd, false, "because of external dependencies");
1182+
noteBuilding(externalCmd, true, false,
1183+
"because of external dependencies");
11711184
}
11721185
return AdditionalOutOfDateCommands;
11731186
}
@@ -1183,7 +1196,7 @@ namespace driver {
11831196
externalSwiftDeps, [&](const void *node) {
11841197
// Sadly, the non-experimental dependency graph is type-unsafe
11851198
const Job *externalCmd = reinterpret_cast<const Job *>(node);
1186-
noteBuilding(externalCmd, true,
1199+
noteBuilding(externalCmd, true, true,
11871200
"because of external dependencies");
11881201
results.push_back(externalCmd);
11891202
});
@@ -1218,7 +1231,7 @@ namespace driver {
12181231
IncrementalTracer);
12191232
}
12201233
for (auto *transitiveCmd : AdditionalOutOfDateCommands)
1221-
noteBuilding(transitiveCmd, false, "because of the initial set");
1234+
noteBuilding(transitiveCmd, true, false, "because of the initial set");
12221235

12231236
return AdditionalOutOfDateCommands;
12241237
}

lib/Driver/DriverIncrementalRanges.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,20 @@ Ranges SourceRangeBasedInfo::computeNonlocalChangedRanges(
219219
// MARK: scheduling
220220
//==============================================================================
221221

222-
223222
bool SourceRangeBasedInfo::shouldScheduleCompileJob(
224223
const llvm::StringMap<SourceRangeBasedInfo> &allInfos, const Job *Cmd,
225-
function_ref<void(Twine)> noteBuilding) {
224+
function_ref<void(bool, Twine)> noteBuilding) {
226225
const auto primary = Cmd->getFirstSwiftPrimaryInput();
227226
if (primary.empty())
228227
return false; // not a compile
229228

230229
auto iter = allInfos.find(primary);
231230
if (iter == allInfos.end()) {
232-
noteBuilding("(could not obtain range info from frontend)");
231+
noteBuilding(true, "(could not obtain range info from frontend)");
233232
return true;
234233
}
235234
if (!iter->second.changedRanges.empty()) {
236-
noteBuilding("(this file changed)");
235+
noteBuilding(true, "(this file changed)");
237236
return true;
238237
}
239238
return iter->second.didPrimaryParseAnyNonlocalNonprimaryChanges(
@@ -242,14 +241,14 @@ bool SourceRangeBasedInfo::shouldScheduleCompileJob(
242241

243242
bool SourceRangeBasedInfo::didPrimaryParseAnyNonlocalNonprimaryChanges(
244243
StringRef primary, const llvm::StringMap<SourceRangeBasedInfo> &allInfos,
245-
function_ref<void(Twine)> noteBuilding) const {
244+
function_ref<void(bool, Twine)> noteBuilding) const {
246245
return !wasEveryNonprimaryNonlocalChangeUnparsed(primary, allInfos,
247246
noteBuilding);
248247
}
249248

250249
bool SourceRangeBasedInfo::wasEveryNonprimaryNonlocalChangeUnparsed(
251250
StringRef primary, const llvm::StringMap<SourceRangeBasedInfo> &allInfos,
252-
function_ref<void(Twine)> noteBuilding) const {
251+
function_ref<void(bool, Twine)> noteBuilding) const {
253252

254253
const auto &myUnparsedRangesByNonPri =
255254
swiftRangesFileContents.unparsedRangesByNonPrimary;
@@ -261,18 +260,21 @@ bool SourceRangeBasedInfo::wasEveryNonprimaryNonlocalChangeUnparsed(
261260
auto unparsedRanges = myUnparsedRangesByNonPri.find(nonPri);
262261
const auto nonPriFilename = llvm::sys::path::filename(nonPri);
263262
if (unparsedRanges == myUnparsedRangesByNonPri.end()) {
264-
noteBuilding(Twine(nonPriFilename) +
265-
" changed non-locally but I have no unparsed ranges there");
263+
noteBuilding(
264+
true, Twine(nonPriFilename) +
265+
" changed non-locally but I have no unparsed ranges there");
266266
return false;
267267
}
268268
const auto whatChanged = SerializableSourceRange::findOutlierIfAny(
269269
nonPriInfo.nonlocalChangedRanges, unparsedRanges->second);
270270
if (whatChanged) {
271-
noteBuilding(Twine("(changed: ") + nonPriFilename + ":" +
272-
whatChanged->printString() + ")");
271+
noteBuilding(true, Twine("(changed: ") + nonPriFilename + ":" +
272+
whatChanged->printString() + ")");
273273
return false;
274274
}
275275
}
276+
noteBuilding(false,
277+
"nothing that this file parsed changed in any other file");
276278
return true;
277279
}
278280

0 commit comments

Comments
 (0)