@@ -605,98 +605,79 @@ namespace {
605
605
mustConsider = nullptr) {
606
606
// Find the type variable associated with the function, if any.
607
607
auto tyvarType = CS.getType (expr->getFn ())->getAs <TypeVariableType>();
608
- if (!tyvarType)
608
+ if (!tyvarType || CS. getFixedType (tyvarType) )
609
609
return ;
610
610
611
611
// This type variable is only currently associated with the function
612
612
// being applied, and the only constraint attached to it should
613
613
// be the disjunction constraint for the overload group.
614
- auto &CG = CS.getConstraintGraph ();
615
- llvm::SetVector<Constraint *> disjunctions;
616
- CG.gatherConstraints (tyvarType, disjunctions,
617
- ConstraintGraph::GatheringKind::EquivalenceClass,
618
- [](Constraint *constraint) -> bool {
619
- return constraint->getKind () ==
620
- ConstraintKind::Disjunction;
621
- });
622
- if (disjunctions.empty ())
614
+ auto disjunction = CS.getUnboundBindOverloadDisjunction (tyvarType);
615
+ if (!disjunction)
623
616
return ;
624
617
625
- // Look for the disjunction that binds the overload set.
626
- for (auto *disjunction : disjunctions) {
627
- auto oldConstraints = disjunction->getNestedConstraints ();
628
- auto csLoc = CS.getConstraintLocator (expr->getFn ());
618
+ auto oldConstraints = disjunction->getNestedConstraints ();
619
+ auto csLoc = CS.getConstraintLocator (expr->getFn ());
629
620
630
- // Only replace the disjunctive overload constraint.
631
- if (oldConstraints[0 ]->getKind () != ConstraintKind::BindOverload) {
632
- continue ;
621
+ if (mustConsider) {
622
+ bool hasMustConsider = false ;
623
+ for (auto oldConstraint : oldConstraints) {
624
+ auto overloadChoice = oldConstraint->getOverloadChoice ();
625
+ if (overloadChoice.isDecl () &&
626
+ mustConsider (overloadChoice.getDecl ()))
627
+ hasMustConsider = true ;
633
628
}
634
-
635
- if (mustConsider) {
636
- bool hasMustConsider = false ;
637
- for (auto oldConstraint : oldConstraints) {
638
- auto overloadChoice = oldConstraint->getOverloadChoice ();
639
- if (overloadChoice.isDecl () &&
640
- mustConsider (overloadChoice.getDecl ()))
641
- hasMustConsider = true ;
642
- }
643
- if (hasMustConsider) {
644
- continue ;
645
- }
629
+ if (hasMustConsider) {
630
+ return ;
646
631
}
632
+ }
647
633
648
- // Copy over the existing bindings, dividing the constraints up
649
- // into "favored" and non-favored lists.
650
- SmallVector<Constraint *, 4 > favoredConstraints;
651
- SmallVector<Constraint *, 4 > fallbackConstraints;
652
- for (auto oldConstraint : oldConstraints) {
653
- if (!oldConstraint->getOverloadChoice ().isDecl ())
654
- continue ;
655
- auto decl = oldConstraint->getOverloadChoice ().getDecl ();
656
- if (!decl->getAttrs ().isUnavailable (CS.getASTContext ()) &&
657
- isFavored (decl))
658
- favoredConstraints.push_back (oldConstraint);
659
- else
660
- fallbackConstraints.push_back (oldConstraint);
661
- }
634
+ // Copy over the existing bindings, dividing the constraints up
635
+ // into "favored" and non-favored lists.
636
+ SmallVector<Constraint *, 4 > favoredConstraints;
637
+ SmallVector<Constraint *, 4 > fallbackConstraints;
638
+ for (auto oldConstraint : oldConstraints) {
639
+ if (!oldConstraint->getOverloadChoice ().isDecl ())
640
+ return ;
641
+ auto decl = oldConstraint->getOverloadChoice ().getDecl ();
642
+ if (!decl->getAttrs ().isUnavailable (CS.getASTContext ()) &&
643
+ isFavored (decl))
644
+ favoredConstraints.push_back (oldConstraint);
645
+ else
646
+ fallbackConstraints.push_back (oldConstraint);
647
+ }
662
648
663
- // If we did not find any favored constraints, we're done.
664
- if (favoredConstraints.empty ()) break ;
649
+ // If we did not find any favored constraints, we're done.
650
+ if (favoredConstraints.empty ()) return ;
665
651
666
- if (favoredConstraints.size () == 1 ) {
667
- auto overloadChoice = favoredConstraints[0 ]->getOverloadChoice ();
668
- auto overloadType = overloadChoice.getDecl ()->getInterfaceType ();
669
- auto resultType = overloadType->getAs <AnyFunctionType>()->getResult ();
670
- CS.setFavoredType (expr, resultType.getPointer ());
671
- }
652
+ if (favoredConstraints.size () == 1 ) {
653
+ auto overloadChoice = favoredConstraints[0 ]->getOverloadChoice ();
654
+ auto overloadType = overloadChoice.getDecl ()->getInterfaceType ();
655
+ auto resultType = overloadType->getAs <AnyFunctionType>()->getResult ();
656
+ CS.setFavoredType (expr, resultType.getPointer ());
657
+ }
672
658
673
- // Remove the original constraint from the inactive constraint
674
- // list and add the new one.
675
- CS.removeInactiveConstraint (disjunction);
659
+ // Remove the original constraint from the inactive constraint
660
+ // list and add the new one.
661
+ CS.removeInactiveConstraint (disjunction);
676
662
677
- // Create the disjunction of favored constraints.
678
- auto favoredConstraintsDisjunction =
679
- Constraint::createDisjunction (CS,
680
- favoredConstraints,
681
- csLoc);
682
-
683
- favoredConstraintsDisjunction->setFavored ();
684
-
685
- llvm::SmallVector<Constraint *, 2 > aggregateConstraints;
686
- aggregateConstraints.push_back (favoredConstraintsDisjunction);
663
+ // Create the disjunction of favored constraints.
664
+ auto favoredConstraintsDisjunction =
665
+ Constraint::createDisjunction (CS, favoredConstraints, csLoc);
666
+ favoredConstraintsDisjunction->setFavored ();
687
667
688
- if (!fallbackConstraints.empty ()) {
689
- // Find the disjunction of fallback constraints. If any
690
- // constraints were added here, create a new disjunction.
691
- Constraint *fallbackConstraintsDisjunction =
692
- Constraint::createDisjunction (CS, fallbackConstraints, csLoc);
668
+ llvm::SmallVector<Constraint *, 2 > aggregateConstraints;
669
+ aggregateConstraints.push_back (favoredConstraintsDisjunction);
693
670
694
- aggregateConstraints.push_back (fallbackConstraintsDisjunction);
695
- }
671
+ if (!fallbackConstraints.empty ()) {
672
+ // Find the disjunction of fallback constraints. If any
673
+ // constraints were added here, create a new disjunction.
674
+ Constraint *fallbackConstraintsDisjunction =
675
+ Constraint::createDisjunction (CS, fallbackConstraints, csLoc);
696
676
697
- CS.addDisjunctionConstraint (aggregateConstraints, csLoc);
698
- break ;
677
+ aggregateConstraints.push_back (fallbackConstraintsDisjunction);
699
678
}
679
+
680
+ CS.addDisjunctionConstraint (aggregateConstraints, csLoc);
700
681
}
701
682
702
683
size_t getOperandCount (Type t) {
0 commit comments