@@ -107,7 +107,14 @@ void ConstraintGraphNode::addConstraint(Constraint *constraint) {
107
107
assert (ConstraintIndex.count (constraint) == 0 && " Constraint re-insertion" );
108
108
ConstraintIndex[constraint] = Constraints.size ();
109
109
Constraints.push_back (constraint);
110
- introduceToInference (constraint, /* notifyFixedBindings=*/ true );
110
+
111
+ {
112
+ introduceToInference (constraint);
113
+
114
+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
115
+ referencedVar.introduceToInference (constraint);
116
+ });
117
+ }
111
118
}
112
119
113
120
void ConstraintGraphNode::removeConstraint (Constraint *constraint) {
@@ -119,8 +126,13 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
119
126
ConstraintIndex.erase (pos);
120
127
assert (Constraints[index] == constraint && " Mismatched constraint" );
121
128
122
- retractFromInference (constraint,
123
- /* notifyFixedBindings=*/ true );
129
+ {
130
+ retractFromInference (constraint);
131
+
132
+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
133
+ referencedVar.retractFromInference (constraint);
134
+ });
135
+ }
124
136
125
137
// If this is the last constraint, just pop it off the list and we're done.
126
138
unsigned lastIndex = Constraints.size ()-1 ;
@@ -160,8 +172,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
160
172
affectedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
161
173
162
174
if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
163
- CG[repr].reintroduceToInference (constraint,
164
- /* notifyReferencedVars=*/ false );
175
+ CG[repr].reintroduceToInference (constraint);
165
176
}
166
177
}
167
178
};
@@ -197,6 +208,13 @@ void ConstraintGraphNode::notifyReferencingVars() const {
197
208
}
198
209
}
199
210
211
+ void ConstraintGraphNode::notifyReferencedVars (
212
+ llvm::function_ref<void (ConstraintGraphNode &)> notification) {
213
+ for (auto *fixedBinding : getReferencedVars ()) {
214
+ notification (CG[fixedBinding]);
215
+ }
216
+ }
217
+
200
218
void ConstraintGraphNode::addToEquivalenceClass (
201
219
ArrayRef<TypeVariableType *> typeVars) {
202
220
assert (forRepresentativeVar () &&
@@ -210,7 +228,11 @@ void ConstraintGraphNode::addToEquivalenceClass(
210
228
auto &node = CG[newMember];
211
229
212
230
for (auto *constraint : node.getConstraints ()) {
213
- introduceToInference (constraint, /* notifyReferencedVars=*/ true );
231
+ introduceToInference (constraint);
232
+
233
+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
234
+ referencedVar.introduceToInference (constraint);
235
+ });
214
236
}
215
237
216
238
node.notifyReferencingVars ();
@@ -289,52 +311,51 @@ static bool isUsefulForReferencedVars(Constraint *constraint) {
289
311
}
290
312
}
291
313
292
- void ConstraintGraphNode::introduceToInference (Constraint *constraint,
293
- bool notifyReferencedVars) {
314
+ void ConstraintGraphNode::introduceToInference (Constraint *constraint) {
294
315
if (forRepresentativeVar ()) {
295
316
auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
296
317
if (!fixedType)
297
318
getCurrentBindings ().infer (constraint);
298
319
} else {
299
320
auto *repr =
300
321
getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
301
- CG[repr].introduceToInference (constraint, /* notifyReferencedVars= */ false );
322
+ CG[repr].introduceToInference (constraint);
302
323
}
303
324
325
+ /*
304
326
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
305
327
return;
306
328
307
- for ( auto *fixedBinding : getReferencedVars () ) {
308
- CG[fixedBinding] .introduceToInference (constraint,
309
- /* notifyReferencedVars= */ false );
310
- }
329
+ this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar ) {
330
+ referencedVar .introduceToInference(constraint);
331
+ } );
332
+ */
311
333
}
312
334
313
- void ConstraintGraphNode::retractFromInference (Constraint *constraint,
314
- bool notifyReferencedVars) {
335
+ void ConstraintGraphNode::retractFromInference (Constraint *constraint) {
315
336
if (forRepresentativeVar ()) {
316
337
auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
317
338
if (!fixedType)
318
339
getCurrentBindings ().retract (constraint);
319
340
} else {
320
341
auto *repr =
321
342
getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
322
- CG[repr].retractFromInference (constraint, /* notifyReferencedVars= */ false );
343
+ CG[repr].retractFromInference (constraint);
323
344
}
324
345
346
+ /*
325
347
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
326
348
return;
327
349
328
- for ( auto *fixedBinding : getReferencedVars () ) {
329
- CG[fixedBinding] .retractFromInference (constraint,
330
- /* notifyReferencedVars= */ false );
331
- }
350
+ this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar ) {
351
+ referencedVar .retractFromInference(constraint);
352
+ } );
353
+ */
332
354
}
333
355
334
- void ConstraintGraphNode::reintroduceToInference (Constraint *constraint,
335
- bool notifyReferencedVars) {
336
- retractFromInference (constraint, notifyReferencedVars);
337
- introduceToInference (constraint, notifyReferencedVars);
356
+ void ConstraintGraphNode::reintroduceToInference (Constraint *constraint) {
357
+ retractFromInference (constraint);
358
+ introduceToInference (constraint);
338
359
}
339
360
340
361
void ConstraintGraphNode::introduceToInference (Type fixedType) {
@@ -360,8 +381,7 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
360
381
// all of the constraints that reference bound type variable.
361
382
for (auto *constraint : getConstraints ()) {
362
383
if (isUsefulForReferencedVars (constraint))
363
- node.reintroduceToInference (constraint,
364
- /* notifyReferencedVars=*/ false );
384
+ node.reintroduceToInference (constraint);
365
385
}
366
386
}
367
387
}
0 commit comments