From dae358c792e49390b6dd32d4e30fe923eaeba1fe Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 29 Jul 2020 15:22:21 +0300 Subject: [PATCH] JVM: KT-40664 disable optimization for 'ULong in range of UInt' case --- ...PrimitiveNumberRangeIntrinsicRangeValue.kt | 8 +++---- .../range/comparison/ComparisonGenerator.kt | 5 +++- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 ++++ .../unsigned/outOfBoundsInMixedContains.kt | 11 +++++++++ .../ranges/inMixedUnsignedRange.kt | 24 +++++++++---------- .../codegen/BlackBoxCodegenTestGenerated.java | 5 ++++ .../LightAnalysisModeTestGenerated.java | 5 ++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 ++++ .../IrJsCodegenBoxES6TestGenerated.java | 5 ++++ .../IrJsCodegenBoxTestGenerated.java | 5 ++++ .../semantics/JsCodegenBoxTestGenerated.java | 5 ++++ 11 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt index 7442b182faa..14d5e088cfb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeIntrinsicRangeValue.kt @@ -29,7 +29,6 @@ import org.jetbrains.kotlin.codegen.range.inExpression.InExpressionGenerator import org.jetbrains.kotlin.codegen.range.inExpression.InFloatingPointRangeLiteralExpressionGenerator import org.jetbrains.kotlin.codegen.range.inExpression.InIntegralContinuousRangeExpressionGenerator import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.isTopLevelInPackage import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.psi.KtSimpleNameExpression @@ -70,9 +69,10 @@ abstract class PrimitiveNumberRangeIntrinsicRangeValue( ?: throw AssertionError("Floating point intrinsic range value should be a range literal") InFloatingPointRangeLiteralExpressionGenerator(operatorReference, rangeLiteral, comparisonGenerator, codegen.frameMap) } - else -> InIntegralContinuousRangeExpressionGenerator( - operatorReference, rangeContainsTypeInfo, getBoundedValue(codegen), comparisonGenerator, codegen.frameMap - ) + else -> + InIntegralContinuousRangeExpressionGenerator( + operatorReference, rangeContainsTypeInfo, getBoundedValue(codegen), comparisonGenerator, codegen.frameMap + ) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/comparison/ComparisonGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/comparison/ComparisonGenerator.kt index ca4b68cb241..a8a9d1dcf69 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/comparison/ComparisonGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/comparison/ComparisonGenerator.kt @@ -87,7 +87,10 @@ fun getComparisonGeneratorForRangeContainsCall( getComparisonGeneratorForKotlinType(elementType) KotlinBuiltIns.isUInt(elementType) -> - UIntComparisonGenerator + if (KotlinBuiltIns.isULong(valueParameterType)) + null + else + UIntComparisonGenerator KotlinBuiltIns.isULong(elementType) -> ULongComparisonGenerator diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index c8e7869f00d..4206bc780f7 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -24361,6 +24361,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt b/compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt new file mode 100644 index 00000000000..99830393053 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +fun testIn(x: ULong) = + x in UInt.MIN_VALUE..UInt.MAX_VALUE + +fun box(): String = + if (testIn(UInt.MAX_VALUE.toULong() + 1UL)) + "Failed" + else + "OK" diff --git a/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt b/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt index 6080300f80a..7d70491dc7c 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt @@ -16,9 +16,9 @@ fun ui_us(x: UInt, a: UShort, b: UShort) = x in a..b fun ui_ui(x: UInt, a: UInt, b: UInt) = x in a..b fun ui_ul(x: UInt, a: ULong, b: ULong) = x in a..b -fun ul_ub(x: ULong, a: UByte, b: UByte) = x in a..b -fun ul_us(x: ULong, a: UShort, b: UShort) = x in a..b -fun ul_ui(x: ULong, a: UInt, b: UInt) = x in a..b +fun ul_ub(x: ULong, a: UByte, b: UByte) = x in a..b // ULong in range of UInt, uses non-intrinsic 'contains' +fun ul_us(x: ULong, a: UShort, b: UShort) = x in a..b // ULong in range of UInt, uses non-intrinsic 'contains' +fun ul_ui(x: ULong, a: UInt, b: UInt) = x in a..b // ULong in range of UInt, uses non-intrinsic 'contains' fun ul_ul(x: ULong, a: ULong, b: ULong) = x in a..b fun n_ub_ub(x: UByte, a: UByte, b: UByte) = x !in a..b @@ -36,17 +36,17 @@ fun n_ui_us(x: UInt, a: UShort, b: UShort) = x !in a..b fun n_ui_ui(x: UInt, a: UInt, b: UInt) = x !in a..b fun n_ui_ul(x: UInt, a: ULong, b: ULong) = x !in a..b -fun n_ul_ub(x: ULong, a: UByte, b: UByte) = x !in a..b -fun n_ul_us(x: ULong, a: UShort, b: UShort) = x !in a..b -fun n_ul_ui(x: ULong, a: UInt, b: UInt) = x !in a..b +fun n_ul_ub(x: ULong, a: UByte, b: UByte) = x !in a..b // ULong in range of UInt, uses non-intrinsic 'contains' +fun n_ul_us(x: ULong, a: UShort, b: UShort) = x !in a..b // ULong in range of UInt, uses non-intrinsic 'contains' +fun n_ul_ui(x: ULong, a: UInt, b: UInt) = x !in a..b // ULong in range of UInt, uses non-intrinsic 'contains' fun n_ul_ul(x: ULong, a: ULong, b: ULong) = x !in a..b -// 0 contains -// 16 IFLE -// 16 IFLT -// 16 IFGE -// 16 IFGT -// 6 L2I +// 6 contains +// 13 IFLE +// 13 IFLT +// 13 IFGE +// 13 IFGT +// 0 L2I // 22 SIPUSH 255 // 24 LDC 65535 // 2 LDC 4294967295 diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 7046df58952..e8b605c6525 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -25957,6 +25957,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index dde80c35d45..bbefe37a56b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -23591,6 +23591,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 45f5d958c21..ec7bb2bbcb0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -24361,6 +24361,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index aacdbf871c9..72712da8a61 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -20727,6 +20727,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index e85f091219e..9e099e65b64 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -20727,6 +20727,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 1e2440ff05c..e47cd58d521 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -20742,6 +20742,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt"); } + @TestMetadata("outOfBoundsInMixedContains.kt") + public void testOutOfBoundsInMixedContains() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/outOfBoundsInMixedContains.kt"); + } + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)