@@ -242,8 +242,10 @@ void ConstraintGraphNode::notifyReferencingVars(
242
242
243
243
void ConstraintGraphNode::notifyReferencedVars (
244
244
llvm::function_ref<void (ConstraintGraphNode &)> notification) const {
245
- for (auto *fixedBinding : getReferencedVars ()) {
246
- notification (CG[fixedBinding]);
245
+ for (auto *referencedVar : getReferencedVars ()) {
246
+ auto *repr = referencedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
247
+ if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
248
+ notification (CG[repr]);
247
249
}
248
250
}
249
251
@@ -297,30 +299,6 @@ void ConstraintGraphNode::removeReferencedBy(TypeVariableType *typeVar) {
297
299
}
298
300
}
299
301
300
- void ConstraintGraphNode::introduceToInference (Constraint *constraint) {
301
- if (forRepresentativeVar ()) {
302
- auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
303
- if (!fixedType)
304
- getPotentialBindings ().infer (CG.getConstraintSystem (), TypeVar, constraint);
305
- } else {
306
- auto *repr =
307
- getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
308
- CG[repr].introduceToInference (constraint);
309
- }
310
- }
311
-
312
- void ConstraintGraphNode::retractFromInference (Constraint *constraint) {
313
- if (forRepresentativeVar ()) {
314
- auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
315
- if (!fixedType)
316
- getPotentialBindings ().retract (CG.getConstraintSystem (), TypeVar,constraint);
317
- } else {
318
- auto *repr =
319
- getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
320
- CG[repr].retractFromInference (constraint);
321
- }
322
- }
323
-
324
302
void ConstraintGraphNode::updateFixedType (
325
303
Type fixedType,
326
304
llvm::function_ref<void (ConstraintGraphNode &,
@@ -340,7 +318,11 @@ void ConstraintGraphNode::updateFixedType(
340
318
fixedType->getTypeVariables (referencedVars);
341
319
342
320
for (auto *referencedVar : referencedVars) {
343
- auto &node = CG[referencedVar];
321
+ auto *repr = referencedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
322
+ if (repr->getImpl ().getFixedType (/* record=*/ nullptr ))
323
+ continue ;
324
+
325
+ auto &node = CG[repr];
344
326
345
327
// Newly referred vars need to re-introduce all constraints associated
346
328
// with this type variable since they are now going to be used in
@@ -353,18 +335,20 @@ void ConstraintGraphNode::updateFixedType(
353
335
}
354
336
355
337
void ConstraintGraphNode::retractFromInference (Type fixedType) {
338
+ auto &cs = CG.getConstraintSystem ();
356
339
return updateFixedType (
357
340
fixedType,
358
- [](ConstraintGraphNode &node, Constraint *constraint) {
359
- node.retractFromInference ( constraint);
341
+ [&cs ](ConstraintGraphNode &node, Constraint *constraint) {
342
+ node.getPotentialBindings (). retract (cs, node. getTypeVariable (), constraint);
360
343
});
361
344
}
362
345
363
346
void ConstraintGraphNode::introduceToInference (Type fixedType) {
347
+ auto &cs = CG.getConstraintSystem ();
364
348
return updateFixedType (
365
349
fixedType,
366
- [](ConstraintGraphNode &node, Constraint *constraint) {
367
- node.introduceToInference ( constraint);
350
+ [&cs ](ConstraintGraphNode &node, Constraint *constraint) {
351
+ node.getPotentialBindings (). infer (cs, node. getTypeVariable (), constraint);
368
352
});
369
353
}
370
354
@@ -396,13 +380,13 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
396
380
397
381
addConstraint (typeVar, constraint);
398
382
399
- auto &node = (* this )[typeVar] ;
400
-
401
- node. introduceToInference ( constraint);
383
+ auto *repr = typeVar-> getImpl (). getRepresentative ( /* record= */ nullptr ) ;
384
+ if (!repr-> getImpl (). getFixedType ( /* record= */ nullptr ))
385
+ (* this )[repr]. getPotentialBindings (). infer (CS, repr, constraint);
402
386
403
387
if (isUsefulForReferencedVars (constraint)) {
404
- node .notifyReferencedVars ([&](ConstraintGraphNode &referencedVar ) {
405
- referencedVar. introduceToInference ( constraint);
388
+ (* this )[typeVar] .notifyReferencedVars ([&](ConstraintGraphNode &node ) {
389
+ node. getPotentialBindings (). infer (CS, node. getTypeVariable (), constraint);
406
390
});
407
391
}
408
392
}
@@ -434,14 +418,13 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
434
418
// For the nodes corresponding to each type variable...
435
419
auto referencedTypeVars = constraint->getTypeVariables ();
436
420
for (auto typeVar : referencedTypeVars) {
437
- // Find the node for this type variable.
438
- auto &node = (*this )[typeVar];
439
-
440
- node.retractFromInference (constraint);
421
+ auto *repr = typeVar->getImpl ().getRepresentative (/* record=*/ nullptr );
422
+ if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
423
+ (*this )[repr].getPotentialBindings ().retract (CS, repr, constraint);
441
424
442
425
if (isUsefulForReferencedVars (constraint)) {
443
- node .notifyReferencedVars ([&](ConstraintGraphNode &referencedVar ) {
444
- referencedVar. retractFromInference ( constraint);
426
+ (* this )[typeVar] .notifyReferencedVars ([&](ConstraintGraphNode &node ) {
427
+ node. getPotentialBindings (). retract (CS, node. getTypeVariable (), constraint);
445
428
});
446
429
}
447
430
@@ -487,7 +470,7 @@ void ConstraintGraph::mergeNodesPre(TypeVariableType *typeVar2) {
487
470
488
471
node.notifyReferencingVars (
489
472
[&](ConstraintGraphNode &node, Constraint *constraint) {
490
- node.retractFromInference ( constraint);
473
+ node.getPotentialBindings (). retract (CS, node. getTypeVariable (), constraint);
491
474
});
492
475
}
493
476
}
@@ -517,19 +500,20 @@ void ConstraintGraph::mergeNodes(TypeVariableType *typeVar1,
517
500
auto &node = (*this )[newMember];
518
501
519
502
for (auto *constraint : node.getConstraints ()) {
520
- repNode.introduceToInference (constraint);
503
+ if (!typeVar1->getImpl ().getFixedType (/* record=*/ nullptr ))
504
+ repNode.getPotentialBindings ().infer (CS, typeVar1, constraint);
521
505
522
506
if (!isUsefulForReferencedVars (constraint))
523
507
continue ;
524
508
525
- repNode.notifyReferencedVars ([&](ConstraintGraphNode &referencedVar ) {
526
- referencedVar. introduceToInference ( constraint);
509
+ repNode.notifyReferencedVars ([&](ConstraintGraphNode &node ) {
510
+ node. getPotentialBindings (). infer (CS, node. getTypeVariable (), constraint);
527
511
});
528
512
}
529
513
530
514
node.notifyReferencingVars (
531
515
[&](ConstraintGraphNode &node, Constraint *constraint) {
532
- node.introduceToInference ( constraint);
516
+ node.getPotentialBindings (). infer (CS, node. getTypeVariable (), constraint);
533
517
});
534
518
}
535
519
}
0 commit comments