JVM_IR: Treat suspend main wrapper as always tail-call function
In other words, never generate suspend call markers inside it.
This commit is contained in:
+5
-1
@@ -113,6 +113,10 @@ internal fun IrFunction.isInvokeSuspendOfContinuation(): Boolean =
|
||||
internal fun IrFunction.isInvokeOfSuspendCallableReference(): Boolean = isSuspend && name.asString() == "invoke" &&
|
||||
parentAsClass.origin == JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL
|
||||
|
||||
// Wrapper of suspend main is always tail-call and it is not generated as suspend function.
|
||||
private fun IrFunction.isInvokeOfSuspendMainWrapper(): Boolean = !isSuspend && name.asString() == "invoke" &&
|
||||
parentAsClass.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL
|
||||
|
||||
internal fun IrFunction.isKnownToBeTailCall(): Boolean =
|
||||
when (origin) {
|
||||
IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER,
|
||||
@@ -125,7 +129,7 @@ internal fun IrFunction.isKnownToBeTailCall(): Boolean =
|
||||
IrDeclarationOrigin.BRIDGE,
|
||||
IrDeclarationOrigin.BRIDGE_SPECIAL,
|
||||
IrDeclarationOrigin.DELEGATED_MEMBER -> true
|
||||
else -> isInvokeOfSuspendCallableReference()
|
||||
else -> isInvokeOfSuspendMainWrapper() || isInvokeOfSuspendCallableReference()
|
||||
}
|
||||
|
||||
internal fun IrFunction.shouldNotContainSuspendMarkers(): Boolean =
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_COROUTINES
|
||||
// TREAT_AS_ONE_FILE
|
||||
|
||||
suspend fun main() {}
|
||||
|
||||
// 0 INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark
|
||||
@@ -1371,6 +1371,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeText/coroutines/returnUnitInLambda.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendMain.kt")
|
||||
public void testSuspendMain() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/coroutines/suspendMain.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("throwOnFailure.kt")
|
||||
public void testThrowOnFailure() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/coroutines/throwOnFailure.kt");
|
||||
|
||||
+5
@@ -1376,6 +1376,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeText/coroutines/returnUnitInLambda.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendMain.kt")
|
||||
public void testSuspendMain() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/coroutines/suspendMain.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("throwOnFailure.kt")
|
||||
public void testThrowOnFailure() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/coroutines/throwOnFailure.kt");
|
||||
|
||||
Reference in New Issue
Block a user