@@ -437,11 +437,9 @@ namespace driver {
437
437
// / invalidated by any new dependency edges introduced by it. If reloading
438
438
// / fails, this can cause deferred jobs to be immediately scheduled.
439
439
440
- template <unsigned N>
441
- void reloadAndRemarkDeps (const Job *FinishedCmd, int ReturnCode,
442
- SmallVector<const Job *, N> &Dependents,
440
+ std::vector<const Job*>
441
+ reloadAndRemarkDeps (const Job *FinishedCmd, int ReturnCode,
443
442
const bool forRanges) {
444
-
445
443
const CommandOutput &Output = FinishedCmd->getOutput ();
446
444
StringRef DependenciesFile =
447
445
Output.getAdditionalOutputForType (file_types::TY_SwiftDeps);
@@ -454,7 +452,7 @@ namespace driver {
454
452
// not using either of those right now, and this logic should probably
455
453
// be revisited when we are.
456
454
assert (FinishedCmd->getCondition () == Job::Condition::Always);
457
- return ;
455
+ return {} ;
458
456
}
459
457
// If we have a dependency file /and/ the frontend task exited normally,
460
458
// we can be discerning about what downstream files to rebuild.
@@ -470,61 +468,61 @@ namespace driver {
470
468
471
469
switch (loadDepGraphFromPath (FinishedCmd, DependenciesFile,
472
470
Comp.getDiags (), forRanges)) {
473
- case CoarseGrainedDependencyGraphImpl ::LoadResult::HadError:
474
- if (ReturnCode == EXIT_SUCCESS) {
475
- dependencyLoadFailed (DependenciesFile);
476
- // Better try compiling whatever was waiting on more info.
477
- for ( const Job *Cmd : DeferredCommands)
478
- scheduleCommandIfNecessaryAndPossible (Cmd);
479
- DeferredCommands. clear ();
480
- Dependents. clear ( );
481
- } // else, let the next build handle it.
471
+ case CoarseGrainedDependencyGraph ::LoadResult::HadError:
472
+ if (ReturnCode != EXIT_SUCCESS)
473
+ // let the next build handle it.
474
+ break ;
475
+ dependencyLoadFailed (DependenciesFile);
476
+ // Better try compiling whatever was waiting on more info.
477
+ for ( const Job *Cmd : DeferredCommands)
478
+ scheduleCommandIfNecessaryAndPossible (Cmd );
479
+ DeferredCommands. clear ();
482
480
break ;
483
- case CoarseGrainedDependencyGraphImpl::LoadResult::UpToDate:
481
+
482
+ case CoarseGrainedDependencyGraph::LoadResult::UpToDate:
484
483
if (!wasCascading)
485
484
break ;
486
485
LLVM_FALLTHROUGH;
487
- case CoarseGrainedDependencyGraphImpl ::LoadResult::AffectsDownstream:
488
- markTransitiveInDepGraph (Dependents, FinishedCmd, forRanges,
486
+ case CoarseGrainedDependencyGraph ::LoadResult::AffectsDownstream:
487
+ return markTransitiveInDepGraph (FinishedCmd, forRanges,
489
488
IncrementalTracer);
490
- break ;
491
489
}
492
- } else {
493
- // If there's an abnormal exit (a crash), assume the worst.
494
- switch (FinishedCmd->getCondition ()) {
495
- case Job::Condition::NewlyAdded:
496
- // The job won't be treated as newly added next time. Conservatively
497
- // mark it as affecting other jobs, because some of them may have
498
- // completed already.
499
- markTransitiveInDepGraph (Dependents, FinishedCmd, forRanges,
500
- IncrementalTracer);
501
- break ;
502
- case Job::Condition::Always:
503
- // Any incremental task that shows up here has already been marked;
504
- // we didn't need to wait for it to finish to start downstream
505
- // tasks.
506
- assert (isMarkedInDepGraph (FinishedCmd, forRanges));
507
- break ;
508
- case Job::Condition::RunWithoutCascading:
509
- // If this file changed, it might have been a non-cascading change
510
- // and it might not. Unfortunately, the interface hash has been
511
- // updated or compromised, so we don't actually know anymore; we
512
- // have to conservatively assume the changes could affect other
513
- // files.
514
- markTransitiveInDepGraph (Dependents, FinishedCmd, forRanges,
515
- IncrementalTracer);
516
- break ;
517
- case Job::Condition::CheckDependencies:
518
- // If the only reason we're running this is because something else
519
- // changed, then we can trust the dependency graph as to whether
520
- // it's a cascading or non-cascading change. That is, if whatever
521
- // /caused/ the error isn't supposed to affect other files, and
522
- // whatever /fixes/ the error isn't supposed to affect other files,
523
- // then there's no need to recompile any other inputs. If either of
524
- // those are false, we /do/ need to recompile other inputs.
525
- break ;
526
- }
490
+ return {};
527
491
}
492
+ // If there's an abnormal exit (a crash), assume the worst.
493
+ switch (FinishedCmd->getCondition ()) {
494
+ case Job::Condition::NewlyAdded:
495
+ // The job won't be treated as newly added next time. Conservatively
496
+ // mark it as affecting other jobs, because some of them may have
497
+ // completed already.
498
+ return markTransitiveInDepGraph (FinishedCmd, forRanges,
499
+ IncrementalTracer);
500
+ case Job::Condition::Always:
501
+ // Any incremental task that shows up here has already been marked;
502
+ // we didn't need to wait for it to finish to start downstream
503
+ // tasks.
504
+ assert (isMarkedInDepGraph (FinishedCmd, forRanges));
505
+ break ;
506
+ case Job::Condition::RunWithoutCascading:
507
+ // If this file changed, it might have been a non-cascading change
508
+ // and it might not. Unfortunately, the interface hash has been
509
+ // updated or compromised, so we don't actually know anymore; we
510
+ // have to conservatively assume the changes could affect other
511
+ // files.
512
+ return markTransitiveInDepGraph (FinishedCmd, forRanges,
513
+ IncrementalTracer);
514
+
515
+ case Job::Condition::CheckDependencies:
516
+ // If the only reason we're running this is because something else
517
+ // changed, then we can trust the dependency graph as to whether
518
+ // it's a cascading or non-cascading change. That is, if whatever
519
+ // /caused/ the error isn't supposed to affect other files, and
520
+ // whatever /fixes/ the error isn't supposed to affect other files,
521
+ // then there's no need to recompile any other inputs. If either of
522
+ // those are false, we /do/ need to recompile other inputs.
523
+ break ;
524
+ }
525
+ return {};
528
526
}
529
527
530
528
// / Check to see if a job produced a zero-length serialized diagnostics
@@ -744,8 +742,7 @@ namespace driver {
744
742
const bool forRanges) {
745
743
if (!Comp.getIncrementalBuildEnabled ())
746
744
return {};
747
- SmallVector<const Job *, 16 > Dependents;
748
- reloadAndRemarkDeps (FinishedCmd, ReturnCode, Dependents, forRanges);
745
+ auto Dependents = reloadAndRemarkDeps (FinishedCmd, ReturnCode, forRanges);
749
746
CommandSet DepSet;
750
747
for (const Job *Cmd : Dependents)
751
748
DepSet.insert (Cmd);
@@ -1035,12 +1032,12 @@ namespace driver {
1035
1032
const auto loadResult = loadDepGraphFromPath (Cmd, DependenciesFile,
1036
1033
Comp.getDiags (), forRanges);
1037
1034
switch (loadResult) {
1038
- case CoarseGrainedDependencyGraphImpl ::LoadResult::HadError:
1035
+ case CoarseGrainedDependencyGraph ::LoadResult::HadError:
1039
1036
dependencyLoadFailed (DependenciesFile, /* Warn=*/ true );
1040
1037
return None;
1041
- case CoarseGrainedDependencyGraphImpl ::LoadResult::UpToDate:
1038
+ case CoarseGrainedDependencyGraph ::LoadResult::UpToDate:
1042
1039
return std::make_pair (Cmd->getCondition (), true );
1043
- case CoarseGrainedDependencyGraphImpl ::LoadResult::AffectsDownstream:
1040
+ case CoarseGrainedDependencyGraph ::LoadResult::AffectsDownstream:
1044
1041
if (Comp.getEnableFineGrainedDependencies ()) {
1045
1042
// The fine-grained graph reports a change, since it lumps new
1046
1043
// files together with new "Provides".
@@ -1106,15 +1103,16 @@ namespace driver {
1106
1103
}
1107
1104
}
1108
1105
1109
- SmallVector< const Job *, 16 > collectCascadedJobsFromDependencyGraph (
1106
+ CommandSet collectCascadedJobsFromDependencyGraph (
1110
1107
const CommandSet &InitialCascadingCommands, const bool forRanges) {
1111
- SmallVector< const Job *, 16 > CascadedJobs;
1108
+ CommandSet CascadedJobs;
1112
1109
// We scheduled all of the files that have actually changed. Now add the
1113
1110
// files that haven't changed, so that they'll get built in parallel if
1114
1111
// possible and after the first set of files if it's not.
1115
1112
for (auto *Cmd : InitialCascadingCommands) {
1116
- markTransitiveInDepGraph (CascadedJobs, Cmd, forRanges,
1117
- IncrementalTracer);
1113
+ for (const auto *transitiveCmd: markTransitiveInDepGraph (Cmd, forRanges,
1114
+ IncrementalTracer))
1115
+ CascadedJobs.insert (transitiveCmd);
1118
1116
}
1119
1117
for (auto *transitiveCmd : CascadedJobs)
1120
1118
noteBuilding (transitiveCmd, /* willBeBuilding=*/ true ,
@@ -1133,7 +1131,8 @@ namespace driver {
1133
1131
// If the dependency has been modified since the oldest built file,
1134
1132
// or if we can't stat it for some reason (perhaps it's been
1135
1133
// deleted?), trigger rebuilds through the dependency graph.
1136
- markExternalInDepGraph (ExternallyDependentJobs, dependency, forRanges);
1134
+ for (const Job * marked: markExternalInDepGraph (dependency, forRanges))
1135
+ ExternallyDependentJobs.push_back (marked);
1137
1136
});
1138
1137
for (auto *externalCmd : ExternallyDependentJobs) {
1139
1138
noteBuilding (externalCmd, /* willBeBuilding=*/ true ,
@@ -1574,15 +1573,12 @@ namespace driver {
1574
1573
return Dependencies;
1575
1574
}
1576
1575
1577
- template <unsigned N>
1578
- void markExternalInDepGraph (SmallVector<const driver::Job *, N> &uses,
1579
- StringRef externalDependency,
1576
+ std::vector<const Job*>
1577
+ markExternalInDepGraph (StringRef externalDependency,
1580
1578
const bool forRanges) {
1581
- if (Comp.getEnableFineGrainedDependencies ())
1582
- getFineGrainedDepGraph (forRanges).markExternal (uses,
1583
- externalDependency);
1584
- else
1585
- getDepGraph (forRanges).markExternal (uses, externalDependency);
1579
+ return Comp.getEnableFineGrainedDependencies ()
1580
+ ? getFineGrainedDepGraph (forRanges).markExternal (externalDependency)
1581
+ : getDepGraph (forRanges).markExternal (externalDependency);
1586
1582
}
1587
1583
1588
1584
bool markIntransitiveInDepGraph (const Job *Cmd, const bool forRanges) {
@@ -1600,15 +1596,13 @@ namespace driver {
1600
1596
: getDepGraph (forRanges).loadFromPath (Cmd, path, diags);
1601
1597
}
1602
1598
1603
- template <unsigned N>
1604
- void markTransitiveInDepGraph (
1605
- SmallVector<const Job *, N> &visited, const Job *Cmd,
1599
+ std::vector<const Job*> markTransitiveInDepGraph (
1600
+ const Job *Cmd,
1606
1601
const bool forRanges,
1607
1602
CoarseGrainedDependencyGraph::MarkTracer *tracer = nullptr ) {
1608
- if (Comp.getEnableFineGrainedDependencies ())
1609
- getFineGrainedDepGraph (forRanges).markTransitive (visited, Cmd, tracer);
1610
- else
1611
- getDepGraph (forRanges).markTransitive (visited, Cmd, tracer);
1603
+ return Comp.getEnableFineGrainedDependencies ()
1604
+ ? getFineGrainedDepGraph (forRanges).markTransitive (Cmd, tracer)
1605
+ : getDepGraph (forRanges).markTransitive (Cmd, tracer);
1612
1606
}
1613
1607
1614
1608
void addIndependentNodeToDepGraph (const Job *Cmd, const bool forRanges) {
0 commit comments