From e96fc74ffa444eacf2347b66ed1a23f80f97b3bf Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 1 Dec 2020 12:40:03 +0300 Subject: [PATCH] JVM_IR KT-43519 no delegates for external funs in multifile facades Also add ABI tests for @JvmStatic/JvmOverloads + 'external'. --- .../jvm/lower/GenerateMultifileFacades.kt | 3 +++ .../bytecodeListing/jvmOverloadsExternal.kt | 4 +++ .../bytecodeListing/jvmOverloadsExternal.txt | 7 +++++ .../bytecodeListing/jvmStaticExternal.kt | 14 ++++++++++ .../bytecodeListing/jvmStaticExternal.txt | 27 +++++++++++++++++++ .../codegen/bytecodeListing/kt43519.kt | 5 ++++ .../codegen/bytecodeListing/kt43519.txt | 10 +++++++ .../codegen/BytecodeListingTestGenerated.java | 15 +++++++++++ .../ir/IrBytecodeListingTestGenerated.java | 15 +++++++++++ 9 files changed, 100 insertions(+) create mode 100644 compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt create mode 100644 compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.txt create mode 100644 compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt create mode 100644 compiler/testData/codegen/bytecodeListing/jvmStaticExternal.txt create mode 100644 compiler/testData/codegen/bytecodeListing/kt43519.kt create mode 100644 compiler/testData/codegen/bytecodeListing/kt43519.txt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt index cab6684f634..70c09b607ae 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt @@ -145,6 +145,9 @@ private fun generateMultifileFacades( for (member in partClass.declarations) { if (member !is IrSimpleFunction) continue + // KT-43519 Don't generate delegates for external methods + if (member.isExternal) continue + val correspondingProperty = member.correspondingPropertySymbol?.owner if (member.hasAnnotation(INLINE_ONLY_ANNOTATION_FQ_NAME) || correspondingProperty?.hasAnnotation(INLINE_ONLY_ANNOTATION_FQ_NAME) == true diff --git a/compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt b/compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt new file mode 100644 index 00000000000..105182652f1 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME + +@JvmOverloads +external fun foo(x: Int = 42) \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.txt b/compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.txt new file mode 100644 index 00000000000..9e296bb4516 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.txt @@ -0,0 +1,7 @@ +@kotlin.Metadata +public final class JvmOverloadsExternalKt { + // source: 'jvmOverloadsExternal.kt' + public synthetic static method foo$default(p0: int, p1: int, p2: java.lang.Object): void + public final static @kotlin.jvm.JvmOverloads method foo(): void + public native final static @kotlin.jvm.JvmOverloads method foo(p0: int): void +} diff --git a/compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt b/compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt new file mode 100644 index 00000000000..298afa2de27 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +// JVM_TARGET: 1.8 + +object TestObject { + @JvmStatic + external fun foo() +} + +class TestClassCompanion { + companion object { + @JvmStatic + external fun foo() + } +} diff --git a/compiler/testData/codegen/bytecodeListing/jvmStaticExternal.txt b/compiler/testData/codegen/bytecodeListing/jvmStaticExternal.txt new file mode 100644 index 00000000000..98fbff61b2e --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/jvmStaticExternal.txt @@ -0,0 +1,27 @@ +@kotlin.Metadata +public final class TestClassCompanion$Companion { + // source: 'jvmStaticExternal.kt' + private method (): void + public synthetic method (p0: kotlin.jvm.internal.DefaultConstructorMarker): void + public final @kotlin.jvm.JvmStatic method foo(): void + public final inner class TestClassCompanion$Companion +} + +@kotlin.Metadata +public final class TestClassCompanion { + // source: 'jvmStaticExternal.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: TestClassCompanion$Companion + static method (): void + public method (): void + public native final static @kotlin.jvm.JvmStatic method foo(): void + public final inner class TestClassCompanion$Companion +} + +@kotlin.Metadata +public final class TestObject { + // source: 'jvmStaticExternal.kt' + public final static @org.jetbrains.annotations.NotNull field INSTANCE: TestObject + static method (): void + private method (): void + public native final static @kotlin.jvm.JvmStatic method foo(): void +} diff --git a/compiler/testData/codegen/bytecodeListing/kt43519.kt b/compiler/testData/codegen/bytecodeListing/kt43519.kt new file mode 100644 index 00000000000..ffe9d17f0c0 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/kt43519.kt @@ -0,0 +1,5 @@ +// WITH_RUNTIME +@file:JvmMultifileClass() +@file:JvmName("a") + +external fun externalFun(): Long \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/kt43519.txt b/compiler/testData/codegen/bytecodeListing/kt43519.txt new file mode 100644 index 00000000000..75df6902263 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/kt43519.txt @@ -0,0 +1,10 @@ +@kotlin.Metadata +public final class a { + // source: 'kt43519.kt' +} + +@kotlin.Metadata +synthetic final class a__Kt43519Kt { + // source: 'kt43519.kt' + public native final static method externalFun(): long +} diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 77db5a0f348..c51b8439e0a 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -99,6 +99,16 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/jvmOverloadsAndParametersAnnotations.kt"); } + @TestMetadata("jvmOverloadsExternal.kt") + public void testJvmOverloadsExternal() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt"); + } + + @TestMetadata("jvmStaticExternal.kt") + public void testJvmStaticExternal() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt"); + } + @TestMetadata("jvmStaticWithDefaultParameters.kt") public void testJvmStaticWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/jvmStaticWithDefaultParameters.kt"); @@ -124,6 +134,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/kt43440.kt"); } + @TestMetadata("kt43519.kt") + public void testKt43519() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/kt43519.kt"); + } + @TestMetadata("localFunctionInInitBlock.kt") public void testLocalFunctionInInitBlock() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/localFunctionInInitBlock.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index aacd9cf3344..e2bdfb7564b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -99,6 +99,16 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/jvmOverloadsAndParametersAnnotations.kt"); } + @TestMetadata("jvmOverloadsExternal.kt") + public void testJvmOverloadsExternal() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt"); + } + + @TestMetadata("jvmStaticExternal.kt") + public void testJvmStaticExternal() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt"); + } + @TestMetadata("jvmStaticWithDefaultParameters.kt") public void testJvmStaticWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/jvmStaticWithDefaultParameters.kt"); @@ -124,6 +134,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/kt43440.kt"); } + @TestMetadata("kt43519.kt") + public void testKt43519() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/kt43519.kt"); + } + @TestMetadata("localFunctionInInitBlock.kt") public void testLocalFunctionInInitBlock() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/localFunctionInInitBlock.kt");