Replace CHECKCAST kotlin/Unit with ARETURN for tail call optimization

Sometimes instead of {POP, GETSTATIC Unit.INSTANCE, ARETURN} sequence
the codegen emits {CHECKCAST Unit, ARETURN} sequence, which breaks tail
call optimization. By replacing CHECKCAST with ARETURN we eliminate
this issue.

 #KT-19790: Fixed
This commit is contained in:
Ilmir Usmanov
2018-03-27 19:59:17 +03:00
parent 7b2de2de5e
commit eb81c205c7
18 changed files with 223 additions and 58 deletions
@@ -6836,6 +6836,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
doTest(fileName);
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/tailOperations")
@@ -157,30 +157,6 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
doTest(fileName);
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailCallIntrinsics.kt");
doTest(fileName);
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailSuspendUnitFun.kt");
doTest(fileName);
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tryCatchTailCall.kt");
doTest(fileName);
}
@TestMetadata("unreachable.kt")
public void testUnreachable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/unreachable.kt");
doTest(fileName);
}
@TestMetadata("compiler/testData/codegen/bytecodeListing/annotations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -357,4 +333,43 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
}
}
}
@TestMetadata("compiler/testData/codegen/bytecodeListing/tailcall")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Tailcall extends AbstractBytecodeListingTest {
public void testAllFilesPresentInTailcall() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/tailcall"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailcall/tailCallIntrinsics.kt");
doTest(fileName);
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailcall/tailSuspendUnitFun.kt");
doTest(fileName);
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailcall/tryCatchTailCall.kt");
doTest(fileName);
}
@TestMetadata("unreachable.kt")
public void testUnreachable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailcall/unreachable.kt");
doTest(fileName);
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/tailcall/whenUnit.kt");
doTest(fileName);
}
}
}
@@ -6836,6 +6836,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
doTest(fileName);
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/tailOperations")