@@ -375,18 +375,19 @@ static bool getCompilationRecordPath(std::string &buildRecordPath,
375
375
return false ;
376
376
}
377
377
378
- static bool failedToReadOutOfDateMap (bool ShowIncrementalBuildDecisions,
379
- StringRef buildRecordPath,
380
- StringRef reason = " " ) {
378
+ static StringRef failedToReadOutOfDateMap (bool ShowIncrementalBuildDecisions,
379
+ StringRef buildRecordPath,
380
+ StringRef reason = " " ) {
381
+ std::string why = " malformed build record file" ;
382
+ if (!reason.empty ()) {
383
+ why += " " ;
384
+ why += reason;
385
+ }
381
386
if (ShowIncrementalBuildDecisions) {
382
- llvm::outs () << " Incremental compilation has been disabled due to "
383
- << " malformed build record file '" << buildRecordPath << " '." ;
384
- if (!reason.empty ()) {
385
- llvm::outs () << " " << reason;
386
- }
387
- llvm::outs () << " \n " ;
387
+ llvm::outs () << " Incremental compilation has been disabled due to " << why
388
+ << " '" << buildRecordPath << " '.\n " ;
388
389
}
389
- return true ;
390
+ return why ;
390
391
}
391
392
392
393
static SmallVector<StringRef, 8 > findRemovedInputs (
@@ -396,20 +397,19 @@ static SmallVector<StringRef, 8> findRemovedInputs(
396
397
static void dealWithRemovedInputs (ArrayRef<StringRef> removedInputs,
397
398
bool ShowIncrementalBuildDecisions);
398
399
399
- // / Returns true on error.
400
- static bool populateOutOfDateMap (InputInfoMap &map,
401
- llvm::sys::TimePoint<> &LastBuildTime,
402
- StringRef argsHashStr,
403
- const InputFileList &inputs,
404
- StringRef buildRecordPath,
405
- const bool EnableSourceRangeDependencies,
406
- const bool ShowIncrementalBuildDecisions) {
400
+ // / Returns why ignore incrementality
401
+ static StringRef
402
+ populateOutOfDateMap (InputInfoMap &map, llvm::sys::TimePoint<> &LastBuildTime,
403
+ StringRef argsHashStr, const InputFileList &inputs,
404
+ StringRef buildRecordPath,
405
+ const bool EnableSourceRangeDependencies,
406
+ const bool ShowIncrementalBuildDecisions) {
407
407
// Treat a missing file as "no previous build".
408
408
auto buffer = llvm::MemoryBuffer::getFile (buildRecordPath);
409
409
if (!buffer) {
410
410
if (ShowIncrementalBuildDecisions)
411
411
llvm::outs () << " Incremental compilation could not read build record.\n " ;
412
- return false ;
412
+ return " could not read build record " ;
413
413
}
414
414
415
415
namespace yaml = llvm::yaml;
@@ -499,7 +499,7 @@ static bool populateOutOfDateMap(InputInfoMap &map,
499
499
} else if (keyStr == compilation_record::getName (TopLevelKey::Options)) {
500
500
auto *value = dyn_cast<yaml::ScalarNode>(i->getValue ());
501
501
if (!value)
502
- return true ;
502
+ return " no name node in build record " ;
503
503
optionsMatch = (argsHashStr == value->getValue (scratch));
504
504
505
505
} else if (keyStr == compilation_record::getName (TopLevelKey::BuildTime)) {
@@ -512,7 +512,7 @@ static bool populateOutOfDateMap(InputInfoMap &map,
512
512
}
513
513
llvm::sys::TimePoint<> timeVal;
514
514
if (readTimeValue (i->getValue (), timeVal))
515
- return true ;
515
+ return " could not read time value in build record " ;
516
516
LastBuildTime = timeVal;
517
517
518
518
} else if (keyStr == compilation_record::getName (TopLevelKey::Inputs)) {
@@ -529,21 +529,21 @@ static bool populateOutOfDateMap(InputInfoMap &map,
529
529
for (auto i = inputMap->begin (), e = inputMap->end (); i != e; ++i) {
530
530
auto *key = dyn_cast<yaml::ScalarNode>(i->getKey ());
531
531
if (!key)
532
- return true ;
532
+ return " no input entry in build record " ;
533
533
534
534
auto *value = dyn_cast<yaml::SequenceNode>(i->getValue ());
535
535
if (!value)
536
- return true ;
536
+ return " no sequence node for input entry in build record " ;
537
537
538
538
using compilation_record::getInfoStatusForIdentifier;
539
539
auto previousBuildState =
540
540
getInfoStatusForIdentifier (value->getRawTag ());
541
541
if (!previousBuildState)
542
- return true ;
542
+ return " no previous build state in build record " ;
543
543
544
544
llvm::sys::TimePoint<> timeValue;
545
545
if (readTimeValue (value, timeValue))
546
- return true ;
546
+ return " could not read time value in build record " ;
547
547
548
548
auto inputName = key->getValue (scratch);
549
549
previousInputs[inputName] = { *previousBuildState, timeValue };
@@ -561,15 +561,15 @@ static bool populateOutOfDateMap(InputInfoMap &map,
561
561
<< " \t Previously compiled with: "
562
562
<< CompilationRecordSwiftVersion << " \n " ;
563
563
}
564
- return true ;
564
+ return " compiler version mismatch " ;
565
565
}
566
566
567
567
if (!optionsMatch) {
568
568
if (ShowIncrementalBuildDecisions) {
569
569
llvm::outs () << " Incremental compilation has been disabled, because "
570
570
<< " different arguments were passed to the compiler.\n " ;
571
571
}
572
- return true ;
572
+ return " different arguments passed to compiler " ;
573
573
}
574
574
575
575
unsigned numMatchingPreviouslyCompiledInputs = 0 ;
@@ -586,13 +586,14 @@ static bool populateOutOfDateMap(InputInfoMap &map,
586
586
auto const wereAnyInputsRemoved =
587
587
numMatchingPreviouslyCompiledInputs < previousInputs.size ();
588
588
if (!wereAnyInputsRemoved)
589
- return false ;
589
+ return " " ;
590
590
591
591
const auto removedInputs = findRemovedInputs (inputs, previousInputs);
592
592
assert (!removedInputs.empty ());
593
593
594
594
dealWithRemovedInputs (removedInputs, ShowIncrementalBuildDecisions);
595
- return true ; // recompile everything; could do better someday
595
+ return " an input was removed" ; // recompile everything; could do better
596
+ // someday
596
597
}
597
598
598
599
static SmallVector<StringRef, 8 > findRemovedInputs (
@@ -892,16 +893,16 @@ Driver::buildCompilation(const ToolChain &TC,
892
893
computeArgsHash (ArgsHash, *TranslatedArgList);
893
894
llvm::sys::TimePoint<> LastBuildTime = llvm::sys::TimePoint<>::min ();
894
895
InputInfoMap outOfDateMap;
895
- bool rebuildEverything = true ;
896
- if (Incremental && !buildRecordPath. empty ()) {
897
- if ( populateOutOfDateMap (outOfDateMap, LastBuildTime, ArgsHash, Inputs,
898
- buildRecordPath, EnableSourceRangeDependencies,
899
- ShowIncrementalBuildDecisions)) {
900
- // FIXME: Distinguish errors from "file removed", which is benign.
901
- } else {
902
- rebuildEverything = false ;
903
- }
904
- }
896
+ StringRef whyIgnoreIncrementallity =
897
+ !Incremental
898
+ ? " "
899
+ : buildRecordPath. empty ()
900
+ ? " no build record path "
901
+ : populateOutOfDateMap (outOfDateMap, LastBuildTime, ArgsHash,
902
+ Inputs, buildRecordPath,
903
+ EnableSourceRangeDependencies,
904
+ ShowIncrementalBuildDecisions);
905
+ // FIXME: Distinguish errors from "file removed", which is benign.
905
906
906
907
size_t DriverFilelistThreshold;
907
908
if (getFilelistThreshold (*TranslatedArgList, DriverFilelistThreshold, Diags))
@@ -994,7 +995,7 @@ Driver::buildCompilation(const ToolChain &TC,
994
995
// Construct the graph of Actions.
995
996
SmallVector<const Action *, 8 > TopLevelActions;
996
997
buildActions (TopLevelActions, TC, OI,
997
- rebuildEverything ? nullptr : &outOfDateMap , *C);
998
+ whyIgnoreIncrementallity. empty () ? &outOfDateMap : nullptr , *C);
998
999
999
1000
if (Diags.hadAnyError ())
1000
1001
return nullptr ;
@@ -1025,8 +1026,8 @@ Driver::buildCompilation(const ToolChain &TC,
1025
1026
1026
1027
// This has to happen after building jobs, because otherwise we won't even
1027
1028
// emit .swiftdeps files for the next build.
1028
- if (rebuildEverything )
1029
- C->disableIncrementalBuild ();
1029
+ if (!whyIgnoreIncrementallity. empty () )
1030
+ C->disableIncrementalBuild (whyIgnoreIncrementallity. str () );
1030
1031
1031
1032
if (Diags.hadAnyError ())
1032
1033
return nullptr ;
0 commit comments