Do not generate non-standard compareTo as primitive comparison in all backends

Previous changes related to this in the old JVM backend were in
582b1c5e66 and
0482f7e9c5, but they did not affect the
`ProperIeee754Comparisons` mode which became the default in 1.4.0. As a
result, we had a regression here.

Since the `PRIMITIVE_NUMERIC_COMPARISON_INFO` slice is used in psi2ir to
determine how to generate the comparison, this fixes the regression both
in the old JVM backend, and in all IR backends.

 #KT-41426 Fixed
This commit is contained in:
Alexander Udalov
2020-08-27 17:30:32 +02:00
parent 9d81e50128
commit 74c6d2b951
10 changed files with 105 additions and 5 deletions
@@ -4104,15 +4104,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
TypeAndNullability right754Type = calcTypeForIeee754ArithmeticIfNeeded(right, getRightOperandType(primitiveNumericComparisonInfo));
boolean isSame754ArithmeticTypes = left754Type != null && right754Type != null && left754Type.type.equals(right754Type.type);
boolean properIeee754Comparisons = shouldUseProperIeee754Comparisons();
boolean isStandardCompareTo = primitiveNumericComparisonInfo != null;
if (properIeee754Comparisons && left754Type != null && right754Type != null) {
if (properIeee754Comparisons && isStandardCompareTo && left754Type != null && right754Type != null) {
type = comparisonOperandType(left754Type.type, right754Type.type);
//type = comparisonOperandType(leftType, rightType);
leftValue = gen(left);
rightValue = gen(right);
}
else if (!properIeee754Comparisons &&
state.getIntrinsics().getIntrinsic((FunctionDescriptor) resolvedCall.getResultingDescriptor()) instanceof CompareTo &&
else if (!properIeee754Comparisons && isStandardCompareTo &&
((isPrimitive(leftType) && isPrimitive(rightType)) || isSame754ArithmeticTypes)) {
type = isSame754ArithmeticTypes ? left754Type.type : comparisonOperandType(leftType, rightType);
leftValue = gen(left);