IR: propagate original declaration info via attributeOwnerId
For IrProperty, IrSimpleFunction we need to pass information about original declaration to JVM_IR codegen. Instead of descriptors, use the attributeOwnerId field.
This commit is contained in:
@@ -153,4 +153,6 @@ class Fir2IrLazyProperty(
|
||||
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = fir.containerSource
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
}
|
||||
|
||||
@@ -572,6 +572,8 @@ fun IrFactory.createStaticFunctionWithReceivers(
|
||||
}
|
||||
|
||||
if (copyMetadata) metadata = oldFunction.metadata
|
||||
|
||||
copyAttributes(oldFunction as? IrAttributeContainer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -549,6 +549,7 @@ private fun IrFunction.generateDefaultsFunctionImpl(
|
||||
}
|
||||
else -> throw IllegalStateException("Unknown function type")
|
||||
}
|
||||
(newFunction as? IrAttributeContainer)?.copyAttributes(this@generateDefaultsFunctionImpl as? IrAttributeContainer)
|
||||
newFunction.copyTypeParametersFrom(this)
|
||||
newFunction.parent = parent
|
||||
newFunction.returnType = returnType.remapTypeParameters(classIfConstructor, newFunction.classIfConstructor)
|
||||
|
||||
@@ -11,6 +11,9 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
|
||||
interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin {
|
||||
object CLASS_STATIC_INITIALIZER : IrDeclarationOriginImpl("CLASS_STATIC_INITIALIZER")
|
||||
object DEFAULT_IMPLS : IrDeclarationOriginImpl("DEFAULT_IMPLS")
|
||||
object DEFAULT_IMPLS_WITH_MOVED_RECEIVERS : IrDeclarationOriginImpl("STATIC_WITH_MOVED_RECEIVERS")
|
||||
object DEFAULT_IMPLS_WITH_MOVED_RECEIVERS_SYNTHETIC :
|
||||
IrDeclarationOriginImpl("STATIC_WITH_MOVED_RECEIVERS_SYNTHETIC", isSynthetic = true)
|
||||
object DEFAULT_IMPLS_BRIDGE : IrDeclarationOriginImpl("DEFAULT_IMPLS_BRIDGE")
|
||||
object DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY : IrDeclarationOriginImpl("DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY")
|
||||
object DEFAULT_IMPLS_BRIDGE_TO_SYNTHETIC : IrDeclarationOriginImpl("DEFAULT_IMPLS_BRIDGE_TO_SYNTHETIC", isSynthetic = true)
|
||||
|
||||
+6
-1
@@ -151,7 +151,12 @@ class JvmCachedDeclarations(
|
||||
// is supposed to allow using `I2.DefaultImpls.f` as if it was inherited from `I1.DefaultImpls`.
|
||||
// The classes are not actually related and `I2.DefaultImpls.f` is not a fake override but a bridge.
|
||||
origin = when {
|
||||
!forCompatibilityMode && !interfaceFun.isFakeOverride -> interfaceFun.origin
|
||||
!forCompatibilityMode && !interfaceFun.isFakeOverride ->
|
||||
when {
|
||||
interfaceFun.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER -> interfaceFun.origin
|
||||
interfaceFun.origin.isSynthetic -> JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_WITH_MOVED_RECEIVERS_SYNTHETIC
|
||||
else -> JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_WITH_MOVED_RECEIVERS
|
||||
}
|
||||
interfaceFun.resolveFakeOverride()!!.origin.isSynthetic ->
|
||||
if (forCompatibilityMode) JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY_SYNTHETIC
|
||||
else JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_TO_SYNTHETIC
|
||||
|
||||
+28
-2
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
|
||||
internal val addContinuationPhase = makeIrFilePhase(
|
||||
::AddContinuationLowering,
|
||||
@@ -660,10 +661,35 @@ private fun IrFunction.suspendFunctionViewOrStub(context: JvmBackendContext): Ir
|
||||
}
|
||||
|
||||
internal fun IrFunction.suspendFunctionOriginal(): IrFunction =
|
||||
if (this is IrSimpleFunction && isSuspend && !isStaticInlineClassReplacement)
|
||||
if (this is IrSimpleFunction && isSuspend &&
|
||||
!isStaticInlineClassReplacement &&
|
||||
!isOrOverridesDefaultParameterStub() &&
|
||||
!isDefaultImplsFunction
|
||||
)
|
||||
attributeOwnerId as IrFunction
|
||||
else this
|
||||
|
||||
private fun IrSimpleFunction.isOrOverridesDefaultParameterStub(): Boolean =
|
||||
// Cannot use resolveFakeOverride here because of KT-36188.
|
||||
DFS.ifAny(
|
||||
listOf(this),
|
||||
{ it.overriddenSymbols.map { it.owner } },
|
||||
{ it.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER }
|
||||
)
|
||||
|
||||
val defaultImplsOrigins = setOf(
|
||||
IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_WITH_MOVED_RECEIVERS,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_WITH_MOVED_RECEIVERS_SYNTHETIC,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_TO_SYNTHETIC,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY_SYNTHETIC
|
||||
)
|
||||
|
||||
private val IrSimpleFunction.isDefaultImplsFunction: Boolean
|
||||
get() = origin in defaultImplsOrigins
|
||||
|
||||
private fun IrFunction.createSuspendFunctionStub(context: JvmBackendContext): IrFunction {
|
||||
require(this.isSuspend && this is IrSimpleFunction)
|
||||
return factory.buildFun {
|
||||
@@ -737,7 +763,7 @@ private fun <T : IrMemberAccessExpression<IrFunctionSymbol>> T.retargetToSuspend
|
||||
}
|
||||
if (caller != null) {
|
||||
// At this point the only LOCAL_FUNCTION_FOR_LAMBDAs are inline and crossinline lambdas.
|
||||
val continuation = if (caller.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA)
|
||||
val continuation = if (caller.originalFunction.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA)
|
||||
context.fakeContinuation
|
||||
else
|
||||
IrGetValueImpl(
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
|
||||
private fun transformSimpleFunctionFlat(function: IrSimpleFunction, replacement: IrSimpleFunction): List<IrDeclaration> {
|
||||
replacement.valueParameters.forEach { it.transformChildrenVoid() }
|
||||
replacement.body = function.body?.transform(this, null)?.patchDeclarationParents(replacement)
|
||||
(replacement as? IrAttributeContainer)?.copyAttributes(function)
|
||||
replacement.copyAttributes(function)
|
||||
|
||||
// Don't create a wrapper for functions which are only used in an unboxed context
|
||||
if (function.overriddenSymbols.isEmpty() || replacement.dispatchReceiverParameter != null)
|
||||
|
||||
+1
@@ -202,6 +202,7 @@ private class MakeCallsStatic(
|
||||
it.annotations += annotations
|
||||
it.copyParameterDeclarationsFrom(this)
|
||||
it.dispatchReceiverParameter = null
|
||||
it.copyAttributes(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -211,6 +211,7 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean, pr
|
||||
metadata = function.metadata
|
||||
function.metadata = null
|
||||
}
|
||||
copyAttributes(function as? IrAttributeContainer)
|
||||
|
||||
if (function is IrSimpleFunction) {
|
||||
val propertySymbol = function.correspondingPropertySymbol
|
||||
@@ -221,6 +222,7 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean, pr
|
||||
updateFrom(propertySymbol.owner)
|
||||
}.apply {
|
||||
parent = propertySymbol.owner.parent
|
||||
copyAttributes(propertySymbol.owner)
|
||||
}
|
||||
}
|
||||
correspondingPropertySymbol = property.symbol
|
||||
|
||||
+2
@@ -54,6 +54,8 @@ abstract class IrPropertyCommonImpl(
|
||||
override var setter: IrSimpleFunction? = null
|
||||
|
||||
override var metadata: MetadataSource? = null
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
}
|
||||
|
||||
class IrPropertyImpl(
|
||||
|
||||
+11
@@ -95,6 +95,17 @@ internal abstract class PersistentIrPropertyCommon(
|
||||
setCarrier().metadataField = v
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
override var attributeOwnerIdField: IrAttributeContainer = this
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer
|
||||
get() = getCarrier().attributeOwnerIdField
|
||||
set(v) {
|
||||
if (attributeOwnerId !== v) {
|
||||
setCarrier().attributeOwnerIdField = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class PersistentIrProperty(
|
||||
|
||||
+5
-2
@@ -13,6 +13,7 @@ internal interface PropertyCarrier : DeclarationCarrier {
|
||||
var getterField: IrSimpleFunction?
|
||||
var setterField: IrSimpleFunction?
|
||||
var metadataField: MetadataSource?
|
||||
var attributeOwnerIdField: IrAttributeContainer
|
||||
|
||||
override fun clone(): PropertyCarrier {
|
||||
return PropertyCarrierImpl(
|
||||
@@ -23,7 +24,8 @@ internal interface PropertyCarrier : DeclarationCarrier {
|
||||
backingFieldField,
|
||||
getterField,
|
||||
setterField,
|
||||
metadataField
|
||||
metadataField,
|
||||
attributeOwnerIdField,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -36,5 +38,6 @@ internal class PropertyCarrierImpl(
|
||||
override var backingFieldField: IrField?,
|
||||
override var getterField: IrSimpleFunction?,
|
||||
override var setterField: IrSimpleFunction?,
|
||||
override var metadataField: MetadataSource?
|
||||
override var metadataField: MetadataSource?,
|
||||
override var attributeOwnerIdField: IrAttributeContainer
|
||||
) : PropertyCarrier
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
|
||||
abstract class IrProperty : IrDeclarationBase(), IrOverridableMember, IrMetadataSourceOwner {
|
||||
abstract class IrProperty : IrDeclarationBase(), IrOverridableMember, IrMetadataSourceOwner, IrAttributeContainer {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
abstract override val descriptor: PropertyDescriptor
|
||||
abstract override val symbol: IrPropertySymbol
|
||||
|
||||
@@ -86,7 +86,10 @@ class IrLazyFunction(
|
||||
stubGenerator.generateFunctionStub(it.original).symbol
|
||||
}
|
||||
}
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer
|
||||
get() = this
|
||||
set(_) = error("We should never need to change attributeOwnerId of external declarations.")
|
||||
|
||||
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||
|
||||
|
||||
@@ -78,4 +78,8 @@ class IrLazyProperty(
|
||||
override var metadata: MetadataSource?
|
||||
get() = null
|
||||
set(_) = error("We should never need to store metadata of external declarations.")
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer
|
||||
get() = this
|
||||
set(_) = error("We should never need to change attributeOwnerId of external declarations.")
|
||||
}
|
||||
|
||||
@@ -547,3 +547,9 @@ fun IrExpression.isSafeToUseWithoutCopying() =
|
||||
this is IrGetEnumValue ||
|
||||
this is IrConst<*> ||
|
||||
this is IrGetValue && symbol.isBound && symbol.owner.isImmutable
|
||||
|
||||
val IrFunction.originalFunction: IrFunction
|
||||
get() = (this as? IrAttributeContainer)?.attributeOwnerId as? IrFunction ?: this
|
||||
|
||||
val IrProperty.originalProperty: IrProperty
|
||||
get() = attributeOwnerId as? IrProperty ?: this
|
||||
Reference in New Issue
Block a user