@@ -1641,6 +1641,24 @@ void ConstraintSystem::shrink(Expr *expr) {
1641
1641
return { true , expr };
1642
1642
}
1643
1643
1644
+ // / Determine whether this is an arithmetic expression comprised entirely
1645
+ // / of literals.
1646
+ static bool isArithmeticExprOfLiterals (Expr *expr) {
1647
+ expr = expr->getSemanticsProvidingExpr ();
1648
+
1649
+ if (auto prefix = dyn_cast<PrefixUnaryExpr>(expr))
1650
+ return isArithmeticExprOfLiterals (prefix->getArg ());
1651
+
1652
+ if (auto postfix = dyn_cast<PostfixUnaryExpr>(expr))
1653
+ return isArithmeticExprOfLiterals (postfix->getArg ());
1654
+
1655
+ if (auto binary = dyn_cast<BinaryExpr>(expr))
1656
+ return isArithmeticExprOfLiterals (binary->getArg ()->getElement (0 )) &&
1657
+ isArithmeticExprOfLiterals (binary->getArg ()->getElement (1 ));
1658
+
1659
+ return isa<IntegerLiteralExpr>(expr) || isa<FloatLiteralExpr>(expr);
1660
+ }
1661
+
1644
1662
Expr *walkToExprPost (Expr *expr) override {
1645
1663
if (expr == PrimaryExpr) {
1646
1664
// If this is primary expression and there are no candidates
@@ -1688,7 +1706,7 @@ void ConstraintSystem::shrink(Expr *expr) {
1688
1706
// If there are fewer than two overloads in the chain
1689
1707
// there is no point of solving this expression,
1690
1708
// because we won't be able to reduce its domain.
1691
- if (numOverloadSets > 1 )
1709
+ if (numOverloadSets > 1 && ! isArithmeticExprOfLiterals (expr) )
1692
1710
Candidates.push_back (Candidate (CS, expr));
1693
1711
1694
1712
return expr;
0 commit comments