Skip to content

Commit ff61b24

Browse files
committed
Remove Type's hash_value function
Defining `hash_value` for `Type` makes it easy to forget that the underlying pointer is being hashed directly without canonicalization. Instead, define it only for `CanType`, and make `Type` users spell `getPointer` explicitly.
1 parent 2a377bc commit ff61b24

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

include/swift/AST/Requirement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Requirement {
142142
case RequirementKind::Conformance:
143143
case RequirementKind::Superclass:
144144
case RequirementKind::SameType:
145-
second = hash_value(requirement.getSecondType());
145+
second = hash_value(requirement.getSecondType().getPointer());
146146
break;
147147

148148
case RequirementKind::Layout:

include/swift/AST/Type.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ class Type {
325325
/// Return the name of the type as a string, for use in diagnostics only.
326326
std::string getString(const PrintOptions &PO = PrintOptions()) const;
327327

328-
friend llvm::hash_code hash_value(Type type) {
329-
using llvm::hash_value;
330-
return hash_value(type.getPointer());
331-
}
332-
333328
/// Return the name of the type, adding parens in cases where
334329
/// appending or prepending text to the result would cause that text
335330
/// to be appended to only a portion of the returned type. For
@@ -502,6 +497,10 @@ class CanType : public Type {
502497
bool operator==(CanType T) const { return getPointer() == T.getPointer(); }
503498
bool operator!=(CanType T) const { return !operator==(T); }
504499

500+
friend llvm::hash_code hash_value(CanType T) {
501+
return llvm::hash_value(T.getPointer());
502+
}
503+
505504
bool operator<(CanType T) const { return getPointer() < T.getPointer(); }
506505
};
507506

include/swift/AST/Witness.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct TypeWitnessAndDecl {
206206
}
207207

208208
friend llvm::hash_code hash_value(const TypeWitnessAndDecl &owner) {
209-
return llvm::hash_combine(owner.witnessType,
209+
return llvm::hash_combine(owner.witnessType.getPointer(),
210210
owner.witnessDecl);
211211
}
212212

0 commit comments

Comments
 (0)