@@ -230,8 +230,10 @@ void ConstraintGraphNode::notifyReferencingVars(
230
230
231
231
void ConstraintGraphNode::notifyReferencedVars (
232
232
llvm::function_ref<void (ConstraintGraphNode &)> notification) const {
233
- for (auto *fixedBinding : getReferencedVars ()) {
234
- notification (CG[fixedBinding]);
233
+ for (auto *referencedVar : getReferencedVars ()) {
234
+ auto *repr = referencedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
235
+ if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
236
+ notification (CG[repr]);
235
237
}
236
238
}
237
239
@@ -285,30 +287,6 @@ void ConstraintGraphNode::removeReferencedBy(TypeVariableType *typeVar) {
285
287
}
286
288
}
287
289
288
- void ConstraintGraphNode::introduceToInference (Constraint *constraint) {
289
- if (forRepresentativeVar ()) {
290
- auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
291
- if (!fixedType)
292
- getPotentialBindings ().infer (CG.getConstraintSystem (), TypeVar, constraint);
293
- } else {
294
- auto *repr =
295
- getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
296
- CG[repr].introduceToInference (constraint);
297
- }
298
- }
299
-
300
- void ConstraintGraphNode::retractFromInference (Constraint *constraint) {
301
- if (forRepresentativeVar ()) {
302
- auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
303
- if (!fixedType)
304
- getPotentialBindings ().retract (CG.getConstraintSystem (), TypeVar,constraint);
305
- } else {
306
- auto *repr =
307
- getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
308
- CG[repr].retractFromInference (constraint);
309
- }
310
- }
311
-
312
290
void ConstraintGraphNode::updateFixedType (
313
291
Type fixedType,
314
292
llvm::function_ref<void (ConstraintGraphNode &,
@@ -328,7 +306,11 @@ void ConstraintGraphNode::updateFixedType(
328
306
fixedType->getTypeVariables (referencedVars);
329
307
330
308
for (auto *referencedVar : referencedVars) {
331
- auto &node = CG[referencedVar];
309
+ auto *repr = referencedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
310
+ if (repr->getImpl ().getFixedType (/* record=*/ nullptr ))
311
+ continue ;
312
+
313
+ auto &node = CG[repr];
332
314
333
315
// Newly referred vars need to re-introduce all constraints associated
334
316
// with this type variable since they are now going to be used in
@@ -341,18 +323,20 @@ void ConstraintGraphNode::updateFixedType(
341
323
}
342
324
343
325
void ConstraintGraphNode::retractFromInference (Type fixedType) {
326
+ auto &cs = CG.getConstraintSystem ();
344
327
return updateFixedType (
345
328
fixedType,
346
- [](ConstraintGraphNode &node, Constraint *constraint) {
347
- node.retractFromInference ( constraint);
329
+ [&cs ](ConstraintGraphNode &node, Constraint *constraint) {
330
+ node.getPotentialBindings (). retract (cs, node. getTypeVariable (), constraint);
348
331
});
349
332
}
350
333
351
334
void ConstraintGraphNode::introduceToInference (Type fixedType) {
335
+ auto &cs = CG.getConstraintSystem ();
352
336
return updateFixedType (
353
337
fixedType,
354
- [](ConstraintGraphNode &node, Constraint *constraint) {
355
- node.introduceToInference ( constraint);
338
+ [&cs ](ConstraintGraphNode &node, Constraint *constraint) {
339
+ node.getPotentialBindings (). infer (cs, node. getTypeVariable (), constraint);
356
340
});
357
341
}
358
342
@@ -377,13 +361,13 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
377
361
378
362
addConstraint (typeVar, constraint);
379
363
380
- auto &node = (* this )[typeVar] ;
381
-
382
- node. introduceToInference ( constraint);
364
+ auto *repr = typeVar-> getImpl (). getRepresentative ( /* record= */ nullptr ) ;
365
+ if (!repr-> getImpl (). getFixedType ( /* record= */ nullptr ))
366
+ (* this )[repr]. getPotentialBindings (). infer (CS, repr, constraint);
383
367
384
368
if (isUsefulForReferencedVars (constraint)) {
385
- node .notifyReferencedVars ([&](ConstraintGraphNode &referencedVar ) {
386
- referencedVar. introduceToInference ( constraint);
369
+ (* this )[typeVar] .notifyReferencedVars ([&](ConstraintGraphNode &node ) {
370
+ node. getPotentialBindings (). infer (CS, node. getTypeVariable (), constraint);
387
371
});
388
372
}
389
373
}
@@ -415,14 +399,13 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
415
399
// For the nodes corresponding to each type variable...
416
400
auto referencedTypeVars = constraint->getTypeVariables ();
417
401
for (auto typeVar : referencedTypeVars) {
418
- // Find the node for this type variable.
419
- auto &node = (*this )[typeVar];
420
-
421
- node.retractFromInference (constraint);
402
+ auto *repr = typeVar->getImpl ().getRepresentative (/* record=*/ nullptr );
403
+ if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
404
+ (*this )[repr].getPotentialBindings ().retract (CS, repr, constraint);
422
405
423
406
if (isUsefulForReferencedVars (constraint)) {
424
- node .notifyReferencedVars ([&](ConstraintGraphNode &referencedVar ) {
425
- referencedVar. retractFromInference ( constraint);
407
+ (* this )[typeVar] .notifyReferencedVars ([&](ConstraintGraphNode &node ) {
408
+ node. getPotentialBindings (). retract (CS, node. getTypeVariable (), constraint);
426
409
});
427
410
}
428
411
@@ -468,7 +451,7 @@ void ConstraintGraph::mergeNodesPre(TypeVariableType *typeVar2) {
468
451
469
452
node.notifyReferencingVars (
470
453
[&](ConstraintGraphNode &node, Constraint *constraint) {
471
- node.retractFromInference ( constraint);
454
+ node.getPotentialBindings (). retract (CS, node. getTypeVariable (), constraint);
472
455
});
473
456
}
474
457
}
@@ -498,19 +481,20 @@ void ConstraintGraph::mergeNodes(TypeVariableType *typeVar1,
498
481
auto &node = (*this )[newMember];
499
482
500
483
for (auto *constraint : node.getConstraints ()) {
501
- repNode.introduceToInference (constraint);
484
+ if (!typeVar1->getImpl ().getFixedType (/* record=*/ nullptr ))
485
+ repNode.getPotentialBindings ().infer (CS, typeVar1, constraint);
502
486
503
487
if (!isUsefulForReferencedVars (constraint))
504
488
continue ;
505
489
506
- repNode.notifyReferencedVars ([&](ConstraintGraphNode &referencedVar ) {
507
- referencedVar. introduceToInference ( constraint);
490
+ repNode.notifyReferencedVars ([&](ConstraintGraphNode &node ) {
491
+ node. getPotentialBindings (). infer (CS, node. getTypeVariable (), constraint);
508
492
});
509
493
}
510
494
511
495
node.notifyReferencingVars (
512
496
[&](ConstraintGraphNode &node, Constraint *constraint) {
513
- node.introduceToInference ( constraint);
497
+ node.getPotentialBindings (). infer (CS, node. getTypeVariable (), constraint);
514
498
});
515
499
}
516
500
}
0 commit comments