Skip to content

Commit b0f0587

Browse files
committed
Keep a Cache of Externally-Dependent Jobs
A more durable form of swiftlang#34218. Keep a side cache of externally-dependent jobs for now. This ensures our pseudo-Jobs don't get prematurely deallocated before the tracing machinery has had a chance to report the structure of the Job graph. rdar://70053563
1 parent 38b1da3 commit b0f0587

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
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
///

lib/Driver/Compilation.cpp

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

11801180
// Cons up a fake `Job` to satisfy the incremental job tracing
11811181
// code's internal invariants.
1182-
Job fakeJob(Comp.getDerivedOutputFileMap(), external);
1182+
const auto *externalJob = Comp.addExternalJob(
1183+
std::make_unique<Job>(Comp.getDerivedOutputFileMap(), external));
11831184
auto subChanges =
11841185
getFineGrainedDepGraph(forRanges).loadFromSwiftModuleBuffer(
1185-
&fakeJob, *buffer.get(), Comp.getDiags());
1186+
externalJob, *buffer.get(), Comp.getDiags());
11861187

11871188
// If the incremental dependency graph failed to load, fall back to
11881189
// treating this as plain external job.
@@ -1194,7 +1195,7 @@ namespace driver {
11941195
for (auto *CMD :
11951196
getFineGrainedDepGraph(forRanges)
11961197
.findJobsToRecompileWhenNodesChange(subChanges.getValue())) {
1197-
if (CMD == &fakeJob) {
1198+
if (CMD == externalJob) {
11981199
continue;
11991200
}
12001201
ExternallyDependentJobs.push_back(CMD);
@@ -1717,6 +1718,12 @@ Job *Compilation::addJob(std::unique_ptr<Job> J) {
17171718
return result;
17181719
}
17191720

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

0 commit comments

Comments
 (0)