Add a key to enable spilling of all variables in a suspending context

This commit adds a new key that will allow users to enhance their
debugging experience in suspending contexts when using the IR backend.
After the key is enabled, the following things are changed:
1. All variables in a suspending context are spilled regardless their
liveness.
2. Their LVT records are not shrunk.
3. ACONST_NULL is not spilled to dead variables.

#KT-48678 In progress
This commit is contained in:
Nikita Nazarov
2022-06-11 16:36:09 +03:00
committed by Nikita Nazarov
parent 2bdd45f659
commit 38d97d0621
5 changed files with 31 additions and 9 deletions
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.backend.jvm.unboxInlineClass
import org.jetbrains.kotlin.codegen.ClassBuilder
import org.jetbrains.kotlin.codegen.coroutines.CoroutineTransformerMethodVisitor
import org.jetbrains.kotlin.codegen.coroutines.reportSuspensionPointInsideMonitor
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
@@ -36,13 +37,14 @@ internal fun MethodNode.acceptWithStateMachine(
varsCountByType: Map<Type, Int>,
obtainContinuationClassBuilder: () -> ClassBuilder,
) {
val state = classCodegen.context.state
val context = classCodegen.context
val state = context.state
val languageVersionSettings = state.languageVersionSettings
assert(languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)) { "Experimental coroutines are unsupported in JVM_IR backend" }
val element = if (irFunction.isSuspend)
irFunction.psiElement ?: classCodegen.irClass.psiElement
else
classCodegen.context.suspendLambdaToOriginalFunctionMap[classCodegen.irClass.attributeOwnerId]!!.psiElement
context.suspendLambdaToOriginalFunctionMap[classCodegen.irClass.attributeOwnerId]!!.psiElement
val lineNumber = if (irFunction.isSuspend) {
val irFile = irFunction.file
@@ -74,6 +76,7 @@ internal fun MethodNode.acceptWithStateMachine(
internalNameForDispatchReceiver = classCodegen.type.internalName,
putContinuationParameterToLvt = false,
initialVarsCountByType = varsCountByType,
shouldOptimiseUnusedVariables = !context.configuration.getBoolean(JVMConfigurationKeys.ENABLE_DEBUG_MODE)
)
accept(visitor)
}