Skip to content

Commit c3881d9

Browse files
committed
[NFC] Pull the Computation of Fingerprints Into the Common Base Class
1 parent af5fa5e commit c3881d9

3 files changed

+27
-61
lines changed

include/swift/AST/AbstractSourceFileDepGraphFactory.h

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H
1414
#define SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H
1515

16+
#include "swift/AST/Decl.h"
1617
#include "swift/AST/DeclContext.h"
1718
#include "swift/AST/FineGrainedDependencies.h"
1819

@@ -72,6 +73,21 @@ class AbstractSourceFileDepGraphFactory {
7273
Optional<StringRef> fingerprint);
7374

7475
void addAUsedDecl(const DependencyKey &def, const DependencyKey &use);
76+
77+
static Optional<std::string> getFingerprintIfAny(
78+
std::pair<const NominalTypeDecl *, const ValueDecl *>) {
79+
return None;
80+
}
81+
82+
static Optional<std::string> getFingerprintIfAny(const Decl *d) {
83+
if (const auto *idc = dyn_cast<IterableDeclContext>(d)) {
84+
auto result = idc->getBodyFingerprint();
85+
assert((!result || !result->empty()) &&
86+
"Fingerprint should never be empty");
87+
return result;
88+
}
89+
return None;
90+
}
7591
};
7692

7793
} // namespace fine_grained_dependencies

lib/AST/FrontendSourceFileDepGraphFactory.cpp

+11-49
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ std::string FrontendSourceFileDepGraphFactory::getFingerprint(SourceFile *SF) {
229229
return getInterfaceHash(SF);
230230
}
231231

232+
std::string
233+
FrontendSourceFileDepGraphFactory::getInterfaceHash(SourceFile *SF) {
234+
llvm::SmallString<32> interfaceHash;
235+
SF->getInterfaceHash(interfaceHash);
236+
return interfaceHash.str().str();
237+
}
238+
232239
//==============================================================================
233240
// MARK: FrontendSourceFileDepGraphFactory - adding collections of defined Decls
234241
//==============================================================================
@@ -407,7 +414,8 @@ template <NodeKind kind, typename ContentsT>
407414
void FrontendSourceFileDepGraphFactory::addAllDefinedDeclsOfAGivenType(
408415
std::vector<ContentsT> &contentsVec) {
409416
for (const auto &declOrPair : contentsVec) {
410-
Optional<std::string> fp = getFingerprintIfAny(declOrPair);
417+
Optional<std::string> fp =
418+
AbstractSourceFileDepGraphFactory::getFingerprintIfAny(declOrPair);
411419
addADefinedDecl(
412420
DependencyKey::createForProvidedEntityInterface<kind>(declOrPair),
413421
fp ? StringRef(fp.getValue()) : Optional<StringRef>());
@@ -519,33 +527,6 @@ void FrontendSourceFileDepGraphFactory::addAllUsedDecls() {
519527
.enumerateAllUses();
520528
}
521529

522-
//==============================================================================
523-
// MARK: FrontendSourceFileDepGraphFactory - adding individual defined Decls
524-
//==============================================================================
525-
526-
std::string
527-
FrontendSourceFileDepGraphFactory::getInterfaceHash(SourceFile *SF) {
528-
llvm::SmallString<32> interfaceHash;
529-
SF->getInterfaceHash(interfaceHash);
530-
return interfaceHash.str().str();
531-
}
532-
533-
/// At present, only \c NominalTypeDecls have (body) fingerprints
534-
Optional<std::string> FrontendSourceFileDepGraphFactory::getFingerprintIfAny(
535-
std::pair<const NominalTypeDecl *, const ValueDecl *>) {
536-
return None;
537-
}
538-
Optional<std::string>
539-
FrontendSourceFileDepGraphFactory::getFingerprintIfAny(const Decl *d) {
540-
if (const auto *idc = dyn_cast<IterableDeclContext>(d)) {
541-
auto result = idc->getBodyFingerprint();
542-
assert((!result || !result->empty()) &&
543-
"Fingerprint should never be empty");
544-
return result;
545-
}
546-
return None;
547-
}
548-
549530
//==============================================================================
550531
// MARK: ModuleDepGraphFactory
551532
//==============================================================================
@@ -591,29 +572,10 @@ template <NodeKind kind, typename ContentsT>
591572
void ModuleDepGraphFactory::addAllDefinedDeclsOfAGivenType(
592573
std::vector<ContentsT> &contentsVec) {
593574
for (const auto &declOrPair : contentsVec) {
594-
Optional<std::string> fp = getFingerprintIfAny(declOrPair);
575+
Optional<std::string> fp =
576+
AbstractSourceFileDepGraphFactory::getFingerprintIfAny(declOrPair);
595577
addADefinedDecl(
596578
DependencyKey::createForProvidedEntityInterface<kind>(declOrPair),
597579
fp ? StringRef(fp.getValue()) : Optional<StringRef>());
598580
}
599581
}
600-
601-
//==============================================================================
602-
// MARK: ModuleDepGraphFactory - adding individual defined Decls
603-
//==============================================================================
604-
605-
/// At present, only \c NominalTypeDecls have (body) fingerprints
606-
Optional<std::string> ModuleDepGraphFactory::getFingerprintIfAny(
607-
std::pair<const NominalTypeDecl *, const ValueDecl *>) {
608-
return None;
609-
}
610-
Optional<std::string>
611-
ModuleDepGraphFactory::getFingerprintIfAny(const Decl *d) {
612-
if (const auto *idc = dyn_cast<IterableDeclContext>(d)) {
613-
auto result = idc->getBodyFingerprint();
614-
assert((!result || !result->empty()) &&
615-
"Fingerprint should never be empty");
616-
return result;
617-
}
618-
return None;
619-
}

lib/AST/FrontendSourceFileDepGraphFactory.h

-12
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ class FrontendSourceFileDepGraphFactory
4444
/// create node pairs for context and name
4545
template <NodeKind kind, typename ContentsT>
4646
void addAllDefinedDeclsOfAGivenType(std::vector<ContentsT> &contentsVec);
47-
48-
/// At present, only nominals, protocols, and extensions have (body)
49-
/// fingerprints
50-
static Optional<std::string>
51-
getFingerprintIfAny(std::pair<const NominalTypeDecl *, const ValueDecl *>);
52-
static Optional<std::string> getFingerprintIfAny(const Decl *d);
5347
};
5448

5549
class ModuleDepGraphFactory : public AbstractSourceFileDepGraphFactory {
@@ -68,12 +62,6 @@ class ModuleDepGraphFactory : public AbstractSourceFileDepGraphFactory {
6862
/// create node pairs for context and name
6963
template <NodeKind kind, typename ContentsT>
7064
void addAllDefinedDeclsOfAGivenType(std::vector<ContentsT> &contentsVec);
71-
72-
/// At present, only nominals, protocols, and extensions have (body)
73-
/// fingerprints
74-
static Optional<std::string> getFingerprintIfAny(
75-
std::pair<const NominalTypeDecl *, const ValueDecl *>);
76-
static Optional<std::string> getFingerprintIfAny(const Decl *d);
7765
};
7866

7967
} // namespace fine_grained_dependencies

0 commit comments

Comments
 (0)