@@ -4638,13 +4638,13 @@ class ConstraintSystem {
4638
4638
4639
4639
PotentialBinding (Type type, AllowedBindingKind kind,
4640
4640
PointerUnion<Constraint *, ConstraintLocator *> source)
4641
- : BindingType(type->getWithoutParens ()), Kind(kind),
4642
- BindingSource(source) {}
4641
+ : BindingType(type), Kind(kind), BindingSource(source) {}
4643
4642
4644
4643
public:
4645
4644
PotentialBinding (Type type, AllowedBindingKind kind, Constraint *source)
4646
- : BindingType(type->getWithoutParens ()), Kind(kind),
4647
- BindingSource(source) {}
4645
+ : PotentialBinding(
4646
+ type->getWithoutParens (), kind,
4647
+ PointerUnion<Constraint *, ConstraintLocator *>(source)) {}
4648
4648
4649
4649
bool isDefaultableBinding () const {
4650
4650
if (auto *constraint = BindingSource.dyn_cast <Constraint *>())
@@ -4695,6 +4695,11 @@ class ConstraintSystem {
4695
4695
AllowedBindingKind::Exact,
4696
4696
/* source=*/ locator};
4697
4697
}
4698
+
4699
+ static PotentialBinding forPlaceholder (Type placeholderTy) {
4700
+ return {placeholderTy, AllowedBindingKind::Exact,
4701
+ PointerUnion<Constraint *, ConstraintLocator *>()};
4702
+ }
4698
4703
};
4699
4704
4700
4705
struct LiteralRequirement {
@@ -6233,6 +6238,53 @@ struct DenseMapInfo<swift::constraints::SolutionApplicationTargetsKey> {
6233
6238
}
6234
6239
};
6235
6240
6241
+ template <>
6242
+ struct DenseMapInfo <swift::constraints::ConstraintSystem::PotentialBinding> {
6243
+ using Binding = swift::constraints::ConstraintSystem::PotentialBinding;
6244
+
6245
+ static Binding getEmptyKey () {
6246
+ return placeholderKey (llvm::DenseMapInfo<swift::TypeBase *>::getEmptyKey ());
6247
+ }
6248
+
6249
+ static Binding getTombstoneKey () {
6250
+ return placeholderKey (
6251
+ llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey ());
6252
+ }
6253
+
6254
+ static unsigned getHashValue (const Binding &Val) {
6255
+ return DenseMapInfo<swift::Type>::getHashValue (Val.BindingType );
6256
+ }
6257
+
6258
+ static bool isEqual (const Binding &LHS, const Binding &RHS) {
6259
+ auto lhsTy = LHS.BindingType .getPointer ();
6260
+ auto rhsTy = RHS.BindingType .getPointer ();
6261
+
6262
+ // Fast path: pointer equality.
6263
+ if (DenseMapInfo<swift::TypeBase *>::isEqual (lhsTy, rhsTy))
6264
+ return true ;
6265
+
6266
+ // If either side is empty or tombstone, let's use pointer equality.
6267
+ {
6268
+ auto emptyTy = llvm::DenseMapInfo<swift::TypeBase *>::getEmptyKey ();
6269
+ auto tombstoneTy =
6270
+ llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey ();
6271
+
6272
+ if (lhsTy == emptyTy || lhsTy == tombstoneTy)
6273
+ return lhsTy == rhsTy;
6274
+
6275
+ if (rhsTy == emptyTy || rhsTy == tombstoneTy)
6276
+ return lhsTy == rhsTy;
6277
+ }
6278
+
6279
+ // Otherwise let's drop the sugar and check.
6280
+ return LHS.BindingType ->isEqual (RHS.BindingType );
6281
+ }
6282
+
6283
+ private:
6284
+ static Binding placeholderKey (swift::Type type) {
6285
+ return Binding::forPlaceholder (type);
6286
+ }
6287
+ };
6236
6288
}
6237
6289
6238
6290
#endif // LLVM_SWIFT_SEMA_CONSTRAINT_SYSTEM_H
0 commit comments