[IrSerializer] Fixed issues with properties/fields
This commit is contained in:
+27
-38
@@ -388,6 +388,8 @@ abstract class IrModuleDeserializer(
|
|||||||
return IrInstanceInitializerCallImpl(start, end, symbol, builtIns.unitType)
|
return IrInstanceInitializerCallImpl(start, end, symbol, builtIns.unitType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val getterToPropertyDescriptorMap = mutableMapOf<IrSimpleFunctionSymbol, WrappedPropertyDescriptor>()
|
||||||
|
|
||||||
private fun deserializePropertyReference(
|
private fun deserializePropertyReference(
|
||||||
proto: KonanIr.IrPropertyReference,
|
proto: KonanIr.IrPropertyReference,
|
||||||
start: Int, end: Int, type: IrType
|
start: Int, end: Int, type: IrType
|
||||||
@@ -396,7 +398,12 @@ abstract class IrModuleDeserializer(
|
|||||||
val field = if (proto.hasField()) deserializeIrSymbol(proto.field) as IrFieldSymbol else null
|
val field = if (proto.hasField()) deserializeIrSymbol(proto.field) as IrFieldSymbol else null
|
||||||
val getter = if (proto.hasGetter()) deserializeIrSymbol(proto.getter) as IrSimpleFunctionSymbol else null
|
val getter = if (proto.hasGetter()) deserializeIrSymbol(proto.getter) as IrSimpleFunctionSymbol else null
|
||||||
val setter = if (proto.hasSetter()) deserializeIrSymbol(proto.setter) as IrSimpleFunctionSymbol else null
|
val setter = if (proto.hasSetter()) deserializeIrSymbol(proto.setter) as IrSimpleFunctionSymbol else null
|
||||||
val descriptor = WrappedPropertyDescriptor()
|
val descriptor =
|
||||||
|
if (proto.hasDescriptor())
|
||||||
|
deserializeDescriptorReference(proto.descriptor) as PropertyDescriptor
|
||||||
|
else
|
||||||
|
field?.descriptor as? WrappedPropertyDescriptor // If field's descriptor coincides with property's.
|
||||||
|
?: getterToPropertyDescriptorMap.getOrPut(getter!!) { WrappedPropertyDescriptor() }
|
||||||
|
|
||||||
val callable = IrPropertyReferenceImpl(
|
val callable = IrPropertyReferenceImpl(
|
||||||
start, end, type,
|
start, end, type,
|
||||||
@@ -823,7 +830,7 @@ abstract class IrModuleDeserializer(
|
|||||||
|
|
||||||
private fun deserializeIrFunction(
|
private fun deserializeIrFunction(
|
||||||
proto: KonanIr.IrFunction,
|
proto: KonanIr.IrFunction,
|
||||||
start: Int, end: Int, origin: IrDeclarationOrigin, correspondingProperty: IrProperty? = null
|
start: Int, end: Int, origin: IrDeclarationOrigin
|
||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
|
|
||||||
logger.log { "### deserializing IrFunction ${deserializeString(proto.base.name)}" }
|
logger.log { "### deserializing IrFunction ${deserializeString(proto.base.name)}" }
|
||||||
@@ -848,8 +855,6 @@ abstract class IrModuleDeserializer(
|
|||||||
val overridden = proto.overriddenList.map { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
val overridden = proto.overriddenList.map { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
||||||
function.overriddenSymbols.addAll(overridden)
|
function.overriddenSymbols.addAll(overridden)
|
||||||
|
|
||||||
function.correspondingProperty = correspondingProperty
|
|
||||||
|
|
||||||
return function
|
return function
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,13 +1004,20 @@ abstract class IrModuleDeserializer(
|
|||||||
origin: IrDeclarationOrigin
|
origin: IrDeclarationOrigin
|
||||||
): IrProperty {
|
): IrProperty {
|
||||||
|
|
||||||
val backingField = if (proto.hasBackingField()) {
|
val backingField = if (proto.hasBackingField()) deserializeIrField(proto.backingField, start, end, origin) else null
|
||||||
deserializeIrField(proto.backingField, start, end, origin)
|
val getter = if (proto.hasGetter()) deserializeIrFunction(proto.getter, start, end, origin) else null
|
||||||
} else null
|
val setter = if (proto.hasSetter()) deserializeIrFunction(proto.setter, start, end, origin) else null
|
||||||
|
|
||||||
|
backingField?.let { (it.descriptor as? WrappedFieldDescriptor)?.bind(it) }
|
||||||
|
getter?.let { (it.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(it) }
|
||||||
|
setter?.let { (it.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(it) }
|
||||||
|
|
||||||
val descriptor =
|
val descriptor =
|
||||||
if (proto.hasDescriptor()) deserializeDescriptorReference(proto.descriptor) as PropertyDescriptor else null
|
if (proto.hasDescriptor())
|
||||||
?: WrappedPropertyDescriptor()
|
deserializeDescriptorReference(proto.descriptor) as PropertyDescriptor
|
||||||
|
else
|
||||||
|
backingField?.descriptor as? WrappedPropertyDescriptor // If field's descriptor coincides with property's.
|
||||||
|
?: getterToPropertyDescriptorMap.getOrPut(getter!!.symbol) { WrappedPropertyDescriptor() }
|
||||||
|
|
||||||
val property = IrPropertyImpl(
|
val property = IrPropertyImpl(
|
||||||
start, end, origin,
|
start, end, origin,
|
||||||
@@ -1021,37 +1033,14 @@ abstract class IrModuleDeserializer(
|
|||||||
)
|
)
|
||||||
|
|
||||||
symbolTable.referenceProperty(descriptor, { property })
|
symbolTable.referenceProperty(descriptor, { property })
|
||||||
/*
|
|
||||||
backingField?.descriptor?.let {
|
|
||||||
symbolTable.declareField(UNDEFINED_OFFSET,
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
irrelevantOrigin,
|
|
||||||
it,
|
|
||||||
builtIns.unitType,
|
|
||||||
{ symbol -> backingField })
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
property.backingField = backingField
|
property.backingField = backingField
|
||||||
|
property.getter = getter
|
||||||
|
property.setter = setter
|
||||||
|
|
||||||
backingField?.let { it.correspondingProperty = property }
|
backingField?.let { it.correspondingProperty = property }
|
||||||
|
getter?.let { it.correspondingProperty = property }
|
||||||
property.getter =
|
setter?.let { it.correspondingProperty = property }
|
||||||
if (proto.hasGetter()) deserializeIrFunction(proto.getter, start, end, origin, property) else null
|
|
||||||
property.setter =
|
|
||||||
if (proto.hasSetter()) deserializeIrFunction(proto.setter, start, end, origin, property) else null
|
|
||||||
|
|
||||||
property.getter?.let {
|
|
||||||
val descriptor = it.descriptor
|
|
||||||
if (descriptor is WrappedSimpleFunctionDescriptor) descriptor.bind(it)
|
|
||||||
symbolTable.declareSimpleFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
|
||||||
descriptor, { symbol -> it })
|
|
||||||
|
|
||||||
}
|
|
||||||
property.setter?.let {
|
|
||||||
val descriptor = it.descriptor
|
|
||||||
if (descriptor is WrappedSimpleFunctionDescriptor) descriptor.bind(it)
|
|
||||||
symbolTable.declareSimpleFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
|
||||||
descriptor, { symbol -> it })
|
|
||||||
}
|
|
||||||
|
|
||||||
return property
|
return property
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -129,7 +129,7 @@ internal class IrModuleSerializer(
|
|||||||
is IrReturnableBlockSymbol ->
|
is IrReturnableBlockSymbol ->
|
||||||
KonanIr.IrSymbolKind.RETURNABLE_BLOCK_SYMBOL
|
KonanIr.IrSymbolKind.RETURNABLE_BLOCK_SYMBOL
|
||||||
is IrFieldSymbol ->
|
is IrFieldSymbol ->
|
||||||
if (symbol.owner.correspondingProperty == null)
|
if (symbol.owner.correspondingProperty.let { it == null || it.isDelegated })
|
||||||
KonanIr.IrSymbolKind.STANDALONE_FIELD_SYMBOL
|
KonanIr.IrSymbolKind.STANDALONE_FIELD_SYMBOL
|
||||||
else
|
else
|
||||||
KonanIr.IrSymbolKind.FIELD_SYMBOL
|
KonanIr.IrSymbolKind.FIELD_SYMBOL
|
||||||
@@ -430,6 +430,8 @@ internal class IrModuleSerializer(
|
|||||||
callable.getter?.let { proto.getter = serializeIrSymbol(it) }
|
callable.getter?.let { proto.getter = serializeIrSymbol(it) }
|
||||||
callable.setter?.let { proto.setter = serializeIrSymbol(it) }
|
callable.setter?.let { proto.setter = serializeIrSymbol(it) }
|
||||||
callable.origin?.let { proto.origin = serializeIrStatementOrigin(it) }
|
callable.origin?.let { proto.origin = serializeIrStatementOrigin(it) }
|
||||||
|
val property = callable.getter!!.owner.correspondingProperty!!
|
||||||
|
descriptorReferenceSerializer.serializeDescriptorReference(property)?.let { proto.setDescriptor(it) }
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -251,6 +251,7 @@ message IrPropertyReference {
|
|||||||
optional IrSymbol setter = 3;
|
optional IrSymbol setter = 3;
|
||||||
optional IrStatementOrigin origin = 4;
|
optional IrStatementOrigin origin = 4;
|
||||||
required MemberAccessCommon member_access = 5;
|
required MemberAccessCommon member_access = 5;
|
||||||
|
optional DescriptorReference descriptor = 6; // IrProperty doesn't have a symbol at all. Preserve this rudiment for now.
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrComposite {
|
message IrComposite {
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ class KonanIrModuleDeserializer(
|
|||||||
?: WrappedEnumEntryDescriptor()
|
?: WrappedEnumEntryDescriptor()
|
||||||
)
|
)
|
||||||
KonanIr.IrSymbolKind.STANDALONE_FIELD_SYMBOL ->
|
KonanIr.IrSymbolKind.STANDALONE_FIELD_SYMBOL ->
|
||||||
IrFieldSymbolImpl(WrappedFieldDescriptor())
|
symbolTable.referenceField(WrappedFieldDescriptor())
|
||||||
|
|
||||||
KonanIr.IrSymbolKind.FIELD_SYMBOL ->
|
KonanIr.IrSymbolKind.FIELD_SYMBOL ->
|
||||||
symbolTable.referenceField(
|
symbolTable.referenceField(
|
||||||
|
|||||||
Reference in New Issue
Block a user