Do not add continuation parameter for super interface bridges

If there is superinterface (more specifically, fun interface) in one
file with default suspend function, we lower the function, adding
continuation parameter. Then, when we compile another file with a child,
we generate a bridge to the default suspend function, which is already
lowered. So, we do not need to add the continuation parameter.

If the child is in the same file, then we add continuation parameter
after we create a bridge, so, AddContinuationLowering can encounter
bridges to suspend default functions in superinterfaces with
continuation parameter only in multifile examples.

 #KT-47549 Fixed
This commit is contained in:
Ilmir Usmanov
2021-12-02 00:43:40 +01:00
committed by Space
parent be6409f0af
commit b26a81435f
12 changed files with 253 additions and 47 deletions
@@ -9828,12 +9828,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@Test
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
@@ -10663,6 +10657,34 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
public class FunInterface {
@Test
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@Test
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@@ -385,8 +385,13 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower
// the result is called 'view', just to be consistent with old backend.
private fun IrSimpleFunction.suspendFunctionViewOrStub(context: JvmBackendContext): IrSimpleFunction {
if (!isSuspend) return this
// If superinterface is in another file, the bridge to default method will already have continuation parameter,
// so skip it. See KT-47549.
if (origin == JvmLoweredDeclarationOrigin.SUPER_INTERFACE_METHOD_BRIDGE &&
valueParameters.lastOrNull()?.origin == JvmLoweredDeclarationOrigin.CONTINUATION_CLASS
) return this
// We need to use suspend function originals here, since if we use 'this' here,
// turing FlowCollector into 'fun interface' leads to AbstractMethodError
// turing FlowCollector into 'fun interface' leads to AbstractMethodError. See KT-49294.
return context.suspendFunctionOriginalToView.getOrPut(suspendFunctionOriginal()) { createSuspendFunctionStub(context) }
}
@@ -0,0 +1,12 @@
// WITH_STDLIB
// FILE: 1.kt
fun interface I {
fun f(): String
suspend fun s() {}
}
// FILE: box.kt
fun box(): String =
I { "OK" }.f()
@@ -0,0 +1,10 @@
// WITH_STDLIB
fun interface I {
fun f(): String
suspend fun s() {}
}
fun box(): String =
I { "OK" }.f()
@@ -9750,12 +9750,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@Test
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
@@ -10585,6 +10579,34 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
public class FunInterface {
@Test
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@Test
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@@ -9828,12 +9828,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@Test
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
@@ -10663,6 +10657,34 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
public class FunInterface {
@Test
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@Test
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@@ -7280,11 +7280,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@TestMetadata("kt49294.kt")
public void ignoreKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@TestMetadata("suspendFunctionAsSupertype.kt")
public void ignoreSuspendFunctionAsSupertype() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt");
@@ -8366,6 +8361,34 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractLightAnalysisModeTest {
@TestMetadata("kt49294.kt")
public void ignoreKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6968,12 +6968,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@Test
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
@@ -7701,6 +7695,34 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
public class FunInterface {
@Test
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@Test
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@Test
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@@ -7010,12 +7010,6 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@Test
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
@@ -7743,6 +7737,34 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
public class FunInterface {
@Test
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@Test
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@@ -6060,11 +6060,6 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
@@ -6708,6 +6703,34 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractIrCodegenBoxWasmTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath);
}
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -9931,12 +9931,6 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt49294.kt");
}
@Test
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop() throws Exception {
@@ -10774,6 +10768,35 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest {
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface")
@TestDataPath("$PROJECT_ROOT")
@NativeBlackBoxTestCaseGroupProvider(ExtTestCaseGroupProvider.class)
public class FunInterface {
@Test
public void testAllFilesPresentInFunInterface() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("kt47549.kt")
public void testKt47549() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549.kt");
}
@Test
@TestMetadata("kt47549_1.kt")
public void testKt47549_1() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt47549_1.kt");
}
@Test
@TestMetadata("kt49294.kt")
public void testKt49294() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface/kt49294.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")