Skip to content

Commit 7889bfb

Browse files
author
David Ungar
committed
Improvements inspired by review
1 parent 41cbcfd commit 7889bfb

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

include/swift/Driver/Action.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,17 @@ class CompileJobAction : public JobAction {
173173
/// if 0 or >1 such inputs exist, return nullptr.
174174
const InputAction *findSingleSwiftInput() const {
175175
auto Inputs = getInputs();
176-
const InputAction *IA = nullptr;
177-
for (auto const *I : Inputs) {
178-
if (auto const *S = dyn_cast<InputAction>(I)) {
179-
if (S->getType() == file_types::TY_Swift) {
180-
if (IA == nullptr) {
181-
IA = S;
182-
} else {
183-
// Already found one, two is too many.
184-
return nullptr;
185-
}
186-
}
187-
}
188-
}
189-
return IA;
176+
auto isSwiftInput = [](const Action *A) -> const InputAction* {
177+
if (auto const *S = dyn_cast<InputAction>(A))
178+
return S->getType() == file_types::TY_Swift ? S : nullptr;
179+
return nullptr;
180+
};
181+
const auto loc1 = std::find_if(Inputs.begin(), Inputs.end(), isSwiftInput);
182+
if (loc1 == Inputs.end())
183+
return nullptr; // none found
184+
// Ensure uniqueness
185+
const auto loc2 = std::find_if(loc1 + 1, Inputs.end(), isSwiftInput);
186+
return loc2 == Inputs.end() ? dyn_cast<InputAction>(*loc1) : nullptr;
190187
}
191188
};
192189

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class ModuleDepGraph {
487487
return swiftDepsOfJobsThatNeedRunning.insert(swiftDeps).second;
488488
}
489489

490-
/// For debugging, write out the graph to a dot file.
490+
/// For debugging and visualization, write out the graph to a dot file.
491491
/// \p diags may be null if no diagnostics are needed.
492492
void emitDotFileForJob(DiagnosticEngine &, const driver::Job *);
493493
void emitDotFile(DiagnosticEngine &, StringRef baseName);

lib/AST/FineGrainedDependencies.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,19 @@ SourceFileDepGraph::findExistingNodePairOrCreateAndAddIfNew(
9090
DependencyKey(k, DeclAspect::implementation, context, name),
9191
fingerprint, true /* = isProvides */)};
9292
// if interface changes, have to rebuild implementation.
93+
// This dependency used to be represented by
94+
// addArc(nodePair.getInterface(), nodePair.getImplementation());
95+
// However, recall that the dependency scheme as of 1/2020 chunks
96+
// declarations together by base name.
97+
// So if the arc were added, a dirtying of a same-based-named interface
98+
// in a different file would dirty the implementation in this file,
99+
// causing the needless recompilation of this file.
93100
// But, if an arc is added for this, then *any* change that causes
94101
// a same-named interface to be dirty will dirty this implementation,
95102
// even if that interface is in another file.
96-
// So, make the interface->implementation arc implicit.
103+
// Therefor no such arc is added here, and any dirtying of either
104+
// the interface or implementation of this declaration will cause
105+
// the driver to recompile this source file.
97106
return nodePair;
98107
}
99108

lib/Driver/FineGrainedDependencyDriverGraph.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ void ModuleDepGraph::traceDeparture(size_t pathLengthAfterArrival) {
428428
currentPath.pop_back();
429429
}
430430

431-
// Emitting Dot file for ModuleDepGraph
432-
// ===========================================
431+
// =============================================================================
432+
// MARK: Emitting Dot file for ModuleDepGraph
433+
// =============================================================================
433434

434435
void ModuleDepGraph::emitDotFileForJob(DiagnosticEngine &diags,
435436
const Job *job) {

0 commit comments

Comments
 (0)