From a157b58c61f51043863d91e0348ddf05f23a8135 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 30 Nov 2020 11:27:11 +0300 Subject: [PATCH] JVM_IR KT-43610 keep track of "special bridges" for interface funs --- .../kotlin/backend/jvm/lower/BridgeLowering.kt | 12 ++++++++++-- .../specialBridges/signatures/kt43610.kt | 7 +++++++ .../specialBridges/signatures/kt43610.txt | 13 +++++++++++++ .../codegen/BytecodeListingTestGenerated.java | 5 +++++ .../codegen/ir/IrBytecodeListingTestGenerated.java | 5 +++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.kt create mode 100644 compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.txt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index 32cedb790c0..b6231123816 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -188,8 +188,16 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass return false // We don't produce bridges for abstract functions in interfaces. - if (irFunction.isJvmAbstract(context.state.jvmDefaultMode)) - return !irFunction.parentAsClass.isJvmInterface + if (irFunction.isJvmAbstract(context.state.jvmDefaultMode)) { + if (irFunction.parentAsClass.isJvmInterface) { + // If function requires a special bridge, we should record it for generic signatures generation. + if (irFunction.specialBridgeOrNull != null) { + context.functionsWithSpecialBridges.add(irFunction) + } + return false + } + return true + } // Finally, the JVM backend also ignores concrete fake overrides whose implementation is directly inherited from an interface. // This is sound, since we do not generate type-specialized versions of fake overrides and if the method diff --git a/compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.kt b/compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.kt new file mode 100644 index 00000000000..d1177f0a7f5 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.kt @@ -0,0 +1,7 @@ +// WITH_SIGNATURES + +class B(val a: T) + +interface IColl : Collection> { + override fun contains(element: B): kotlin.Boolean +} diff --git a/compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.txt b/compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.txt new file mode 100644 index 00000000000..f7cf234e401 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.txt @@ -0,0 +1,13 @@ +@kotlin.Metadata +public final class<Ljava/lang/Object;> B { + // source: 'kt43610.kt' + public final <()TT;> method getA(): java.lang.Object + public <(TT;)V> method (p0: java.lang.Object): void + private final field a: java.lang.Object +} + +@kotlin.Metadata +public interface;>;Lkotlin/jvm/internal/markers/KMappedMarker;> IColl { + // source: 'kt43610.kt' + public abstract <(LB;)Z> method contains(@org.jetbrains.annotations.NotNull p0: B): boolean +} diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 50083f9262c..1a8ec1ca579 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -1552,6 +1552,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/specialBridges/signatures/implementsSortedMap.kt"); } + @TestMetadata("kt43610.kt") + public void testKt43610() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.kt"); + } + @TestMetadata("nonGenericClass.kt") public void testNonGenericClass() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/specialBridges/signatures/nonGenericClass.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 16284c09f95..51cdf696c7d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -1522,6 +1522,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/specialBridges/signatures/implementsSortedMap.kt"); } + @TestMetadata("kt43610.kt") + public void testKt43610() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/specialBridges/signatures/kt43610.kt"); + } + @TestMetadata("nonGenericClass.kt") public void testNonGenericClass() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/specialBridges/signatures/nonGenericClass.kt");