@@ -28,22 +28,26 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
28
28
&inferredBindings) {
29
29
using BindingKind = ConstraintSystem::AllowedBindingKind;
30
30
31
- llvm::SmallVector<Constraint *, 4 > subtypeOf ;
32
- // First, let's collect all of the `subtype` constraints associated
31
+ llvm::SmallVector<Constraint *, 4 > conversions ;
32
+ // First, let's collect all of the conversions associated
33
33
// with this type variable.
34
- llvm::copy_if (Sources, std::back_inserter (subtypeOf),
35
- [&](const Constraint *constraint) -> bool {
36
- if (constraint->getKind () != ConstraintKind::Subtype)
37
- return false ;
38
-
39
- auto rhs = cs.simplifyType (constraint->getSecondType ());
40
- return rhs->getAs <TypeVariableType>() == TypeVar;
41
- });
42
-
43
- if (subtypeOf.empty ())
34
+ llvm::copy_if (
35
+ Sources, std::back_inserter (conversions),
36
+ [&](const Constraint *constraint) -> bool {
37
+ if (constraint->getKind () != ConstraintKind::Subtype &&
38
+ constraint->getKind () != ConstraintKind::Conversion &&
39
+ constraint->getKind () != ConstraintKind::ArgumentConversion &&
40
+ constraint->getKind () != ConstraintKind::OperatorArgumentConversion)
41
+ return false ;
42
+
43
+ auto rhs = cs.simplifyType (constraint->getSecondType ());
44
+ return rhs->getAs <TypeVariableType>() == TypeVar;
45
+ });
46
+
47
+ if (conversions.empty ())
44
48
return ;
45
49
46
- for (auto *constraint : subtypeOf ) {
50
+ for (auto *constraint : conversions ) {
47
51
auto *tv =
48
52
cs.simplifyType (constraint->getFirstType ())->getAs <TypeVariableType>();
49
53
if (!tv)
@@ -53,6 +57,15 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
53
57
if (relatedBindings == inferredBindings.end ())
54
58
continue ;
55
59
60
+ // Infer transitive protocol requirements.
61
+ for (auto *protocol : relatedBindings->getSecond ().Protocols ) {
62
+ Protocols.push_back (protocol);
63
+ }
64
+
65
+ // TODO: We shouldn't need this in the future.
66
+ if (constraint->getKind () != ConstraintKind::Subtype)
67
+ continue ;
68
+
56
69
for (auto &binding : relatedBindings->getSecond ().Bindings ) {
57
70
// We need the binding kind for the potential binding to
58
71
// either be Exact or Supertypes in order for it to make sense
@@ -76,11 +89,6 @@ void ConstraintSystem::PotentialBindings::inferTransitiveBindings(
76
89
addPotentialBinding (
77
90
binding.withSameSource (type, BindingKind::Supertypes));
78
91
}
79
-
80
- // Infer transitive protocol requirements.
81
- for (auto *protocol : relatedBindings->getSecond ().Protocols ) {
82
- Protocols.push_back (protocol);
83
- }
84
92
}
85
93
}
86
94
0 commit comments