JVM_IR: do not optimize suspend$$forInline functions

`$$forInline` functions do not pass through the state machine generator,
and optimizing `Ref`s before that changes how assignments inside lambdas
passed to `suspendCoroutine`, etc. behave: without a `Ref`, the
assignment is not reflected in the continuation object, so the variable
has old value on resumption.

These functions will be optimized later, after they are inlined
somewhere and the state machine is generated.

^KT-52198 Fixed
This commit is contained in:
pyos
2022-04-29 13:29:42 +02:00
committed by Ilmir Usmanov
parent 153f878df4
commit effd21d074
14 changed files with 109 additions and 7 deletions
@@ -57,7 +57,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jetbrains.org.objectweb.asm.*
import org.jetbrains.org.objectweb.asm.commons.Method
import java.io.File
import java.lang.RuntimeException
class ClassCodegen private constructor(
val irClass: IrClass,
@@ -509,10 +508,15 @@ class ClassCodegen private constructor(
private val IrDeclaration.descriptorOrigin: JvmDeclarationOrigin
get() {
val psiElement = PsiSourceManager.findPsiElement(this)
return if (origin == IrDeclarationOrigin.FILE_CLASS)
JvmDeclarationOrigin(JvmDeclarationOriginKind.PACKAGE_PART, psiElement, toIrBasedDescriptor())
else
OtherOrigin(psiElement, toIrBasedDescriptor())
return when {
origin == IrDeclarationOrigin.FILE_CLASS ->
JvmDeclarationOrigin(JvmDeclarationOriginKind.PACKAGE_PART, psiElement, toIrBasedDescriptor())
(this is IrSimpleFunction && isSuspend && isEffectivelyInlineOnly()) ||
origin == JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE ||
origin == JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE ->
JvmDeclarationOrigin(JvmDeclarationOriginKind.INLINE_VERSION_OF_SUSPEND_FUN, psiElement, toIrBasedDescriptor())
else -> OtherOrigin(psiElement, toIrBasedDescriptor())
}
}
private fun storeSerializedIr(serializedIr: ByteArray) {