@@ -103,6 +103,23 @@ ConstraintGraphNode::getEquivalenceClassUnsafe() const{
103
103
}
104
104
105
105
#pragma mark Node mutation
106
+
107
+ static bool isUsefulForReferencedVars (Constraint *constraint) {
108
+ switch (constraint->getKind ()) {
109
+ // Don't attempt to propagate information about `Bind`s and
110
+ // `BindOverload`s to referenced variables since they are
111
+ // adjacent through that binding already, and there is no
112
+ // useful information in trying to process that kind of
113
+ // constraint.
114
+ case ConstraintKind::Bind:
115
+ case ConstraintKind::BindOverload:
116
+ return false ;
117
+
118
+ default :
119
+ return true ;
120
+ }
121
+ }
122
+
106
123
void ConstraintGraphNode::addConstraint (Constraint *constraint) {
107
124
assert (ConstraintIndex.count (constraint) == 0 && " Constraint re-insertion" );
108
125
ConstraintIndex[constraint] = Constraints.size ();
@@ -111,9 +128,11 @@ void ConstraintGraphNode::addConstraint(Constraint *constraint) {
111
128
{
112
129
introduceToInference (constraint);
113
130
114
- notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
115
- referencedVar.introduceToInference (constraint);
116
- });
131
+ if (isUsefulForReferencedVars (constraint)) {
132
+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
133
+ referencedVar.introduceToInference (constraint);
134
+ });
135
+ }
117
136
}
118
137
}
119
138
@@ -129,9 +148,11 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
129
148
{
130
149
retractFromInference (constraint);
131
150
132
- notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
133
- referencedVar.retractFromInference (constraint);
134
- });
151
+ if (isUsefulForReferencedVars (constraint)) {
152
+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
153
+ referencedVar.retractFromInference (constraint);
154
+ });
155
+ }
135
156
}
136
157
137
158
// If this is the last constraint, just pop it off the list and we're done.
@@ -230,6 +251,9 @@ void ConstraintGraphNode::addToEquivalenceClass(
230
251
for (auto *constraint : node.getConstraints ()) {
231
252
introduceToInference (constraint);
232
253
254
+ if (!isUsefulForReferencedVars (constraint))
255
+ continue ;
256
+
233
257
notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
234
258
referencedVar.introduceToInference (constraint);
235
259
});
@@ -295,22 +319,6 @@ inference::PotentialBindings &ConstraintGraphNode::getCurrentBindings() {
295
319
return *Bindings;
296
320
}
297
321
298
- static bool isUsefulForReferencedVars (Constraint *constraint) {
299
- switch (constraint->getKind ()) {
300
- // Don't attempt to propagate information about `Bind`s and
301
- // `BindOverload`s to referenced variables since they are
302
- // adjacent through that binding already, and there is no
303
- // useful information in trying to process that kind of
304
- // constraint.
305
- case ConstraintKind::Bind:
306
- case ConstraintKind::BindOverload:
307
- return false ;
308
-
309
- default :
310
- return true ;
311
- }
312
- }
313
-
314
322
void ConstraintGraphNode::introduceToInference (Constraint *constraint) {
315
323
if (forRepresentativeVar ()) {
316
324
auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
0 commit comments