[JS IR] Generate debug info for JS switch statements

#KT-46276
This commit is contained in:
Sergej Jaskiewicz
2022-10-26 13:10:32 +02:00
committed by Space Team
parent b2b7958b62
commit fe0e9db3aa
13 changed files with 100 additions and 15 deletions
@@ -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<IrSimpleFunctionSymbol> { "Expected function symbol" }.owner.returnType
+irReturn(generateDelegatedCall(functionReturnType, call))
}
}
}
@@ -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) }
}
}
}