Skip to content

Commit 4668718

Browse files
author
David Ungar
committed
-only-one-dependency-file causes only the first frontend job to emit a real dependency file.
1 parent 171987a commit 4668718

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

include/swift/Driver/Compilation.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ class Compilation {
257257
/// limit filelists will be used.
258258
size_t FilelistThreshold;
259259

260+
/// Because each frontend job outputs the same info in its .d file, only do it
261+
/// on the first job that actually runs. Write out dummies for the rest of the
262+
/// jobs. This hack saves a lot of time in the build system when incrementally
263+
/// building a project with many files. Record if a scheduled job has already
264+
/// added -emit-dependency-path.
265+
bool HaveAlreadyAddedDependencyPath = false;
266+
267+
/// Set if the -only-one-dependency-file flag is set
268+
const bool OnlyOneDependencyFile;
269+
260270
/// Scaffolding to permit experimentation with finer-grained dependencies and
261271
/// faster rebuilds.
262272
const bool EnableFineGrainedDependencies;
@@ -309,6 +319,7 @@ class Compilation {
309319
bool SaveTemps = false,
310320
bool ShowDriverTimeCompilation = false,
311321
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr,
322+
bool OnlyOneDependencyFile = false,
312323
bool EnableFineGrainedDependencies = false,
313324
bool VerifyFineGrainedDependencyGraphAfterEveryImport = false,
314325
bool EmitFineGrainedDependencyDotFileAfterEveryImport = false,
@@ -427,6 +438,14 @@ class Compilation {
427438
return FilelistThreshold;
428439
}
429440

441+
/// Called to decide whether to add a dependency path argument, or whether to
442+
/// create a dummy file. Responds by invoking one of the two passed-in
443+
/// functions.
444+
void addDependencyPathOrCreateDummy(
445+
const CommandOutput &Output,
446+
function_ref<void(StringRef)> addDependencyPath,
447+
function_ref<void(StringRef)> createDummy);
448+
430449
UnifiedStatsReporter *getStatsReporter() const {
431450
return Stats.get();
432451
}

include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ def enable_fine_grained_dependencies :
139139
Flag<["-"], "enable-fine-grained-dependencies">, Flags<[FrontendOption, HelpHidden]>,
140140
HelpText<"Experimental work-in-progress to be more selective about incremental recompilation">;
141141

142+
143+
def only_one_dependency_file :
144+
Flag<["-"], "only-one-dependency-file">, Flags<[DoesNotAffectIncrementalBuild]>,
145+
HelpText<"Experimental flag for faster thousand-source-file incremental builds">;
146+
147+
142148
def enable_source_range_dependencies :
143149
Flag<["-"], "enable-source-range-dependencies">, Flags<[]>,
144150
HelpText<"Try using source range information">;

lib/Driver/Compilation.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ Compilation::Compilation(DiagnosticEngine &Diags,
121121
bool SaveTemps,
122122
bool ShowDriverTimeCompilation,
123123
std::unique_ptr<UnifiedStatsReporter> StatsReporter,
124+
bool OnlyOneDependencyFile,
124125
bool EnableFineGrainedDependencies,
125126
bool VerifyFineGrainedDependencyGraphAfterEveryImport,
126127
bool EmitFineGrainedDependencyDotFileAfterEveryImport,
127128
bool FineGrainedDependenciesIncludeIntrafileOnes,
128129
bool EnableSourceRangeDependencies,
129130
bool CompareIncrementalSchemes,
130-
StringRef CompareIncrementalSchemesPath)
131+
StringRef CompareIncrementalSchemesPath
132+
)
131133
: Diags(Diags), TheToolChain(TC),
132134
TheOutputInfo(OI),
133135
Level(Level),
@@ -149,14 +151,16 @@ Compilation::Compilation(DiagnosticEngine &Diags,
149151
ShowDriverTimeCompilation(ShowDriverTimeCompilation),
150152
Stats(std::move(StatsReporter)),
151153
FilelistThreshold(FilelistThreshold),
154+
OnlyOneDependencyFile(OnlyOneDependencyFile),
152155
EnableFineGrainedDependencies(EnableFineGrainedDependencies),
153156
VerifyFineGrainedDependencyGraphAfterEveryImport(
154157
VerifyFineGrainedDependencyGraphAfterEveryImport),
155158
EmitFineGrainedDependencyDotFileAfterEveryImport(
156159
EmitFineGrainedDependencyDotFileAfterEveryImport),
157160
FineGrainedDependenciesIncludeIntrafileOnes(
158161
FineGrainedDependenciesIncludeIntrafileOnes),
159-
EnableSourceRangeDependencies(EnableSourceRangeDependencies) {
162+
EnableSourceRangeDependencies(EnableSourceRangeDependencies)
163+
{
160164
if (CompareIncrementalSchemes)
161165
IncrementalComparator.emplace(
162166
// Ensure the references are to inst vars, NOT arguments
@@ -2036,3 +2040,19 @@ unsigned Compilation::countSwiftInputs() const {
20362040
++inputCount;
20372041
return inputCount;
20382042
}
2043+
2044+
void Compilation::addDependencyPathOrCreateDummy(
2045+
const CommandOutput &Output,
2046+
function_ref<void(StringRef)> addDependencyPath,
2047+
function_ref<void(StringRef)> createDummy) {
2048+
StringRef path =
2049+
Output.getAdditionalOutputForType(file_types::TY_Dependencies);
2050+
if (path.empty())
2051+
return;
2052+
if (HaveAlreadyAddedDependencyPath && OnlyOneDependencyFile)
2053+
createDummy(path);
2054+
else {
2055+
addDependencyPath(path);
2056+
HaveAlreadyAddedDependencyPath = true;
2057+
}
2058+
}

lib/Driver/Driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,11 @@ Driver::buildCompilation(const ToolChain &TC,
951951
ArgList->hasArg(options::OPT_driver_time_compilation);
952952
std::unique_ptr<UnifiedStatsReporter> StatsReporter =
953953
createStatsReporter(ArgList.get(), Inputs, OI, DefaultTargetTriple);
954+
955+
const bool OnlyOneDependencyFile =
956+
ArgList->hasArg(options::OPT_only_one_dependency_file);
954957
// relies on the new dependency graph
958+
955959
const bool EnableFineGrainedDependencies =
956960
ArgList->hasArg(options::OPT_enable_fine_grained_dependencies);
957961

@@ -984,6 +988,7 @@ Driver::buildCompilation(const ToolChain &TC,
984988
SaveTemps,
985989
ShowDriverTimeCompilation,
986990
std::move(StatsReporter),
991+
OnlyOneDependencyFile,
987992
EnableFineGrainedDependencies,
988993
VerifyFineGrainedDependencyGraphAfterEveryImport,
989994
EmitFineGrainedDependencyDotFileAfterEveryImport,

lib/Driver/ToolChains.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,20 @@ void ToolChain::JobContext::addFrontendSupplementaryOutputArguments(
671671
"mode!");
672672
}
673673

674-
addOutputsOfType(arguments, Output, Args, file_types::TY_Dependencies,
675-
"-emit-dependencies-path");
674+
C.addDependencyPathOrCreateDummy(
675+
Output,
676+
[&](StringRef) {
677+
addOutputsOfType(arguments, Output, Args, file_types::TY_Dependencies,
678+
"-emit-dependencies-path");
679+
},
680+
[&](StringRef dependencyFile) {
681+
// Create an empty file
682+
using namespace llvm::sys::fs;
683+
if (auto file = openNativeFileForWrite(dependencyFile, CD_CreateAlways,
684+
OF_Text))
685+
closeFile(file.get());
686+
});
687+
676688
addOutputsOfType(arguments, Output, Args, file_types::TY_SwiftDeps,
677689
"-emit-reference-dependencies-path");
678690
addOutputsOfType(arguments, Output, Args, file_types::TY_SwiftRanges,

0 commit comments

Comments
 (0)