Skip to content

Commit dab204e

Browse files
committed
Plumb Module Fingerprints Into ModuleDepGraphFactory
1 parent 29904e7 commit dab204e

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

include/swift/AST/AbstractSourceFileDepGraphFactory.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ class AbstractSourceFileDepGraphFactory {
8787

8888
void addAUsedDecl(const DependencyKey &def, const DependencyKey &use);
8989

90+
/// Add an external dependency node to the graph. If the provided fingerprint
91+
/// is not \c None, it is added to the def key.
92+
void addAnExternalDependency(const DependencyKey &def,
93+
const DependencyKey &use,
94+
Optional<Fingerprint> dependencyFingerprint);
95+
9096
static Optional<Fingerprint>
9197
getFingerprintIfAny(std::pair<const NominalTypeDecl *, const ValueDecl *>) {
9298
return None;

lib/AST/AbstractSourceFileDepGraphFactory.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ void AbstractSourceFileDepGraphFactory::addAUsedDecl(
108108
assert(useNode->getIsProvides() && "Use (using node) must be a provides");
109109
g.addArc(defNode, useNode);
110110
}
111+
112+
void AbstractSourceFileDepGraphFactory::addAnExternalDependency(
113+
const DependencyKey &defKey, const DependencyKey &useKey,
114+
Optional<Fingerprint> maybeFP) {
115+
auto *defNode = g.findExistingNodeOrCreateIfNew(defKey, maybeFP,
116+
false /* = !isProvides */);
117+
118+
auto nullableUse = g.findExistingNode(useKey);
119+
assert(nullableUse.isNonNull() && "Use must be an already-added provides");
120+
auto *useNode = nullableUse.get();
121+
assert(useNode->getIsProvides() && "Use (using node) must be a provides");
122+
g.addArc(defNode, useNode);
123+
}

lib/AST/FrontendSourceFileDepGraphFactory.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,10 @@ void FrontendSourceFileDepGraphFactory::addAllUsedDecls() {
499499

500500
ModuleDepGraphFactory::ModuleDepGraphFactory(const ModuleDecl *Mod,
501501
bool emitDot)
502-
: AbstractSourceFileDepGraphFactory(Mod->getASTContext().hadError(),
503-
Mod->getNameStr(), Fingerprint::ZERO(),
504-
emitDot, Mod->getASTContext().Diags),
505-
506-
Mod(Mod) {
507-
// Since a fingerprint only summarizes the state of the module but not
508-
// the state of its fingerprinted sub-declarations, and since a module
509-
// contains no state other than sub-declarations, its fingerprint does not
510-
// matter and can just be some arbitrary value. Should it be the case that a
511-
// change in a declaration that does not have a fingerprint must cause
512-
// a rebuild of a file outside of the module, this assumption will need
513-
// to be revisited.
514-
}
502+
: AbstractSourceFileDepGraphFactory(
503+
Mod->getASTContext().hadError(), Mod->getNameStr(),
504+
Mod->getFingerprint(), emitDot, Mod->getASTContext().Diags),
505+
Mod(Mod) {}
515506

516507
void ModuleDepGraphFactory::addAllDefinedDecls() {
517508
// TODO: express the multiple provides and depends streams with variadic

0 commit comments

Comments
 (0)