IR: IrPropertySymbol introduced, some code cleaned up

#KT-30304
This commit is contained in:
Dmitry Petrov
2019-02-27 13:56:13 +03:00
parent 1bc35b1b0c
commit 04fad012a0
34 changed files with 345 additions and 170 deletions
@@ -80,7 +80,7 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
IrPropertyReferenceImpl(
expression.startOffset, expression.endOffset,
expression.type,
expression.descriptor,
expression.symbol, // TODO remap property symbol based on remapped getter/setter?
expression.typeArgumentsCount,
expression.field,
memberMap[expression.getter]?.symbol ?: expression.getter,
@@ -292,6 +292,7 @@ private class IrUnboundSymbolReplacer(
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
expression.replaceTypeArguments()
val property = expression.symbol.replaceOrSame(SymbolTable::referenceProperty)
val field = expression.field?.replaceOrSame(SymbolTable::referenceField)
val getter = expression.getter?.replace(SymbolTable::referenceSimpleFunction) ?: expression.getter
val setter = expression.setter?.replace(SymbolTable::referenceSimpleFunction) ?: expression.setter
@@ -302,12 +303,15 @@ private class IrUnboundSymbolReplacer(
expression.transformChildrenVoid(this)
return with(expression) {
IrPropertyReferenceImpl(startOffset, endOffset, type, descriptor, 0,
field,
getter,
setter,
origin).also {
IrPropertyReferenceImpl(
startOffset, endOffset, type,
property,
0,
field,
getter,
setter,
origin
).also {
it.copyArgumentsFrom(this)
it.copyTypeArgumentsFrom(this)
}
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptorImpl
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.expressions.mapValueParameters
@@ -204,13 +203,13 @@ class ClassGenerator(
irDelegate: IrField,
delegatedDescriptor: PropertyDescriptor,
overriddenDescriptor: PropertyDescriptor
): IrPropertyImpl {
): IrProperty {
val startOffset = irDelegate.startOffset
val endOffset = irDelegate.endOffset
val irProperty = IrPropertyImpl(
val irProperty = context.symbolTable.declareProperty(
startOffset, endOffset, IrDeclarationOrigin.DELEGATED_MEMBER,
false, delegatedDescriptor
delegatedDescriptor
)
irProperty.getter = generateDelegatedFunction(irDelegate, delegatedDescriptor.getter!!, overriddenDescriptor.getter!!)
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.builders.irGet
import org.jetbrains.kotlin.ir.builders.irReturn
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrLocalDelegatedPropertyImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptor
import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptorImpl
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor
@@ -55,10 +54,10 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
val kPropertyType = getKPropertyTypeForDelegatedProperty(propertyDescriptor)
val irProperty = IrPropertyImpl(
val irProperty = context.symbolTable.declareProperty(
ktProperty.startOffsetSkippingComments, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
isDelegated = true,
descriptor = propertyDescriptor
propertyDescriptor,
isDelegated = true
).apply {
backingField = generateDelegateFieldForProperty(propertyDescriptor, kPropertyType, ktDelegate)
}
@@ -145,14 +144,15 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
val irDelegateInitializer = declarationGenerator.generateInitializerBody(scopeOwner, ktDelegateExpression)
val provideDelegateResolvedCall = get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, property)
?: return irDelegateInitializer
?: return irDelegateInitializer
val statementGenerator = createBodyGenerator(scopeOwner).createStatementGenerator()
val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall)
provideDelegateCall.setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer.expression))
provideDelegateCall.irValueArgumentsByIndex[1] = createCallableReference(ktDelegate, kPropertyType, property, scopeOwner)
val irProvideDelegate =
CallGenerator(statementGenerator).generateCall(ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall)
val irProvideDelegate = CallGenerator(statementGenerator).generateCall(
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall
)
return IrExpressionBodyImpl(irProvideDelegate)
}
@@ -241,30 +241,30 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
val getterDescriptor = variableDescriptor.getter!!
val delegateReceiverValue = createVariableValueForDelegate(irDelegate.symbol, ktDelegate)
irLocalDelegatedProperty.getter =
createLocalPropertyAccessor(getterDescriptor, ktDelegate) { irGetter ->
generateDelegatedPropertyGetterBody(
irGetter, ktDelegate, getterDescriptor, delegateReceiverValue,
createLocalDelegatedPropertyReference(
ktDelegate, kPropertyType,
variableDescriptor, irDelegate.symbol,
irGetter.symbol
)
createLocalPropertyAccessor(getterDescriptor, ktDelegate) { irGetter ->
generateDelegatedPropertyGetterBody(
irGetter, ktDelegate, getterDescriptor, delegateReceiverValue,
createLocalDelegatedPropertyReference(
ktDelegate, kPropertyType,
variableDescriptor, irDelegate.symbol,
irGetter.symbol
)
}
)
}
if (variableDescriptor.isVar) {
val setterDescriptor = variableDescriptor.setter!!
irLocalDelegatedProperty.setter =
createLocalPropertyAccessor(setterDescriptor, ktDelegate) { irSetter ->
generateDelegatedPropertySetterBody(
irSetter, ktDelegate, setterDescriptor, delegateReceiverValue,
createLocalDelegatedPropertyReference(
ktDelegate, kPropertyType,
variableDescriptor, irDelegate.symbol,
irSetter.symbol
)
createLocalPropertyAccessor(setterDescriptor, ktDelegate) { irSetter ->
generateDelegatedPropertySetterBody(
irSetter, ktDelegate, setterDescriptor, delegateReceiverValue,
createLocalDelegatedPropertyReference(
ktDelegate, kPropertyType,
variableDescriptor, irDelegate.symbol,
irSetter.symbol
)
}
)
}
}
return irLocalDelegatedProperty
@@ -320,14 +320,21 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall).apply {
setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer))
irValueArgumentsByIndex[1] =
createLocalDelegatedPropertyReference(ktDelegate, kPropertyType, variableDescriptor, delegateSymbol, scopeOwner)
createLocalDelegatedPropertyReference(ktDelegate, kPropertyType, variableDescriptor, delegateSymbol, scopeOwner)
}
return CallGenerator(statementGenerator).generateCall(ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall)
return CallGenerator(statementGenerator).generateCall(
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, provideDelegateCall
)
}
private fun createVariableValueForDelegate(irDelegate: IrVariableSymbol, ktDelegate: KtPropertyDelegate) =
VariableLValue(context, ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, irDelegate, irDelegate.descriptor.type.toIrType())
VariableLValue(
context,
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset,
irDelegate,
irDelegate.descriptor.type.toIrType()
)
private inline fun createLocalPropertyAccessor(
getterDescriptor: VariableAccessorDescriptor,
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
@@ -27,9 +26,9 @@ 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
import org.jetbrains.kotlin.psi2ir.pureEndOffsetOrUndefined
import org.jetbrains.kotlin.psi2ir.pureStartOffsetOrUndefined
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.hasBackingField
@@ -47,33 +46,34 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
val propertyDescriptor = getOrFail(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, ktParameter)
val irPropertyType = propertyDescriptor.type.toIrType()
return IrPropertyImpl(
return context.symbolTable.declareProperty(
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
IrDeclarationOrigin.DEFINED, false,
propertyDescriptor
IrDeclarationOrigin.DEFINED,
propertyDescriptor,
isDelegated = false
).also { irProperty ->
irProperty.backingField =
generatePropertyBackingField(ktParameter, propertyDescriptor) {
IrExpressionBodyImpl(
IrGetValueImpl(
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
irPropertyType,
irValueParameter.symbol,
IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER
)
generatePropertyBackingField(ktParameter, propertyDescriptor) {
IrExpressionBodyImpl(
IrGetValueImpl(
ktParameter.startOffsetSkippingComments, ktParameter.endOffset,
irPropertyType,
irValueParameter.symbol,
IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER
)
}
)
}
val getter = propertyDescriptor.getter
?: throw AssertionError("Property declared in primary constructor has no getter: $propertyDescriptor")
?: throw AssertionError("Property declared in primary constructor has no getter: $propertyDescriptor")
irProperty.getter =
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(getter, ktParameter)
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(getter, ktParameter)
if (propertyDescriptor.isVar) {
val setter = propertyDescriptor.setter
?: throw AssertionError("Property declared in primary constructor has no setter: $propertyDescriptor")
?: throw AssertionError("Property declared in primary constructor has no setter: $propertyDescriptor")
irProperty.setter =
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter)
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter)
}
}
}
@@ -101,35 +101,33 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
.generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor)
private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrProperty =
IrPropertyImpl(
context.symbolTable.declareProperty(
ktProperty.startOffsetSkippingComments, ktProperty.endOffset,
IrDeclarationOrigin.DEFINED,
false,
propertyDescriptor
propertyDescriptor,
isDelegated = false
).buildWithScope { irProperty ->
irProperty.backingField =
if (propertyDescriptor.hasBackingField(context.bindingContext))
generatePropertyBackingField(ktProperty, propertyDescriptor) { irField ->
ktProperty.initializer?.let { ktInitializer ->
val compileTimeConst = propertyDescriptor.compileTimeInitializer
if (propertyDescriptor.isConst && compileTimeConst != null)
IrExpressionBodyImpl(
context.constantValueGenerator.generateConstantValueAsExpression(
ktInitializer.startOffsetSkippingComments, ktInitializer.endOffset,
compileTimeConst
)
if (propertyDescriptor.hasBackingField(context.bindingContext))
generatePropertyBackingField(ktProperty, propertyDescriptor) { irField ->
ktProperty.initializer?.let { ktInitializer ->
val compileTimeConst = propertyDescriptor.compileTimeInitializer
if (propertyDescriptor.isConst && compileTimeConst != null)
IrExpressionBodyImpl(
context.constantValueGenerator.generateConstantValueAsExpression(
ktInitializer.startOffsetSkippingComments, ktInitializer.endOffset,
compileTimeConst
)
else
declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer)
}
)
else
declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer)
}
else
null
}
else
null
irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor)
irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor)
irProperty.metadata = MetadataSource.Property(propertyDescriptor)
}
fun generateFakeOverrideProperty(propertyDescriptor: PropertyDescriptor, ktElement: KtPureElement): IrProperty? {
@@ -142,21 +140,20 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
if (propertyDescriptor.hasBackingField(context.bindingContext))
context.symbolTable.declareFieldWithOverrides(
startOffset, endOffset, IrDeclarationOrigin.FAKE_OVERRIDE,
propertyDescriptor, propertyDescriptor.type.toIrType(),
{ it.hasBackingField(context.bindingContext) }
)
propertyDescriptor, propertyDescriptor.type.toIrType()
) { it.hasBackingField(context.bindingContext) }
else
null
return IrPropertyImpl(
startOffset, endOffset,
IrDeclarationOrigin.FAKE_OVERRIDE,
false,
propertyDescriptor,
backingField,
propertyDescriptor.getter?.let { FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement) },
propertyDescriptor.setter?.let { FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement) }
)
return context.symbolTable.declareProperty(startOffset, endOffset, IrDeclarationOrigin.FAKE_OVERRIDE, propertyDescriptor).apply {
this.backingField = backingField
this.getter = propertyDescriptor.getter?.let {
FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement)
}
this.setter = propertyDescriptor.setter?.let {
FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement)
}
}
}
private fun generateGetterIfRequired(ktProperty: KtProperty, property: PropertyDescriptor): IrSimpleFunction? {
@@ -172,7 +169,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
private fun getPropertyDescriptor(ktProperty: KtProperty): PropertyDescriptor {
val variableDescriptor = getOrFail(BindingContext.VARIABLE, ktProperty)
return variableDescriptor as? PropertyDescriptor ?: TODO("not a property?")
return variableDescriptor as? PropertyDescriptor ?: TODO("not a property: $variableDescriptor")
}
}
@@ -48,7 +48,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
} else {
val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor
val typeClass = typeConstructorDeclaration
?: throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration")
?: throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration")
IrClassReferenceImpl(
ktClassLiteral.startOffsetSkippingComments, ktClassLiteral.endOffset, resultType,
context.symbolTable.referenceClassifier(typeClass), lhs.type.toIrType()
@@ -139,17 +139,16 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
val getterDescriptor = propertyDescriptor.getter
val setterDescriptor = if (mutable) propertyDescriptor.setter else null
val fieldSymbol = if (getterDescriptor == null) context.symbolTable.referenceField(propertyDescriptor) else null
val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) }
val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) }
return IrPropertyReferenceImpl(
startOffset, endOffset, type.toIrType(),
propertyDescriptor, propertyDescriptor.typeParametersCount,
fieldSymbol, getterSymbol, setterSymbol,
context.symbolTable.referenceProperty(propertyDescriptor.original),
propertyDescriptor.typeParametersCount,
getterDescriptor?.run { context.symbolTable.referenceField(propertyDescriptor) },
getterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) },
setterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) },
origin
).apply {
putTypeArguments(typeArguments) { it.toIrType()}
putTypeArguments(typeArguments) { it.toIrType() }
}
}
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ir
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.lang.AssertionError
interface IrElement {
val startOffset: Int
@@ -8,7 +8,9 @@ package org.jetbrains.kotlin.ir.builders.declarations
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.builders.IrElementBuilder
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithVisibility
import org.jetbrains.kotlin.name.Name
abstract class IrDeclarationBuilder : IrElementBuilder() {
@@ -19,10 +19,8 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
interface IrClass :
IrSymbolDeclaration<IrClassSymbol>, IrDeclarationWithName, IrDeclarationWithVisibility,
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.types.IrType
interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration<IrFieldSymbol>,
@@ -20,7 +21,9 @@ interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration
val isStatic: Boolean
var initializer: IrExpressionBody?
var correspondingProperty: IrProperty?
var correspondingPropertySymbol: IrPropertySymbol?
override val metadata: MetadataSource.Property?
}
@@ -18,9 +18,15 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
interface IrProperty :
IrDeclarationWithName,
IrDeclarationWithVisibility,
IrSymbolOwner {
interface IrProperty : IrDeclarationWithName, IrDeclarationWithVisibility {
override val descriptor: PropertyDescriptor
override val symbol: IrPropertySymbol
val modality: Modality
val isVar: Boolean
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol
interface IrReturnTarget : IrSymbolOwner {
@@ -17,15 +17,21 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
interface IrSimpleFunction : IrFunction, IrSymbolDeclaration<IrSimpleFunctionSymbol>, IrOverridableDeclaration<IrSimpleFunctionSymbol> {
interface IrSimpleFunction :
IrFunction,
IrSymbolDeclaration<IrSimpleFunctionSymbol>,
IrOverridableDeclaration<IrSimpleFunctionSymbol> {
val modality: Modality
val isTailrec: Boolean
val isSuspend: Boolean
var correspondingProperty: IrProperty?
var correspondingPropertySymbol: IrPropertySymbol?
}
val IrFunction.isPropertyAccessor: Boolean
get() = this is IrSimpleFunction && correspondingProperty != null
get() = this is IrSimpleFunction && correspondingPropertySymbol != null
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
@@ -77,7 +78,15 @@ class IrFieldImpl(
override val descriptor: PropertyDescriptor = symbol.descriptor
override var initializer: IrExpressionBody? = null
override var correspondingProperty: IrProperty? = null
override var correspondingProperty: IrProperty?
get() = correspondingPropertySymbol?.owner
set(value) {
correspondingPropertySymbol = value?.symbol
}
override var correspondingPropertySymbol: IrPropertySymbol? = null
override val overriddenSymbols: MutableList<IrFieldSymbol> = mutableListOf()
override var metadata: MetadataSource.Property? = null
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
@@ -59,7 +61,13 @@ class IrFunctionImpl(
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> = SmartList()
override var correspondingProperty: IrProperty? = null
override var correspondingProperty: IrProperty?
get() = correspondingPropertySymbol?.owner
set(value) {
correspondingPropertySymbol = value?.symbol
}
override var correspondingPropertySymbol: IrPropertySymbol? = null
// Used by kotlin-native in InteropLowering.kt and IrUtils2.kt
constructor(
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
@@ -20,27 +20,56 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
@Suppress("DEPRECATION_ERROR")
class IrPropertyImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val descriptor: PropertyDescriptor,
override val name: Name,
override val visibility: Visibility,
override val modality: Modality,
override val isVar: Boolean,
override val isConst: Boolean,
override val isLateinit: Boolean,
override val isDelegated: Boolean,
override val isExternal: Boolean
override val symbol: IrPropertySymbol,
override val name: Name = symbol.descriptor.name,
override val visibility: Visibility = symbol.descriptor.visibility,
override val modality: Modality = symbol.descriptor.modality,
override val isVar: Boolean = symbol.descriptor.isVar,
override val isConst: Boolean = symbol.descriptor.isConst,
override val isLateinit: Boolean = symbol.descriptor.isLateInit,
override val isDelegated: Boolean = symbol.descriptor.isDelegated,
override val isExternal: Boolean = symbol.descriptor.isEffectivelyExternal()
) : IrDeclarationBase(startOffset, endOffset, origin),
IrProperty {
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
name: Name,
visibility: Visibility,
modality: Modality,
isVar: Boolean,
isConst: Boolean,
isLateinit: Boolean,
isDelegated: Boolean,
isExternal: Boolean
) : this(
startOffset, endOffset, origin,
IrPropertySymbolImpl(descriptor),
name, visibility, modality,
isVar = isVar,
isConst = isConst,
isLateinit = isLateinit,
isDelegated = isDelegated,
isExternal = isExternal
)
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
constructor(
startOffset: Int,
endOffset: Int,
@@ -57,6 +86,7 @@ class IrPropertyImpl(
isExternal = descriptor.isEffectivelyExternal()
)
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
constructor(
startOffset: Int,
endOffset: Int,
@@ -64,6 +94,7 @@ class IrPropertyImpl(
descriptor: PropertyDescriptor
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor)
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
constructor(
startOffset: Int,
endOffset: Int,
@@ -75,6 +106,7 @@ class IrPropertyImpl(
this.backingField = backingField
}
@Deprecated(message = "Don't use descriptor-based API for IrProperty", level = DeprecationLevel.ERROR)
constructor(
startOffset: Int,
endOffset: Int,
@@ -89,6 +121,12 @@ class IrPropertyImpl(
this.setter = setter
}
init {
symbol.bind(this)
}
override val descriptor: PropertyDescriptor = symbol.descriptor
override var backingField: IrField? = null
override var getter: IrSimpleFunction? = null
override var setter: IrSimpleFunction? = null
@@ -8,7 +8,10 @@ package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
@@ -5,11 +5,14 @@
package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
import org.jetbrains.kotlin.ir.util.TypeTranslator
@@ -82,7 +85,13 @@ class IrLazyFunction(
}
}
override var correspondingProperty: IrProperty? = null
override var correspondingProperty: IrProperty?
get() = correspondingPropertySymbol?.owner
set(value) {
correspondingPropertySymbol = value?.symbol
}
override var correspondingPropertySymbol: IrPropertySymbol? = null
init {
symbol.bind(this)
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.types.IrType
@@ -18,7 +17,6 @@ import org.jetbrains.kotlin.ir.util.transform
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
abstract class IrLazyFunctionBase(
startOffset: Int,
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
import org.jetbrains.kotlin.ir.util.TypeTranslator
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
@@ -25,7 +26,7 @@ class IrLazyProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val descriptor: PropertyDescriptor,
override val symbol: IrPropertySymbol,
override val name: Name,
override val visibility: Visibility,
override val modality: Modality,
@@ -45,23 +46,31 @@ class IrLazyProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
symbol: IrPropertySymbol,
stubGenerator: DeclarationStubGenerator,
typeTranslator: TypeTranslator,
bindingContext: BindingContext?
) : this(
startOffset, endOffset, origin, descriptor,
descriptor.name, descriptor.visibility, descriptor.modality,
isVar = descriptor.isVar,
isConst = descriptor.isConst,
isLateinit = descriptor.isLateInit,
isDelegated = descriptor.isDelegated,
isExternal = descriptor.isEffectivelyExternal(),
startOffset, endOffset, origin,
symbol,
symbol.descriptor.name, symbol.descriptor.visibility, symbol.descriptor.modality,
isVar = symbol.descriptor.isVar,
isConst = symbol.descriptor.isConst,
isLateinit = symbol.descriptor.isLateInit,
isDelegated = symbol.descriptor.isDelegated,
isExternal = symbol.descriptor.isEffectivelyExternal(),
stubGenerator = stubGenerator,
typeTranslator = typeTranslator,
bindingContext = bindingContext
)
init {
symbol.bind(this)
}
override val descriptor: PropertyDescriptor
get() = symbol.descriptor
override var backingField: IrField? by lazyVar {
if (descriptor.hasBackingField(bindingContext)) {
stubGenerator.generateFieldStub(descriptor).apply {
@@ -5,9 +5,14 @@
package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.SymbolTable
class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable {
@@ -6,11 +6,10 @@
package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.TypeParametersResolver
import java.util.*
class LazyScopedTypeParametersResolver(private val symbolTable: ReferenceSymbolTable) : TypeParametersResolver {
@@ -20,10 +20,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
import org.jetbrains.kotlin.ir.symbols.*
interface IrCallableReference : IrMemberAccessExpression {
override val descriptor: CallableDescriptor
@@ -36,6 +33,7 @@ interface IrFunctionReference : IrCallableReference {
interface IrPropertyReference : IrCallableReference {
override val descriptor: PropertyDescriptor
val symbol: IrPropertySymbol
val field: IrFieldSymbol?
val getter: IrSimpleFunctionSymbol?
val setter: IrSimpleFunctionSymbol?
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.ir.expressions.IrBranch
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.utils.SmartList
@@ -20,7 +20,9 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -28,7 +30,7 @@ class IrPropertyReferenceImpl(
startOffset: Int,
endOffset: Int,
type: IrType,
override val descriptor: PropertyDescriptor,
override val symbol: IrPropertySymbol,
typeArgumentsCount: Int,
override val field: IrFieldSymbol?,
override val getter: IrSimpleFunctionSymbol?,
@@ -38,6 +40,26 @@ class IrPropertyReferenceImpl(
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, typeArgumentsCount, origin),
IrPropertyReference {
@Deprecated(message = "Don't use descriptor-based API for IrPropertyReference", level = DeprecationLevel.ERROR)
constructor(
startOffset: Int,
endOffset: Int,
type: IrType,
descriptor: PropertyDescriptor,
typeArgumentsCount: Int,
field: IrFieldSymbol?,
getter: IrSimpleFunctionSymbol?,
setter: IrSimpleFunctionSymbol?,
origin: IrStatementOrigin? = null
) : this(
startOffset, endOffset, type,
IrPropertySymbolImpl(descriptor),
typeArgumentsCount, field, getter, setter, origin
)
override val descriptor: PropertyDescriptor
get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertyReference(this, data)
}
@@ -73,3 +73,5 @@ interface IrConstructorSymbol : IrFunctionSymbol, IrBindableSymbol<ClassConstruc
interface IrSimpleFunctionSymbol : IrFunctionSymbol, IrBindableSymbol<FunctionDescriptor, IrSimpleFunction>
interface IrReturnableBlockSymbol : IrReturnTargetSymbol, IrBindableSymbol<FunctionDescriptor, IrReturnableBlock>
interface IrPropertySymbol : IrBindableSymbol<PropertyDescriptor, IrProperty>
@@ -101,3 +101,8 @@ class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) :
class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor),
IrReturnableBlockSymbol
class IrPropertySymbolImpl(descriptor: PropertyDescriptor) :
IrBindableSymbolBase<PropertyDescriptor, IrProperty>(descriptor),
IrPropertySymbol
@@ -84,10 +84,20 @@ class DeclarationStubGenerator(
internal fun generatePropertyStub(
descriptor: PropertyDescriptor,
bindingContext: BindingContext? = null
): IrProperty = symbolTable.referenceProperty(descriptor) {
deserializer?.findDeserializedDeclaration(descriptor) ?: IrLazyProperty(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor), descriptor, this, typeTranslator, bindingContext
)
): IrProperty {
val referenced = symbolTable.referenceProperty(descriptor)
if (referenced.isBound) {
return referenced.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareProperty(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original,
isDelegated = descriptor.isDelegated
) {
deserializer?.findDeserializedDeclaration(descriptor)
?: IrLazyProperty(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator, bindingContext)
}
}
fun generateFieldStub(descriptor: PropertyDescriptor): IrField {
@@ -101,21 +111,13 @@ class DeclarationStubGenerator(
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, origin, descriptor.original, descriptor.type.toIrType()) {
deserializer?.findDeserializedDeclaration(referenced) as? IrField
?: IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType())
}.apply {
initializer = descriptor.compileTimeInitializer?.let {
IrExpressionBodyImpl(
constantValueGenerator.generateConstantValueAsExpression(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, it
)
constantValueGenerator.generateConstantValueAsExpression(UNDEFINED_OFFSET, UNDEFINED_OFFSET, it)
)
}
}
@@ -188,9 +190,7 @@ class DeclarationStubGenerator(
return referenceClass.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareClass(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor
) {
return symbolTable.declareClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass
?: IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
@@ -203,9 +203,10 @@ open class DeepCopyIrTreeWithSymbols(
}
override fun visitProperty(declaration: IrProperty): IrProperty =
IrPropertyImpl(declaration.startOffset, declaration.endOffset,
IrPropertyImpl(
declaration.startOffset, declaration.endOffset,
mapDeclarationOrigin(declaration.origin),
declaration.descriptor,
symbolRemapper.getDeclaredProperty(declaration.symbol),
declaration.name,
declaration.visibility,
declaration.modality,
@@ -567,7 +568,7 @@ open class DeepCopyIrTreeWithSymbols(
IrPropertyReferenceImpl(
expression.startOffset, expression.endOffset,
expression.type.remapType(),
expression.descriptor,
symbolRemapper.getReferencedProperty(expression.symbol),
expression.typeArgumentsCount,
expression.field?.let { symbolRemapper.getReferencedField(it) },
expression.getter?.let { symbolRemapper.getReferencedSimpleFunction(it) },
@@ -36,6 +36,7 @@ open class DeepCopySymbolRemapper(
private val fields = hashMapOf<IrFieldSymbol, IrFieldSymbol>()
private val files = hashMapOf<IrFileSymbol, IrFileSymbol>()
private val functions = hashMapOf<IrSimpleFunctionSymbol, IrSimpleFunctionSymbol>()
private val properties = hashMapOf<IrPropertySymbol, IrPropertySymbol>()
private val returnableBlocks = hashMapOf<IrReturnableBlockSymbol, IrReturnableBlockSymbol>()
private val typeParameters = hashMapOf<IrTypeParameterSymbol, IrTypeParameterSymbol>()
private val valueParameters = hashMapOf<IrValueParameterSymbol, IrValueParameterSymbol>()
@@ -103,6 +104,13 @@ open class DeepCopySymbolRemapper(
declaration.acceptChildrenVoid(this)
}
override fun visitProperty(declaration: IrProperty) {
remapSymbol(properties, declaration) {
IrPropertySymbolImpl(descriptorsRemapper.remapDeclaredProperty(it.descriptor))
}
declaration.acceptChildrenVoid(this)
}
override fun visitTypeParameter(declaration: IrTypeParameter) {
remapSymbol(typeParameters, declaration) {
IrTypeParameterSymbolImpl(descriptorsRemapper.remapDeclaredTypeParameter(it.descriptor))
@@ -143,6 +151,7 @@ open class DeepCopySymbolRemapper(
override fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol = classes.getDeclared(symbol)
override fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getDeclared(symbol)
override fun getDeclaredProperty(symbol: IrPropertySymbol): IrPropertySymbol = properties.getDeclared(symbol)
override fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getDeclared(symbol)
override fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol = files.getDeclared(symbol)
override fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getDeclared(symbol)
@@ -161,6 +170,7 @@ open class DeepCopySymbolRemapper(
override fun getReferencedField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getReferenced(symbol)
override fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getReferenced(symbol)
override fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getReferenced(symbol)
override fun getReferencedProperty(symbol: IrPropertySymbol): IrPropertySymbol = properties.getReferenced(symbol)
override fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol =
when (symbol) {
is IrValueParameterSymbol -> valueParameters.getReferenced(symbol)
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import kotlin.math.min
class ExternalDependenciesGenerator(
moduleDescriptor: ModuleDescriptor,
@@ -49,6 +51,9 @@ class ExternalDependenciesGenerator(
ArrayList(symbolTable.unboundSimpleFunctions).forEach {
stubGenerator.generateFunctionStub(it.descriptor)
}
ArrayList(symbolTable.unboundProperties).forEach {
stubGenerator.generatePropertyStub(it.descriptor)
}
ArrayList(symbolTable.unboundTypeParameters).forEach {
stubGenerator.generateOrGetTypeParameterStub(it.descriptor)
}
@@ -57,11 +62,19 @@ class ExternalDependenciesGenerator(
if (deserializer != null) return
assert(symbolTable.unboundClasses.isEmpty())
assert(symbolTable.unboundConstructors.isEmpty())
assert(symbolTable.unboundEnumEntries.isEmpty())
assert(symbolTable.unboundFields.isEmpty())
assert(symbolTable.unboundSimpleFunctions.isEmpty())
assert(symbolTable.unboundTypeParameters.isEmpty())
assertEmpty(symbolTable.unboundClasses, "classes")
assertEmpty(symbolTable.unboundConstructors, "constructors")
assertEmpty(symbolTable.unboundEnumEntries, "enum entries")
assertEmpty(symbolTable.unboundFields, "fields")
assertEmpty(symbolTable.unboundSimpleFunctions, "simple functions")
assertEmpty(symbolTable.unboundProperties, "properties")
assertEmpty(symbolTable.unboundTypeParameters, "type parameters")
}
}
private fun assertEmpty(s: Set<IrSymbol>, marker: String) {
assert(s.isEmpty()) {
"$marker: ${s.size} unbound:\n" +
s.toList().subList(0, min(10, s.size)).joinToString(separator = "\n") { it.descriptor.toString() }
}
}
}
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.symbols.*
interface SymbolRemapper {
fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol
fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
fun getDeclaredProperty(symbol: IrPropertySymbol): IrPropertySymbol
fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol
fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol
fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
@@ -37,6 +38,7 @@ interface SymbolRemapper {
fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol
fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol
fun getReferencedProperty(symbol: IrPropertySymbol): IrPropertySymbol
fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol
fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol
@@ -42,6 +42,7 @@ interface IrDeserializer {
// For now we have to live with a special treatment of properties.
// TODO: eventually get rid of this asymmetry.
fun findDeserializedDeclaration(propertyDescriptor: PropertyDescriptor): IrProperty?
fun declareForwardDeclarations()
}
@@ -200,6 +201,7 @@ open class SymbolTable : ReferenceSymbolTable {
private val enumEntrySymbolTable = FlatSymbolTable<ClassDescriptor, IrEnumEntry, IrEnumEntrySymbol>()
private val fieldSymbolTable = FlatSymbolTable<PropertyDescriptor, IrField, IrFieldSymbol>()
private val simpleFunctionSymbolTable = FlatSymbolTable<FunctionDescriptor, IrSimpleFunction, IrSimpleFunctionSymbol>()
private val propertySymbolTable = FlatSymbolTable<PropertyDescriptor, IrProperty, IrPropertySymbol>()
private val globalTypeParameterSymbolTable = FlatSymbolTable<TypeParameterDescriptor, IrTypeParameter, IrTypeParameterSymbol>()
private val scopedTypeParameterSymbolTable = ScopedSymbolTable<TypeParameterDescriptor, IrTypeParameter, IrTypeParameterSymbol>()
@@ -321,10 +323,35 @@ open class SymbolTable : ReferenceSymbolTable {
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
@Deprecated(message = "Use declareProperty/referenceProperty", level = DeprecationLevel.WARNING)
val propertyTable = HashMap<PropertyDescriptor, IrProperty>()
override fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty =
propertyTable.getOrPut(descriptor, generate)
fun declareProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
isDelegated: Boolean = descriptor.isDelegated,
propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol ->
IrPropertyImpl(startOffset, endOffset, origin, symbol, isDelegated = isDelegated).apply {
metadata = MetadataSource.Property(symbol.descriptor)
}
}
): IrProperty =
propertySymbolTable.declare(
descriptor,
{ IrPropertySymbolImpl(descriptor) },
propertyFactory
)
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol =
propertySymbolTable.referenced(descriptor) { IrPropertySymbolImpl(descriptor) }
val unboundProperties: Set<IrPropertySymbol> get() = propertySymbolTable.unboundSymbols
fun declareSimpleFunction(
startOffset: Int,
endOffset: Int,