Skip to content

Commit d2a98f3

Browse files
committed
Address Review Comments
1 parent 91f4c8c commit d2a98f3

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

include/swift/Basic/Fingerprint.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IO;
2828

2929
namespace swift {
3030

31-
/// A \c Fingerprint represents a stable point of identity for a piece of data
31+
/// A \c Fingerprint represents a stable summary of a given piece of data
3232
/// in the compiler.
3333
///
3434
/// A \c Fingerprint value is subject to the following invariants:
@@ -109,6 +109,15 @@ class Fingerprint final {
109109
return llvm::hash_value(fp.Core);
110110
}
111111

112+
public:
113+
/// The fingerprint value consisting of 32 bytes of zeroes.
114+
///
115+
/// This fingerprint is a perfectly fine value for an MD5 hash, but it is
116+
/// completely arbitrary.
117+
static Fingerprint ZERO() {
118+
return Fingerprint("00000000000000000000000000000000");
119+
}
120+
112121
private:
113122
/// llvm::yaml would like us to be default constructible, but \c Fingerprint
114123
/// would prefer to enforce its internal invariants.

lib/AST/DeclContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,9 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
10121012
}
10131013

10141014
Optional<Fingerprint> IterableDeclContext::getBodyFingerprint() const {
1015-
auto &ctx = getASTContext();
10161015
auto mutableThis = const_cast<IterableDeclContext *>(this);
1017-
return evaluateOrDefault(ctx.evaluator, ParseMembersRequest{mutableThis},
1016+
return evaluateOrDefault(getASTContext().evaluator,
1017+
ParseMembersRequest{mutableThis},
10181018
FingerprintAndMembers())
10191019
.fingerprint;
10201020
}

lib/AST/FrontendSourceFileDepGraphFactory.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,18 @@ void FrontendSourceFileDepGraphFactory::addAllUsedDecls() {
506506
ModuleDepGraphFactory::ModuleDepGraphFactory(const ModuleDecl *Mod,
507507
bool emitDot)
508508
: AbstractSourceFileDepGraphFactory(Mod->getASTContext().hadError(),
509-
Mod->getNameStr(),
510-
Fingerprint("00000000000000000000000000000000"),
511-
emitDot,
512-
Mod->getASTContext().Diags),
513-
Mod(Mod) {}
509+
Mod->getNameStr(), Fingerprint::ZERO(),
510+
emitDot, Mod->getASTContext().Diags),
511+
512+
Mod(Mod) {
513+
// Since a fingerprint only summarizes the state of the module but not
514+
// the state of its fingerprinted sub-declarations, and since a module
515+
// contains no state other than sub-declarations, its fingerprint does not
516+
// matter and can just be some arbitrary value. Should it be the case that a
517+
// change in a declaration that does not have a fingerprint must cause
518+
// a rebuild of a file outside of the module, this assumption will need
519+
// to be revisited.
520+
}
514521

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

lib/Driver/Driver.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,10 @@ populateOutOfDateMap(InputInfoMap &map, llvm::sys::TimePoint<> &LastBuildTime,
547547
// -swift-version argument is handled in the argsHashStr check that
548548
// follows.
549549
CompilationRecordSwiftVersion = value->getValue(scratch);
550-
versionValid = CompilationRecordSwiftVersion.equals(version::getSwiftFullVersion(version::Version::getCurrentLanguageVersion()));
550+
versionValid = (CompilationRecordSwiftVersion
551+
== version::getSwiftFullVersion(
552+
version::Version::getCurrentLanguageVersion()));
553+
551554
} else if (keyStr == compilation_record::getName(TopLevelKey::Options)) {
552555
auto *value = dyn_cast<yaml::ScalarNode>(i->getValue());
553556
if (!value)

lib/Serialization/ModuleFileCoreTableInfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ class ModuleFileSharedCore::DeclUSRTableInfo {
566566
}
567567
};
568568

569+
/// Serialization for the table mapping module-level declIDs for serialized
570+
/// iterable decl contexts to their corresponding \c Fingerprint values.
569571
class ModuleFileSharedCore::DeclFingerprintsTableInfo {
570572
public:
571573
using internal_key_type = uint32_t;

lib/Serialization/Serialization.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ namespace {
435435
}
436436
};
437437

438+
// Side table information for serializing the table keyed under
439+
// \c DeclFingerprintsLayout.
438440
class DeclFingerprintsTableInfo {
439441
public:
440442
using key_type = DeclID;

lib/Serialization/Serialization.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class Serializer : public SerializerBase {
279279

280280
// In-memory representation of what will eventually be an on-disk
281281
// hash table of the fingerprint associated with a serialized
282-
// iterable decl context.
282+
// iterable decl context. It is keyed by that context's decl ID.
283283
using DeclFingerprintsTable = llvm::MapVector<uint32_t, Fingerprint>;
284284

285285
private:

0 commit comments

Comments
 (0)