@@ -53,6 +53,18 @@ BindingSet::BindingSet(ConstraintSystem &CS, TypeVariableType *TypeVar,
5353 for (const auto &binding : info.Bindings )
5454 addBinding (binding, /* isTransitive=*/ false );
5555
56+ for (auto *constraint : info.Constraints ) {
57+ switch (constraint->getKind ()) {
58+ case ConstraintKind::ConformsTo: {
59+ if (constraint->getSecondType ()->is <ProtocolType>())
60+ Protocols.push_back (constraint);
61+ break ;
62+ }
63+ default :
64+ break ;
65+ }
66+ }
67+
5668 for (auto *literal : info.Literals )
5769 addLiteralRequirement (literal);
5870
@@ -1956,6 +1968,7 @@ void PotentialBindings::infer(ConstraintSystem &CS,
19561968 case ConstraintKind::PackElementOf:
19571969 case ConstraintKind::SameShape:
19581970 case ConstraintKind::MaterializePackExpansion:
1971+ case ConstraintKind::ConformsTo:
19591972 // Constraints from which we can't do anything.
19601973 break ;
19611974
@@ -1996,13 +2009,6 @@ void PotentialBindings::infer(ConstraintSystem &CS,
19962009 DelayedBy.push_back (constraint);
19972010 break ;
19982011
1999- case ConstraintKind::ConformsTo: {
2000- auto protocolTy = constraint->getSecondType ();
2001- if (protocolTy->is <ProtocolType>())
2002- Protocols.push_back (constraint);
2003- break ;
2004- }
2005-
20062012 case ConstraintKind::LiteralConformsTo: {
20072013 // Record constraint where protocol requirement originated
20082014 // this is useful to use for the binding later.
@@ -2084,7 +2090,7 @@ void PotentialBindings::retract(ConstraintSystem &CS,
20842090
20852091 LLVM_DEBUG (
20862092 llvm::dbgs () << Constraints.size () << " " << Bindings.size () << " "
2087- << Protocols. size () << " " << Literals.size () << " "
2093+ << Literals.size () << " "
20882094 << AdjacentVars.size () << " " << DelayedBy.size () << " "
20892095 << SubtypeOf.size () << " " << SupertypeOf.size () << " "
20902096 << EquivalentTo.size () << " \n " );
@@ -2096,22 +2102,7 @@ void PotentialBindings::retract(ConstraintSystem &CS,
20962102 }),
20972103 Bindings.end ());
20982104
2099- auto isMatchingConstraint = [&constraint](Constraint *existing) {
2100- return existing == constraint;
2101- };
2102-
2103- auto hasMatchingSource =
2104- [&constraint](
2105- const std::pair<TypeVariableType *, Constraint *> &adjacency) {
2106- return adjacency.second == constraint;
2107- };
2108-
21092105 switch (constraint->getKind ()) {
2110- case ConstraintKind::ConformsTo:
2111- Protocols.erase (llvm::remove_if (Protocols, isMatchingConstraint),
2112- Protocols.end ());
2113- break ;
2114-
21152106 case ConstraintKind::LiteralConformsTo:
21162107 Literals.erase (constraint);
21172108 break ;
@@ -2137,9 +2128,19 @@ void PotentialBindings::retract(ConstraintSystem &CS,
21372128 AdjacentVars.erase (std::make_pair (adjacentVar, constraint));
21382129 }
21392130
2131+ auto isMatchingConstraint = [&constraint](Constraint *existing) {
2132+ return existing == constraint;
2133+ };
2134+
21402135 DelayedBy.erase (llvm::remove_if (DelayedBy, isMatchingConstraint),
21412136 DelayedBy.end ());
21422137
2138+ auto hasMatchingSource =
2139+ [&constraint](
2140+ const std::pair<TypeVariableType *, Constraint *> &adjacency) {
2141+ return adjacency.second == constraint;
2142+ };
2143+
21432144 SubtypeOf.remove_if (hasMatchingSource);
21442145 SupertypeOf.remove_if (hasMatchingSource);
21452146 EquivalentTo.remove_if (hasMatchingSource);
@@ -2149,7 +2150,6 @@ void PotentialBindings::reset() {
21492150 if (CONDITIONAL_ASSERT_enabled ()) {
21502151 ASSERT (Constraints.empty ());
21512152 ASSERT (Bindings.empty ());
2152- ASSERT (Protocols.empty ());
21532153 ASSERT (Literals.empty ());
21542154 ASSERT (Defaults.empty ());
21552155 ASSERT (DelayedBy.empty ());
0 commit comments