Fir2Ir: fix deserializing IR for property accessors
1. Need to register Fir2IrLazyPropertyAccessors in symbol table. 2. Need to set their bodies.
This commit is contained in:
committed by
Alexander Udalov
parent
f94b0bbcea
commit
1fbd79e310
+2
-5
@@ -7,8 +7,6 @@ package org.jetbrains.kotlin.fir.lazy
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrBindableSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||||
@@ -19,11 +17,10 @@ import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
|||||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
import kotlin.properties.ReadWriteProperty
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
|
||||||
interface AbstractFir2IrLazyDeclaration<F, D : IrDeclaration> :
|
interface AbstractFir2IrLazyDeclaration<F> :
|
||||||
IrDeclaration, IrLazyDeclarationBase, Fir2IrComponents where F : FirMemberDeclaration, F : FirAnnotationContainer {
|
IrDeclaration, IrLazyDeclarationBase, Fir2IrComponents where F : FirAnnotationContainer {
|
||||||
|
|
||||||
val fir: F
|
val fir: F
|
||||||
override val symbol: Fir2IrBindableSymbol<*, D>
|
|
||||||
|
|
||||||
override val factory: IrFactory
|
override val factory: IrFactory
|
||||||
get() = irFactory
|
get() = irFactory
|
||||||
|
|||||||
+22
-6
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrSimpleFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunctionBase
|
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunctionBase
|
||||||
@@ -21,7 +20,9 @@ import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
|
import org.jetbrains.kotlin.ir.util.DeserializableClass
|
||||||
import org.jetbrains.kotlin.ir.util.isFacadeClass
|
import org.jetbrains.kotlin.ir.util.isFacadeClass
|
||||||
import org.jetbrains.kotlin.ir.util.isObject
|
import org.jetbrains.kotlin.ir.util.isObject
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -33,9 +34,9 @@ abstract class AbstractFir2IrLazyFunction<F : FirCallableDeclaration>(
|
|||||||
override val startOffset: Int,
|
override val startOffset: Int,
|
||||||
override val endOffset: Int,
|
override val endOffset: Int,
|
||||||
override var origin: IrDeclarationOrigin,
|
override var origin: IrDeclarationOrigin,
|
||||||
override val symbol: Fir2IrSimpleFunctionSymbol,
|
override val symbol: IrSimpleFunctionSymbol,
|
||||||
override val isFakeOverride: Boolean
|
override val isFakeOverride: Boolean
|
||||||
) : IrSimpleFunction(), AbstractFir2IrLazyDeclaration<F, IrSimpleFunction>, Fir2IrTypeParametersContainer, IrLazyFunctionBase,
|
) : IrSimpleFunction(), AbstractFir2IrLazyDeclaration<F>, Fir2IrTypeParametersContainer, IrLazyFunctionBase,
|
||||||
Fir2IrComponents by components {
|
Fir2IrComponents by components {
|
||||||
|
|
||||||
override lateinit var typeParameters: List<IrTypeParameter>
|
override lateinit var typeParameters: List<IrTypeParameter>
|
||||||
@@ -66,9 +67,9 @@ abstract class AbstractFir2IrLazyFunction<F : FirCallableDeclaration>(
|
|||||||
override val isExpect: Boolean
|
override val isExpect: Boolean
|
||||||
get() = fir.isExpect
|
get() = fir.isExpect
|
||||||
|
|
||||||
override var body: IrBody?
|
override var body: IrBody? by lazyVar(lock) {
|
||||||
get() = null
|
if (tryLoadIr()) body else null
|
||||||
set(_) = error("We should never need to store body of external functions.")
|
}
|
||||||
|
|
||||||
override var visibility: DescriptorVisibility by lazyVar(lock) {
|
override var visibility: DescriptorVisibility by lazyVar(lock) {
|
||||||
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility)
|
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility)
|
||||||
@@ -107,6 +108,21 @@ abstract class AbstractFir2IrLazyFunction<F : FirCallableDeclaration>(
|
|||||||
return super<AbstractFir2IrLazyDeclaration>.createLazyAnnotations()
|
return super<AbstractFir2IrLazyDeclaration>.createLazyAnnotations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun tryLoadIr(): Boolean {
|
||||||
|
if (!isInline || isFakeOverride) return false
|
||||||
|
if (!extensions.irNeedsDeserialization) return false
|
||||||
|
val toplevel = getToplevel()
|
||||||
|
return (toplevel as? DeserializableClass)?.loadIr() ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getToplevel(): IrDeclaration {
|
||||||
|
var current: IrDeclaration = this
|
||||||
|
while (current.parent !is IrPackageFragment) {
|
||||||
|
current = current.parent as IrDeclaration
|
||||||
|
}
|
||||||
|
return current
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val JVM_STATIC_CLASS_ID = ClassId.topLevel(JVM_STATIC_ANNOTATION_FQ_NAME)
|
private val JVM_STATIC_CLASS_ID = ClassId.topLevel(JVM_STATIC_ANNOTATION_FQ_NAME)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class Fir2IrLazyClass(
|
|||||||
override var origin: IrDeclarationOrigin,
|
override var origin: IrDeclarationOrigin,
|
||||||
override val fir: FirRegularClass,
|
override val fir: FirRegularClass,
|
||||||
override val symbol: Fir2IrClassSymbol,
|
override val symbol: Fir2IrClassSymbol,
|
||||||
) : IrClass(), AbstractFir2IrLazyDeclaration<FirRegularClass, IrClass>, Fir2IrTypeParametersContainer,
|
) : IrClass(), AbstractFir2IrLazyDeclaration<FirRegularClass>, Fir2IrTypeParametersContainer,
|
||||||
IrMaybeDeserializedClass, DeserializableClass, Fir2IrComponents by components {
|
IrMaybeDeserializedClass, DeserializableClass, Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Fir2IrLazyConstructor(
|
|||||||
override var origin: IrDeclarationOrigin,
|
override var origin: IrDeclarationOrigin,
|
||||||
override val fir: FirConstructor,
|
override val fir: FirConstructor,
|
||||||
override val symbol: Fir2IrConstructorSymbol,
|
override val symbol: Fir2IrConstructorSymbol,
|
||||||
) : IrConstructor(), AbstractFir2IrLazyDeclaration<FirConstructor, IrConstructor>, Fir2IrTypeParametersContainer,
|
) : IrConstructor(), AbstractFir2IrLazyDeclaration<FirConstructor>, Fir2IrTypeParametersContainer,
|
||||||
Fir2IrComponents by components {
|
Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class Fir2IrLazyProperty(
|
|||||||
internal val containingClass: FirRegularClass?,
|
internal val containingClass: FirRegularClass?,
|
||||||
override val symbol: Fir2IrPropertySymbol,
|
override val symbol: Fir2IrPropertySymbol,
|
||||||
override val isFakeOverride: Boolean
|
override val isFakeOverride: Boolean
|
||||||
) : IrProperty(), AbstractFir2IrLazyDeclaration<FirProperty, IrProperty>, Fir2IrComponents by components {
|
) : IrProperty(), AbstractFir2IrLazyDeclaration<FirProperty>, Fir2IrComponents by components {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
classifierStorage.preCacheTypeParameters(fir)
|
classifierStorage.preCacheTypeParameters(fir)
|
||||||
@@ -160,20 +160,19 @@ class Fir2IrLazyProperty(
|
|||||||
|
|
||||||
override var getter: IrSimpleFunction? by lazyVar(lock) {
|
override var getter: IrSimpleFunction? by lazyVar(lock) {
|
||||||
if (fir.isConst) return@lazyVar null
|
if (fir.isConst) return@lazyVar null
|
||||||
Fir2IrLazyPropertyAccessor(
|
val signature = signatureComposer.composeAccessorSignature(fir, isSetter = false, containingClass?.symbol?.toLookupTag())!!
|
||||||
components, startOffset, endOffset,
|
symbolTable.declareSimpleFunction(signature, symbolFactory = { Fir2IrSimpleFunctionSymbol(signature) }) { symbol ->
|
||||||
when {
|
Fir2IrLazyPropertyAccessor(
|
||||||
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
|
components, startOffset, endOffset,
|
||||||
fir.delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
|
when {
|
||||||
fir.getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
|
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
|
||||||
else -> origin
|
fir.delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
|
||||||
},
|
fir.getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
|
||||||
fir.getter, isSetter = false, fir, containingClass,
|
else -> origin
|
||||||
Fir2IrSimpleFunctionSymbol(
|
},
|
||||||
signatureComposer.composeAccessorSignature(fir, isSetter = false, containingClass?.symbol?.toLookupTag())!!
|
fir.getter, isSetter = false, fir, containingClass, symbol, isFakeOverride
|
||||||
),
|
)
|
||||||
isFakeOverride
|
}.apply {
|
||||||
).apply {
|
|
||||||
parent = this@Fir2IrLazyProperty.parent
|
parent = this@Fir2IrLazyProperty.parent
|
||||||
correspondingPropertySymbol = this@Fir2IrLazyProperty.symbol
|
correspondingPropertySymbol = this@Fir2IrLazyProperty.symbol
|
||||||
with(classifierStorage) {
|
with(classifierStorage) {
|
||||||
@@ -188,29 +187,31 @@ class Fir2IrLazyProperty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var setter: IrSimpleFunction? by lazyVar(lock) {
|
override var setter: IrSimpleFunction? by lazyVar(lock) {
|
||||||
if (!fir.isVar) null else Fir2IrLazyPropertyAccessor(
|
if (!fir.isVar) null
|
||||||
components, startOffset, endOffset,
|
else {
|
||||||
when {
|
val signature = signatureComposer.composeAccessorSignature(fir, isSetter = true, containingClass?.symbol?.toLookupTag())!!
|
||||||
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
|
symbolTable.declareSimpleFunction(signature, symbolFactory = { Fir2IrSimpleFunctionSymbol(signature) }) { symbol ->
|
||||||
fir.delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
|
Fir2IrLazyPropertyAccessor(
|
||||||
fir.setter is FirDefaultPropertySetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
|
components, startOffset, endOffset,
|
||||||
else -> origin
|
when {
|
||||||
},
|
origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB -> origin
|
||||||
fir.setter, isSetter = true, fir, containingClass,
|
fir.delegate != null -> IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR
|
||||||
Fir2IrSimpleFunctionSymbol(
|
fir.setter is FirDefaultPropertySetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
|
||||||
signatureComposer.composeAccessorSignature(fir, isSetter = true, containingClass?.symbol?.toLookupTag())!!
|
else -> origin
|
||||||
),
|
},
|
||||||
isFakeOverride
|
fir.setter, isSetter = true, fir, containingClass, symbol, isFakeOverride
|
||||||
).apply {
|
).apply {
|
||||||
parent = this@Fir2IrLazyProperty.parent
|
parent = this@Fir2IrLazyProperty.parent
|
||||||
correspondingPropertySymbol = this@Fir2IrLazyProperty.symbol
|
correspondingPropertySymbol = this@Fir2IrLazyProperty.symbol
|
||||||
with(classifierStorage) {
|
with(classifierStorage) {
|
||||||
setTypeParameters(
|
setTypeParameters(
|
||||||
this@Fir2IrLazyProperty.fir, ConversionTypeContext(
|
this@Fir2IrLazyProperty.fir, ConversionTypeContext(
|
||||||
definitelyNotNull = false,
|
definitelyNotNull = false,
|
||||||
origin = ConversionTypeOrigin.SETTER
|
origin = ConversionTypeOrigin.SETTER
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Fir2IrLazyPropertyAccessor(
|
|||||||
private val isSetter: Boolean,
|
private val isSetter: Boolean,
|
||||||
private val firParentProperty: FirProperty,
|
private val firParentProperty: FirProperty,
|
||||||
firParentClass: FirRegularClass?,
|
firParentClass: FirRegularClass?,
|
||||||
symbol: Fir2IrSimpleFunctionSymbol,
|
symbol: IrSimpleFunctionSymbol,
|
||||||
isFakeOverride: Boolean
|
isFakeOverride: Boolean
|
||||||
) : AbstractFir2IrLazyFunction<FirCallableDeclaration>(components, startOffset, endOffset, origin, symbol, isFakeOverride) {
|
) : AbstractFir2IrLazyFunction<FirCallableDeclaration>(components, startOffset, endOffset, origin, symbol, isFakeOverride) {
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -51,10 +51,6 @@ class Fir2IrLazySimpleFunction(
|
|||||||
fir.returnTypeRef.toIrType(typeConverter)
|
fir.returnTypeRef.toIrType(typeConverter)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var body: IrBody? by lazyVar(lock) {
|
|
||||||
if (tryLoadIr()) body else null
|
|
||||||
}
|
|
||||||
|
|
||||||
override var dispatchReceiverParameter: IrValueParameter? by lazyVar(lock) {
|
override var dispatchReceiverParameter: IrValueParameter? by lazyVar(lock) {
|
||||||
val containingClass = parent as? IrClass
|
val containingClass = parent as? IrClass
|
||||||
if (containingClass != null && shouldHaveDispatchReceiver(containingClass, fir)) {
|
if (containingClass != null && shouldHaveDispatchReceiver(containingClass, fir)) {
|
||||||
@@ -110,19 +106,4 @@ class Fir2IrLazySimpleFunction(
|
|||||||
|
|
||||||
override val containerSource: DeserializedContainerSource?
|
override val containerSource: DeserializedContainerSource?
|
||||||
get() = fir.containerSource
|
get() = fir.containerSource
|
||||||
|
|
||||||
private fun tryLoadIr(): Boolean {
|
|
||||||
if (!isInline || isFakeOverride) return false
|
|
||||||
if (!extensions.irNeedsDeserialization) return false
|
|
||||||
val toplevel = getToplevel()
|
|
||||||
return (toplevel as? DeserializableClass)?.loadIr() ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getToplevel(): IrDeclaration {
|
|
||||||
var current: IrDeclaration = this
|
|
||||||
while (current.parent !is IrPackageFragment) {
|
|
||||||
current = current.parent as IrDeclaration
|
|
||||||
}
|
|
||||||
return current
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user