Skip to content

Keep a Cache of Externally-Dependent Jobs #34219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion include/swift/Driver/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ class Compilation {

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

/// The original (untranslated) input argument list.
///
Expand Down Expand Up @@ -348,7 +358,6 @@ class Compilation {
UnwrappedArrayView<const Job> getJobs() const {
return llvm::makeArrayRef(Jobs);
}
Job *addJob(std::unique_ptr<Job> J);

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

private:
friend class Driver;
friend class PerformJobsState;

Job *addJob(std::unique_ptr<Job> J);
Job *addExternalJob(std::unique_ptr<Job> J);

private:
/// Perform all jobs.
///
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Driver/FineGrainedDependencyDriverGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class ModuleDepGraph {
void printPath(raw_ostream &out, const driver::Job *node) const;

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

/// Print one node on the dependency path.
static void printOneNodeOfPath(raw_ostream &out, const DependencyKey &key,
Expand Down
13 changes: 10 additions & 3 deletions lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,11 @@ namespace driver {

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

// If the incremental dependency graph failed to load, fall back to
// treating this as plain external job.
Expand All @@ -1194,7 +1195,7 @@ namespace driver {
for (auto *CMD :
getFineGrainedDepGraph(forRanges)
.findJobsToRecompileWhenNodesChange(subChanges.getValue())) {
if (CMD == &fakeJob) {
if (CMD == externalJob) {
continue;
}
ExternallyDependentJobs.push_back(CMD);
Expand Down Expand Up @@ -1717,6 +1718,12 @@ Job *Compilation::addJob(std::unique_ptr<Job> J) {
return result;
}

Job *Compilation::addExternalJob(std::unique_ptr<Job> J) {
Job *result = J.get();
ExternalJobs.emplace_back(std::move(J));
return result;
}

static void checkForOutOfDateInputs(DiagnosticEngine &diags,
const InputInfoMap &inputs) {
for (const auto &inputPair : inputs) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/FineGrainedDependencyDriverGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ void ModuleDepGraph::printPath(raw_ostream &out,
}

StringRef ModuleDepGraph::getProvidingFilename(
const Optional<std::string> swiftDeps) const {
const Optional<std::string> &swiftDeps) const {
if (!swiftDeps)
return "<unknown";
auto ext = llvm::sys::path::extension(*swiftDeps);
Expand Down