From 890fbd6b0be253ee2ca5ddbd3bd621b11f4a0258 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Thu, 16 Nov 2023 13:25:51 +0000 Subject: [PATCH] [K/JS] Process JS-specific returnable blocks before the state machine building ^KT-60785 Fixed ^KT-63207 Fixed --- .../kotlin/ir/backend/js/JsLoweringPhases.kt | 5 ++- .../intrinsicSemantics/intercepted.kt | 1 - .../intrinsicSemantics/releaseIntercepted.kt | 1 - .../inlineLocalsStateMachineTransform.kt | 2 - .../debug/localVariables/suspend/mergeLvt.kt | 1 + .../nestedInsideSuspendUnintercepted.kt | 1 + .../suspend/nestedSuspendUnintercepted.kt | 1 + ...dSuspendUninterceptedWithDeepLambdaCall.kt | 1 + .../js/test/fir/FirJsBoxTestGenerated.java | 6 +++ .../js/test/fir/FirJsES6BoxTestGenerated.java | 6 +++ .../js/test/ir/IrBoxJsES6TestGenerated.java | 6 +++ .../js/test/ir/IrBoxJsTestGenerated.java | 6 +++ .../boxingUnboxingInsideTheSuspendFunction.kt | 2 - .../coroutines/suspendLambdaWithValueClass.kt | 43 +++++++++++++++++++ .../testData/lineNumbers/coroutine.kt | 3 +- 15 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt index 0839973c4e5..513bb699602 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt @@ -429,7 +429,8 @@ private val innerClassConstructorCallsLoweringPhase = makeIrModulePhase: // test.kt:38 doResume: // test.kt:38 doResume: +// test.kt:38 doResume: // test.kt:27 doResume: // test.kt:28 doResume: a=Unit diff --git a/compiler/testData/debug/localVariables/suspend/nestedInsideSuspendUnintercepted.kt b/compiler/testData/debug/localVariables/suspend/nestedInsideSuspendUnintercepted.kt index 1d23f9f0903..85248d18082 100644 --- a/compiler/testData/debug/localVariables/suspend/nestedInsideSuspendUnintercepted.kt +++ b/compiler/testData/debug/localVariables/suspend/nestedInsideSuspendUnintercepted.kt @@ -71,5 +71,6 @@ suspend fun box() { // test.kt:7 id: obj=2:number // test.kt:38 doResume: c=1:number, b=2:number // test.kt:38 doResume: c=1:number, b=2:number +// test.kt:39 doResume: c=1:number, b=2:number // test.kt:30 doResume: c=1:number, b=2:number // test.kt:31 doResume: c=1:number, b=2:number, a=Unit diff --git a/compiler/testData/debug/localVariables/suspend/nestedSuspendUnintercepted.kt b/compiler/testData/debug/localVariables/suspend/nestedSuspendUnintercepted.kt index c135da1465c..47802d8c24b 100644 --- a/compiler/testData/debug/localVariables/suspend/nestedSuspendUnintercepted.kt +++ b/compiler/testData/debug/localVariables/suspend/nestedSuspendUnintercepted.kt @@ -42,5 +42,6 @@ suspend fun box() { // EXPECTATIONS JS_IR // test.kt:31 doResume: // test.kt:31 doResume: +// test.kt:31 doResume: // test.kt:22 doResume: // test.kt:23 doResume: a=Unit diff --git a/compiler/testData/debug/localVariables/suspend/nestedSuspendUninterceptedWithDeepLambdaCall.kt b/compiler/testData/debug/localVariables/suspend/nestedSuspendUninterceptedWithDeepLambdaCall.kt index 5c8c0c4de00..fb7c4c3c437 100644 --- a/compiler/testData/debug/localVariables/suspend/nestedSuspendUninterceptedWithDeepLambdaCall.kt +++ b/compiler/testData/debug/localVariables/suspend/nestedSuspendUninterceptedWithDeepLambdaCall.kt @@ -103,5 +103,6 @@ suspend fun box() { // test.kt:7 id: obj=5:number // test.kt:44 doResume: b=2:number, e=5:number // test.kt:44 doResume: b=2:number, e=5:number +// test.kt:45 doResume: b=2:number, e=5:number // test.kt:33 doResume: b=2:number, e=5:number // test.kt:37 doResume: b=2:number, e=5:number, result=Unit diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java index d1110ac8c01..20bc9e69554 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java @@ -962,6 +962,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest { runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt"); } + @Test + @TestMetadata("suspendLambdaWithValueClass.kt") + public void testSuspendLambdaWithValueClass() throws Exception { + runTest("js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt"); + } + @Test @TestMetadata("suspendMethodWithSuperCall.kt") public void testSuspendMethodWithSuperCall() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java index bf0c998502a..d77c3a86652 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java @@ -962,6 +962,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest { runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt"); } + @Test + @TestMetadata("suspendLambdaWithValueClass.kt") + public void testSuspendLambdaWithValueClass() throws Exception { + runTest("js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt"); + } + @Test @TestMetadata("suspendMethodWithSuperCall.kt") public void testSuspendMethodWithSuperCall() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java index 2c2fccb3311..2721135823f 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java @@ -962,6 +962,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt"); } + @Test + @TestMetadata("suspendLambdaWithValueClass.kt") + public void testSuspendLambdaWithValueClass() throws Exception { + runTest("js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt"); + } + @Test @TestMetadata("suspendMethodWithSuperCall.kt") public void testSuspendMethodWithSuperCall() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index 555215572a7..fafd8d2dd29 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -962,6 +962,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/coroutines/suspendInvokeWithSuspendKlassRef.kt"); } + @Test + @TestMetadata("suspendLambdaWithValueClass.kt") + public void testSuspendLambdaWithValueClass() throws Exception { + runTest("js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt"); + } + @Test @TestMetadata("suspendMethodWithSuperCall.kt") public void testSuspendMethodWithSuperCall() throws Exception { diff --git a/js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt b/js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt index fe3814024d3..ce4c8e67e13 100644 --- a/js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt +++ b/js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt @@ -1,8 +1,6 @@ // WITH_STDLIB // EXPECTED_REACHABLE_NODES: 1292 // KT-60785 -// Ignored until the rr/vgrechko/accidental-reification-2 will be merged -// IGNORE_BACKEND: JS_IR, JS_IR_ES6 import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* diff --git a/js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt b/js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt new file mode 100644 index 00000000000..3ff285c67db --- /dev/null +++ b/js/js.translator/testData/box/coroutines/suspendLambdaWithValueClass.kt @@ -0,0 +1,43 @@ +// WITH_STDLIB +// WITH_COROUTINES +// IGNORE_BACKEND: JS +import helpers.* +import kotlin.coroutines.* + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(object : Continuation { + override val context = EmptyCoroutineContext + override fun resumeWith(result: Result) { + result.getOrThrow() + } + }) +} + +fun box(): String { + val a: suspend () -> Unit = { + mapOf( + 0x0000000000000000UL to 0x0000000000000000UL + ).forEach { (base: ULong) -> + 0x0000000000000000UL.ror(2) + base.ror(1) + } + } + + val b: () -> Unit = { + mapOf( + 0x0000000000000000UL to 0x0000000000000000UL + ).forEach { (base: ULong) -> + 0x0000000000000000UL.ror(2) + base.ror(1) + } + } + + builder { + a() + b() + } + + return "OK" +} + +infix fun ULong.ror(shift: Int): ULong = this shr shift \ No newline at end of file diff --git a/js/js.translator/testData/lineNumbers/coroutine.kt b/js/js.translator/testData/lineNumbers/coroutine.kt index 334744c9898..d4c8a23589c 100644 --- a/js/js.translator/testData/lineNumbers/coroutine.kt +++ b/js/js.translator/testData/lineNumbers/coroutine.kt @@ -15,5 +15,4 @@ suspend fun bar(): Unit { } // LINES(JS): 39 4 4 4 7 5 5 45 45 5 93 45 5 5 6 4 4 4 9 15 9 9 9 * 9 15 10 10 11 11 11 11 11 * 11 12 12 13 13 13 13 13 13 13 14 14 * 9 15 9 9 9 9 -// LINES(JS_IR): 4 4 * 93 3 45 45 7 7 6 9 9 * 9 * 9 * 10 10 * 11 * 11 12 12 * 13 * 13 14 14 15 15 - +// LINES(JS_IR): 4 4 * 9 9 * 4 * 4 * 19 5 5 * 19 * 19 19 * 19 19 * 6 6 * 19 * 19 * 4 * 9 * 9 * 10 10 * 11 * 11 12 12 * 13 * 13 14 14 15 15