From d44799fa78f58c5d606e6c7428cc635ee3ef1da8 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Tue, 23 Feb 2021 15:59:51 +0100 Subject: [PATCH] JVM IR: Use INVOKESPECIAL instead of INVOKEVIRTUAL for default private suspend functions. #KT-26592 --- .../FirBlackBoxCodegenTestGenerated.java | 6 ++++ .../jvm/codegen/MethodSignatureMapper.kt | 2 +- .../featureIntersection/jvmDefault.kt | 34 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++++ .../LightAnalysisModeTestGenerated.java | 5 +++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index d5d9d6903a5..c9046994e5f 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -9549,6 +9549,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt"); } + @Test + @TestMetadata("jvmDefault.kt") + public void testJvmDefault() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt"); + } + @Test @TestMetadata("overrideInInlineClass.kt") public void testOverrideInInlineClass() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index 5bec4388da2..3850c9657f4 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -403,7 +403,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { callee.dispatchReceiverParameter == null -> Opcodes.INVOKESTATIC isSuperCall -> Opcodes.INVOKESPECIAL isInterface && !DescriptorVisibilities.isPrivate(callee.visibility) -> Opcodes.INVOKEINTERFACE - DescriptorVisibilities.isPrivate(callee.visibility) && !callee.isSuspend -> Opcodes.INVOKESPECIAL + DescriptorVisibilities.isPrivate(callee.visibility) -> Opcodes.INVOKESPECIAL else -> Opcodes.INVOKEVIRTUAL } diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt new file mode 100644 index 00000000000..543cbfe87bd --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt @@ -0,0 +1,34 @@ +// WITH_RUNTIME +// !JVM_DEFAULT_MODE: all +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// IGNORE_BACKEND: JVM + +import kotlin.coroutines.* + +interface Foo { + private suspend fun test(): String { + return "OK" + } + + suspend fun foo(): String { + return test() + } +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(Continuation(EmptyCoroutineContext) { + it.getOrThrow() + }) +} + +fun box(): String { + var res = "FAIL" + + builder { + val foo: Foo = object : Foo{} + res = foo.foo() + } + + return res +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index a63e361300f..76b9c83a3a0 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -9549,6 +9549,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt"); } + @Test + @TestMetadata("jvmDefault.kt") + public void testJvmDefault() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt"); + } + @Test @TestMetadata("overrideInInlineClass.kt") public void testOverrideInInlineClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index ed7f37b9f4f..a611f81af60 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -9549,6 +9549,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt"); } + @Test + @TestMetadata("jvmDefault.kt") + public void testJvmDefault() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt"); + } + @Test @TestMetadata("overrideInInlineClass.kt") public void testOverrideInInlineClass() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index be628907911..fe021bbcca9 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7517,6 +7517,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface.kt"); } + @TestMetadata("jvmDefault.kt") + public void ignoreJvmDefault() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); }