IR: get rid of WrappedDescriptorWithContainerSource
This commit is contained in:
+2
-6
@@ -404,9 +404,7 @@ class Fir2IrDeclarationStorage(
|
||||
factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
||||
): IrSimpleFunction {
|
||||
if (signature == null) {
|
||||
val descriptor =
|
||||
if (containerSource != null) WrappedFunctionDescriptorWithContainerSource()
|
||||
else WrappedSimpleFunctionDescriptor()
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) }
|
||||
}
|
||||
return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory)
|
||||
@@ -687,9 +685,7 @@ class Fir2IrDeclarationStorage(
|
||||
factory: (IrPropertySymbol) -> IrProperty
|
||||
): IrProperty {
|
||||
if (signature == null) {
|
||||
val descriptor =
|
||||
if (containerSource != null) WrappedPropertyDescriptorWithContainerSource()
|
||||
else WrappedPropertyDescriptor()
|
||||
val descriptor = WrappedPropertyDescriptor()
|
||||
return symbolTable.declareProperty(0, 0, IrDeclarationOrigin.DEFINED, descriptor, isDelegated = false, factory).apply {
|
||||
descriptor.bind(this)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir.symbols
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
@@ -42,8 +40,6 @@ abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolO
|
||||
is IrClass -> WrappedClassDescriptor().apply { bind(owner) }
|
||||
is IrConstructor -> WrappedClassConstructorDescriptor().apply { bind(owner) }
|
||||
is IrSimpleFunction -> when {
|
||||
containerSource != null ->
|
||||
WrappedFunctionDescriptorWithContainerSource()
|
||||
owner.name.isSpecial && owner.name.asString().startsWith(GETTER_PREFIX) ->
|
||||
WrappedPropertyGetterDescriptor()
|
||||
owner.name.isSpecial && owner.name.asString().startsWith(SETTER_PREFIX) ->
|
||||
@@ -54,11 +50,7 @@ abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolO
|
||||
is IrVariable -> WrappedVariableDescriptor().apply { bind(owner) }
|
||||
is IrValueParameter -> WrappedValueParameterDescriptor().apply { bind(owner) }
|
||||
is IrTypeParameter -> WrappedTypeParameterDescriptor().apply { bind(owner) }
|
||||
is IrProperty -> if (containerSource != null) {
|
||||
WrappedPropertyDescriptorWithContainerSource()
|
||||
} else {
|
||||
WrappedPropertyDescriptor()
|
||||
}.apply { bind(owner) }
|
||||
is IrProperty -> WrappedPropertyDescriptor().apply { bind(owner) }
|
||||
is IrField -> WrappedFieldDescriptor().apply { bind(owner) }
|
||||
is IrTypeAlias -> WrappedTypeAliasDescriptor().apply { bind(owner) }
|
||||
else -> throw IllegalStateException("Unsupported owner in Fir2IrBindableSymbol: $owner")
|
||||
|
||||
@@ -497,9 +497,7 @@ fun IrFactory.createStaticFunctionWithReceivers(
|
||||
copyMetadata: Boolean = true,
|
||||
typeParametersFromContext: List<IrTypeParameter> = listOf()
|
||||
): IrSimpleFunction {
|
||||
val descriptor = (oldFunction.descriptor as? DescriptorWithContainerSource)?.let {
|
||||
WrappedFunctionDescriptorWithContainerSource()
|
||||
} ?: WrappedSimpleFunctionDescriptor()
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
return createFunction(
|
||||
oldFunction.startOffset, oldFunction.endOffset,
|
||||
origin,
|
||||
|
||||
+2
-8
@@ -11,8 +11,6 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyProperty
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
@@ -77,9 +75,7 @@ fun IrClass.addField(fieldName: String, fieldType: IrType, fieldVisibility: Desc
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildProperty(builder: IrPropertyBuilder): IrProperty = with(builder) {
|
||||
val wrappedDescriptor = if (originalDeclaration is IrLazyProperty || containerSource != null)
|
||||
WrappedPropertyDescriptorWithContainerSource()
|
||||
else WrappedPropertyDescriptor()
|
||||
val wrappedDescriptor = WrappedPropertyDescriptor()
|
||||
|
||||
createProperty(
|
||||
startOffset, endOffset, origin,
|
||||
@@ -117,9 +113,7 @@ inline fun IrProperty.addGetter(builder: IrFunctionBuilder.() -> Unit = {}): IrS
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildFunction(builder: IrFunctionBuilder): IrSimpleFunction = with(builder) {
|
||||
val wrappedDescriptor = if (originalDeclaration is IrLazyFunction || containerSource != null)
|
||||
WrappedFunctionDescriptorWithContainerSource()
|
||||
else WrappedSimpleFunctionDescriptor()
|
||||
val wrappedDescriptor = WrappedSimpleFunctionDescriptor()
|
||||
createFunction(
|
||||
startOffset, endOffset, origin,
|
||||
IrSimpleFunctionSymbolImpl(wrappedDescriptor),
|
||||
|
||||
@@ -13,8 +13,6 @@ import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyProperty
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
@@ -371,7 +369,9 @@ open class IrBasedVariableDescriptorWithAccessor(owner: IrLocalDelegatedProperty
|
||||
|
||||
fun IrLocalDelegatedProperty.toIrBasedDescriptor() = IrBasedVariableDescriptorWithAccessor(this)
|
||||
|
||||
open class IrBasedSimpleFunctionDescriptor(owner: IrSimpleFunction) : SimpleFunctionDescriptor,
|
||||
// We make all IR-based function descriptors instances of DescriptorWithContainerSource, and use .parentClassId to
|
||||
// check whether declaration is deserialized. See IrInlineCodegen.descriptorIsDeserialized
|
||||
open class IrBasedSimpleFunctionDescriptor(owner: IrSimpleFunction) : SimpleFunctionDescriptor, DescriptorWithContainerSource,
|
||||
IrBasedCallableDescriptor<IrSimpleFunction>(owner) {
|
||||
|
||||
override fun getOverriddenDescriptors(): List<FunctionDescriptor> = owner.overriddenSymbols.map { it.owner.toIrBasedDescriptor() }
|
||||
@@ -402,6 +402,9 @@ open class IrBasedSimpleFunctionDescriptor(owner: IrSimpleFunction) : SimpleFunc
|
||||
override fun isInfix() = false
|
||||
override fun isOperator() = false
|
||||
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = owner.containerSource
|
||||
|
||||
override fun getOriginal() = this
|
||||
override fun substitute(substitutor: TypeSubstitutor): SimpleFunctionDescriptor {
|
||||
TODO("")
|
||||
@@ -444,19 +447,8 @@ open class IrBasedSimpleFunctionDescriptor(owner: IrSimpleFunction) : SimpleFunc
|
||||
}
|
||||
}
|
||||
|
||||
class IrBasedFunctionDescriptorWithContainerSource(owner: IrSimpleFunction) : IrBasedSimpleFunctionDescriptor(owner),
|
||||
DescriptorWithContainerSource {
|
||||
override val containerSource: DeserializedContainerSource? get() = owner.containerSource
|
||||
}
|
||||
|
||||
fun IrSimpleFunction.toIrBasedDescriptor() =
|
||||
if (originalFunction is IrLazyFunction || containerSource != null)
|
||||
when {
|
||||
isGetter -> IrBasedPropertyGetterDescriptorWithContainerSource(this)
|
||||
isSetter -> IrBasedPropertySetterDescriptorWithContainerSource(this)
|
||||
else -> IrBasedFunctionDescriptorWithContainerSource(this)
|
||||
}
|
||||
else when {
|
||||
when {
|
||||
isGetter -> IrBasedPropertyGetterDescriptor(this)
|
||||
isSetter -> IrBasedPropertySetterDescriptor(this)
|
||||
else -> IrBasedSimpleFunctionDescriptor(this)
|
||||
@@ -759,7 +751,8 @@ open class IrBasedEnumEntryDescriptor(owner: IrEnumEntry) : ClassDescriptor, IrB
|
||||
|
||||
fun IrEnumEntry.toIrBasedDescriptor() = IrBasedEnumEntryDescriptor(this)
|
||||
|
||||
open class IrBasedPropertyDescriptor(owner: IrProperty) : PropertyDescriptor, IrBasedDeclarationDescriptor<IrProperty>(owner) {
|
||||
open class IrBasedPropertyDescriptor(owner: IrProperty) :
|
||||
PropertyDescriptor, DescriptorWithContainerSource, IrBasedDeclarationDescriptor<IrProperty>(owner) {
|
||||
override fun getModality() = owner.modality
|
||||
|
||||
override fun setOverriddenDescriptors(overriddenDescriptors: MutableCollection<out CallableMemberDescriptor>) {
|
||||
@@ -806,6 +799,8 @@ open class IrBasedPropertyDescriptor(owner: IrProperty) : PropertyDescriptor, Ir
|
||||
|
||||
override val setter: PropertySetterDescriptor? get() = owner.setter?.toIrBasedDescriptor() as? PropertySetterDescriptor
|
||||
|
||||
override val containerSource: DeserializedContainerSource? = owner.containerSource
|
||||
|
||||
override fun getOriginal() = this
|
||||
|
||||
override fun isExpect() = false
|
||||
@@ -861,16 +856,7 @@ open class IrBasedPropertyDescriptor(owner: IrProperty) : PropertyDescriptor, Ir
|
||||
override fun <V : Any?> getUserData(key: CallableDescriptor.UserDataKey<V>?): V? = null
|
||||
}
|
||||
|
||||
class IrBasedPropertyDescriptorWithContainerSource(
|
||||
owner: IrProperty
|
||||
) : IrBasedPropertyDescriptor(owner), DescriptorWithContainerSource {
|
||||
override val containerSource: DeserializedContainerSource? = owner.containerSource
|
||||
}
|
||||
|
||||
fun IrProperty.toIrBasedDescriptor() = if (originalProperty is IrLazyProperty || containerSource != null)
|
||||
IrBasedPropertyDescriptorWithContainerSource(this)
|
||||
else
|
||||
IrBasedPropertyDescriptor(this)
|
||||
fun IrProperty.toIrBasedDescriptor() = IrBasedPropertyDescriptor(this)
|
||||
|
||||
abstract class IrBasedPropertyAccessorDescriptor(owner: IrSimpleFunction) : IrBasedSimpleFunctionDescriptor(owner),
|
||||
PropertyAccessorDescriptor {
|
||||
@@ -891,22 +877,12 @@ open class IrBasedPropertyGetterDescriptor(owner: IrSimpleFunction) : IrBasedPro
|
||||
override fun getOriginal(): IrBasedPropertyGetterDescriptor = this
|
||||
}
|
||||
|
||||
class IrBasedPropertyGetterDescriptorWithContainerSource(owner: IrSimpleFunction) : IrBasedPropertyGetterDescriptor(owner),
|
||||
DescriptorWithContainerSource {
|
||||
override val containerSource: DeserializedContainerSource? get() = owner.containerSource
|
||||
}
|
||||
|
||||
open class IrBasedPropertySetterDescriptor(owner: IrSimpleFunction) : IrBasedPropertyAccessorDescriptor(owner), PropertySetterDescriptor {
|
||||
override fun getOverriddenDescriptors() = super.getOverriddenDescriptors().map { it as PropertySetterDescriptor }
|
||||
|
||||
override fun getOriginal(): IrBasedPropertySetterDescriptor = this
|
||||
}
|
||||
|
||||
class IrBasedPropertySetterDescriptorWithContainerSource(owner: IrSimpleFunction) : IrBasedPropertySetterDescriptor(owner),
|
||||
DescriptorWithContainerSource {
|
||||
override val containerSource: DeserializedContainerSource? get() = owner.containerSource
|
||||
}
|
||||
|
||||
open class IrBasedTypeAliasDescriptor(owner: IrTypeAlias) : IrBasedDeclarationDescriptor<IrTypeAlias>(owner), TypeAliasDescriptor {
|
||||
|
||||
override val underlyingType: SimpleType
|
||||
|
||||
@@ -365,8 +365,11 @@ open class WrappedVariableDescriptorWithAccessor : VariableDescriptorWithAccesso
|
||||
|
||||
}
|
||||
|
||||
// We make all wrapped function descriptors instances of DescriptorWithContainerSource, and use .parentClassId to
|
||||
// check whether declaration is deserialized. See IrInlineCodegen.descriptorIsDeserialized
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
open class WrappedSimpleFunctionDescriptor : SimpleFunctionDescriptor, WrappedCallableDescriptor<IrSimpleFunction>() {
|
||||
open class WrappedSimpleFunctionDescriptor :
|
||||
SimpleFunctionDescriptor, DescriptorWithContainerSource, WrappedCallableDescriptor<IrSimpleFunction>() {
|
||||
|
||||
override fun getOverriddenDescriptors() = owner.overriddenSymbols.map { it.descriptor }
|
||||
|
||||
@@ -402,6 +405,9 @@ open class WrappedSimpleFunctionDescriptor : SimpleFunctionDescriptor, WrappedCa
|
||||
override fun isInfix() = false
|
||||
override fun isOperator() = false
|
||||
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = owner.containerSource
|
||||
|
||||
override fun getOriginal() = this
|
||||
override fun substitute(substitutor: TypeSubstitutor): SimpleFunctionDescriptor {
|
||||
TODO("")
|
||||
@@ -444,12 +450,6 @@ open class WrappedSimpleFunctionDescriptor : SimpleFunctionDescriptor, WrappedCa
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
class WrappedFunctionDescriptorWithContainerSource : WrappedSimpleFunctionDescriptor(), DescriptorWithContainerSource {
|
||||
override val containerSource
|
||||
get() = owner.containerSource
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
open class WrappedClassConstructorDescriptor : ClassConstructorDescriptor, WrappedCallableDescriptor<IrConstructor>() {
|
||||
override fun getContainingDeclaration() = (owner.parent as IrClass).descriptor
|
||||
@@ -877,7 +877,8 @@ open class WrappedEnumEntryDescriptor : ClassDescriptor, WrappedDeclarationDescr
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
open class WrappedPropertyDescriptor : PropertyDescriptor, WrappedDeclarationDescriptor<IrProperty>() {
|
||||
open class WrappedPropertyDescriptor :
|
||||
PropertyDescriptor, DescriptorWithContainerSource, WrappedDeclarationDescriptor<IrProperty>() {
|
||||
override fun getModality() = owner.modality
|
||||
|
||||
override fun setOverriddenDescriptors(overriddenDescriptors: MutableCollection<out CallableMemberDescriptor>) {
|
||||
@@ -924,6 +925,9 @@ open class WrappedPropertyDescriptor : PropertyDescriptor, WrappedDeclarationDes
|
||||
|
||||
override val setter: PropertySetterDescriptor? get() = owner.setter?.descriptor as? PropertySetterDescriptor
|
||||
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = owner.containerSource
|
||||
|
||||
override fun getOriginal() = this
|
||||
|
||||
override fun isExpect() = false
|
||||
@@ -979,11 +983,6 @@ open class WrappedPropertyDescriptor : PropertyDescriptor, WrappedDeclarationDes
|
||||
override fun <V : Any?> getUserData(key: CallableDescriptor.UserDataKey<V>?): V? = null
|
||||
}
|
||||
|
||||
class WrappedPropertyDescriptorWithContainerSource : WrappedPropertyDescriptor(), DescriptorWithContainerSource {
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = owner.containerSource
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
abstract class WrappedPropertyAccessorDescriptor : WrappedSimpleFunctionDescriptor(), PropertyAccessorDescriptor {
|
||||
override fun isDefault(): Boolean = false
|
||||
|
||||
@@ -13,8 +13,8 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrScriptImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedFunctionDescriptorWithContainerSource
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptorWithContainerSource
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
@@ -1025,24 +1025,24 @@ class SymbolTable(
|
||||
fun wrappedTopLevelCallableDescriptors(): Set<DescriptorWithContainerSource> {
|
||||
val result = mutableSetOf<DescriptorWithContainerSource>()
|
||||
for (descriptor in simpleFunctionSymbolTable.descriptorToSymbol.keys) {
|
||||
if (descriptor is WrappedFunctionDescriptorWithContainerSource && descriptor.owner.parent !is IrClass) {
|
||||
if (descriptor is WrappedSimpleFunctionDescriptor && descriptor.owner.parent !is IrClass) {
|
||||
result.add(descriptor)
|
||||
}
|
||||
}
|
||||
for (symbol in simpleFunctionSymbolTable.idSigToSymbol.values) {
|
||||
val descriptor = symbol.descriptor
|
||||
if (descriptor is WrappedFunctionDescriptorWithContainerSource && symbol.owner.parent !is IrClass) {
|
||||
if (descriptor is WrappedSimpleFunctionDescriptor && symbol.owner.parent !is IrClass) {
|
||||
result.add(descriptor)
|
||||
}
|
||||
}
|
||||
for (descriptor in propertySymbolTable.descriptorToSymbol.keys) {
|
||||
if (descriptor is WrappedPropertyDescriptorWithContainerSource && descriptor.owner.parent !is IrClass) {
|
||||
if (descriptor is WrappedPropertyDescriptor && descriptor.owner.parent !is IrClass) {
|
||||
result.add(descriptor)
|
||||
}
|
||||
}
|
||||
for (symbol in propertySymbolTable.idSigToSymbol.values) {
|
||||
val descriptor = symbol.descriptor
|
||||
if (descriptor is WrappedPropertyDescriptorWithContainerSource && symbol.owner.parent !is IrClass) {
|
||||
if (descriptor is WrappedPropertyDescriptor && symbol.owner.parent !is IrClass) {
|
||||
result.add(descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user