@@ -633,22 +633,22 @@ namespace driver {
633
633
static_cast <const BatchJob *>(FinishedCmd));
634
634
}
635
635
636
- SmallVector< const Job *, 16 > Dependents;
636
+ CommandSet Dependents;
637
637
if (!Comp.getUseSourceRangeDependencies ()) {
638
+ // Can just do the cheapest thing
638
639
if (!Comp.IncrementalComparator )
639
640
Dependents = subsequentJobsNeededForDeps (FinishedCmd, ReturnCode);
640
641
else {
641
- SmallVector< const Job *, 16 > DependentsForDeps;
642
+ CommandSet DependentsForDeps;
642
643
std::tie (Dependents, DependentsForDeps) =
643
- subsequentJobsNeededForRanges (FinishedCmd, ReturnCode);
644
+ subsequentJobsNeededForDepsOrRanges (FinishedCmd, ReturnCode);
644
645
Dependents = DependentsForDeps;
645
646
}
646
647
} else {
647
- SmallVector< const Job *, 16 > DependentsForDeps;
648
+ CommandSet DependentsForDeps;
648
649
std::tie (Dependents, DependentsForDeps) =
649
- subsequentJobsNeededForRanges (FinishedCmd, ReturnCode);
650
+ subsequentJobsNeededForDepsOrRanges (FinishedCmd, ReturnCode);
650
651
651
- // Will reload again, sigh
652
652
if (Comp.getShowIncrementalBuildDecisions () &&
653
653
(!DependentsForDeps.empty () || !Dependents.empty ())) {
654
654
llvm::outs () << " After completion of " << LogJob (FinishedCmd)
@@ -742,39 +742,43 @@ namespace driver {
742
742
// /
743
743
// / FIXME: too much global state floating around, e.g.
744
744
// / getIncrementalBuildEnabled
745
- SmallVector< const Job *, 16 >
746
- subsequentJobsNeededForDeps ( const Job *FinishedCmd, const int ReturnCode) {
745
+ CommandSet subsequentJobsNeededForDeps ( const Job *FinishedCmd,
746
+ const int ReturnCode) {
747
747
if (!Comp.getIncrementalBuildEnabled ())
748
748
return {};
749
749
SmallVector<const Job *, 16 > Dependents;
750
750
reloadAndRemarkDeps (FinishedCmd, ReturnCode, Dependents);
751
- return Dependents;
751
+ CommandSet DepSet;
752
+ for (const Job *Cmd : Dependents)
753
+ DepSet.insert (Cmd);
754
+ return DepSet;
752
755
}
753
756
754
757
// Returns a pair of jobs needed when using ranges, and jobs needed
755
758
// when using dependencies.
756
- std::pair<SmallVector< const Job *, 16 >, SmallVector< const Job *, 16 > >
757
- subsequentJobsNeededForRanges (const Job *FinishedCmd,
758
- const int ReturnCode) {
759
+ std::pair<CommandSet, CommandSet >
760
+ subsequentJobsNeededForDepsOrRanges (const Job *FinishedCmd,
761
+ const int ReturnCode) {
759
762
760
763
if (!Comp.getIncrementalBuildEnabled ())
761
764
return {};
762
765
// FIXME: crude, could just use dependencies to schedule only those jobs
763
766
// depending on the added tops
764
767
const size_t topsBefore = countTopLevelProvides (FinishedCmd);
765
768
766
- SmallVector< const Job *, 16 > jobsForDependencies;
767
- reloadAndRemarkDeps (FinishedCmd, ReturnCode, jobsForDependencies );
769
+ CommandSet jobsForDependencies =
770
+ subsequentJobsNeededForDeps (FinishedCmd, ReturnCode);
768
771
769
772
const size_t topsAfter = countTopLevelProvides (FinishedCmd);
770
- const bool fallBack = topsAfter > topsBefore;
773
+ // TODO: see if new type was added outside of a struct (etc) body
774
+ const bool userAddedTopLevel = topsAfter > topsBefore;
771
775
772
776
// TODO: instead of scheduling *all* the jobs, could figure out
773
777
// which ones use the introduced top-level names and only schedule those.
774
778
// However, as it stands, the caller will fall back to the old
775
779
// dependency scheme in this case anyway.
776
- SmallVector< const Job *, 16 > jobsForRanges =
777
- fallBack ? jobsForDependencies : SmallVector< const Job *, 16 > ();
780
+ CommandSet jobsForRanges =
781
+ userAddedTopLevel ? jobsForDependencies : CommandSet ();
778
782
779
783
Comp.updateIncrementalComparison (jobsForDependencies, jobsForRanges, {});
780
784
@@ -880,10 +884,9 @@ namespace driver {
880
884
void scheduleFirstRoundJobsForIncrementalCompilation (
881
885
DependencyGraphT &DepGraph) {
882
886
883
- CommandSet compileJobsToSchedule;
884
- for (const Job *Cmd :
885
- computeFirstRoundCompileJobsForIncrementalCompilation (DepGraph))
886
- compileJobsToSchedule.insert (Cmd);
887
+ CommandSet compileJobsToSchedule =
888
+ computeFirstRoundCompileJobsForIncrementalCompilation (DepGraph);
889
+
887
890
for (const Job *Cmd : Comp.getJobs ()) {
888
891
if (Cmd->getFirstSwiftPrimaryInput ().empty () ||
889
892
compileJobsToSchedule.count (Cmd))
@@ -896,8 +899,7 @@ namespace driver {
896
899
// / Figure out the best strategy and return those jobs. May return
897
900
// / duplicates.
898
901
template <typename DependencyGraphT>
899
- llvm::SmallVector<const Job *, 16 >
900
- computeFirstRoundCompileJobsForIncrementalCompilation (
902
+ CommandSet computeFirstRoundCompileJobsForIncrementalCompilation (
901
903
DependencyGraphT &DepGraph) {
902
904
auto compileJobsToScheduleViaDependencies =
903
905
computeDependenciesAndGetNeededCompileJobs (DepGraph);
@@ -909,10 +911,8 @@ namespace driver {
909
911
return compileJobsToScheduleViaDependencies;
910
912
911
913
auto jobs = computeRangesAndGetNeededCompileJobs (DepGraph);
912
- llvm::SmallVector<const Job *, 16 > &compileJobsToScheduleViaSourceRanges =
913
- jobs.first ;
914
- llvm::SmallVector<const Job *, 16 >
915
- &jobsLackingSourceRangeSupplementaryOutputs = jobs.second ;
914
+ CommandSet &compileJobsToScheduleViaSourceRanges = jobs.first ;
915
+ CommandSet &jobsLackingSourceRangeSupplementaryOutputs = jobs.second ;
916
916
917
917
const bool shouldFallBack =
918
918
decideAndExplainWhetherToFallBackToDependencies (
@@ -937,21 +937,20 @@ namespace driver {
937
937
// Even if dependencies would not schedule these, we want them to run
938
938
// to create the supplementary outputs for next time.
939
939
for (const Job *Cmd : jobsLackingSourceRangeSupplementaryOutputs)
940
- compileJobsToScheduleWhenFallingBack.push_back (Cmd);
940
+ compileJobsToScheduleWhenFallingBack.insert (Cmd);
941
941
942
942
return compileJobsToScheduleWhenFallingBack;
943
943
}
944
944
945
945
bool decideAndExplainWhetherToFallBackToDependencies (
946
- const ArrayRef<const Job *> compileJobsToScheduleViaSourceRanges,
947
- const ArrayRef<const Job *>
948
- &jobsLackingSourceRangeSupplementaryOutputs) {
946
+ const CommandSet &compileJobsToScheduleViaSourceRanges,
947
+ const CommandSet &jobsLackingSourceRangeSupplementaryOutputs) {
949
948
if (!jobsLackingSourceRangeSupplementaryOutputs.empty ()) {
950
949
if (Comp.getShowIncrementalBuildDecisions ()) {
951
950
llvm::outs ()
952
951
<< " Using dependencies: At least one input ('"
953
952
<< llvm::sys::path::filename (
954
- jobsLackingSourceRangeSupplementaryOutputs.front ( )
953
+ (* jobsLackingSourceRangeSupplementaryOutputs.begin () )
955
954
->getFirstSwiftPrimaryInput ())
956
955
<< " ') lacks a supplementary output needed for the source "
957
956
" range strategy.\n Maybe dependencies can do better than "
@@ -961,10 +960,8 @@ namespace driver {
961
960
}
962
961
// Unless the source-range scheme would compile every file,
963
962
// it's likely a better bet.
964
- CommandSet uniqueJobs;
965
- for (const auto *J : compileJobsToScheduleViaSourceRanges)
966
- uniqueJobs.insert (J);
967
- if (uniqueJobs.size () < Comp.countSwiftInputs ()) {
963
+ if (compileJobsToScheduleViaSourceRanges.size () <
964
+ Comp.countSwiftInputs ()) {
968
965
if (Comp.getShowIncrementalBuildDecisions ())
969
966
llvm::outs () << " Using ranges\n " ;
970
967
return false ;
@@ -980,8 +977,7 @@ namespace driver {
980
977
// / must be compiled to use ranges in the future (because they were lacking
981
978
// / supplementary output files). May include duplicates.
982
979
template <typename DependencyGraphT>
983
- std::pair<llvm::SmallVector<const Job *, 16 >,
984
- llvm::SmallVector<const Job *, 16 >>
980
+ std::pair<CommandSet, CommandSet>
985
981
computeRangesAndGetNeededCompileJobs (DependencyGraphT &DepGraph) {
986
982
using namespace incremental_ranges ;
987
983
@@ -1001,16 +997,16 @@ namespace driver {
1001
997
// primaries, could just keep on.
1002
998
// load dependencies for external dependencies and interfacehashes
1003
999
1004
- llvm::SmallVector< const Job *, 16 > neededJobs;
1000
+ CommandSet neededJobs;
1005
1001
for (const Job *Cmd : Comp.getJobs ()) {
1006
1002
if (SourceRangeBasedInfo::shouldScheduleCompileJob (
1007
1003
allSourceRangeInfo, Cmd, [&](const bool willBuild, Twine why) {
1008
1004
noteBuilding (Cmd, willBuild, true , why.str ());
1009
1005
}))
1010
- neededJobs.push_back (Cmd);
1006
+ neededJobs.insert (Cmd);
1011
1007
}
1012
1008
1013
- llvm::SmallVector< const Job *, 16 > jobsLackingSupplementaryOutputs;
1009
+ CommandSet jobsLackingSupplementaryOutputs;
1014
1010
for (const Job *Cmd : Comp.getJobs ()) {
1015
1011
auto pri = Cmd->getFirstSwiftPrimaryInput ();
1016
1012
if (pri.empty ())
@@ -1024,21 +1020,23 @@ namespace driver {
1024
1020
noteBuilding (Cmd, true , true ,
1025
1021
" to create source-range and compiled-source files for the "
1026
1022
" next time when falling back from source-ranges" );
1027
- jobsLackingSupplementaryOutputs.push_back (Cmd);
1023
+ jobsLackingSupplementaryOutputs.insert (Cmd);
1028
1024
}
1029
1025
1030
1026
for (const Job *Cmd :
1031
1027
externallyDependentJobsForRangeBasedIncrementalCompilation (DepGraph))
1032
- neededJobs.push_back (Cmd);
1028
+ neededJobs.insert (Cmd);
1033
1029
1030
+ assert (neededJobs.size () <= Comp.countSwiftInputs ());
1031
+ assert (jobsLackingSupplementaryOutputs.size () <= Comp.countSwiftInputs ());
1034
1032
return {neededJobs, jobsLackingSupplementaryOutputs};
1035
1033
}
1036
1034
1037
1035
// / Return jobs to run if using dependencies, may include duplicates.
1038
1036
template <typename DependencyGraphT>
1039
- llvm::SmallVector< const Job *, 16 >
1037
+ CommandSet
1040
1038
computeDependenciesAndGetNeededCompileJobs (DependencyGraphT &DepGraph) {
1041
- llvm::SmallVector< const Job *, 16 > jobsToSchedule;
1039
+ CommandSet jobsToSchedule;
1042
1040
for (const Job *Cmd : Comp.getJobs ()) {
1043
1041
if (Cmd->getFirstSwiftPrimaryInput ().empty ())
1044
1042
continue ; // not Compile
@@ -1049,19 +1047,19 @@ namespace driver {
1049
1047
// Dependency load error, just run them all
1050
1048
for (const Job *Cmd : Comp.getJobs ()) {
1051
1049
if (!Cmd->getFirstSwiftPrimaryInput ().empty ())
1052
- jobsToSchedule.push_back (Cmd);
1050
+ jobsToSchedule.insert (Cmd);
1053
1051
}
1054
1052
return jobsToSchedule;
1055
1053
}
1056
1054
if (shouldSched.getValue ())
1057
- jobsToSchedule.push_back (Cmd);
1055
+ jobsToSchedule.insert (Cmd);
1058
1056
}
1059
1057
{
1060
1058
const auto additionalJobs =
1061
1059
additionalJobsToScheduleForDependencyBasedIncrementalCompilation (
1062
1060
DepGraph);
1063
1061
for (const auto *Cmd : additionalJobs)
1064
- jobsToSchedule.push_back (Cmd);
1062
+ jobsToSchedule.insert (Cmd);
1065
1063
}
1066
1064
return jobsToSchedule;
1067
1065
}
@@ -1165,7 +1163,7 @@ namespace driver {
1165
1163
SmallVector<const Job *, 16 >
1166
1164
additionalJobsToScheduleForDependencyBasedIncrementalCompilation (
1167
1165
DependencyGraphT &DepGraph) {
1168
- SmallVector< const Job *, 16 > AdditionalOutOfDateCommands =
1166
+ auto AdditionalOutOfDateCommands =
1169
1167
collectSecondaryJobsFromDependencyGraph (DepGraph);
1170
1168
1171
1169
size_t firstSize = AdditionalOutOfDateCommands.size ();
@@ -1958,8 +1956,9 @@ const char *Compilation::getAllSourcesPath() const {
1958
1956
}
1959
1957
1960
1958
void Compilation::IncrementalSchemeComparator::update (
1961
- const ArrayRef<const Job *> depJobs, const ArrayRef<const Job *> rangeJobs,
1962
- const ArrayRef<const Job *> lackingSuppJobs) {
1959
+ const CommandSet &depJobs,
1960
+ const CommandSet &rangeJobs,
1961
+ const CommandSet &lackingSuppJobs) {
1963
1962
for (const auto *cmd : depJobs)
1964
1963
DependencyCompileJobs.insert (cmd);
1965
1964
for (const auto *cmd : rangeJobs)
@@ -1995,9 +1994,9 @@ void Compilation::IncrementalSchemeComparator::outputComparison(
1995
1994
<< " supplementary output creation: " << SourceRangeLackingSuppJobs.size ()
1996
1995
<< " , "
1997
1996
<< " total: " << SwiftInputCount << " , "
1998
- << " scheme requested: "
1997
+ << " requested: "
1999
1998
<< (EnableSourceRangeDependencies ? " ranges" : " deps" ) << " , "
2000
- << " scheme used : " << (UseSourceRangeDependencies ? " ranges" : " deps" )
1999
+ << " using : " << (UseSourceRangeDependencies ? " ranges" : " deps" )
2001
2000
<< " \n " ;
2002
2001
}
2003
2002
0 commit comments