Skip to content

Commit 47f5707

Browse files
authored
[Serialization] Use specialized decl hash function for GlobalDeclID (#95730)
See the comment: #92083 (comment) After the patch, #92083, the lower 32 bits of DeclID can be the same commonly. This may produce many collisions. It will be best to change the default hash implementation for uint64_t. But sent this one as a quick workaround. Feel free to update this if you prefer other hash functions.
1 parent 9f8e7c3 commit 47f5707

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clang/include/clang/AST/DeclID.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LLVM_CLANG_AST_DECLID_H
1818

1919
#include "llvm/ADT/DenseMapInfo.h"
20+
#include "llvm/ADT/Hashing.h"
2021
#include "llvm/ADT/iterator.h"
2122

2223
#include <climits>
@@ -230,7 +231,11 @@ template <> struct DenseMapInfo<clang::GlobalDeclID> {
230231
}
231232

232233
static unsigned getHashValue(const GlobalDeclID &Key) {
233-
return DenseMapInfo<DeclID>::getHashValue(Key.get());
234+
// Our default hash algorithm for 64 bits integer may not be very good.
235+
// In GlobalDeclID's case, it is pretty common that the lower 32 bits can
236+
// be same.
237+
// FIXME: Remove this when we fix the underlying issue.
238+
return llvm::hash_value(Key.get());
234239
}
235240

236241
static bool isEqual(const GlobalDeclID &L, const GlobalDeclID &R) {

0 commit comments

Comments
 (0)