@@ -156,16 +156,17 @@ Compilation::Compilation(DiagnosticEngine &Diags,
156
156
EmitExperimentalDependencyDotFileAfterEveryImport),
157
157
ExperimentalDependenciesIncludeIntrafileOnes(
158
158
ExperimentalDependenciesIncludeIntrafileOnes),
159
- EnableSourceRangeDependencies(EnableSourceRangeDependencies),
160
- CompareIncrementalSchemes(CompareIncrementalSchemes),
161
- CompareIncrementalSchemesPath(CompareIncrementalSchemesPath) {
159
+ EnableSourceRangeDependencies(EnableSourceRangeDependencies) {
160
+ if (CompareIncrementalSchemes)
161
+ IncrementalComparator.emplace (
162
+ EnableSourceRangeDependencies, UseSourceRangeDependencies,
163
+ CompareIncrementalSchemesPath, countSwiftInputs (), getDiags ());
162
164
};
163
165
// clang-format on
164
166
165
167
static bool writeFilelistIfNecessary (const Job *job, const ArgList &args,
166
168
DiagnosticEngine &diags);
167
169
168
- using CommandSet = llvm::SmallPtrSet<const Job *, 16 >;
169
170
using CommandSetVector = llvm::SetVector<const Job*>;
170
171
using BatchPartition = std::vector<std::vector<const Job*>>;
171
172
@@ -265,7 +266,7 @@ namespace driver {
265
266
if (ScheduledCommands.count (cmd))
266
267
return ;
267
268
if (!Comp.getEnableSourceRangeDependencies () &&
268
- !Comp.CompareIncrementalSchemes && !willBeBuilding)
269
+ !Comp.IncrementalComparator && !willBeBuilding)
269
270
return ; // preserve legacy behavior
270
271
const bool isHypothetical =
271
272
Comp.getUseSourceRangeDependencies () == forRanges;
@@ -634,7 +635,7 @@ namespace driver {
634
635
635
636
SmallVector<const Job *, 16 > Dependents;
636
637
if (!Comp.getUseSourceRangeDependencies ()) {
637
- if (!Comp.CompareIncrementalSchemes )
638
+ if (!Comp.IncrementalComparator )
638
639
Dependents = subsequentJobsNeededForDeps (FinishedCmd, ReturnCode);
639
640
else {
640
641
SmallVector<const Job *, 16 > DependentsForDeps;
@@ -775,10 +776,7 @@ namespace driver {
775
776
SmallVector<const Job *, 16 > jobsForRanges =
776
777
fallBack ? jobsForDependencies : SmallVector<const Job *, 16 >();
777
778
778
- if (fallBack)
779
- Comp.setFallingBackForComparison ();
780
-
781
- Comp.updateJobsForComparison (jobsForDependencies, jobsForRanges);
779
+ Comp.updateIncrementalComparison (jobsForDependencies, jobsForRanges, {});
782
780
783
781
return {jobsForRanges, jobsForDependencies};
784
782
}
@@ -882,7 +880,7 @@ namespace driver {
882
880
void scheduleFirstRoundJobsForIncrementalCompilation (
883
881
DependencyGraphT &DepGraph) {
884
882
885
- llvm::SmallPtrSet< const Job *, 16 > compileJobsToSchedule;
883
+ CommandSet compileJobsToSchedule;
886
884
for (const Job *Cmd :
887
885
computeFirstRoundCompileJobsForIncrementalCompilation (DepGraph))
888
886
compileJobsToSchedule.insert (Cmd);
@@ -904,8 +902,8 @@ namespace driver {
904
902
auto compileJobsToScheduleViaDependencies =
905
903
computeDependenciesAndGetNeededCompileJobs (DepGraph);
906
904
907
- const bool mustConsultRanges = Comp. getEnableSourceRangeDependencies () ||
908
- Comp.CompareIncrementalSchemes ;
905
+ const bool mustConsultRanges =
906
+ Comp. getEnableSourceRangeDependencies () || Comp.IncrementalComparator ;
909
907
910
908
if (!mustConsultRanges)
911
909
return compileJobsToScheduleViaDependencies;
@@ -921,30 +919,32 @@ namespace driver {
921
919
compileJobsToScheduleViaSourceRanges,
922
920
jobsLackingSourceRangeSupplementaryOutputs);
923
921
924
- Comp.updateJobsForComparison (compileJobsToScheduleViaDependencies,
925
- compileJobsToScheduleViaSourceRanges);
926
- if (shouldFallBack)
927
- Comp. setFallingBackForComparison ( );
922
+ Comp.updateIncrementalComparison (
923
+ compileJobsToScheduleViaDependencies,
924
+ compileJobsToScheduleViaSourceRanges,
925
+ jobsLackingSourceRangeSupplementaryOutputs );
928
926
929
927
if (!Comp.getEnableSourceRangeDependencies ())
930
928
return compileJobsToScheduleViaDependencies;
931
929
932
930
Comp.setUseSourceRangeDependencies (!shouldFallBack);
933
931
934
- if (shouldFallBack) {
935
- // Even if dependencies would not schedule these, we want them to run
936
- // to create the supplementary outputs for next time.
937
- for (const Job *Cmd : jobsLackingSourceRangeSupplementaryOutputs)
938
- compileJobsToScheduleViaDependencies.push_back (Cmd);
939
- }
940
- return shouldFallBack ? compileJobsToScheduleViaDependencies
941
- : compileJobsToScheduleViaSourceRanges;
932
+ if (!shouldFallBack)
933
+ return compileJobsToScheduleViaSourceRanges;
934
+
935
+ auto compileJobsToScheduleWhenFallingBack =
936
+ std::move (compileJobsToScheduleViaDependencies);
937
+ // Even if dependencies would not schedule these, we want them to run
938
+ // to create the supplementary outputs for next time.
939
+ for (const Job *Cmd : jobsLackingSourceRangeSupplementaryOutputs)
940
+ compileJobsToScheduleWhenFallingBack.push_back (Cmd);
941
+
942
+ return compileJobsToScheduleWhenFallingBack;
942
943
}
943
944
944
945
bool decideAndExplainWhetherToFallBackToDependencies (
945
- llvm::SmallVector<const Job *, 16 >
946
- &compileJobsToScheduleViaSourceRanges,
947
- const llvm::SmallVector<const Job *, 16 >
946
+ const ArrayRef<const Job *> compileJobsToScheduleViaSourceRanges,
947
+ const ArrayRef<const Job *>
948
948
&jobsLackingSourceRangeSupplementaryOutputs) {
949
949
if (!jobsLackingSourceRangeSupplementaryOutputs.empty ()) {
950
950
if (Comp.getShowIncrementalBuildDecisions ()) {
@@ -961,7 +961,7 @@ namespace driver {
961
961
}
962
962
// Unless the source-range scheme would compile every file,
963
963
// it's likely a better bet.
964
- llvm::SmallPtrSet< const Job *, 16 > uniqueJobs;
964
+ CommandSet uniqueJobs;
965
965
for (const auto *J : compileJobsToScheduleViaSourceRanges)
966
966
uniqueJobs.insert (J);
967
967
if (uniqueJobs.size () < Comp.countSwiftInputs ()) {
@@ -1921,7 +1921,8 @@ int Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
1921
1921
bool abnormalExit;
1922
1922
int result = performJobsImpl (abnormalExit, std::move (TQ));
1923
1923
1924
- outputComparison ();
1924
+ if (IncrementalComparator)
1925
+ IncrementalComparator->outputComparison ();
1925
1926
1926
1927
if (!SaveTemps) {
1927
1928
for (const auto &pathPair : TempFilePaths) {
@@ -1955,23 +1956,18 @@ const char *Compilation::getAllSourcesPath() const {
1955
1956
return AllSourceFilesPath;
1956
1957
}
1957
1958
1958
- template < typename DepJobsT, typename RangeJobsT>
1959
- void Compilation::updateJobsForComparison ( const DepJobsT & depJobs,
1960
- const RangeJobsT &rangeJobs ) {
1959
+ void Compilation::IncrementalSchemeComparator::update (
1960
+ const ArrayRef< const Job *> depJobs, const ArrayRef< const Job *> rangeJobs ,
1961
+ const ArrayRef< const Job *> lackingSuppJobs ) {
1961
1962
for (const auto *cmd : depJobs)
1962
1963
DependencyCompileJobs.insert (cmd);
1963
1964
for (const auto *cmd : rangeJobs)
1964
1965
SourceRangeCompileJobs.insert (cmd);
1966
+ for (const auto *cmd : lackingSuppJobs)
1967
+ SourceRangeLackingSuppJobs.insert (cmd);
1965
1968
}
1966
1969
1967
- void Compilation::setFallingBackForComparison () {
1968
- FallingBackToDependiesFromSourceRanges = true ;
1969
- }
1970
-
1971
- void Compilation::outputComparison () const {
1972
- if (!CompareIncrementalSchemes)
1973
- return ;
1974
-
1970
+ void Compilation::IncrementalSchemeComparator::outputComparison () const {
1975
1971
if (CompareIncrementalSchemesPath.empty ()) {
1976
1972
outputComparison (llvm::outs ());
1977
1973
return ;
@@ -1983,30 +1979,25 @@ void Compilation::outputComparison() const {
1983
1979
FA_Write, OF_Append | OF_Text);
1984
1980
1985
1981
if (EC) {
1986
- getDiags ().diagnose (SourceLoc (),
1987
- diag::unable_to_open_incremental_comparison_log,
1988
- CompareIncrementalSchemesPath);
1982
+ Diags.diagnose (SourceLoc (), diag::unable_to_open_incremental_comparison_log,
1983
+ CompareIncrementalSchemesPath);
1989
1984
return ;
1990
1985
}
1991
1986
outputComparison (OS);
1992
1987
}
1993
1988
1994
- void Compilation::outputComparison (llvm::raw_ostream &out) const {
1995
- if (!getIncrementalBuildEnabled ())
1996
- out << " *** Comparing incremental strategies is moot: incremental "
1997
- " compilation disabled ***\n " ;
1998
- else if (FallingBackToDependiesFromSourceRanges)
1999
- out << " *** Comparing deps: " << DependencyCompileJobs.size ()
2000
- << " , ranges: " << SourceRangeCompileJobs.size ()
2001
- << " , total: " << countSwiftInputs () << " ***\n " ;
2002
- else
2003
- out << " *** Comparing incremental strategies is moot: would fall "
2004
- " back and run "
2005
- << DependencyCompileJobs.size ()
2006
- << " , ranges: " << SourceRangeCompileJobs.size ()
2007
- << " , total: " << countSwiftInputs ()
2008
- << " , plus more to create source-range and compiled-source files"
2009
- << " ***\n " ;
1989
+ void Compilation::IncrementalSchemeComparator::outputComparison (
1990
+ llvm::raw_ostream &out) const {
1991
+ out << " *** Comparing incremental schemes: "
1992
+ << " deps: " << DependencyCompileJobs.size () << " , "
1993
+ << " ranges: " << SourceRangeCompileJobs.size () << " , "
1994
+ << " supplementary output creation: " << SourceRangeLackingSuppJobs.size ()
1995
+ << " , "
1996
+ << " total: " << SwiftInputCount << " , "
1997
+ << " scheme requested: "
1998
+ << (EnableSourceRangeDependencies ? " ranges" : " deps" ) << " , "
1999
+ << " scheme used: " << (UseSourceRangeDependencies ? " ranges" : " deps" )
2000
+ << " \n " ;
2010
2001
}
2011
2002
2012
2003
unsigned Compilation::countSwiftInputs () const {
0 commit comments