JVM: fix inline cycle detection

1. use the correct descriptor in the old backend;
 2. clear the temporary variables for arguments in the IR backend.

 #KT-45292 Fixed
This commit is contained in:
pyos
2021-03-10 14:14:21 +01:00
committed by max-kammerer
parent 4e98d1b857
commit e06bacafad
8 changed files with 33 additions and 12 deletions
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.jvm.lower.suspendFunctionOriginal
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
import org.jetbrains.kotlin.ir.util.render
interface IrInlineCallGenerator : IrCallGenerator {
override fun genCall(
@@ -21,11 +20,9 @@ interface IrInlineCallGenerator : IrCallGenerator {
) {
val element = PsiSourceManager.findPsiElement(expression, codegen.irFunction)
?: PsiSourceManager.findPsiElement(codegen.irFunction)
if (!codegen.state.globalInlineContext.enterIntoInlining(
expression.symbol.owner.suspendFunctionOriginal().toIrBasedDescriptor(), element)
) {
val message = "Call is a part of inline call cycle: ${expression.render()}"
AsmUtil.genThrow(codegen.visitor, "java/lang/UnsupportedOperationException", message)
val descriptor = expression.symbol.owner.suspendFunctionOriginal().toIrBasedDescriptor()
if (!codegen.state.globalInlineContext.enterIntoInlining(descriptor, element)) {
genCycleStub(expression.psiElement?.text ?: "<no source>", codegen)
return
}
try {
@@ -41,4 +38,8 @@ interface IrInlineCallGenerator : IrCallGenerator {
expression: IrFunctionAccessExpression,
isInsideIfCondition: Boolean,
)
fun genCycleStub(text: String, codegen: ExpressionCodegen) {
AsmUtil.genThrow(codegen.visitor, "java/lang/UnsupportedOperationException", "Call is a part of inline call cycle: $text")
}
}
@@ -153,6 +153,10 @@ class IrInlineCodegen(
)
}
override fun genCycleStub(text: String, codegen: ExpressionCodegen) {
generateStub(text, codegen)
}
override fun extractDefaultLambdas(node: MethodNode): List<DefaultLambda> {
if (maskStartIndex == -1) return listOf()
return expandMaskConditionsAndUpdateVariableNodes(