@@ -29,29 +29,8 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
2929 &inferredBindings) {
3030 using BindingKind = ConstraintSystem::AllowedBindingKind;
3131
32- llvm::SmallVector<Constraint *, 4 > conversions;
33- // First, let's collect all of the conversions associated
34- // with this type variable.
35- llvm::copy_if (
36- Sources, std::back_inserter (conversions),
37- [&](const Constraint *constraint) -> bool {
38- if (constraint->getKind () != ConstraintKind::Subtype &&
39- constraint->getKind () != ConstraintKind::Conversion &&
40- constraint->getKind () != ConstraintKind::ArgumentConversion &&
41- constraint->getKind () != ConstraintKind::OperatorArgumentConversion)
42- return false ;
43-
44- auto rhs = cs.simplifyType (constraint->getSecondType ());
45- return rhs->getAs <TypeVariableType>() == TypeVar;
46- });
47-
48- for (auto *constraint : conversions) {
49- auto *tv =
50- cs.simplifyType (constraint->getFirstType ())->getAs <TypeVariableType>();
51- if (!tv || tv == TypeVar)
52- continue ;
53-
54- auto relatedBindings = inferredBindings.find (tv);
32+ for (const auto &entry : SupertypeOf) {
33+ auto relatedBindings = inferredBindings.find (entry.first );
5534 if (relatedBindings == inferredBindings.end ())
5635 continue ;
5736
@@ -89,7 +68,7 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
8968 llvm::copy (bindings.Defaults , std::back_inserter (Defaults));
9069
9170 // TODO: We shouldn't need this in the future.
92- if (constraint ->getKind () != ConstraintKind::Subtype)
71+ if (entry. second ->getKind () != ConstraintKind::Subtype)
9372 continue ;
9473
9574 for (auto &binding : bindings.Bindings ) {
@@ -670,10 +649,6 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
670649
671650 auto *typeVar = result.TypeVar ;
672651
673- // Record constraint which contributes to the
674- // finding of potential bindings.
675- result.Sources .insert (constraint);
676-
677652 auto first = simplifyType (constraint->getFirstType ());
678653 auto second = simplifyType (constraint->getSecondType ());
679654
@@ -798,15 +773,16 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
798773 if (kind == AllowedBindingKind::Subtypes) {
799774 result.SubtypeOf .insert ({bindingTypeVar, constraint});
800775 } else {
801- // TODO: record this type variable as a `supertypeOf`
776+ assert (kind == AllowedBindingKind::Supertypes);
777+ result.SupertypeOf .insert ({bindingTypeVar, constraint});
802778 }
803779 break ;
804780 }
805781
806782 case ConstraintKind::Bind:
807783 case ConstraintKind::BindParam:
808784 case ConstraintKind::Equal: {
809- // TODO: record this type variable as being equal to other type variable.
785+ result. EquivalentTo . insert ({bindingTypeVar, constraint});
810786 break ;
811787 }
812788
0 commit comments