Skip to content

[Serialization] Use specialized decl hash function for GlobalDeclID #95730

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 2 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
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: 5 additions & 1 deletion clang/include/clang/AST/DeclID.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ template <> struct DenseMapInfo<clang::GlobalDeclID> {
}

static unsigned getHashValue(const GlobalDeclID &Key) {
return DenseMapInfo<DeclID>::getHashValue(Key.get());
// Our default hash algorithm for 64 bits integer may not be very good.
// In GlobalDeclID's case, it is pretty common that the lower 32 bits can
// be same.
return DenseMapInfo<uint32_t>::getHashValue(Key.getModuleFileIndex()) ^
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use hash_combine from llvm/ADT/Hash.h?

Copy link
Contributor

@ilya-biryukov ilya-biryukov Jun 17, 2024

Choose a reason for hiding this comment

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

+1 to using hash_combine, it should provide better results than xor.
Update: after asking around, I think hash_value from ADT/Hashing.h on the underlying int64 value would give good results here and make the code even simpler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

DenseMapInfo<uint32_t>::getHashValue(Key.getLocalDeclIndex());
}

static bool isEqual(const GlobalDeclID &L, const GlobalDeclID &R) {
Expand Down
Loading