Skip to content

Commit b0ad06a

Browse files
committed
[Serialization] The hash seed for DeclCommentTableInfo can't change
Unlike compiled modules, swiftdoc files are considered a stable format, so we can't change how information is stored in them. If we add any more string-hashed tables to swiftdoc files, we should consider using a new hash seed for those.
1 parent 11e206a commit b0ad06a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/Serialization/DocFormat.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ const uint16_t SWIFTDOC_VERSION_MAJOR = 1;
6969
/// adhering to the 80-column limit for this line.
7070
const uint16_t SWIFTDOC_VERSION_MINOR = 1; // Last change: skipping 0 for testing purposes
7171

72+
/// The hash seed used for the string hashes in a Swift 5.1 swiftdoc file.
73+
///
74+
/// 0 is not a good seed for llvm::djbHash, but swiftdoc files use a stable
75+
/// format, so we can't change the hash seed without a version bump. Any new
76+
/// hashed strings should use a new stable hash seed constant. (No such constant
77+
/// has been defined at the time this doc comment was last updated because there
78+
/// are no other strings to hash.)
79+
const uint32_t SWIFTDOC_HASH_SEED_5_1 = 0;
80+
7281
/// The record types within the comment block.
7382
///
7483
/// Be very careful when changing this block; it must remain

lib/Serialization/ModuleFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,7 @@ class ModuleFile::DeclCommentTableInfo {
972972

973973
hash_value_type ComputeHash(internal_key_type key) {
974974
assert(!key.empty());
975-
// FIXME: DJB seed=0, audit whether the default seed could be used.
976-
return llvm::djbHash(key, 0);
975+
return llvm::djbHash(key, SWIFTDOC_HASH_SEED_5_1);
977976
}
978977

979978
static bool EqualKey(internal_key_type lhs, internal_key_type rhs) {

lib/Serialization/SerializeDoc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ class DeclCommentTableInfo {
197197

198198
hash_value_type ComputeHash(key_type_ref key) {
199199
assert(!key.empty());
200-
// FIXME: DJB seed=0, audit whether the default seed could be used.
201-
return llvm::djbHash(key, 0);
200+
return llvm::djbHash(key, SWIFTDOC_HASH_SEED_5_1);
202201
}
203202

204203
std::pair<unsigned, unsigned>

0 commit comments

Comments
 (0)