Skip to content

Commit 4fc85d7

Browse files
authored
Merge pull request #75876 from bnbarham/cherry-hash-fixes
[Serialization] Do not serialize unstable hashes
2 parents 00cac25 + 273d7ee commit 4fc85d7

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

include/swift/Localization/LocalizationFormat.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class LocalizationWriterInfo {
7171
using hash_value_type = uint32_t;
7272
using offset_type = uint32_t;
7373

74-
hash_value_type ComputeHash(key_type_ref key) { return llvm::hash_code(key); }
74+
hash_value_type ComputeHash(key_type_ref key) { return key; }
7575

7676
std::pair<offset_type, offset_type> EmitKeyDataLength(llvm::raw_ostream &out,
7777
key_type_ref key,
@@ -113,9 +113,7 @@ class LocalizationReaderInfo {
113113
return lhs == rhs;
114114
}
115115

116-
hash_value_type ComputeHash(internal_key_type key) {
117-
return llvm::hash_code(key);
118-
}
116+
hash_value_type ComputeHash(internal_key_type key) { return key; }
119117

120118
static std::pair<offset_type, offset_type>
121119
ReadKeyDataLength(const unsigned char *&data) {

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ namespace {
11161116
}
11171117

11181118
hash_value_type ComputeHash(key_type_ref key) {
1119-
return llvm::DenseMapInfo<SerializedSwiftName>::getHashValue(key);
1119+
return static_cast<hash_value_type>(key.Kind) + llvm::djbHash(key.Name);
11201120
}
11211121

11221122
std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
@@ -1223,7 +1223,8 @@ namespace {
12231223
}
12241224

12251225
hash_value_type ComputeHash(key_type_ref key) {
1226-
return static_cast<unsigned>(key.first) + llvm::djbHash(key.second);
1226+
return static_cast<hash_value_type>(key.first) +
1227+
llvm::djbHash(key.second);
12271228
}
12281229

12291230
std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
@@ -1414,7 +1415,7 @@ namespace {
14141415
}
14151416

14161417
hash_value_type ComputeHash(internal_key_type key) {
1417-
return llvm::DenseMapInfo<SerializedSwiftName>::getHashValue(key);
1418+
return static_cast<hash_value_type>(key.Kind) + llvm::djbHash(key.Name);
14181419
}
14191420

14201421
static bool EqualKey(internal_key_type lhs, internal_key_type rhs) {
@@ -1502,7 +1503,7 @@ namespace {
15021503
}
15031504

15041505
hash_value_type ComputeHash(internal_key_type key) {
1505-
return static_cast<unsigned>(key.first) + llvm::djbHash(key.second);
1506+
return static_cast<hash_value_type>(key.first) + llvm::djbHash(key.second);
15061507
}
15071508

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

lib/ClangImporter/SwiftLookupTable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MAJOR = 1;
282282
/// Lookup table minor version number.
283283
///
284284
/// When the format changes IN ANY WAY, this number should be incremented.
285-
const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MINOR = 18; // Unsafe C++ method renaming.
286-
285+
const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MINOR = 19; // hash functions
287286

288287
/// A lookup table that maps Swift names to the set of Clang
289288
/// declarations with that particular name.

lib/Serialization/ModuleFileCoreTableInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class ModuleFileSharedCore::DeclMembersTableInfo {
330330
}
331331

332332
hash_value_type ComputeHash(internal_key_type key) {
333-
return llvm::hash_value(key);
333+
return key;
334334
}
335335

336336
static bool EqualKey(internal_key_type lhs, internal_key_type rhs) {
@@ -580,7 +580,7 @@ class ModuleFileSharedCore::DeclFingerprintsTableInfo {
580580
internal_key_type GetInternalKey(external_key_type ID) { return ID; }
581581

582582
hash_value_type ComputeHash(internal_key_type key) {
583-
return llvm::hash_value(key);
583+
return key;
584584
}
585585

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

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 882; // CXXStdlibKind
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 883; // hash functions
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ namespace {
414414
using offset_type = unsigned;
415415

416416
hash_value_type ComputeHash(key_type_ref key) {
417-
return llvm::hash_value(static_cast<uint32_t>(key));
417+
return key;
418418
}
419419

420420
std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
@@ -459,7 +459,7 @@ namespace {
459459
using offset_type = unsigned;
460460

461461
hash_value_type ComputeHash(key_type_ref key) {
462-
return llvm::hash_value(static_cast<uint32_t>(key));
462+
return key;
463463
}
464464

465465
std::pair<unsigned, unsigned>

0 commit comments

Comments
 (0)