Skip to content

[sil] Add missing flag to SILDeclRef's hash and change SILDeclRef to use llvm::hash_combine instead of rolling its own hash combiner. #79825

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
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
39 changes: 19 additions & 20 deletions include/swift/SIL/SILDeclRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,6 @@ struct SILDeclRef {
/// Return the expected linkage of this declaration.
SILLinkage getLinkage(ForDefinition_t forDefinition) const;

/// Return the hash code for the SIL declaration.
friend llvm::hash_code hash_value(const SILDeclRef &ref) {
return llvm::hash_combine(
ref.loc.getOpaqueValue(), static_cast<int>(ref.kind), ref.isForeign,
ref.distributedThunk, ref.defaultArgIndex, ref.isAsyncLetClosure);
}

bool operator==(SILDeclRef rhs) const {
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue() &&
kind == rhs.kind && isForeign == rhs.isForeign &&
Expand Down Expand Up @@ -613,6 +606,24 @@ struct SILDeclRef {

bool hasAsync() const;

/// Return the hash code for the SIL declaration.
friend llvm::hash_code hash_value(swift::SILDeclRef ref) {
return llvm::hash_combine(
llvm::hash_value(ref.loc.getOpaqueValue()),
llvm::hash_value(unsigned(ref.kind)),
llvm::hash_value(
(ref.kind == swift::SILDeclRef::Kind::DefaultArgGenerator)
? ref.defaultArgIndex
: 0),
llvm::hash_value(ref.isForeign),
llvm::hash_value(ref.pointer.getOpaqueValue()),
llvm::hash_value(ref.distributedThunk),
llvm::hash_value(unsigned(ref.backDeploymentKind)),
llvm::hash_value(ref.isKnownToBeLocal),
llvm::hash_value(ref.isRuntimeAccessible),
llvm::hash_value(ref.isAsyncLetClosure));
}

private:
friend struct llvm::DenseMapInfo<swift::SILDeclRef>;
/// Produces a SILDeclRef from an opaque value.
Expand Down Expand Up @@ -660,19 +671,7 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
nullptr);
}
static unsigned getHashValue(swift::SILDeclRef Val) {
unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue());
unsigned h2 = UnsignedInfo::getHashValue(unsigned(Val.kind));
unsigned h3 = (Val.kind == Kind::DefaultArgGenerator)
? UnsignedInfo::getHashValue(Val.defaultArgIndex)
: 0;
unsigned h4 = UnsignedInfo::getHashValue(Val.isForeign);
unsigned h5 = PointerInfo::getHashValue(Val.pointer.getOpaqueValue());
unsigned h6 = UnsignedInfo::getHashValue(Val.distributedThunk);
unsigned h7 = UnsignedInfo::getHashValue(unsigned(Val.backDeploymentKind));
unsigned h8 = UnsignedInfo::getHashValue(Val.isKnownToBeLocal);
unsigned h9 = UnsignedInfo::getHashValue(Val.isRuntimeAccessible);
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7) ^ (h5 << 11) ^ (h6 << 8) ^
(h7 << 10) ^ (h8 << 13) ^ (h9 << 15);
return hash_value(Val);
}
static bool isEqual(swift::SILDeclRef const &LHS,
swift::SILDeclRef const &RHS) {
Expand Down