Skip to content

Commit b532e68

Browse files
authored
Merge pull request swiftlang#34011 from CodaFi/dont-go-chasing-waterfalls
Excise Remaining Usages of Legacy Cascading Dependencies From Frontend
2 parents fcd364d + eea7699 commit b532e68

File tree

271 files changed

+175
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+175
-361
lines changed

docs/DependencyAnalysis.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,6 @@ Note:
5656
> may change its members drastically.
5757
5858

59-
Cascading vs. Non-Cascading Dependencies
60-
========================================
61-
62-
If file A depends on file B, and file B depends on file C, does file A depend
63-
on file C? The answer is: maybe! It depends how file B is using file C. If all
64-
uses are inside function bodies, for example, then changing file C only
65-
requires rebuilding file B, not file A. The terminology here is that file B has
66-
a *non-cascading* dependency on file C.
67-
68-
By contrast, if changing file C affects the interface of file B, then the
69-
dependency is said to be *cascading,* and changing file C would require
70-
rebuilding both file B and file A.
71-
72-
The various dependency tracking throughout the compiler will look at the
73-
context in which information is being used and attempt to determine whether or
74-
not a particular dependency should be considered cascading. If there's not
75-
enough context to decide, the compiler has to go with the conservative choice
76-
and record it as cascading.
77-
78-
79-
Note:
80-
81-
> In the current on-disk representation of dependency information, cascading
82-
> dependencies are the default. Non-cascading dependencies are marked
83-
> `private` by analogy with the Swift `private` keyword.
84-
85-
8659
External Dependencies
8760
=====================
8861

docs/Lexicon.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,6 @@ These can usually be directly compared to test whether two types are the
100100
same; the exception is when generics get involved. In this case you'll need
101101
a [generic environment](#generic-environment). Contrast with [sugared type](#sugared-type).
102102

103-
## cascading dependency
104-
105-
A kind of dependency edge relevant to the incremental name tracking
106-
subsystem. A cascading dependency (as opposed to a
107-
[private dependency](#private-dependency) requires the Swift driver to
108-
transitively consider dependency edges in the file that defines the used
109-
name when incremental compilation is enabled. A cascading dependency is much
110-
safer to produce than its private counterpart, but it comes at the cost of
111-
increased usage of compilation resources - even if those resources are being
112-
wasted on rebuilding a file that didn't actually require rebuilding.
113-
See [DependencyAnalysis.md](DependencyAnalysis.md).
114-
115103
## Clang importer
116104

117105
The part of the compiler that reads C and Objective-C declarations and
@@ -452,18 +440,6 @@ The file currently being compiled, as opposed to the other files that are
452440
only needed for context. See also
453441
[Whole-Module Optimization](#wmo-whole-module-optimization).
454442

455-
## private dependency
456-
457-
A kind of dependency edge relevant to the incremental name tracking
458-
subsystem. A private dependency (as opposed to a
459-
[cascading dependency](#cascading-dependency)) declares a dependency edge
460-
from one file to a name referenced in that file that does not
461-
require further transitive evaluation of dependency edges by the Swift
462-
driver. Private dependencies are therefore cheaper than cascading
463-
dependencies, but must be used with the utmost care or dependent files will
464-
fail to rebuild and the result will most certainly be a miscompile.
465-
See [DependencyAnalysis](DependencyAnalysis.md).
466-
467443
## QoI
468444

469445
"Quality of implementation." The term is meant to describe not how

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,22 +399,14 @@ REMARK(interface_file_lock_timed_out,none,
399399
"timed out waiting to acquire lock file for module interface '%0'", (StringRef))
400400

401401
// Dependency Verifier Diagnostics
402-
ERROR(dependency_cascading_mismatch,none,
403-
"expected %select{non-cascading|cascading}0 dependency; found "
404-
"%select{non-cascading|cascading}1 dependency instead",
405-
(bool, bool))
406-
ERROR(potential_dependency_cascading_mismatch,none,
407-
"expected %select{non-cascading|cascading}0 potential member dependency; "
408-
"found %select{non-cascading|cascading}1 potential member dependency "
409-
"instead", (bool, bool))
410402
ERROR(missing_member_dependency,none,
411403
"expected "
412404
"%select{%error|provided|member|potential member|dynamic member}0 "
413405
"dependency does not exist: %1",
414406
(/*Expectation::Kind*/uint8_t, StringRef))
415407
ERROR(unexpected_dependency,none,
416-
"unexpected %0 %select{%error|%error|member|potential member|dynamic member}1 "
417-
"dependency: %2", (StringRef, /*Expectation::Kind*/uint8_t, StringRef))
408+
"unexpected %select{%error|%error|member|potential member|dynamic member}0 "
409+
"dependency: %1", (/*Expectation::Kind*/uint8_t, StringRef))
418410
ERROR(unexpected_provided_entity,none,
419411
"unexpected provided entity: %0", (StringRef))
420412
ERROR(negative_expectation_violated,none,

include/swift/AST/FineGrainedDependencies.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,6 @@ template <typename NodeT> class InterfaceAndImplementationPair {
393393

394394
NodeT *getInterface() const { return interface; }
395395
NodeT *getImplementation() const { return implementation; }
396-
397-
/// When creating an arc to represent a link from def to use, the use end of
398-
/// the arc depends on if the dependency is a cascading one. Centralize that
399-
/// choice here.
400-
/// ("use" in the name represents the noun, not the verb.)
401-
NodeT *useDependingOnCascading(bool ifCascades) {
402-
return ifCascades ? interface : implementation;
403-
}
404396
};
405397

406398
//==============================================================================
@@ -501,13 +493,6 @@ class DependencyKey {
501493
template <NodeKind kind, typename Entity>
502494
static std::string computeNameForProvidedEntity(Entity);
503495

504-
/// Given some type of depended-upon entity create the key.
505-
static DependencyKey createDependedUponKey(StringRef mangledHolderName,
506-
StringRef memberBaseName);
507-
508-
template <NodeKind kind>
509-
static DependencyKey createDependedUponKey(StringRef);
510-
511496
static DependencyKey createKeyForWholeSourceFile(DeclAspect,
512497
StringRef swiftDeps);
513498

lib/AST/FrontendSourceFileDepGraphFactory.cpp

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -232,47 +232,6 @@ std::string DependencyKey::computeNameForProvidedEntity<
232232
return getBaseName(holderAndMember.second);
233233
}
234234

235-
//==============================================================================
236-
// MARK: createDependedUponKey
237-
//==============================================================================
238-
239-
template <>
240-
DependencyKey
241-
DependencyKey::createDependedUponKey<NodeKind::topLevel>(StringRef name) {
242-
return DependencyKey(NodeKind::topLevel, DeclAspect::interface, "",
243-
name.str());
244-
}
245-
246-
template <>
247-
DependencyKey
248-
DependencyKey::createDependedUponKey<NodeKind::dynamicLookup>(StringRef name) {
249-
return DependencyKey(NodeKind::dynamicLookup, DeclAspect::interface, "",
250-
name.str());
251-
}
252-
253-
template <>
254-
DependencyKey
255-
DependencyKey::createDependedUponKey<NodeKind::externalDepend>(StringRef name) {
256-
return DependencyKey(NodeKind::externalDepend, DeclAspect::interface, "",
257-
name.str());
258-
}
259-
260-
template <>
261-
DependencyKey
262-
DependencyKey::createDependedUponKey<NodeKind::nominal>(StringRef mangledName) {
263-
return DependencyKey(NodeKind::nominal, DeclAspect::interface,
264-
mangledName.str(), "");
265-
}
266-
267-
DependencyKey DependencyKey::createDependedUponKey(StringRef mangledHolderName,
268-
StringRef memberBaseName) {
269-
const bool isMemberBlank = memberBaseName.empty();
270-
const auto kind =
271-
isMemberBlank ? NodeKind::potentialMember : NodeKind::member;
272-
return DependencyKey(kind, DeclAspect::interface, mangledHolderName.str(),
273-
isMemberBlank ? "" : memberBaseName.str());
274-
}
275-
276235
//==============================================================================
277236
// MARK: Entry point into frontend graph construction
278237
//==============================================================================
@@ -579,7 +538,6 @@ class UsedDeclEnumerator {
579538
void enumerateAllUses() {
580539
auto &Ctx = SF->getASTContext();
581540
Ctx.evaluator.enumerateReferencesInFile(SF, [&](const auto &ref) {
582-
const auto cascades = false;
583541
std::string name = ref.name.userFacingName().str();
584542
const auto *nominal = ref.subject;
585543
using Kind = evaluator::DependencyCollector::Reference::Kind;
@@ -589,19 +547,19 @@ class UsedDeclEnumerator {
589547
case Kind::Tombstone:
590548
llvm_unreachable("Cannot enumerate dead reference!");
591549
case Kind::TopLevel:
592-
return enumerateUse<NodeKind::topLevel>("", name, cascades);
550+
return enumerateUse<NodeKind::topLevel>("", name);
593551
case Kind::Dynamic:
594-
return enumerateUse<NodeKind::dynamicLookup>("", name, cascades);
552+
return enumerateUse<NodeKind::dynamicLookup>("", name);
595553
case Kind::PotentialMember: {
596554
std::string context = DependencyKey::computeContextForProvidedEntity<
597555
NodeKind::potentialMember>(nominal);
598-
return enumerateUse<NodeKind::potentialMember>(context, "", cascades);
556+
return enumerateUse<NodeKind::potentialMember>(context, "");
599557
}
600558
case Kind::UsedMember: {
601559
std::string context =
602560
DependencyKey::computeContextForProvidedEntity<NodeKind::member>(
603561
nominal);
604-
return enumerateUse<NodeKind::member>(context, name, cascades);
562+
return enumerateUse<NodeKind::member>(context, name);
605563
}
606564
}
607565
});
@@ -611,11 +569,11 @@ class UsedDeclEnumerator {
611569

612570
private:
613571
template <NodeKind kind>
614-
void enumerateUse(StringRef context, StringRef name, bool isCascadingUse) {
572+
void enumerateUse(StringRef context, StringRef name) {
615573
// Assume that what is depended-upon is the interface
616574
createDefUse(
617575
DependencyKey(kind, DeclAspect::interface, context.str(), name.str()),
618-
isCascadingUse ? sourceFileInterface : sourceFileImplementation);
576+
sourceFileImplementation);
619577
}
620578

621579
void enumerateNominalUses() {
@@ -634,14 +592,13 @@ class UsedDeclEnumerator {
634592
std::string context =
635593
DependencyKey::computeContextForProvidedEntity<NodeKind::nominal>(
636594
subject);
637-
enumerateUse<NodeKind::nominal>(context, "", /*isCascadingUse*/ false);
595+
enumerateUse<NodeKind::nominal>(context, "");
638596
});
639597
}
640598

641599
void enumerateExternalUses() {
642-
// external dependencies always cascade
643600
for (StringRef s : depTracker.getDependencies())
644-
enumerateUse<NodeKind::externalDepend>("", s, true);
601+
enumerateUse<NodeKind::externalDepend>("", s);
645602
}
646603
};
647604
} // end namespace

lib/Driver/FineGrainedDependencyDriverGraph.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ void ModuleDepGraph::forEachUntracedJobDirectlyDependentOnExternalSwiftDeps(
220220
StringRef externalSwiftDeps, function_ref<void(const Job *)> fn) {
221221
// TODO move nameForDep into key
222222
// These nodes will depend on the *interface* of the external Decl.
223-
DependencyKey key =
224-
DependencyKey::createDependedUponKey<NodeKind::externalDepend>(
225-
externalSwiftDeps.str());
223+
DependencyKey key(NodeKind::externalDepend, DeclAspect::interface, "",
224+
externalSwiftDeps.str());
226225
for (const ModuleDepGraphNode *useNode : usesByDef[key]) {
227226
if (!useNode->getHasBeenTraced())
228227
fn(getJob(useNode->getSwiftDepsOfProvides()));

0 commit comments

Comments
 (0)