JVM_IR: basic suspend conversion on argument test passed

This commit is contained in:
Dmitry Petrov
2020-04-29 10:42:04 +03:00
parent 819634c4cd
commit d9fd51c608
9 changed files with 145 additions and 4 deletions
@@ -7837,6 +7837,24 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractFirBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: ");
}
public void testAllFilesPresentInSuspendConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -95,13 +95,15 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
override fun visitFunctionReference(expression: IrFunctionReference) {
expression.acceptChildrenVoid(this)
if (expression.isSuspend && expression.isLambdaOrAdaptedCallableReference() && expression !in inlineReferences) {
if (expression.isSuspend && expression.shouldBeTreatedAsSuspendLambda() && expression !in inlineReferences) {
suspendLambdas[expression] = SuspendLambdaInfo(expression)
}
}
private fun IrFunctionReference.isLambdaOrAdaptedCallableReference() =
origin == IrStatementOrigin.LAMBDA || origin == IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE
private fun IrFunctionReference.shouldBeTreatedAsSuspendLambda() =
origin == IrStatementOrigin.LAMBDA ||
origin == IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE ||
origin == IrStatementOrigin.SUSPEND_CONVERSION
})
for (lambda in suspendLambdas.values) {
@@ -456,7 +456,12 @@ private fun StatementGenerator.createFunctionForSuspendConversion(
if (suspendFunReturnType.isUnit()) {
+irAdapteeCall
} else {
+irReturn(irAdapteeCall)
+IrReturnImpl(
startOffset, endOffset,
context.irBuiltIns.nothingType,
irAdapterFun.symbol,
irAdapteeCall
)
}
}
@@ -0,0 +1,26 @@
// !LANGUAGE: +SuspendConversion
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JVM, NATIVE
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_LIGHT_ANALYSIS
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun runS(fn: suspend (String) -> String) = fn("O")
val lambda: (String) -> String = { it + "K" }
fun box(): String {
var test = "Failed"
builder {
test = runS(lambda)
}
return test
}
@@ -8872,6 +8872,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInSuspendConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -8872,6 +8872,24 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractLightAnalysisModeTest {
@TestMetadata("onArgument.kt")
public void ignoreOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInSuspendConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -7837,6 +7837,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractIrBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
}
public void testAllFilesPresentInSuspendConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6677,6 +6677,24 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractIrJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInSuspendConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6677,6 +6677,24 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendConversion extends AbstractJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInSuspendConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)