@@ -57,6 +57,15 @@ static bool isSupportedOperator(Constraint *disjunction) {
57
57
return false ;
58
58
}
59
59
60
+ static bool isStandardComparisonOperator (ValueDecl *decl) {
61
+ return decl->isOperator () &&
62
+ decl->getBaseIdentifier ().isStandardComparisonOperator ();
63
+ }
64
+
65
+ static bool isArithmeticOperator (ValueDecl *decl) {
66
+ return decl->isOperator () && decl->getBaseIdentifier ().isArithmeticOperator ();
67
+ }
68
+
60
69
static bool isSupportedDisjunction (Constraint *disjunction) {
61
70
auto choices = disjunction->getNestedConstraints ();
62
71
@@ -561,9 +570,7 @@ static Constraint *determineBestChoicesInContext(
561
570
// ones that all have the same result type), regular
562
571
// functions/methods and especially initializers could end up
563
572
// with a lot of favored overloads because on the result type alone.
564
- if (score > 0 ||
565
- (decl->isOperator () &&
566
- !decl->getBaseIdentifier ().isStandardComparisonOperator ())) {
573
+ if (decl->isOperator () && !isStandardComparisonOperator (decl)) {
567
574
if (llvm::any_of (resultTypes, [&](const Type candidateResultTy) {
568
575
return scoreCandidateMatch (genericSig,
569
576
overloadType->getResult (),
@@ -575,15 +582,14 @@ static Constraint *determineBestChoicesInContext(
575
582
}
576
583
577
584
if (score > 0 ) {
578
- if (decl->isOperator () &&
579
- decl->getBaseIdentifier ().isArithmeticOperator () &&
585
+ // Nudge the score slightly to prefer concrete homogeneous
586
+ // arithmetic operators.
587
+ //
588
+ // This is an opportunistic optimization based on the operator
589
+ // use patterns where homogeneous operators are the most
590
+ // heavily used ones.
591
+ if (isArithmeticOperator (decl) &&
580
592
overloadType->getNumParams () == 2 ) {
581
- // Nudge the score slightly to prefer concrete homogeneous
582
- // operators.
583
- //
584
- // This is an opportunistic optimization based on the operator
585
- // use patterns where homogeneous operators are the most
586
- // heavily used ones.
587
593
auto resultTy = overloadType->getResult ();
588
594
if (!resultTy->hasTypeParameter () &&
589
595
llvm::all_of (overloadType->getParams (),
0 commit comments