[JVM IR] Support Suspend Main

This adds supports for (parameterless) suspend main entry points for
the JVM IR backend.

In case main is a suspend function, it gains a continuation during
lowering, so we simply generate a plain old `public static void
main(String[] args)`. This entry point invokes `suspend main` via
`kotlin.coroutines.jvm.internal.RunSuspendKt#runSuspend`.

This PR introduces `runSuspend` as a built-in, and generates the
following `main`, passing `args` as appropriate:

```
fun main(args: Array<String>) {
  runSuspend { main(args) }
}
```

The phase ordering has been reshuffled countrary to previous
discussion on #2780, as the MainMethodGeneration pass now introduces lambdas in
the IR. Hence, it has to run before InventNamesForLocalClasses, yet
still after JvmOverloadsAnnotations.

Some dead code was discovered in AddContinuationLowering
This commit is contained in:
Kristoffer Andersen
2019-11-19 11:18:04 +01:00
committed by Ilmir Usmanov
parent 068d547375
commit 55aafb3430
12 changed files with 237 additions and 34 deletions
@@ -656,4 +656,27 @@ public class IrWriteSignatureTestGenerated extends AbstractIrWriteSignatureTest
runTest("compiler/testData/writeSignature/parameterlessMain/simple.kt");
}
}
@TestMetadata("compiler/testData/writeSignature/suspendMain")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendMain extends AbstractIrWriteSignatureTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
}
public void testAllFilesPresentInSuspendMain() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/writeSignature/suspendMain"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
}
@TestMetadata("parameterlessSuspendMain.kt")
public void testParameterlessSuspendMain() throws Exception {
runTest("compiler/testData/writeSignature/suspendMain/parameterlessSuspendMain.kt");
}
@TestMetadata("suspendMain.kt")
public void testSuspendMain() throws Exception {
runTest("compiler/testData/writeSignature/suspendMain/suspendMain.kt");
}
}
}
@@ -655,4 +655,27 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest {
runTest("compiler/testData/writeSignature/parameterlessMain/simple.kt");
}
}
@TestMetadata("compiler/testData/writeSignature/suspendMain")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SuspendMain extends AbstractWriteSignatureTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInSuspendMain() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/writeSignature/suspendMain"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("parameterlessSuspendMain.kt")
public void testParameterlessSuspendMain() throws Exception {
runTest("compiler/testData/writeSignature/suspendMain/parameterlessSuspendMain.kt");
}
@TestMetadata("suspendMain.kt")
public void testSuspendMain() throws Exception {
runTest("compiler/testData/writeSignature/suspendMain/suspendMain.kt");
}
}
}