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:
@@ -108,11 +108,9 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun generateStub(resolvedCall: ResolvedCall<*>?, codegen: BaseExpressionCodegen) {
|
protected fun generateStub(text: String, codegen: BaseExpressionCodegen) {
|
||||||
leaveTemps()
|
leaveTemps()
|
||||||
assert(resolvedCall != null)
|
AsmUtil.genThrow(codegen.v, "java/lang/UnsupportedOperationException", "Call is part of inline cycle: $text")
|
||||||
val message = "Call is part of inline cycle: " + resolvedCall!!.call.callElement.text
|
|
||||||
AsmUtil.genThrow(codegen.v, "java/lang/UnsupportedOperationException", message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun endCall(result: InlineResult, registerLineNumberAfterwards: Boolean) {
|
protected fun endCall(result: InlineResult, registerLineNumberAfterwards: Boolean) {
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ class PsiInlineCodegen(
|
|||||||
callDefault: Boolean,
|
callDefault: Boolean,
|
||||||
codegen: ExpressionCodegen
|
codegen: ExpressionCodegen
|
||||||
) {
|
) {
|
||||||
if (!state.globalInlineContext.enterIntoInlining(resolvedCall?.resultingDescriptor, resolvedCall?.call?.callElement)) {
|
if (!state.globalInlineContext.enterIntoInlining(functionDescriptor, resolvedCall?.call?.callElement)) {
|
||||||
generateStub(resolvedCall, codegen)
|
generateStub(resolvedCall?.call?.callElement?.text ?: "<no source>", codegen)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
+7
-6
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.jvm.lower.suspendFunctionOriginal
|
|||||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||||
import org.jetbrains.kotlin.ir.util.render
|
|
||||||
|
|
||||||
interface IrInlineCallGenerator : IrCallGenerator {
|
interface IrInlineCallGenerator : IrCallGenerator {
|
||||||
override fun genCall(
|
override fun genCall(
|
||||||
@@ -21,11 +20,9 @@ interface IrInlineCallGenerator : IrCallGenerator {
|
|||||||
) {
|
) {
|
||||||
val element = PsiSourceManager.findPsiElement(expression, codegen.irFunction)
|
val element = PsiSourceManager.findPsiElement(expression, codegen.irFunction)
|
||||||
?: PsiSourceManager.findPsiElement(codegen.irFunction)
|
?: PsiSourceManager.findPsiElement(codegen.irFunction)
|
||||||
if (!codegen.state.globalInlineContext.enterIntoInlining(
|
val descriptor = expression.symbol.owner.suspendFunctionOriginal().toIrBasedDescriptor()
|
||||||
expression.symbol.owner.suspendFunctionOriginal().toIrBasedDescriptor(), element)
|
if (!codegen.state.globalInlineContext.enterIntoInlining(descriptor, element)) {
|
||||||
) {
|
genCycleStub(expression.psiElement?.text ?: "<no source>", codegen)
|
||||||
val message = "Call is a part of inline call cycle: ${expression.render()}"
|
|
||||||
AsmUtil.genThrow(codegen.visitor, "java/lang/UnsupportedOperationException", message)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -41,4 +38,8 @@ interface IrInlineCallGenerator : IrCallGenerator {
|
|||||||
expression: IrFunctionAccessExpression,
|
expression: IrFunctionAccessExpression,
|
||||||
isInsideIfCondition: Boolean,
|
isInsideIfCondition: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun genCycleStub(text: String, codegen: ExpressionCodegen) {
|
||||||
|
AsmUtil.genThrow(codegen.visitor, "java/lang/UnsupportedOperationException", "Call is a part of inline call cycle: $text")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -153,6 +153,10 @@ class IrInlineCodegen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun genCycleStub(text: String, codegen: ExpressionCodegen) {
|
||||||
|
generateStub(text, codegen)
|
||||||
|
}
|
||||||
|
|
||||||
override fun extractDefaultLambdas(node: MethodNode): List<DefaultLambda> {
|
override fun extractDefaultLambdas(node: MethodNode): List<DefaultLambda> {
|
||||||
if (maskStartIndex == -1) return listOf()
|
if (maskStartIndex == -1) return listOf()
|
||||||
return expandMaskConditionsAndUpdateVariableNodes(
|
return expandMaskConditionsAndUpdateVariableNodes(
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
inline val String.foo: String
|
||||||
|
get() = <!INLINE_CALL_CYCLE!>foo<!>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val kotlin.String.foo: kotlin.String
|
||||||
+6
@@ -49,6 +49,12 @@ public class DiagnosticsTestWithJvmIrBackendGenerated extends AbstractDiagnostic
|
|||||||
runTest("compiler/testData/diagnostics/testsWithJvmBackend/noWarningInLV1_5.kt");
|
runTest("compiler/testData/diagnostics/testsWithJvmBackend/noWarningInLV1_5.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("propertyInlineCycle.kt")
|
||||||
|
public void testPropertyInlineCycle() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithJvmBackend/propertyInlineCycle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("suspendInlineCycle_ir.kt")
|
@TestMetadata("suspendInlineCycle_ir.kt")
|
||||||
public void testSuspendInlineCycle_ir() throws Exception {
|
public void testSuspendInlineCycle_ir() throws Exception {
|
||||||
|
|||||||
+6
@@ -49,6 +49,12 @@ public class DiagnosticsTestWithOldJvmBackendGenerated extends AbstractDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/testsWithJvmBackend/noWarningInLV1_5.kt");
|
runTest("compiler/testData/diagnostics/testsWithJvmBackend/noWarningInLV1_5.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("propertyInlineCycle.kt")
|
||||||
|
public void testPropertyInlineCycle() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithJvmBackend/propertyInlineCycle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("suspendInlineCycle.kt")
|
@TestMetadata("suspendInlineCycle.kt")
|
||||||
public void testSuspendInlineCycle() throws Exception {
|
public void testSuspendInlineCycle() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user