JVM_IR: Fix check for whether classes are from Java.
This allows us to not generate redundant immutable collection stubs. The code to generate the immutable collection stubs does not deal well with thinking that all external declarations come from Java.
This commit is contained in:
+1
-1
@@ -72,7 +72,7 @@ class JvmGeneratorExtensions(private val generateFacades: Boolean = true) : Gene
|
||||
null
|
||||
|
||||
override fun computeExternalDeclarationOrigin(descriptor: DeclarationDescriptor): IrDeclarationOrigin? =
|
||||
if (descriptor is JavaCallableMemberDescriptor)
|
||||
if (descriptor is JavaCallableMemberDescriptor || descriptor is JavaClassDescriptor)
|
||||
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
else
|
||||
IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
|
||||
|
||||
+5
-4
@@ -108,7 +108,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
||||
irFunction.modality !== Modality.ABSTRACT &&
|
||||
irFunction.visibility !== Visibilities.INVISIBLE_FAKE &&
|
||||
irFunction.overriddenInClasses().firstOrNull { it.getJvmSignature() != ourSignature || it.origin != IrDeclarationOrigin.FAKE_OVERRIDE }
|
||||
?.let { (it.getJvmName() != ourMethodName || it.getJvmSignature() == specialOverrideSignature) && it.comesFromJava() } == true
|
||||
?.let { (it.getJvmName() != ourMethodName || it.getJvmSignature() == specialOverrideSignature) && it.isExternalDeclaration() } == true
|
||||
) {
|
||||
val resolved = irFunction.findConcreteSuperDeclaration()!!
|
||||
val resolvedSignature = resolved.getJvmSignature()
|
||||
@@ -492,10 +492,11 @@ fun IrSimpleFunction.overriddenInClasses(): Sequence<IrSimpleFunction> =
|
||||
fun IrSimpleFunction.isCollectionStub(): Boolean =
|
||||
origin == IrDeclarationOrigin.IR_BUILTINS_STUB
|
||||
|
||||
// TODO: At present, there is no reliable way to distinguish Java imports from Kotlin cross-module imports.
|
||||
val ORIGINS_FROM_JAVA = setOf(IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB)
|
||||
val EXTERNAL_ORIGIN = setOf(IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB)
|
||||
|
||||
fun IrDeclaration.comesFromJava() = parentAsClass.origin in ORIGINS_FROM_JAVA
|
||||
fun IrDeclaration.comesFromJava() = parentAsClass.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
|
||||
fun IrDeclaration.isExternalDeclaration() = parentAsClass.origin in EXTERNAL_ORIGIN
|
||||
|
||||
// Method has the same name, same arguments as `other`. Return types may differ.
|
||||
fun Method.sameCallAs(other: Method) =
|
||||
|
||||
+1
-1
@@ -204,7 +204,7 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla
|
||||
}.toHashSet()
|
||||
}
|
||||
|
||||
fun IrClass.comesFromJava() = origin in ORIGINS_FROM_JAVA
|
||||
fun IrClass.comesFromJava() = origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
|
||||
private fun Collection<IrType>.findMostSpecificTypeForClass(classifier: IrClassSymbol): IrType {
|
||||
val types = this.filter { it.classifierOrNull == classifier }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_LIGHT_ANALYSIS
|
||||
|
||||
@@ -14,9 +14,12 @@ var v: Int = 1
|
||||
|
||||
fun consumeInt(x: Int) {}
|
||||
|
||||
class A {
|
||||
open class A {
|
||||
val OK: String = "OK"
|
||||
@JvmName("OK") get
|
||||
|
||||
@JvmName("g")
|
||||
fun <T> f(x: T, y: Int = 1) = x
|
||||
}
|
||||
|
||||
annotation class Anno(@get:JvmName("uglyJvmName") val value: String)
|
||||
@@ -25,6 +28,8 @@ annotation class Anno(@get:JvmName("uglyJvmName") val value: String)
|
||||
|
||||
import lib.*
|
||||
|
||||
class B : A()
|
||||
|
||||
@Anno("OK")
|
||||
fun annotated() {}
|
||||
|
||||
@@ -36,5 +41,8 @@ fun box(): String {
|
||||
val annoValue = (::annotated.annotations.single() as Anno).value
|
||||
if (annoValue != "OK") return "Fail annotation value: $annoValue"
|
||||
|
||||
val b = B()
|
||||
if (b.f("OK") != "OK") return "Fail call of annotated method"
|
||||
|
||||
return A().OK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user