Skip to content

Commit 9fb2897

Browse files
committed
RequirementMachine: Make Terms work as DenseMap keys
1 parent f5aa95b commit 9fb2897

File tree

1 file changed

+24
-0
lines changed
  • lib/AST/RequirementMachine

1 file changed

+24
-0
lines changed

lib/AST/RequirementMachine/Term.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class Term final {
6565
return Ptr;
6666
}
6767

68+
static Term fromOpaquePointer(void *ptr) {
69+
return Term((Storage *) ptr);
70+
}
71+
6872
static Term get(const MutableTerm &term, RewriteContext &ctx);
6973

7074
ArrayRef<const ProtocolDecl *> getRootProtocols() const {
@@ -203,4 +207,24 @@ class MutableTerm final {
203207

204208
} // end namespace swift
205209

210+
namespace llvm {
211+
template<> struct DenseMapInfo<swift::rewriting::Term> {
212+
static swift::rewriting::Term getEmptyKey() {
213+
return swift::rewriting::Term::fromOpaquePointer(
214+
llvm::DenseMapInfo<void *>::getEmptyKey());
215+
}
216+
static swift::rewriting::Term getTombstoneKey() {
217+
return swift::rewriting::Term::fromOpaquePointer(
218+
llvm::DenseMapInfo<void *>::getTombstoneKey());
219+
}
220+
static unsigned getHashValue(swift::rewriting::Term Val) {
221+
return DenseMapInfo<void *>::getHashValue(Val.getOpaquePointer());
222+
}
223+
static bool isEqual(swift::rewriting::Term LHS,
224+
swift::rewriting::Term RHS) {
225+
return LHS == RHS;
226+
}
227+
};
228+
} // end namespace llvm
229+
206230
#endif

0 commit comments

Comments
 (0)