IR: remove field fake overrides
This commit is contained in:
+3
-17
@@ -651,7 +651,6 @@ class Fir2IrDeclarationStorage(
|
||||
name: Name,
|
||||
isFinal: Boolean,
|
||||
firInitializerExpression: FirExpression?,
|
||||
thisReceiverOwner: IrClass?,
|
||||
type: IrType? = null
|
||||
): IrField {
|
||||
val inferredType = type ?: firInitializerExpression!!.typeRef.toIrType()
|
||||
@@ -664,12 +663,8 @@ class Fir2IrDeclarationStorage(
|
||||
visibility, isFinal = isFinal,
|
||||
isExternal = property.isExternal,
|
||||
isStatic = property.isStatic || parent !is IrClass,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
).also {
|
||||
it.correspondingPropertySymbol = this@createBackingField.symbol
|
||||
if (!isFakeOverride && thisReceiverOwner != null) {
|
||||
it.populateOverriddenSymbols(thisReceiverOwner)
|
||||
}
|
||||
}.apply {
|
||||
metadata = FirMetadataSource.Property(property)
|
||||
convertAnnotationsFromLibrary(property)
|
||||
@@ -738,7 +733,7 @@ class Fir2IrDeclarationStorage(
|
||||
backingField = createBackingField(
|
||||
property, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, descriptor,
|
||||
property.fieldVisibility, property.name, property.isVal, initializer,
|
||||
thisReceiverOwner, type
|
||||
type
|
||||
).also { field ->
|
||||
if (initializer is FirConstExpression<*>) {
|
||||
// TODO: Normally we shouldn't have error type here
|
||||
@@ -749,8 +744,7 @@ class Fir2IrDeclarationStorage(
|
||||
} else if (delegate != null) {
|
||||
backingField = createBackingField(
|
||||
property, IrDeclarationOrigin.PROPERTY_DELEGATE, descriptor,
|
||||
property.fieldVisibility, Name.identifier("${property.name}\$delegate"), true, delegate,
|
||||
thisReceiverOwner
|
||||
property.fieldVisibility, Name.identifier("${property.name}\$delegate"), true, delegate
|
||||
)
|
||||
}
|
||||
if (irParent != null) {
|
||||
@@ -803,8 +797,7 @@ class Fir2IrDeclarationStorage(
|
||||
field.name, type, field.visibility,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isExternal = false,
|
||||
isStatic = field.isStatic,
|
||||
isFakeOverride = false
|
||||
isStatic = field.isStatic
|
||||
).apply {
|
||||
metadata = FirMetadataSource.Variable(field)
|
||||
descriptor.bind(this)
|
||||
@@ -1028,13 +1021,6 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrField.populateOverriddenSymbols(thisReceiverOwner: IrClass) {
|
||||
thisReceiverOwner.findMatchingOverriddenSymbolsFromSupertypes(components.irBuiltIns, this)
|
||||
.filterIsInstance<IrFieldSymbol>().singleOrNull()?.let {
|
||||
overriddenSymbols = listOf(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrMutableAnnotationContainer.convertAnnotationsFromLibrary(firAnnotationContainer: FirAnnotationContainer) {
|
||||
if ((firAnnotationContainer as? FirDeclaration)?.isFromLibrary == true) {
|
||||
annotationGenerator?.generate(this, firAnnotationContainer)
|
||||
|
||||
+5
@@ -1012,6 +1012,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
||||
runTest("compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmFieldReferenceWithIntersectionTypes.kt")
|
||||
public void testJvmFieldReferenceWithIntersectionTypes() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/jvmFieldReferenceWithIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmInstanceFieldReference.kt")
|
||||
public void testJvmInstanceFieldReference() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.kt");
|
||||
|
||||
+1
-2
@@ -681,8 +681,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
||||
Visibilities.PRIVATE,
|
||||
isFinal = !isMutable,
|
||||
isExternal = false,
|
||||
isStatic = false,
|
||||
isFakeOverride = false
|
||||
isStatic = false
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = this
|
||||
|
||||
+1
-2
@@ -775,8 +775,7 @@ class LocalDeclarationsLowering(
|
||||
visibility,
|
||||
isFinal = true,
|
||||
isExternal = false,
|
||||
isStatic = false,
|
||||
isFakeOverride = false
|
||||
isStatic = false
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = parent
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ fun IrFieldBuilder.buildField(): IrField {
|
||||
return IrFieldImpl(
|
||||
startOffset, endOffset, origin,
|
||||
IrFieldSymbolImpl(wrappedDescriptor),
|
||||
name, type, visibility, isFinal, isExternal, isStatic, isFakeOverride
|
||||
name, type, visibility, isFinal, isExternal, isStatic,
|
||||
).also {
|
||||
it.metadata = metadata
|
||||
wrappedDescriptor.bind(it)
|
||||
|
||||
+1
-2
@@ -67,8 +67,7 @@ class JsDeclarationFactory(mapping: JsMapping) : DeclarationFactory {
|
||||
visibility,
|
||||
isFinal = true,
|
||||
isExternal = false,
|
||||
isStatic = false,
|
||||
isFakeOverride = false
|
||||
isStatic = false
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = parent
|
||||
|
||||
+1
-2
@@ -160,8 +160,7 @@ class JsSharedVariablesManager(val builtIns: IrBuiltIns, val implicitDeclaration
|
||||
Visibilities.PUBLIC,
|
||||
isFinal = false,
|
||||
isExternal = false,
|
||||
isStatic = false,
|
||||
isFakeOverride = false
|
||||
isStatic = false
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = closureBoxClassDeclaration
|
||||
|
||||
+1
-3
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.DeclarationTransformer
|
||||
import org.jetbrains.kotlin.backend.common.getOrPut
|
||||
import org.jetbrains.kotlin.backend.common.ir.copyParameterDeclarationsFrom
|
||||
@@ -70,8 +69,7 @@ class EnumUsageLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
return entry.run {
|
||||
IrFieldImpl(
|
||||
startOffset, endOffset, origin, symbol, name, irClass.defaultType, Visibilities.PUBLIC,
|
||||
isFinal = false, isExternal = true, isStatic = true,
|
||||
isFakeOverride = entry.isFakeOverride
|
||||
isFinal = false, isExternal = true, isStatic = true
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = irClass
|
||||
|
||||
+1
-2
@@ -557,8 +557,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
||||
Visibilities.PRIVATE,
|
||||
isFinal = !isMutable,
|
||||
isExternal = false,
|
||||
isStatic = false,
|
||||
isFakeOverride = false
|
||||
isStatic = false
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = this
|
||||
|
||||
@@ -229,8 +229,6 @@ abstract class ClassCodegen protected constructor(
|
||||
protected abstract fun bindFieldMetadata(field: IrField, fieldType: Type, fieldName: String)
|
||||
|
||||
private fun generateField(field: IrField) {
|
||||
if (field.isFakeOverride) return
|
||||
|
||||
val fieldType = typeMapper.mapType(field)
|
||||
val fieldSignature =
|
||||
if (field.origin == IrDeclarationOrigin.PROPERTY_DELEGATE) null
|
||||
|
||||
+2
-3
@@ -535,9 +535,8 @@ class ExpressionCodegen(
|
||||
assert(callee.constantValue() == null) { "access of const val: ${expression.dump()}" }
|
||||
}
|
||||
|
||||
val realField = callee
|
||||
val fieldType = typeMapper.mapType(realField.type)
|
||||
val fieldName = realField.name.asString()
|
||||
val fieldType = typeMapper.mapType(callee.type)
|
||||
val fieldName = callee.name.asString()
|
||||
val isStatic = expression.receiver == null
|
||||
expression.markLineNumber(startOffset = true)
|
||||
|
||||
|
||||
+4
-12
@@ -191,17 +191,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
|
||||
}
|
||||
}
|
||||
|
||||
private val receiverFieldFromSuper = context.ir.symbols.functionReferenceReceiverField.owner
|
||||
|
||||
val fakeOverrideReceiverField = functionReferenceClass.addField {
|
||||
name = receiverFieldFromSuper.name
|
||||
isFakeOverride = true
|
||||
origin = IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
type = receiverFieldFromSuper.type
|
||||
isFinal = receiverFieldFromSuper.isFinal
|
||||
isStatic = receiverFieldFromSuper.isStatic
|
||||
visibility = receiverFieldFromSuper.visibility
|
||||
}
|
||||
private val receiverField = context.ir.symbols.functionReferenceReceiverField.owner
|
||||
|
||||
fun build(): IrExpression = context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol).run {
|
||||
irBlock(irFunctionReference.startOffset, irFunctionReference.endOffset) {
|
||||
@@ -418,7 +408,9 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
|
||||
// will put it into a field.
|
||||
if (samSuperType == null)
|
||||
irImplicitCast(
|
||||
irGetField(irGet(dispatchReceiverParameter!!), fakeOverrideReceiverField),
|
||||
irGetField(irGet(dispatchReceiverParameter!!),
|
||||
this@FunctionReferenceBuilder.receiverField
|
||||
),
|
||||
boundReceiver.second.type
|
||||
)
|
||||
else
|
||||
|
||||
+4
-14
@@ -299,17 +299,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
|
||||
referenceClass.addOverride(getSignature) { computeSignatureString(expression) }
|
||||
}
|
||||
|
||||
val receiverField = referenceClass.addField {
|
||||
val backingFieldFromSuper = superClass.properties.single { it.name.asString() == "receiver" }.backingField!!
|
||||
name = backingFieldFromSuper.name
|
||||
isFakeOverride = true
|
||||
origin = IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
type = backingFieldFromSuper.type
|
||||
isFinal = backingFieldFromSuper.isFinal
|
||||
isStatic = backingFieldFromSuper.isStatic
|
||||
visibility = backingFieldFromSuper.visibility
|
||||
}
|
||||
|
||||
val backingField = superClass.properties.single { it.name.asString() == "receiver" }.backingField!!
|
||||
val get = superClass.functions.find { it.name.asString() == "get" }
|
||||
val set = superClass.functions.find { it.name.asString() == "set" }
|
||||
val invoke = superClass.functions.find { it.name.asString() == "invoke" }
|
||||
@@ -321,13 +311,13 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
|
||||
call.copyTypeArgumentsFrom(expression)
|
||||
call.dispatchReceiver = call.symbol.owner.dispatchReceiverParameter?.let {
|
||||
if (expression.dispatchReceiver != null)
|
||||
irImplicitCast(irGetField(irGet(arguments[0]), receiverField), it.type)
|
||||
irImplicitCast(irGetField(irGet(arguments[0]), backingField), it.type)
|
||||
else
|
||||
irImplicitCast(irGet(arguments[index++]), it.type)
|
||||
}
|
||||
call.extensionReceiver = call.symbol.owner.extensionReceiverParameter?.let {
|
||||
if (expression.extensionReceiver != null)
|
||||
irImplicitCast(irGetField(irGet(arguments[0]), receiverField), it.type)
|
||||
irImplicitCast(irGetField(irGet(arguments[0]), backingField), it.type)
|
||||
else
|
||||
irImplicitCast(irGet(arguments[index++]), it.type)
|
||||
}
|
||||
@@ -354,7 +344,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
|
||||
field.isStatic ->
|
||||
null
|
||||
expression.dispatchReceiver != null ->
|
||||
irImplicitCast(irGetField(irGet(arguments[0]), receiverField), field.parentAsClass.defaultType)
|
||||
irImplicitCast(irGetField(irGet(arguments[0]), backingField), field.parentAsClass.defaultType)
|
||||
else ->
|
||||
irImplicitCast(irGet(arguments[1]), field.parentAsClass.defaultType)
|
||||
}
|
||||
|
||||
+1
-4
@@ -96,9 +96,7 @@ private class FieldNameCollector : IrElementVisitorVoid {
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
if (!declaration.isFakeOverride) {
|
||||
nameToField.getOrPut(declaration.parent to declaration.name) { mutableListOf() }.add(declaration)
|
||||
}
|
||||
nameToField.getOrPut(declaration.parent to declaration.name) { mutableListOf() }.add(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +111,6 @@ private class FieldRenamer(private val newNames: Map<IrField, Name>) : IrElement
|
||||
return IrFieldImpl(
|
||||
declaration.startOffset, declaration.endOffset, declaration.origin, symbol, newName,
|
||||
declaration.type, declaration.visibility, declaration.isFinal, declaration.isExternal, declaration.isStatic,
|
||||
isFakeOverride = declaration.isFakeOverride
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = declaration.parent
|
||||
|
||||
+2
-9
@@ -160,10 +160,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
val symbol = expression.symbol
|
||||
val parent =
|
||||
symbol.owner.accessorParent(dispatchReceiverType?.classOrNull?.owner ?: symbol.owner.parent) as IrClass
|
||||
val symbolToAccess = symbol.owner.findDescendantIn(parent)?.symbol ?: symbol
|
||||
modifyGetterExpression(
|
||||
expression,
|
||||
getterMap.getOrPut(Pair(symbolToAccess, parent)) { makeGetterAccessorSymbol(symbolToAccess, parent) }
|
||||
getterMap.getOrPut(Pair(symbol, parent)) { makeGetterAccessorSymbol(symbol, parent) }
|
||||
)
|
||||
} else {
|
||||
expression
|
||||
@@ -178,10 +177,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
val symbol = expression.symbol
|
||||
val parent =
|
||||
symbol.owner.accessorParent(dispatchReceiverType?.classOrNull?.owner ?: symbol.owner.parent) as IrClass
|
||||
val symbolToAccess = symbol.owner.findDescendantIn(parent)?.symbol ?: symbol
|
||||
modifySetterExpression(
|
||||
expression,
|
||||
setterMap.getOrPut(Pair(symbolToAccess, parent)) { makeSetterAccessorSymbol(symbolToAccess, parent) }
|
||||
setterMap.getOrPut(Pair(symbol, parent)) { makeSetterAccessorSymbol(symbol, parent) }
|
||||
)
|
||||
} else {
|
||||
expression
|
||||
@@ -189,11 +187,6 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
)
|
||||
}
|
||||
|
||||
private fun IrField.findDescendantIn(derivedClass: IrClass): IrField? =
|
||||
derivedClass.fields.singleOrNull { candidate ->
|
||||
candidate.name == this.name && candidate.overrides(this)
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor): IrStatement {
|
||||
if (declaration.isOrShouldBeHidden) {
|
||||
pendingAccessorsToAdd.add(handleHiddenConstructor(declaration))
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.util.declareFieldWithOverrides
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
||||
|
||||
-2
@@ -16,7 +16,6 @@ class IrFieldBuilder : IrDeclarationBuilder() {
|
||||
var isFinal: Boolean = false
|
||||
var isExternal: Boolean = false
|
||||
var isStatic: Boolean = false
|
||||
var isFakeOverride: Boolean = false
|
||||
var metadata: MetadataSource? = null
|
||||
|
||||
fun updateFrom(from: IrField) {
|
||||
@@ -26,7 +25,6 @@ class IrFieldBuilder : IrDeclarationBuilder() {
|
||||
isFinal = from.isFinal
|
||||
isExternal = from.isExternal
|
||||
isStatic = from.isStatic
|
||||
isFakeOverride = from.isFakeOverride
|
||||
metadata = from.metadata
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
|
||||
interface IrField :
|
||||
IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration<IrFieldSymbol>,
|
||||
IrSymbolDeclaration<IrFieldSymbol>,
|
||||
IrDeclarationWithName, IrDeclarationWithVisibility, IrDeclarationParent {
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
@@ -23,7 +23,6 @@ interface IrField :
|
||||
val isFinal: Boolean
|
||||
val isExternal: Boolean
|
||||
val isStatic: Boolean
|
||||
val isFakeOverride: Boolean
|
||||
|
||||
var initializer: IrExpressionBody?
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ class IrFieldImpl(
|
||||
override val visibility: Visibility,
|
||||
override val isFinal: Boolean,
|
||||
override val isExternal: Boolean,
|
||||
override val isStatic: Boolean,
|
||||
override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
override val isStatic: Boolean
|
||||
) : IrDeclarationBase<FieldCarrier>(startOffset, endOffset, origin),
|
||||
IrField,
|
||||
FieldCarrier {
|
||||
@@ -96,16 +95,6 @@ class IrFieldImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override var overridenSymbolsField: List<IrFieldSymbol> = emptyList()
|
||||
|
||||
override var overriddenSymbols: List<IrFieldSymbol>
|
||||
get() = getCarrier().overridenSymbolsField
|
||||
set(v) {
|
||||
if (overriddenSymbols !== v) {
|
||||
setCarrier().overridenSymbolsField = v
|
||||
}
|
||||
}
|
||||
|
||||
override var metadataField: MetadataSource? = null
|
||||
|
||||
override var metadata: MetadataSource?
|
||||
|
||||
+2
-6
@@ -10,14 +10,12 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
|
||||
interface FieldCarrier : DeclarationCarrier<FieldCarrier> {
|
||||
var initializerField: IrExpressionBody?
|
||||
var correspondingPropertySymbolField: IrPropertySymbol?
|
||||
var metadataField: MetadataSource?
|
||||
var overridenSymbolsField: List<IrFieldSymbol>
|
||||
|
||||
override fun clone(): FieldCarrier {
|
||||
return FieldCarrierImpl(
|
||||
@@ -27,8 +25,7 @@ interface FieldCarrier : DeclarationCarrier<FieldCarrier> {
|
||||
annotationsField,
|
||||
initializerField,
|
||||
correspondingPropertySymbolField,
|
||||
metadataField,
|
||||
overridenSymbolsField
|
||||
metadataField
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -40,6 +37,5 @@ class FieldCarrierImpl(
|
||||
override var annotationsField: List<IrConstructorCall>,
|
||||
override var initializerField: IrExpressionBody?,
|
||||
override var correspondingPropertySymbolField: IrPropertySymbol?,
|
||||
override var metadataField: MetadataSource?,
|
||||
override var overridenSymbolsField: List<IrFieldSymbol>
|
||||
override var metadataField: MetadataSource?
|
||||
): FieldCarrier
|
||||
@@ -35,7 +35,6 @@ class IrLazyField(
|
||||
override val isFinal: Boolean,
|
||||
override val isExternal: Boolean,
|
||||
override val isStatic: Boolean,
|
||||
override val isFakeOverride: Boolean,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
typeTranslator: TypeTranslator
|
||||
) : IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
@@ -51,12 +50,6 @@ class IrLazyField(
|
||||
?: mutableListOf()
|
||||
}
|
||||
|
||||
override var overriddenSymbols: List<IrFieldSymbol> by lazyVar {
|
||||
symbol.descriptor.overriddenDescriptors.map {
|
||||
stubGenerator.generateFieldStub(it.original).symbol
|
||||
}.toMutableList()
|
||||
}
|
||||
|
||||
override var type: IrType by lazyVar {
|
||||
descriptor.type.toIrType()
|
||||
}
|
||||
|
||||
@@ -991,8 +991,7 @@ open class WrappedFieldDescriptor(
|
||||
|
||||
override fun hasSynthesizedParameterNames() = false
|
||||
|
||||
override fun getOverriddenDescriptors(): MutableCollection<out PropertyDescriptor> =
|
||||
owner.overriddenSymbols.map { it.descriptor }.toMutableList()
|
||||
override fun getOverriddenDescriptors(): MutableCollection<out PropertyDescriptor> = mutableListOf()
|
||||
|
||||
override fun copy(
|
||||
newOwner: DeclarationDescriptor?,
|
||||
|
||||
@@ -78,18 +78,6 @@ fun IrSimpleFunction.overrides(other: IrSimpleFunction): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun IrField.overrides(other: IrField): Boolean {
|
||||
if (this == other) return true
|
||||
|
||||
this.overriddenSymbols.forEach {
|
||||
if (it.owner.overrides(other)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private val IrConstructorCall.annotationClass
|
||||
get() = this.symbol.owner.constructedClass
|
||||
|
||||
|
||||
@@ -173,20 +173,14 @@ class DeclarationStubGenerator(
|
||||
return referenced.owner
|
||||
}
|
||||
|
||||
val origin =
|
||||
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE)
|
||||
IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
else computeOrigin(descriptor)
|
||||
|
||||
return symbolTable.declareField(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original, descriptor.type.toIrType()) {
|
||||
return symbolTable.declareField(UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor), descriptor.original, descriptor.type.toIrType()) {
|
||||
IrLazyField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor),
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.visibility,
|
||||
isFinal = !descriptor.isVar,
|
||||
isExternal = descriptor.isEffectivelyExternal(),
|
||||
isStatic = (descriptor.dispatchReceiverParameter == null),
|
||||
isFakeOverride = (origin == IrDeclarationOrigin.FAKE_OVERRIDE),
|
||||
stubGenerator = this, typeTranslator = typeTranslator
|
||||
)
|
||||
}
|
||||
|
||||
@@ -245,12 +245,8 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
isFinal = declaration.isFinal,
|
||||
isExternal = declaration.isExternal,
|
||||
isStatic = declaration.isStatic,
|
||||
isFakeOverride = declaration.isFakeOverride
|
||||
).apply {
|
||||
transformAnnotations(declaration)
|
||||
overriddenSymbols = declaration.overriddenSymbols.map {
|
||||
symbolRemapper.getReferencedField(it)
|
||||
}
|
||||
initializer = declaration.initializer?.transform()
|
||||
}
|
||||
|
||||
|
||||
@@ -145,9 +145,6 @@ class DumpIrTreeVisitor(
|
||||
override fun visitField(declaration: IrField, data: String) {
|
||||
declaration.dumpLabeledElementWith(data) {
|
||||
dumpAnnotations(declaration)
|
||||
declaration.overriddenSymbols.dumpItems("overridden") {
|
||||
it.dump()
|
||||
}
|
||||
declaration.initializer?.accept(this, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ val IrDeclaration.isFakeOverride: Boolean
|
||||
get() = when (this) {
|
||||
is IrSimpleFunction -> isFakeOverride
|
||||
is IrProperty -> isFakeOverride
|
||||
is IrField -> isFakeOverride
|
||||
else -> false
|
||||
}
|
||||
|
||||
@@ -31,15 +30,6 @@ val IrFunction.target: IrFunction get() = when (this) {
|
||||
else -> error(this)
|
||||
}
|
||||
|
||||
fun IrField.resolveFakeOverride(): IrField? {
|
||||
var toVisit = setOf(this)
|
||||
val nonOverridden = mutableSetOf<IrField>()
|
||||
while (toVisit.isNotEmpty()) {
|
||||
nonOverridden += toVisit.filter { it.overriddenSymbols.isEmpty() }
|
||||
toVisit = toVisit.flatMap { it.overriddenSymbols }.map { it.owner }.toSet()
|
||||
}
|
||||
return nonOverridden.singleOrNull()
|
||||
}
|
||||
fun IrSimpleFunction.collectRealOverrides(toSkip: (IrSimpleFunction) -> Boolean = { false }): Set<IrSimpleFunction> {
|
||||
if (isReal && !toSkip(this)) return setOf(this)
|
||||
|
||||
|
||||
@@ -445,7 +445,6 @@ class RenderIrElementVisitor(private val normalizeNames: Boolean = false) : IrEl
|
||||
"final".takeIf { isFinal },
|
||||
"external".takeIf { isExternal },
|
||||
"static".takeIf { isStatic },
|
||||
"fake_override".takeIf { isFakeOverride }
|
||||
)
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: Nothing?): String =
|
||||
|
||||
@@ -45,29 +45,3 @@ fun generateOverriddenFunctionSymbols(
|
||||
symbolTable.referenceSimpleFunction(it.original)
|
||||
}
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun SymbolTable.declareFieldWithOverrides(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: PropertyDescriptor,
|
||||
type: IrType,
|
||||
hasBackingField: (PropertyDescriptor) -> Boolean
|
||||
) =
|
||||
declareField(startOffset, endOffset, origin, descriptor, type).also { declaration ->
|
||||
generateOverriddenFieldSymbols(declaration, this, hasBackingField)
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun generateOverriddenFieldSymbols(
|
||||
declaration: IrField,
|
||||
symbolTable: SymbolTable,
|
||||
hasBackingField: (PropertyDescriptor) -> Boolean
|
||||
) {
|
||||
declaration.overriddenSymbols = declaration.descriptor.overriddenDescriptors.mapNotNull {
|
||||
if (hasBackingField(it)) {
|
||||
symbolTable.referenceField(it.original)
|
||||
} else null
|
||||
}
|
||||
}
|
||||
-1
@@ -1234,7 +1234,6 @@ abstract class IrFileDeserializer(val logger: LoggingContext, val builtIns: IrBu
|
||||
flags.isFinal,
|
||||
flags.isExternal,
|
||||
flags.isStatic,
|
||||
flags.isFakeOverride
|
||||
)
|
||||
}.usingParent {
|
||||
if (proto.hasInitializer())
|
||||
|
||||
+1
-3
@@ -69,15 +69,13 @@ public class IrFlags extends Flags {
|
||||
ProtoBuf.Visibility visibility,
|
||||
boolean isFinal,
|
||||
boolean isExternal,
|
||||
boolean isStatic,
|
||||
boolean isFakeOverride
|
||||
boolean isStatic
|
||||
) {
|
||||
return HAS_ANNOTATIONS.toFlags(hasAnnotations)
|
||||
| VISIBILITY.toFlags(visibility)
|
||||
| IS_FINAL.toFlags(isFinal)
|
||||
| IS_EXTERNAL_FIELD.toFlags(isExternal)
|
||||
| IS_STATIC.toFlags(isStatic)
|
||||
| IS_FAKE_OVERRIDE.toFlags(isFakeOverride)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -191,13 +191,12 @@ inline class FieldFlags(val flags: Long) {
|
||||
val isFinal: Boolean get() = IrFlags.IS_FINAL.get(flags.toInt())
|
||||
val isExternal: Boolean get() = IrFlags.IS_EXTERNAL_FIELD.get(flags.toInt())
|
||||
val isStatic: Boolean get() = IrFlags.IS_STATIC.get(flags.toInt())
|
||||
val isFakeOverride: Boolean get() = IrFlags.IS_FAKE_OVERRIDE.get(flags.toInt())
|
||||
|
||||
companion object {
|
||||
fun encode(field: IrField): Long {
|
||||
return field.run {
|
||||
val visibility = ProtoEnumFlags.visibility(visibility)
|
||||
IrFlags.getFieldFlags(annotations.isNotEmpty(), visibility, isFinal, isExternal, isStatic, isFakeOverride).toLong()
|
||||
IrFlags.getFieldFlags(annotations.isNotEmpty(), visibility, isFinal, isExternal, isStatic).toLong()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FILE: ProtectedField.java
|
||||
|
||||
public abstract class ProtectedField {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: -ProhibitProtectedCallFromInline
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: JavaClass.java
|
||||
|
||||
@@ -7,20 +7,20 @@ FILE fqName:<root> fileName:/Derived.kt
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
|
||||
ANONYMOUS_INITIALIZER isStatic=false
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived' type=<root>.Derived origin=null
|
||||
value: CONST Int type=kotlin.Int value=0
|
||||
FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.Int
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun getValue (): kotlin.Int declared in <root>.Derived'
|
||||
GET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]' type=kotlin.Int origin=GET_PROPERTY
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Int origin=GET_PROPERTY
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.getValue' type=<root>.Derived origin=null
|
||||
FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, value:kotlin.Int) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.Int
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.setValue' type=<root>.Derived origin=null
|
||||
value: GET_VAR 'value: kotlin.Int declared in <root>.Derived.setValue' type=kotlin.Int origin=null
|
||||
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,var]
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ FILE fqName:<root> fileName:/kt16904.kt
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[<root>.J]'
|
||||
ANONYMOUS_INITIALIZER isStatic=false
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:field type:kotlin.Int visibility:public' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2' type=<root>.Test2 origin=null
|
||||
value: CONST Int type=kotlin.Int value=42
|
||||
PROPERTY FAKE_OVERRIDE name:field visibility:public modality:FINAL [fake_override,var]
|
||||
|
||||
@@ -14,7 +14,7 @@ FILE fqName:<root> fileName:/Derived.kt
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.String
|
||||
GET_VAR 'v: kotlin.Any declared in <root>.Derived.setValue' type=kotlin.Any origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.String? visibility:public' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.setValue' type=<root>.Derived origin=null
|
||||
value: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
|
||||
GET_VAR 'v: kotlin.Any declared in <root>.Derived.setValue' type=kotlin.Any origin=null
|
||||
|
||||
@@ -210,14 +210,6 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
visitDeclaration(declaration)
|
||||
|
||||
require((declaration.origin == IrDeclarationOrigin.FAKE_OVERRIDE) == declaration.isFakeOverride) {
|
||||
"${declaration.render()}: origin: ${declaration.origin}; isFakeOverride: ${declaration.isFakeOverride}"
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
visitDeclaration(declaration)
|
||||
|
||||
@@ -199,6 +199,16 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaFields.kt")
|
||||
public void testJavaFields() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaFields.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaFieldsWithIntersectionTypes.kt")
|
||||
public void testJavaFieldsWithIntersectionTypes() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaFieldsWithIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaStatics.kt")
|
||||
public void testJavaStatics() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaStatics.kt");
|
||||
|
||||
+10
@@ -199,6 +199,16 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaExtensionPropertyIntrinsic.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaFields.kt")
|
||||
public void testJavaFields() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaFields.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaFieldsWithIntersectionTypes.kt")
|
||||
public void testJavaFieldsWithIntersectionTypes() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaFieldsWithIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaStatics.kt")
|
||||
public void testJavaStatics() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/javaStatics.kt");
|
||||
|
||||
@@ -1011,6 +1011,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
||||
runTest("compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmFieldReferenceWithIntersectionTypes.kt")
|
||||
public void testJvmFieldReferenceWithIntersectionTypes() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/jvmFieldReferenceWithIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmInstanceFieldReference.kt")
|
||||
public void testJvmInstanceFieldReference() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.kt");
|
||||
|
||||
Reference in New Issue
Block a user