From fe0e9db3aa9456aa7b9f9c335a4475ec2c2c21d7 Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Wed, 26 Oct 2022 13:10:32 +0200 Subject: [PATCH] [JS IR] Generate debug info for JS switch statements #KT-46276 --- .../coroutines/JsSuspendFunctionsLowering.kt | 5 +++-- .../js/transformers/irToJs/SwitchOptimizer.kt | 4 ++-- compiler/testData/debug/stepping/if.kt | 6 +++++- .../testData/debug/stepping/stringSwitches.kt | 14 +++++++++++++- .../debug/stepping/stringSwitchesSmall.kt | 11 ++++++++++- compiler/testData/debug/stepping/when.kt | 16 +++++++++++++++- .../debug/stepping/whenComplicatedSubject.kt | 5 ++++- compiler/testData/debug/stepping/whenConstant.kt | 3 ++- .../testData/debug/stepping/whenMultiLine.kt | 8 +++++++- .../debug/stepping/whenMultiLineSubject.kt | 8 +++++++- .../debug/stepping/whenNullalbeSubject.kt | 3 ++- compiler/testData/debug/stepping/whenSubject.kt | 16 +++++++++++++++- compiler/testData/debug/stepping/whenSubject2.kt | 16 +++++++++++++++- 13 files changed, 100 insertions(+), 15 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt index e7c9f26c6c0..10f486c0210 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.lower.FinallyBlocksLowering import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.backend.common.lower.ReturnableBlockTransformer import org.jetbrains.kotlin.backend.common.lower.coroutines.loweredSuspendFunctionReturnType +import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder import org.jetbrains.kotlin.ir.builders.* @@ -85,7 +86,7 @@ class JsSuspendFunctionsLowering(ctx: JsCommonBackendContext) : AbstractSuspendF val unit = context.irBuiltIns.unitType - val switch = IrWhenImpl(body.startOffset, body.endOffset, unit, JsStatementOrigins.COROUTINE_SWITCH) + val switch = IrWhenImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, unit, JsStatementOrigins.COROUTINE_SWITCH) val stateVar = JsIrBuilder.buildVar(context.irBuiltIns.intType, stateMachineFunction) val switchBlock = IrBlockImpl(switch.startOffset, switch.endOffset, switch.type).apply { statements += stateVar @@ -284,4 +285,4 @@ class JsSuspendFunctionsLowering(ctx: JsCommonBackendContext) : AbstractSuspendF val functionReturnType = scope.scopeOwnerSymbol.assertedCast { "Expected function symbol" }.owner.returnType +irReturn(generateDelegatedCall(functionReturnType, call)) } -} \ No newline at end of file +} diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/SwitchOptimizer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/SwitchOptimizer.kt index feb12afa0a4..305033b18ff 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/SwitchOptimizer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/SwitchOptimizer.kt @@ -179,7 +179,7 @@ class SwitchOptimizer(private val context: JsGenerationContext, private val isEx fun tryOptimize(irWhen: IrWhen): JsStatement? { - return detectSwitch(irWhen)?.let { buildJsSwitch(it) } + return detectSwitch(irWhen)?.let { buildJsSwitch(it).withSource(irWhen, context) } } -} \ No newline at end of file +} diff --git a/compiler/testData/debug/stepping/if.kt b/compiler/testData/debug/stepping/if.kt index 53f63a950f7..0ed2c9bef0a 100644 --- a/compiler/testData/debug/stepping/if.kt +++ b/compiler/testData/debug/stepping/if.kt @@ -1,4 +1,4 @@ -// IGNORE_BACKEND: JS_IR + // FILE: test.kt fun box(): Int { if ( @@ -25,3 +25,7 @@ inline fun getB(): Int { // test.kt:8 box // EXPECTATIONS JS_IR +// test.kt:14 box +// test.kt:5 box +// test.kt:11 getA +// test.kt:14 box diff --git a/compiler/testData/debug/stepping/stringSwitches.kt b/compiler/testData/debug/stepping/stringSwitches.kt index 0a4e856dda9..ce6e76e8975 100644 --- a/compiler/testData/debug/stepping/stringSwitches.kt +++ b/compiler/testData/debug/stepping/stringSwitches.kt @@ -114,31 +114,43 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:29 box +// test.kt:4 stringSwitch // test.kt:5 stringSwitch // test.kt:11 stringSwitch +// test.kt:11 stringSwitch // test.kt:12 stringSwitch // test.kt:19 stringSwitch +// test.kt:18 stringSwitch // test.kt:21 stringSwitch // test.kt:26 stringSwitch // test.kt:30 box +// test.kt:4 stringSwitch // test.kt:6 stringSwitch // test.kt:11 stringSwitch +// test.kt:11 stringSwitch // test.kt:13 stringSwitch // test.kt:19 stringSwitch +// test.kt:18 stringSwitch // test.kt:22 stringSwitch // test.kt:26 stringSwitch // test.kt:31 box +// test.kt:4 stringSwitch // test.kt:7 stringSwitch // test.kt:11 stringSwitch +// test.kt:11 stringSwitch // test.kt:14 stringSwitch // test.kt:19 stringSwitch +// test.kt:18 stringSwitch // test.kt:23 stringSwitch // test.kt:26 stringSwitch // test.kt:32 box +// test.kt:4 stringSwitch // test.kt:8 stringSwitch // test.kt:11 stringSwitch +// test.kt:11 stringSwitch // test.kt:15 stringSwitch // test.kt:19 stringSwitch +// test.kt:18 stringSwitch // test.kt:24 stringSwitch // test.kt:26 stringSwitch -// test.kt:33 box \ No newline at end of file +// test.kt:33 box diff --git a/compiler/testData/debug/stepping/stringSwitchesSmall.kt b/compiler/testData/debug/stepping/stringSwitchesSmall.kt index 2610c78bb24..40c199db822 100644 --- a/compiler/testData/debug/stepping/stringSwitchesSmall.kt +++ b/compiler/testData/debug/stepping/stringSwitchesSmall.kt @@ -97,24 +97,33 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:26 box +// test.kt:4 stringSwitch // test.kt:5 stringSwitch // test.kt:10 stringSwitch +// test.kt:10 stringSwitch // test.kt:11 stringSwitch // test.kt:17 stringSwitch +// test.kt:16 stringSwitch // test.kt:19 stringSwitch // test.kt:23 stringSwitch // test.kt:27 box +// test.kt:4 stringSwitch // test.kt:6 stringSwitch // test.kt:10 stringSwitch +// test.kt:10 stringSwitch // test.kt:12 stringSwitch // test.kt:17 stringSwitch +// test.kt:16 stringSwitch // test.kt:20 stringSwitch // test.kt:23 stringSwitch // test.kt:28 box +// test.kt:4 stringSwitch // test.kt:7 stringSwitch // test.kt:10 stringSwitch +// test.kt:10 stringSwitch // test.kt:13 stringSwitch // test.kt:17 stringSwitch +// test.kt:16 stringSwitch // test.kt:21 stringSwitch // test.kt:23 stringSwitch -// test.kt:29 box \ No newline at end of file +// test.kt:29 box diff --git a/compiler/testData/debug/stepping/when.kt b/compiler/testData/debug/stepping/when.kt index edf6f4100df..e03ac225ff7 100644 --- a/compiler/testData/debug/stepping/when.kt +++ b/compiler/testData/debug/stepping/when.kt @@ -121,23 +121,37 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:18 box +// test.kt:4 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:6 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:13 foo // test.kt:10 foo // test.kt:15 foo +// test.kt:10 foo // test.kt:12 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:13 foo // test.kt:10 foo // test.kt:15 foo // test.kt:10 foo // test.kt:15 foo +// test.kt:10 foo // test.kt:11 foo +// test.kt:4 foo // test.kt:6 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:13 foo // test.kt:10 foo // test.kt:15 foo +// test.kt:10 foo // test.kt:12 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:13 foo // test.kt:10 foo // test.kt:15 foo @@ -145,4 +159,4 @@ fun box() { // test.kt:15 foo // test.kt:10 foo // test.kt:15 foo -// test.kt:19 box \ No newline at end of file +// test.kt:19 box diff --git a/compiler/testData/debug/stepping/whenComplicatedSubject.kt b/compiler/testData/debug/stepping/whenComplicatedSubject.kt index d7db55d09d2..975f9008596 100644 --- a/compiler/testData/debug/stepping/whenComplicatedSubject.kt +++ b/compiler/testData/debug/stepping/whenComplicatedSubject.kt @@ -50,17 +50,20 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:16 box +// test.kt:5 foo // test.kt:6 foo // test.kt:10 foo // test.kt:11 foo // test.kt:13 foo // test.kt:17 box +// test.kt:5 foo // test.kt:7 foo // test.kt:10 foo // test.kt:11 foo // test.kt:13 foo // test.kt:18 box +// test.kt:5 foo // test.kt:8 foo // test.kt:10 foo // test.kt:13 foo -// test.kt:19 box \ No newline at end of file +// test.kt:19 box diff --git a/compiler/testData/debug/stepping/whenConstant.kt b/compiler/testData/debug/stepping/whenConstant.kt index 2a1155f9c1b..87cfbe3adfb 100644 --- a/compiler/testData/debug/stepping/whenConstant.kt +++ b/compiler/testData/debug/stepping/whenConstant.kt @@ -24,4 +24,5 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:4 box -// test.kt:12 box \ No newline at end of file +// test.kt:4 box +// test.kt:12 box diff --git a/compiler/testData/debug/stepping/whenMultiLine.kt b/compiler/testData/debug/stepping/whenMultiLine.kt index edb195d8537..a311e3e824c 100644 --- a/compiler/testData/debug/stepping/whenMultiLine.kt +++ b/compiler/testData/debug/stepping/whenMultiLine.kt @@ -84,12 +84,18 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:26 box +// test.kt:4 foo +// test.kt:13 foo // test.kt:15 foo // test.kt:22 foo // test.kt:27 box +// test.kt:4 foo +// test.kt:13 foo // test.kt:17 foo // test.kt:22 foo // test.kt:28 box +// test.kt:4 foo +// test.kt:13 foo // test.kt:19 foo // test.kt:22 foo -// test.kt:29 box \ No newline at end of file +// test.kt:29 box diff --git a/compiler/testData/debug/stepping/whenMultiLineSubject.kt b/compiler/testData/debug/stepping/whenMultiLineSubject.kt index b1946fed065..eaff6d70ec4 100644 --- a/compiler/testData/debug/stepping/whenMultiLineSubject.kt +++ b/compiler/testData/debug/stepping/whenMultiLineSubject.kt @@ -58,17 +58,23 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:26 box // test.kt:4 foo +// test.kt:4 foo +// test.kt:13 foo // test.kt:13 foo // test.kt:15 foo // test.kt:22 foo // test.kt:27 box // test.kt:4 foo +// test.kt:4 foo +// test.kt:13 foo // test.kt:13 foo // test.kt:17 foo // test.kt:22 foo // test.kt:28 box // test.kt:4 foo +// test.kt:4 foo +// test.kt:13 foo // test.kt:13 foo // test.kt:19 foo // test.kt:22 foo -// test.kt:29 box \ No newline at end of file +// test.kt:29 box diff --git a/compiler/testData/debug/stepping/whenNullalbeSubject.kt b/compiler/testData/debug/stepping/whenNullalbeSubject.kt index 63e06843ba6..b2912c641c4 100644 --- a/compiler/testData/debug/stepping/whenNullalbeSubject.kt +++ b/compiler/testData/debug/stepping/whenNullalbeSubject.kt @@ -26,4 +26,5 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:4 box // test.kt:5 box -// test.kt:16 box \ No newline at end of file +// test.kt:5 box +// test.kt:16 box diff --git a/compiler/testData/debug/stepping/whenSubject.kt b/compiler/testData/debug/stepping/whenSubject.kt index 2565a4906e5..846d0890017 100644 --- a/compiler/testData/debug/stepping/whenSubject.kt +++ b/compiler/testData/debug/stepping/whenSubject.kt @@ -73,17 +73,24 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:18 box // test.kt:4 foo +// test.kt:4 foo // test.kt:5 foo // test.kt:4 foo +// test.kt:4 foo // test.kt:6 foo // test.kt:4 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:10 foo // test.kt:13 foo // test.kt:10 foo // test.kt:15 foo // test.kt:10 foo +// test.kt:10 foo // test.kt:12 foo // test.kt:4 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:10 foo // test.kt:13 foo // test.kt:10 foo @@ -91,17 +98,24 @@ fun box() { // test.kt:10 foo // test.kt:15 foo // test.kt:10 foo +// test.kt:10 foo // test.kt:11 foo // test.kt:4 foo +// test.kt:4 foo // test.kt:6 foo // test.kt:4 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:10 foo // test.kt:13 foo // test.kt:10 foo // test.kt:15 foo // test.kt:10 foo +// test.kt:10 foo // test.kt:12 foo // test.kt:4 foo +// test.kt:4 foo +// test.kt:10 foo // test.kt:10 foo // test.kt:13 foo // test.kt:10 foo @@ -110,4 +124,4 @@ fun box() { // test.kt:15 foo // test.kt:10 foo // test.kt:15 foo -// test.kt:19 box \ No newline at end of file +// test.kt:19 box diff --git a/compiler/testData/debug/stepping/whenSubject2.kt b/compiler/testData/debug/stepping/whenSubject2.kt index 65a96a38cbe..885525f03ce 100644 --- a/compiler/testData/debug/stepping/whenSubject2.kt +++ b/compiler/testData/debug/stepping/whenSubject2.kt @@ -123,36 +123,50 @@ fun box() { // EXPECTATIONS JS_IR // test.kt:22 box // test.kt:5 foo +// test.kt:4 foo // test.kt:7 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:8 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:17 foo // test.kt:12 foo // test.kt:19 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:16 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:17 foo // test.kt:12 foo // test.kt:19 foo // test.kt:12 foo // test.kt:19 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:15 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:8 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:17 foo // test.kt:12 foo // test.kt:19 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:16 foo // test.kt:5 foo +// test.kt:4 foo // test.kt:13 foo +// test.kt:12 foo // test.kt:17 foo // test.kt:12 foo // test.kt:19 foo @@ -160,4 +174,4 @@ fun box() { // test.kt:19 foo // test.kt:12 foo // test.kt:19 foo -// test.kt:23 box \ No newline at end of file +// test.kt:23 box