JVM_IR: mark direct uses of inline lambdas as conditionally suspend

They may or may not be inlined later.

IDK how the test passes when both modules are compiled with the old
backend - perhaps this has something to do with the fact that when `f`
is compiled with the IR backend, the call to `x()` is followed by `pop`
and `getstatic kotlin/Unit.INSTANCE`? This is probably why the original
issue in kotlinx.coroutines reports that everything works fine with
kotlinx-coroutines-core:1.4.3.

^KT-46879 Fixed
^KT-48801 Fixed
This commit is contained in:
pyos
2021-09-20 11:31:33 +02:00
committed by Ilmir Usmanov
parent 41a69ad388
commit f786084a0a
14 changed files with 95 additions and 4 deletions
@@ -4934,6 +4934,12 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -109,9 +109,11 @@ class IrInlineCodegen(
ValueKind.DEFAULT_INLINE_PARAMETER
else
ValueKind.DEFAULT_PARAMETER
// TODO ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_PARAMETER_CALLED_IN_SUSPEND?
isInlineParameter && irValueParameter.type.isSuspendFunctionTypeOrSubtype() ->
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_SUSPEND_PARAMETER
isInlineParameter && irValueParameter.type.isSuspendFunction() ->
if (argumentExpression.isReadOfInlineLambda())
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_PARAMETER_CALLED_IN_SUSPEND
else
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_SUSPEND_PARAMETER
else ->
ValueKind.GENERAL
}
@@ -95,7 +95,7 @@ fun IrFunction.getJvmVisibilityOfDefaultArgumentStub() =
if (DescriptorVisibilities.isPrivate(visibility) || isInlineOnly()) JavaDescriptorVisibilities.PACKAGE_VISIBILITY else DescriptorVisibilities.PUBLIC
fun IrValueParameter.isInlineParameter() =
index >= 0 && !isNoinline && (type.isFunction() || type.isSuspendFunctionTypeOrSubtype()) &&
index >= 0 && !isNoinline && (type.isFunction() || type.isSuspendFunction()) &&
// Parameters with default values are always nullable, so check the expression too.
// Note that the frontend has a diagnostic for nullable inline parameters, so actually
// making this return `false` requires using `@Suppress`.
@@ -0,0 +1,26 @@
// WITH_COROUTINES
// WITH_RUNTIME
// IGNORE_BACKEND_MULTI_MODULE: JVM_MULTI_MODULE_OLD_AGAINST_IR
// FILE: test.kt
package test
inline suspend fun f(crossinline x: suspend () -> Unit) =
object { suspend fun foo() = x() }.foo()
// FILE: main.kt
import test.*
import kotlin.coroutines.*
import helpers.*
inline suspend fun g(crossinline x: suspend () -> Unit) =
f(x)
var result: String = "fail"
inline suspend fun h(crossinline x: suspend () -> String) =
g { result = x() }
fun box(): String {
suspend { h { "OK" } }.startCoroutine(EmptyContinuation)
return result
}
@@ -4904,6 +4904,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -4904,6 +4904,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -4934,6 +4934,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -4934,6 +4934,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -4934,6 +4934,12 @@ public class IrSerializeCompileKotlinAgainstInlineKotlinTestGenerated extends Ab
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -4934,6 +4934,12 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -4904,6 +4904,12 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@Test
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@Test
@TestMetadata("inlineSuspendContinuation.kt")
public void testInlineSuspendContinuation() throws Exception {
@@ -3936,6 +3936,11 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt")
public void testInlineSuspendOfCrossinlineOrdinary() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.kt");
@@ -3936,6 +3936,11 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt")
public void testInlineSuspendOfCrossinlineOrdinary() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.kt");
@@ -3936,6 +3936,11 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest {
runTest("compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt");
}
@TestMetadata("inlinePassthrough.kt")
public void testInlinePassthrough() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlinePassthrough.kt");
}
@TestMetadata("inlineSuspendOfCrossinlineOrdinary.kt")
public void testInlineSuspendOfCrossinlineOrdinary() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfCrossinlineOrdinary.kt");