Introduce CHECK_TAIL_CALL_OPTIMIZATION directive

This directive generates TailCallOptimizationChecker in package helpers.
The check for tail call optimization is based on coroutine stack traces
bug (feature?): when tail call optimization hits, the continuation
object is not generated. Thus, there is no debug metadata for this
suspend function. Consequently, the coroutines stack trace does not
contain stack trace element for that function.
This check is performed by TailCallOptimizationChecker.

Since this is runtime check, unlike bytecode tests, it does not require
test data adjustments on each codegen or inliner change.

Since the check is based on debug metadata, which is JVM specific, there
is not support for other backends yet.
This commit is contained in:
Ilmir Usmanov
2019-04-04 20:33:13 +03:00
parent 40441a18cc
commit 00e952ab15
49 changed files with 633 additions and 1613 deletions
@@ -5774,6 +5774,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");
}
@TestMetadata("falseUnitCoercion.kt")
public void testFalseUnitCoercion_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/falseUnitCoercion.kt", "kotlin.coroutines.experimental");
@@ -8063,13 +8073,8 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
@TestMetadata("also.kt")
public void testAlso_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("also.kt")
public void testAlso_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt", "kotlin.coroutines");
public void testAlso() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt");
}
@TestMetadata("crossinline.kt")
@@ -8082,24 +8087,9 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/crossinline.kt", "kotlin.coroutines");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/epam.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/epam.kt", "kotlin.coroutines");
}
@TestMetadata("inlineWithStateMachine.kt")
public void testInlineWithStateMachine_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("inlineWithStateMachine.kt")
public void testInlineWithStateMachine_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt", "kotlin.coroutines");
public void testInlineWithStateMachine() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt");
}
@TestMetadata("inlineWithoutStateMachine.kt")
@@ -8123,13 +8113,28 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
@TestMetadata("simple.kt")
public void testSimple_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt", "kotlin.coroutines.experimental");
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt");
}
@TestMetadata("simple.kt")
public void testSimple_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt", "kotlin.coroutines");
@TestMetadata("tailCallIfReturnUnit.kt")
public void testTailCallIfReturnUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt");
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIntrinsics.kt");
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailSuspendUnitFun.kt");
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tryCatchTailCall.kt");
}
@TestMetadata("tryCatch.kt")
@@ -8143,23 +8148,13 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt", "kotlin.coroutines");
public void testUnreachable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt", "kotlin.coroutines");
public void testWhenUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt");
}
}
@@ -481,76 +481,4 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
}
}
}
@TestMetadata("compiler/testData/codegen/bytecodeListing/tailcall")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Tailcall extends AbstractBytecodeListingTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception {
KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInTailcall() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/tailcall"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("tailCallIfReturnUnit.kt")
public void testTailCallIfReturnUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tailCallIfReturnUnit.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("tailCallIfReturnUnit.kt")
public void testTailCallIfReturnUnit_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tailCallIfReturnUnit.kt", "kotlin.coroutines");
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tailCallIntrinsics.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tailCallIntrinsics.kt", "kotlin.coroutines");
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tailSuspendUnitFun.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tailSuspendUnitFun.kt", "kotlin.coroutines");
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tryCatchTailCall.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/tryCatchTailCall.kt", "kotlin.coroutines");
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/unreachable.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeListing/tailcall/unreachable.kt", "kotlin.coroutines");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit() throws Exception {
runTest("compiler/testData/codegen/bytecodeListing/tailcall/whenUnit.kt");
}
}
}
@@ -5774,6 +5774,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");
}
@TestMetadata("falseUnitCoercion.kt")
public void testFalseUnitCoercion_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/falseUnitCoercion.kt", "kotlin.coroutines.experimental");
@@ -8063,13 +8073,8 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
@TestMetadata("also.kt")
public void testAlso_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("also.kt")
public void testAlso_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt", "kotlin.coroutines");
public void testAlso() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt");
}
@TestMetadata("crossinline.kt")
@@ -8082,24 +8087,9 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/crossinline.kt", "kotlin.coroutines");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/epam.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/epam.kt", "kotlin.coroutines");
}
@TestMetadata("inlineWithStateMachine.kt")
public void testInlineWithStateMachine_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("inlineWithStateMachine.kt")
public void testInlineWithStateMachine_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt", "kotlin.coroutines");
public void testInlineWithStateMachine() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt");
}
@TestMetadata("inlineWithoutStateMachine.kt")
@@ -8123,13 +8113,28 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
@TestMetadata("simple.kt")
public void testSimple_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt", "kotlin.coroutines.experimental");
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt");
}
@TestMetadata("simple.kt")
public void testSimple_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt", "kotlin.coroutines");
@TestMetadata("tailCallIfReturnUnit.kt")
public void testTailCallIfReturnUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt");
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIntrinsics.kt");
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailSuspendUnitFun.kt");
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tryCatchTailCall.kt");
}
@TestMetadata("tryCatch.kt")
@@ -8143,23 +8148,13 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt", "kotlin.coroutines");
public void testUnreachable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt", "kotlin.coroutines");
public void testWhenUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt");
}
}
@@ -5774,6 +5774,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");
}
@TestMetadata("falseUnitCoercion.kt")
public void testFalseUnitCoercion_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/falseUnitCoercion.kt", "kotlin.coroutines.experimental");
@@ -8063,13 +8073,8 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
@TestMetadata("also.kt")
public void testAlso_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("also.kt")
public void testAlso_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt", "kotlin.coroutines");
public void testAlso() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/also.kt");
}
@TestMetadata("crossinline.kt")
@@ -8082,24 +8087,9 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/crossinline.kt", "kotlin.coroutines");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/epam.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/epam.kt", "kotlin.coroutines");
}
@TestMetadata("inlineWithStateMachine.kt")
public void testInlineWithStateMachine_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("inlineWithStateMachine.kt")
public void testInlineWithStateMachine_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt", "kotlin.coroutines");
public void testInlineWithStateMachine() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/inlineWithStateMachine.kt");
}
@TestMetadata("inlineWithoutStateMachine.kt")
@@ -8123,13 +8113,28 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
@TestMetadata("simple.kt")
public void testSimple_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt", "kotlin.coroutines.experimental");
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt");
}
@TestMetadata("simple.kt")
public void testSimple_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/simple.kt", "kotlin.coroutines");
@TestMetadata("tailCallIfReturnUnit.kt")
public void testTailCallIfReturnUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt");
}
@TestMetadata("tailCallIntrinsics.kt")
public void testTailCallIntrinsics() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIntrinsics.kt");
}
@TestMetadata("tailSuspendUnitFun.kt")
public void testTailSuspendUnitFun() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailSuspendUnitFun.kt");
}
@TestMetadata("tryCatchTailCall.kt")
public void testTryCatchTailCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/tryCatchTailCall.kt");
}
@TestMetadata("tryCatch.kt")
@@ -8143,23 +8148,13 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("unreachable.kt")
public void testUnreachable_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt", "kotlin.coroutines");
public void testUnreachable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/unreachable.kt");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("whenUnit.kt")
public void testWhenUnit_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt", "kotlin.coroutines");
public void testWhenUnit() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/tailCallOptimizations/whenUnit.kt");
}
}