JVM_IR KT-43610 keep track of "special bridges" for interface funs

This commit is contained in:
Dmitry Petrov
2020-11-30 11:27:11 +03:00
parent c43db2ee8d
commit a157b58c61
5 changed files with 40 additions and 2 deletions
@@ -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
@@ -0,0 +1,7 @@
// WITH_SIGNATURES
class B<T>(val a: T)
interface IColl : Collection<B<Int>> {
override fun contains(element: B<Int>): kotlin.Boolean
}
@@ -0,0 +1,13 @@
@kotlin.Metadata
public final class<<T:Ljava/lang/Object;>Ljava/lang/Object;> B {
// source: 'kt43610.kt'
public final <()TT;> method getA(): java.lang.Object
public <(TT;)V> method <init>(p0: java.lang.Object): void
private final field <TT;> a: java.lang.Object
}
@kotlin.Metadata
public interface<Ljava/lang/Object;Ljava/util/Collection<LB<Ljava/lang/Integer;>;>;Lkotlin/jvm/internal/markers/KMappedMarker;> IColl {
// source: 'kt43610.kt'
public abstract <(LB<Ljava/lang/Integer;>;)Z> method contains(@org.jetbrains.annotations.NotNull p0: B): boolean
}
@@ -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");
@@ -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");