Skip to content

Commit 164bd08

Browse files
authored
Merge pull request swiftlang#34219 from CodaFi/negative-externalities
Keep a Cache of Externally-Dependent Jobs
2 parents ca4ce56 + d3c6d36 commit 164bd08

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

include/swift/Driver/Compilation.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ class Compilation {
157157

158158
/// The Jobs which will be performed by this compilation.
159159
SmallVector<std::unique_ptr<const Job>, 32> Jobs;
160+
// The Jobs which represent external actions performed by other drivers in
161+
// the build graph.
162+
//
163+
// These Jobs are never scheduled into the build graph. This vector is
164+
// populated by the routine that computes the set of incremental external
165+
// dependencies that affect the current computation. Due to the way the
166+
// Driver models multiple aspects of the incremental compilation scheduler
167+
// by mapping to and from Jobs, it is necessary to lie and retain a set of
168+
// pseudo-Jobs.
169+
SmallVector<std::unique_ptr<const Job>, 32> ExternalJobs;
160170

161171
/// The original (untranslated) input argument list.
162172
///
@@ -348,7 +358,6 @@ class Compilation {
348358
UnwrappedArrayView<const Job> getJobs() const {
349359
return llvm::makeArrayRef(Jobs);
350360
}
351-
Job *addJob(std::unique_ptr<Job> J);
352361

353362
/// To send job list to places that don't truck in fancy array views.
354363
std::vector<const Job *> getJobsSimply() const {
@@ -515,6 +524,13 @@ class Compilation {
515524
const JobCollection &unsortedJobs,
516525
SmallVectorImpl<const Job *> &sortedJobs) const;
517526

527+
private:
528+
friend class Driver;
529+
friend class PerformJobsState;
530+
531+
Job *addJob(std::unique_ptr<Job> J);
532+
Job *addExternalJob(std::unique_ptr<Job> J);
533+
518534
private:
519535
/// Perform all jobs.
520536
///

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class ModuleDepGraph {
466466
void printPath(raw_ostream &out, const driver::Job *node) const;
467467

468468
/// Get a printable filename, given a node's swiftDeps.
469-
StringRef getProvidingFilename(Optional<std::string> swiftDeps) const;
469+
StringRef getProvidingFilename(const Optional<std::string> &swiftDeps) const;
470470

471471
/// Print one node on the dependency path.
472472
static void printOneNodeOfPath(raw_ostream &out, const DependencyKey &key,

lib/Driver/Compilation.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,10 +1181,11 @@ namespace driver {
11811181

11821182
// Cons up a fake `Job` to satisfy the incremental job tracing
11831183
// code's internal invariants.
1184-
Job fakeJob(Comp.getDerivedOutputFileMap(), external);
1184+
const auto *externalJob = Comp.addExternalJob(
1185+
std::make_unique<Job>(Comp.getDerivedOutputFileMap(), external));
11851186
auto subChanges =
11861187
getFineGrainedDepGraph(forRanges).loadFromSwiftModuleBuffer(
1187-
&fakeJob, *buffer.get(), Comp.getDiags());
1188+
externalJob, *buffer.get(), Comp.getDiags());
11881189

11891190
// If the incremental dependency graph failed to load, fall back to
11901191
// treating this as plain external job.
@@ -1196,7 +1197,7 @@ namespace driver {
11961197
for (auto *CMD :
11971198
getFineGrainedDepGraph(forRanges)
11981199
.findJobsToRecompileWhenNodesChange(subChanges.getValue())) {
1199-
if (CMD == &fakeJob) {
1200+
if (CMD == externalJob) {
12001201
continue;
12011202
}
12021203
ExternallyDependentJobs.push_back(CMD);
@@ -1719,6 +1720,12 @@ Job *Compilation::addJob(std::unique_ptr<Job> J) {
17191720
return result;
17201721
}
17211722

1723+
Job *Compilation::addExternalJob(std::unique_ptr<Job> J) {
1724+
Job *result = J.get();
1725+
ExternalJobs.emplace_back(std::move(J));
1726+
return result;
1727+
}
1728+
17221729
static void checkForOutOfDateInputs(DiagnosticEngine &diags,
17231730
const InputInfoMap &inputs) {
17241731
for (const auto &inputPair : inputs) {

lib/Driver/FineGrainedDependencyDriverGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ void ModuleDepGraph::printPath(raw_ostream &out,
749749
}
750750

751751
StringRef ModuleDepGraph::getProvidingFilename(
752-
const Optional<std::string> swiftDeps) const {
752+
const Optional<std::string> &swiftDeps) const {
753753
if (!swiftDeps)
754754
return "<unknown";
755755
auto ext = llvm::sys::path::extension(*swiftDeps);

0 commit comments

Comments
 (0)