diff --git a/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt b/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt index 8df44a1fb8b..41047e1ed6d 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inArrayIndices.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun testPrimitiveArray(i: Int, ints: IntArray) = i in ints.indices fun testObjectArray(i: Int, xs: Array) = i in xs.indices diff --git a/compiler/testData/codegen/bytecodeText/ranges/inCharSequenceIndices.kt b/compiler/testData/codegen/bytecodeText/ranges/inCharSequenceIndices.kt index ec63ebb6656..dc99f14af48 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inCharSequenceIndices.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inCharSequenceIndices.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun testCharSequence(i: Int, cs: CharSequence) = i in cs.indices fun testLongWithCharSequence(i: Long, cs: CharSequence) = i in cs.indices diff --git a/compiler/testData/codegen/bytecodeText/ranges/inCollectionIndices.kt b/compiler/testData/codegen/bytecodeText/ranges/inCollectionIndices.kt index 2105af659e3..68a38503f69 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inCollectionIndices.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inCollectionIndices.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun testCollection(i: Int, xs: List) = i in xs.indices fun testLongWithCollection(i: Long, xs: List) = i in xs.indices diff --git a/compiler/testData/codegen/bytecodeText/ranges/inComparableRangeLiteral.kt b/compiler/testData/codegen/bytecodeText/ranges/inComparableRangeLiteral.kt index a80d0077daa..45c38e55c13 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inComparableRangeLiteral.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inComparableRangeLiteral.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun test1(a: String) = a in "alpha" .. "omega" fun test2(a: String) = a !in "alpha" .. "omega" diff --git a/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt b/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt index 3093a95ac74..6080300f80a 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inMixedUnsignedRange.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun ub_ub(x: UByte, a: UByte, b: UByte) = x in a..b fun ub_us(x: UByte, a: UShort, b: UShort) = x in a..b diff --git a/compiler/testData/codegen/bytecodeText/ranges/inNonMatchingRangeIntrinsified.kt b/compiler/testData/codegen/bytecodeText/ranges/inNonMatchingRangeIntrinsified.kt index 91430a06284..de8bb4f291b 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inNonMatchingRangeIntrinsified.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inNonMatchingRangeIntrinsified.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun inInt(x: Long): Boolean { return x in 1..2 } diff --git a/compiler/testData/codegen/bytecodeText/ranges/inOptimizableRange.kt b/compiler/testData/codegen/bytecodeText/ranges/inOptimizableRange.kt index 3f626b36f99..78f5b56614e 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inOptimizableRange.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inOptimizableRange.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun Byte.inByte(left: Byte, right: Byte) = this in left..right fun Short.inInt(left: Int, right: Int) = this in left .. right diff --git a/compiler/testData/codegen/bytecodeText/ranges/inOptimizableUnsignedRange.kt b/compiler/testData/codegen/bytecodeText/ranges/inOptimizableUnsignedRange.kt index fed885e8c8c..d28da88ae4f 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inOptimizableUnsignedRange.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inOptimizableUnsignedRange.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun testUIntRangeLiteral(a: UInt, b: UInt) = 42u in a .. b diff --git a/compiler/testData/codegen/bytecodeText/ranges/inUntil.kt b/compiler/testData/codegen/bytecodeText/ranges/inUntil.kt index b38b9409937..cbe4111642a 100644 --- a/compiler/testData/codegen/bytecodeText/ranges/inUntil.kt +++ b/compiler/testData/codegen/bytecodeText/ranges/inUntil.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36829 Optimize 'in' expressions in JVM_IR fun testByte(a: Byte, x: Byte, y: Byte) = a in x until y fun testShort(a: Short, x: Short, y: Short) = a in x until y diff --git a/compiler/testData/codegen/bytecodeText/staticFields/object.kt b/compiler/testData/codegen/bytecodeText/staticFields/object.kt index a30da5b52b9..75b883b8c17 100644 --- a/compiler/testData/codegen/bytecodeText/staticFields/object.kt +++ b/compiler/testData/codegen/bytecodeText/staticFields/object.kt @@ -1,7 +1,12 @@ -// IGNORE_BACKEND: JVM_IR object A { val r: Int = 1 } + +// JVM_TEMPLATES // Field initialized in constant pool // A super constructor call and INSTANCE put -// 2 ALOAD 0 \ No newline at end of file +// 2 ALOAD 0 + +// JVM_IR_TEMPLATES +// JVM_IR generates 'dup' instead of 'astore 0; aload 0' in method of object class +// 1 ALOAD 0 \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/differentTypes.kt b/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/differentTypes.kt index bba44b520d7..71cf5804af3 100644 --- a/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/differentTypes.kt +++ b/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/differentTypes.kt @@ -1,4 +1,4 @@ -// IGNORE_BACKEND: JVM_IR +// -IGNORE_BACKEND: JVM_IR inline fun runAfterLoop(fn: () -> T): T { for (i in 1..2); return fn() @@ -6,18 +6,25 @@ inline fun runAfterLoop(fn: () -> T): T { inline fun bar(x: Int, y: Long, z: Byte, s: String) = runAfterLoop { x.toString() + y.toString() + z.toString() + s } -fun foobar(x: Int, y: Long, s: String, z: Byte) = x.toString() + y.toString() + s + z.toString() +fun foobar(x: Int, y: Long, s: String, z: Byte) {} -fun foo() : String { - return foobar(1, 2L, bar(3, 4L, 5.toByte(), "6"), 7.toByte()) +fun foo() { + foobar(1, 2L, bar(3, 4L, 5.toByte(), "6"), 7.toByte()) } -// fake inline variables occupy 7 ISTOREs. -// 16 ISTORE -// 13 ILOAD // 2 ASTORE -// 8 ALOAD +// 7 ALOAD // 2 LSTORE -// 4 LLOAD +// 3 LLOAD // 1 MAXLOCALS = 10 // 0 InlineMarker + +// JVM_TEMPLATES +// fake inline variables occupy 7 ISTOREs. +// 16 ISTORE +// 11 ILOAD + +// JVM_IR_TEMPLATES +// JVM_IR generates an extra induction variable in 'for (i in 1..2)' (see KT-36837) +// 19 ISTORE +// 14 ILOAD diff --git a/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/primitiveMerge.kt b/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/primitiveMerge.kt index c90e8c9cabf..1a4cbbe0706 100644 --- a/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/primitiveMerge.kt +++ b/compiler/testData/codegen/bytecodeText/storeStackBeforeInline/primitiveMerge.kt @@ -1,4 +1,4 @@ -// IGNORE_BACKEND: JVM_IR +// -IGNORE_BACKEND: JVM_IR inline fun runAfterLoop(fn: () -> T): T { for (i in 1..2); return fn() @@ -6,7 +6,7 @@ inline fun runAfterLoop(fn: () -> T): T { fun bar() : Boolean = true -fun foobar(x: Boolean, y: String, z: String) = x.toString() + y + z +fun foobar(x: Boolean, y: String, z: String) {} inline fun foo() = runAfterLoop { "-" } @@ -14,11 +14,18 @@ fun test() { val result = foobar(if (1 == 1) true else bar(), foo(), "OK") } -// fake inline variables occupy 7 ISTOREs. -// 14 ISTORE -// 8 ILOAD // 2 ASTORE -// 7 ALOAD +// 5 ALOAD // 1 MAXLOCALS = 3 // 1 MAXLOCALS = 4 // 0 InlineMarker + +// JVM_TEMPLATES +// fake inline variables occupy 7 ISTOREs. +// 14 ISTORE +// 7 ILOAD + +// JVM_IR_TEMPLATES +// JVM_IR generates an extra induction variable in 'for (i in 1..2)' (see KT-36837) +// 17 ISTORE +// 10 ILOAD diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntCompare_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntCompare_jvm18.kt index 650c27ba92e..d581efd5cb4 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntCompare_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntCompare_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR val ua = 1234U val ub = 5678U diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntDivide_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntDivide_jvm18.kt index 096f6ee9952..58df5a9128c 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntDivide_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntDivide_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR val ua = 1234U val ub = 5678U diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntRemainder_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntRemainder_jvm18.kt index e42f8d931dd..a1c9be6a204 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntRemainder_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntRemainder_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR val ua = 1234U val ub = 5678U diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntToString_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntToString_jvm18.kt index 8c7d674dbf5..a5e8b953df3 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntToString_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedIntToString_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR fun box(): String { val min = 0U.toString() diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongCompare_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongCompare_jvm18.kt index dd9d95a9237..82dc5abadc5 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongCompare_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongCompare_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR val ua = 1234UL val ub = 5678UL diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongDivide_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongDivide_jvm18.kt index a5009fcdee5..4c323b8b16b 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongDivide_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongDivide_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR val ua = 1234UL val ub = 5678UL diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongRemainder_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongRemainder_jvm18.kt index 3722369f575..5462747fd51 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongRemainder_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongRemainder_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR val ua = 1234UL val ub = 5678UL diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongToString_jvm18.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongToString_jvm18.kt index 3ca1ea43f2f..acab682c5d7 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongToString_jvm18.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/unsignedLongToString_jvm18.kt @@ -1,6 +1,7 @@ // JVM_TARGET: 1.8 // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36838 Use potentially intrinsified methods for unsigned available in JDK 1.8+ in JVM_IR fun box(): String { val min = 0UL.toString() diff --git a/compiler/testData/codegen/bytecodeText/unsignedTypes/whenByUnsigned.kt b/compiler/testData/codegen/bytecodeText/unsignedTypes/whenByUnsigned.kt index 51691fa9be3..452e37241b8 100644 --- a/compiler/testData/codegen/bytecodeText/unsignedTypes/whenByUnsigned.kt +++ b/compiler/testData/codegen/bytecodeText/unsignedTypes/whenByUnsigned.kt @@ -1,5 +1,6 @@ // WITH_RUNTIME // IGNORE_BACKEND: JVM_IR +// TODO KT-36839 Generate 'when' with unsigned subject using TABLESWITCH/LOOKUPSWITCH in JVM_IR const val M1: UInt = 2147483648u diff --git a/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenInitialization.kt b/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenInitialization.kt index c9cdc7d6d2d..8d750b70f73 100644 --- a/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenInitialization.kt +++ b/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenInitialization.kt @@ -1,13 +1,12 @@ -// IGNORE_BACKEND: JVM_IR -enum class A { V } +enum class A { V1, V2, V3 } -fun box(): String { - val a: A = A.V - val b: Boolean - when (a) { - A.V -> b = true - } - return if (b) "OK" else "FAIL" +fun test(a: A) { + val x: Int + when (a) { + A.V1 -> x = 11 + A.V2 -> x = 22 + A.V3 -> x = 33 + } } // 1 TABLESWITCH diff --git a/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenReturn.kt b/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenReturn.kt index b281d361a40..92dd644c778 100644 --- a/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenReturn.kt +++ b/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenReturn.kt @@ -1,10 +1,11 @@ -// IGNORE_BACKEND: JVM_IR -enum class A { V } +//- IGNORE_BACKEND: JVM_IR +enum class A { V1, V2, V3 } -fun box(): String { - val a: A = A.V +fun box(a: A): String { when (a) { - A.V -> return "OK" + A.V1 -> return "V1" + A.V2 -> return "V2" + A.V3 -> return "V3" } } diff --git a/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenUnitStatement.kt b/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenUnitStatement.kt index 5eaf6a9eb5e..62a35740285 100644 --- a/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenUnitStatement.kt +++ b/compiler/testData/codegen/bytecodeText/when/exhaustiveWhenUnitStatement.kt @@ -1,4 +1,6 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36840 Don't generate 'throw' clause for statement 'when' in JVM_IR + enum class AccessMode { READ, WRITE, EXECUTE } fun whenExpr(access: AccessMode) { @@ -9,11 +11,6 @@ fun whenExpr(access: AccessMode) { } } -fun box(): String { - whenExpr(AccessMode.EXECUTE) - return "OK" -} - // 1 TABLESWITCH // 0 LOOKUPSWITCH // 0 ATHROW diff --git a/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt b/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt index 5f47c3e0fcc..dac7c856c92 100644 --- a/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt +++ b/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt @@ -1,6 +1,9 @@ -// IGNORE_BACKEND: JVM_IR fun foo1(x: Int): Boolean { when(x) { + 0 -> return true + 1 -> return false + 2 -> return true + 3 -> return false 2 + 2 -> return true else -> return false } @@ -8,9 +11,14 @@ fun foo1(x: Int): Boolean { fun foo2(x: Int): Boolean { when(x) { + 0 -> return true + 1 -> return false + 2 -> return true + 3 -> return false Integer.MAX_VALUE -> return true else -> return false } } -// 2 TABLESWITCH +// 1 TABLESWITCH +// 1 LOOKUPSWITCH diff --git a/compiler/testData/codegen/bytecodeText/when/noBoxingInDefaultWhenWithSpecialCases.kt b/compiler/testData/codegen/bytecodeText/when/noBoxingInDefaultWhenWithSpecialCases.kt index 6a620f149cb..04f2021cfd4 100644 --- a/compiler/testData/codegen/bytecodeText/when/noBoxingInDefaultWhenWithSpecialCases.kt +++ b/compiler/testData/codegen/bytecodeText/when/noBoxingInDefaultWhenWithSpecialCases.kt @@ -1,27 +1,20 @@ // IGNORE_BACKEND: JVM_IR -// FILE: C.kt -class CInt(val value: Int) -val nCInt3: CInt? = CInt(3) +// TODO KT-36646 Don't box primitive values in equality comparison with objects in JVM_IR -class CLong(val value: Long) -val nCLong3: CLong? = CLong(3) - -// FILE: test.kt fun testInt(i: Int?) = - when (i) { - 0 -> "zero" - 42 -> "magic" - else -> "other" - } + when (i) { + 0 -> "zero" + 42 -> "magic" + else -> "other" + } fun testLong(i: Long?) = - when (i) { - 0L -> "zero" - 42L -> "magic" - else -> "other" - } + when (i) { + 0L -> "zero" + 42L -> "magic" + else -> "other" + } -// @TestKt.class: // 0 valueOf // 0 Integer.valueOf // 0 Long.valueOf diff --git a/compiler/testData/codegen/bytecodeText/when/whenZero.kt b/compiler/testData/codegen/bytecodeText/when/whenZero.kt index 8b2c0dee9d3..97620cd2f50 100644 --- a/compiler/testData/codegen/bytecodeText/when/whenZero.kt +++ b/compiler/testData/codegen/bytecodeText/when/whenZero.kt @@ -1,4 +1,6 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36841 Generate integer comparison with 0 instructions (IFNE, etc) when comparing integers with 0 in JVM_IR + fun test(a: Int, b: Int, c: Int) { when (0) { a -> throw IllegalArgumentException("a is 0") diff --git a/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14597_full.kt b/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14597_full.kt index 6c499513335..e006b5a0a45 100644 --- a/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14597_full.kt +++ b/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14597_full.kt @@ -1,23 +1,20 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36845 Generate enum-based TABLESWITCH/LOOKUPSWITCH on a value with smart cast to enum in JVM_IR + enum class En { A, B, С } -fun main(args: Array) { - -} - -fun box(): String { - var res1 = "fail" - var res2 = "fail2" +fun box() { + var r = "" val en: En = En.A when (en) { - En.A -> {res1 = ""} + En.A -> { r = "when-1" } En.B -> {} En.С -> {} } when (en as En) { - En.A -> {res1 += "O"} + En.A -> { r = "when-2" } En.B -> {} En.С -> {} } @@ -27,13 +24,13 @@ fun box(): String { val en2: Any? = En.A if (en2 is En) { when (en2) { - En.A -> {res1 += "K"} + En.A -> { r = "when-3" } En.B -> {} En.С -> {} } when (en2 as En) { - En.A -> {res2 = ""} + En.A -> { r = "when-4" } En.B -> {} En.С -> {} } @@ -44,20 +41,17 @@ fun box(): String { val en1: Any = En.A if (en1 is En) { when (en1) { - En.A -> {res2 += "O"} + En.A -> { r = "when-5" } En.B -> {} En.С -> {} } // Working without other examples when (en1 as En) { - En.A -> {res2 += "K"} + En.A -> { r = "when-6" } En.B -> {} En.С -> {} } } - - if (res1 != res2) return "different results: $res1 != $res2" - return res1 } // 6 TABLESWITCH \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14802.kt b/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14802.kt index f41d9db31ca..96b7ce38d35 100644 --- a/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14802.kt +++ b/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt14802.kt @@ -1,4 +1,6 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36845 Generate enum-based TABLESWITCH/LOOKUPSWITCH on a value with smart cast to enum in JVM_IR + class EncapsulatedEnum>(val value: T) enum class MyEnum(val value: String) { diff --git a/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt15806.kt b/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt15806.kt index 50990e3c0b1..5be6fa29db8 100644 --- a/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt15806.kt +++ b/compiler/testData/codegen/bytecodeText/whenEnumOptimization/kt15806.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JVM_IR +// TODO KT-36845 Generate enum-based TABLESWITCH/LOOKUPSWITCH on a value with smart cast to enum in JVM_IR private fun Any?.doTheThing(): String { when (this) { diff --git a/compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode.kt b/compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode.kt index 5498514ced4..a235c1e3e22 100644 --- a/compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode.kt +++ b/compiler/testData/codegen/bytecodeText/whenStringOptimization/duplicatingItemsSameHashCode.kt @@ -1,5 +1,5 @@ // IGNORE_BACKEND: JVM_IR -import kotlin.test.assertEquals +// TODO KT-36846 Generate TABLESWITCH/LOOKUPSWITCH in case of matching hashCodes in JVM_IR fun foo(x : String) : String { assert("abz]".hashCode() == "aby|".hashCode())