Skip to content

[Serialization] Do not serialize unstable hashes #75876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions include/swift/Localization/LocalizationFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LocalizationWriterInfo {
using hash_value_type = uint32_t;
using offset_type = uint32_t;

hash_value_type ComputeHash(key_type_ref key) { return llvm::hash_code(key); }
Copy link
Contributor Author

@bnbarham bnbarham Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a no-op - it was converting to 64 bits and then back to 32 bit. I was just here because I looked for all serialization tables 😅 . Seems worth changing since hash_code is a Hashing.h type.

hash_value_type ComputeHash(key_type_ref key) { return key; }

std::pair<offset_type, offset_type> EmitKeyDataLength(llvm::raw_ostream &out,
key_type_ref key,
Expand Down Expand Up @@ -113,9 +113,7 @@ class LocalizationReaderInfo {
return lhs == rhs;
}

hash_value_type ComputeHash(internal_key_type key) {
return llvm::hash_code(key);
}
hash_value_type ComputeHash(internal_key_type key) { return key; }

static std::pair<offset_type, offset_type>
ReadKeyDataLength(const unsigned char *&data) {
Expand Down
9 changes: 5 additions & 4 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ namespace {
}

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

std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
Expand Down Expand Up @@ -1223,7 +1223,8 @@ namespace {
}

hash_value_type ComputeHash(key_type_ref key) {
return static_cast<unsigned>(key.first) + llvm::djbHash(key.second);
return static_cast<hash_value_type>(key.first) +
llvm::djbHash(key.second);
}

std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
Expand Down Expand Up @@ -1414,7 +1415,7 @@ namespace {
}

hash_value_type ComputeHash(internal_key_type key) {
return llvm::DenseMapInfo<SerializedSwiftName>::getHashValue(key);
return static_cast<hash_value_type>(key.Kind) + llvm::djbHash(key.Name);
}

static bool EqualKey(internal_key_type lhs, internal_key_type rhs) {
Expand Down Expand Up @@ -1502,7 +1503,7 @@ namespace {
}

hash_value_type ComputeHash(internal_key_type key) {
return static_cast<unsigned>(key.first) + llvm::djbHash(key.second);
return static_cast<hash_value_type>(key.first) + llvm::djbHash(key.second);
}

static bool EqualKey(internal_key_type lhs, internal_key_type rhs) {
Expand Down
3 changes: 1 addition & 2 deletions lib/ClangImporter/SwiftLookupTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MAJOR = 1;
/// Lookup table minor version number.
///
/// When the format changes IN ANY WAY, this number should be incremented.
const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MINOR = 18; // Unsafe C++ method renaming.

const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MINOR = 19; // hash functions

/// A lookup table that maps Swift names to the set of Clang
/// declarations with that particular name.
Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/ModuleFileCoreTableInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class ModuleFileSharedCore::DeclMembersTableInfo {
}

hash_value_type ComputeHash(internal_key_type key) {
return llvm::hash_value(key);
return key;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash_value ends up calling getHashValue and for a uint32_t that was just val * 37. Happy to change it to that, to reinterpret_cast then djbHash, or just leave it like this - let me know!

}

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

hash_value_type ComputeHash(internal_key_type key) {
return llvm::hash_value(key);
return key;
}

static bool EqualKey(internal_key_type lhs, internal_key_type rhs) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 882; // CXXStdlibKind
const uint16_t SWIFTMODULE_VERSION_MINOR = 883; // hash functions

/// A standard hash seed used for all string hashes in a serialized module.
///
Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ namespace {
using offset_type = unsigned;

hash_value_type ComputeHash(key_type_ref key) {
return llvm::hash_value(static_cast<uint32_t>(key));
return key;
}

std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
Expand Down Expand Up @@ -459,7 +459,7 @@ namespace {
using offset_type = unsigned;

hash_value_type ComputeHash(key_type_ref key) {
return llvm::hash_value(static_cast<uint32_t>(key));
return key;
}

std::pair<unsigned, unsigned>
Expand Down