Skip to content

Commit 27d2926

Browse files
committed
[NFC] Traffic in Fingerprints
1 parent 8e5d64f commit 27d2926

24 files changed

+72
-69
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SWIFT_TYPEID(BodyInitKind)
2121
SWIFT_TYPEID(BodyInitKindAndExpr)
2222
SWIFT_TYPEID(CtorInitializerKind)
2323
SWIFT_TYPEID(ResultBuilderBodyPreCheck)
24+
SWIFT_TYPEID(Fingerprint)
2425
SWIFT_TYPEID(GenericSignature)
2526
SWIFT_TYPEID(ImplicitImportList)
2627
SWIFT_TYPEID(ImplicitMemberAction)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ConstructorDecl;
3434
class CustomAttr;
3535
class Decl;
3636
class EnumDecl;
37+
class Fingerprint;
3738
class FuncDecl;
3839
enum class ResultBuilderBodyPreCheck : uint8_t;
3940
class GenericParamList;

include/swift/AST/AbstractSourceFileDepGraphFactory.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,30 @@ class AbstractSourceFileDepGraphFactory {
7171
template <NodeKind kind, typename ContentsT>
7272
void addAllDefinedDeclsOfAGivenType(std::vector<ContentsT> &contentsVec) {
7373
for (const auto &declOrPair : contentsVec) {
74-
Optional<std::string> fp =
74+
auto fp =
7575
AbstractSourceFileDepGraphFactory::getFingerprintIfAny(declOrPair);
7676
addADefinedDecl(
7777
DependencyKey::createForProvidedEntityInterface<kind>(declOrPair),
78-
fp ? StringRef(fp.getValue()) : Optional<StringRef>());
78+
fp);
7979
}
8080
}
8181

8282
/// Add an pair of interface, implementation nodes to the graph, which
8383
/// represent some \c Decl defined in this source file. \param key the
8484
/// interface key of the pair
8585
void addADefinedDecl(const DependencyKey &key,
86-
Optional<StringRef> fingerprint);
86+
Optional<Fingerprint> fingerprint);
8787

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

90-
static Optional<std::string> getFingerprintIfAny(
91-
std::pair<const NominalTypeDecl *, const ValueDecl *>) {
90+
static Optional<Fingerprint>
91+
getFingerprintIfAny(std::pair<const NominalTypeDecl *, const ValueDecl *>) {
9292
return None;
9393
}
9494

95-
static Optional<std::string> getFingerprintIfAny(const Decl *d) {
95+
static Optional<Fingerprint> getFingerprintIfAny(const Decl *d) {
9696
if (const auto *idc = dyn_cast<IterableDeclContext>(d)) {
97-
auto result = idc->getBodyFingerprint();
98-
assert((!result || !result->empty()) &&
99-
"Fingerprint should never be empty");
100-
return result;
97+
return idc->getBodyFingerprint();
10198
}
10299
return None;
103100
}

include/swift/AST/DeclContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/ResilienceExpansion.h"
2525
#include "swift/AST/TypeAlignments.h"
2626
#include "swift/Basic/Debug.h"
27+
#include "swift/Basic/Fingerprint.h"
2728
#include "swift/Basic/LLVM.h"
2829
#include "swift/Basic/STLExtras.h"
2930
#include "swift/Basic/SourceLoc.h"
@@ -871,7 +872,7 @@ class IterableDeclContext {
871872

872873
/// Return a hash of all tokens in the body for dependency analysis, if
873874
/// available.
874-
Optional<std::string> getBodyFingerprint() const;
875+
Optional<Fingerprint> getBodyFingerprint() const;
875876

876877
private:
877878
/// Add a member to the list for iteration purposes, but do not notify the

include/swift/AST/FineGrainedDependencies.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_AST_FINE_GRAINED_DEPENDENCIES_H
1515

1616
#include "swift/Basic/Debug.h"
17+
#include "swift/Basic/Fingerprint.h"
1718
#include "swift/Basic/LLVM.h"
1819
#include "swift/Basic/NullablePtr.h"
1920
#include "swift/Basic/Range.h"
@@ -599,22 +600,15 @@ class DepGraphNode {
599600
/// frontend creates an interface node,
600601
// it adds a dependency to it from the implementation source file node (which
601602
// has the intefaceHash as its fingerprint).
602-
Optional<std::string> fingerprint;
603+
Optional<Fingerprint> fingerprint;
603604

604605
friend ::llvm::yaml::MappingTraits<DepGraphNode>;
605606

606607
public:
607608
/// See \ref SourceFileDepGraphNode::SourceFileDepGraphNode().
608609
DepGraphNode() : key(), fingerprint() {}
609610

610-
/// See SourceFileDepGraphNode::SourceFileDepGraphNode(...) and
611-
/// ModuleDepGraphNode::ModuleDepGraphNode(...) Don't set swiftDeps on
612-
/// creation because this field can change if a node is moved.
613-
DepGraphNode(DependencyKey key, Optional<StringRef> fingerprint)
614-
: DepGraphNode(key, fingerprint ? fingerprint->str()
615-
: Optional<std::string>()) {}
616-
617-
DepGraphNode(DependencyKey key, Optional<std::string> fingerprint)
611+
DepGraphNode(DependencyKey key, Optional<Fingerprint> fingerprint)
618612
: key(key), fingerprint(fingerprint) {}
619613
DepGraphNode(const DepGraphNode &other) = default;
620614

@@ -630,12 +624,7 @@ class DepGraphNode {
630624
this->key = key;
631625
}
632626

633-
const Optional<StringRef> getFingerprint() const {
634-
if (fingerprint) {
635-
return StringRef(fingerprint.getValue());
636-
}
637-
return None;
638-
}
627+
const Optional<Fingerprint> getFingerprint() const { return fingerprint; }
639628
/// When driver reads a SourceFileDepGraphNode, it may be a node that was
640629
/// created to represent a name-lookup (a.k.a a "depend") in the frontend. In
641630
/// that case, the node represents an entity that resides in some other file
@@ -644,9 +633,7 @@ class DepGraphNode {
644633
/// (someday) have a fingerprint. In order to preserve the
645634
/// ModuleDepGraphNode's identity but bring its fingerprint up to date, it
646635
/// needs to set the fingerprint *after* the node has been created.
647-
void setFingerprint(Optional<StringRef> fp) {
648-
fingerprint = fp ? fp->str() : Optional<std::string>();
649-
}
636+
void setFingerprint(Optional<Fingerprint> fp) { fingerprint = fp; }
650637

651638
SWIFT_DEBUG_DUMP;
652639
void dump(llvm::raw_ostream &os) const;
@@ -693,7 +680,7 @@ class SourceFileDepGraphNode : public DepGraphNode {
693680
SourceFileDepGraphNode() : DepGraphNode() {}
694681

695682
/// Used by the frontend to build nodes.
696-
SourceFileDepGraphNode(DependencyKey key, Optional<StringRef> fingerprint,
683+
SourceFileDepGraphNode(DependencyKey key, Optional<Fingerprint> fingerprint,
697684
bool isProvides)
698685
: DepGraphNode(key, fingerprint), isProvides(isProvides) {
699686
assert(key.verify());
@@ -827,14 +814,14 @@ class SourceFileDepGraph {
827814
/// file itself.
828815
InterfaceAndImplementationPair<SourceFileDepGraphNode>
829816
findExistingNodePairOrCreateAndAddIfNew(const DependencyKey &interfaceKey,
830-
Optional<StringRef> fingerprint);
817+
Optional<Fingerprint> fingerprint);
831818

832819
NullablePtr<SourceFileDepGraphNode>
833820
findExistingNode(const DependencyKey &key);
834821

835822
SourceFileDepGraphNode *
836823
findExistingNodeOrCreateIfNew(const DependencyKey &key,
837-
const Optional<StringRef> fingerprint,
824+
const Optional<Fingerprint> fingerprint,
838825
bool isProvides);
839826

840827
/// \p Use is the Node that must be rebuilt when \p def changes.

include/swift/AST/LazyResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class alignas(void*) LazyMemberLoader {
8686

8787
/// Returns the fingerprint associated with the given iterable decl context,
8888
/// or \c None if no such fingerprint is available.
89-
virtual Optional<std::string>
89+
virtual Optional<Fingerprint>
9090
loadFingerprint(const IterableDeclContext *IDC) = 0;
9191

9292
/// Populates the given vector with all conformances for \p D.

include/swift/AST/ParseRequests.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/ASTTypeIDs.h"
2020
#include "swift/AST/EvaluatorDependencies.h"
2121
#include "swift/AST/SimpleRequest.h"
22+
#include "swift/Basic/Fingerprint.h"
2223
#include "swift/Syntax/SyntaxNodes.h"
2324

2425
namespace swift {
@@ -30,7 +31,7 @@ void reportEvaluatedRequest(UnifiedStatsReporter &stats,
3031
const Request &request);
3132

3233
struct FingerprintAndMembers {
33-
Optional<std::string> fingerprint = None;
34+
Optional<Fingerprint> fingerprint = None;
3435
ArrayRef<Decl *> members = {};
3536
bool operator==(const FingerprintAndMembers &x) const {
3637
return fingerprint == x.fingerprint && members == x.members;

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/AST/FineGrainedDependencies.h"
1717
#include "swift/Basic/Debug.h"
18+
#include "swift/Basic/Fingerprint.h"
1819
#include "swift/Basic/LLVM.h"
1920
#include "swift/Basic/OptionSet.h"
2021
#include "swift/Driver/Job.h"
@@ -55,7 +56,8 @@ class ModuleDepGraphNode : public DepGraphNode {
5556
bool hasBeenTracedAsADependent = false;
5657

5758
public:
58-
ModuleDepGraphNode(const DependencyKey &key, Optional<StringRef> fingerprint,
59+
ModuleDepGraphNode(const DependencyKey &key,
60+
Optional<Fingerprint> fingerprint,
5961
Optional<std::string> swiftDeps)
6062
: DepGraphNode(key, fingerprint), swiftDeps(swiftDeps) {}
6163

include/swift/Parse/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ class Parser {
941941
bool IsAtStartOfLineOrPreviousHadSemi,
942942
llvm::function_ref<void(Decl*)> Handler);
943943

944-
std::pair<std::vector<Decl *>, Optional<std::string>>
944+
std::pair<std::vector<Decl *>, Optional<Fingerprint>>
945945
parseDeclListDelayed(IterableDeclContext *IDC);
946946

947947
bool parseMemberDeclList(SourceLoc &LBLoc, SourceLoc &RBLoc,
@@ -1085,7 +1085,7 @@ class Parser {
10851085
ParserStatus parseDeclItem(bool &PreviousHadSemi,
10861086
ParseDeclOptions Options,
10871087
llvm::function_ref<void(Decl*)> handler);
1088-
std::pair<std::vector<Decl *>, Optional<std::string>>
1088+
std::pair<std::vector<Decl *>, Optional<Fingerprint>>
10891089
parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag,
10901090
ParseDeclOptions Options, IterableDeclContext *IDC,
10911091
bool &hadError);

lib/AST/AbstractSourceFileDepGraphFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ void AbstractSourceFileDepGraphFactory::addSourceFileNodesToGraph() {
6060
g.findExistingNodePairOrCreateAndAddIfNew(
6161
DependencyKey::createKeyForWholeSourceFile(DeclAspect::interface,
6262
swiftDeps),
63-
StringRef(fileFingerprint));
63+
Fingerprint{fileFingerprint});
6464
}
6565

6666
void AbstractSourceFileDepGraphFactory::addADefinedDecl(
67-
const DependencyKey &interfaceKey, Optional<StringRef> fingerprint) {
67+
const DependencyKey &interfaceKey, Optional<Fingerprint> fingerprint) {
6868

6969
auto nodePair =
7070
g.findExistingNodePairOrCreateAndAddIfNew(interfaceKey, fingerprint);

0 commit comments

Comments
 (0)