IR: removing WrappedDescriptors from symbols

This commit is contained in:
Georgy Bronnikov
2020-11-30 12:36:50 +03:00
parent 989d4350b1
commit d714adacae
32 changed files with 266 additions and 282 deletions
@@ -19,7 +19,7 @@ interface AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrSymbolOw
IrDeclaration, IrDeclarationParent, Fir2IrComponents { IrDeclaration, IrDeclarationParent, Fir2IrComponents {
val fir: F val fir: F
val symbol: Fir2IrBindableSymbol<*, D> override val symbol: Fir2IrBindableSymbol<*, D>
override val factory: IrFactory override val factory: IrFactory
get() = irFactory get() = irFactory
@@ -60,6 +60,10 @@ abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolO
result as D result as D
} }
@ObsoleteDescriptorBasedAPI
override val hasDescriptor: Boolean
get() = false
companion object { companion object {
private const val GETTER_PREFIX = "<get" private const val GETTER_PREFIX = "<get"
private const val SETTER_PREFIX = "<set" private const val SETTER_PREFIX = "<set"
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
import java.io.StringWriter import java.io.StringWriter
fun ir2string(ir: IrElement?): String = ir?.render() ?: "" fun ir2string(ir: IrElement?): String = ir?.render() ?: ""
@@ -129,12 +128,7 @@ fun IrValueParameter.copyTo(
isNoinline: Boolean = this.isNoinline, isNoinline: Boolean = this.isNoinline,
isAssignable: Boolean = this.isAssignable isAssignable: Boolean = this.isAssignable
): IrValueParameter { ): IrValueParameter {
val descriptor = if (index < 0) { val symbol = IrValueParameterSymbolImpl()
WrappedReceiverParameterDescriptor()
} else {
WrappedValueParameterDescriptor()
}
val symbol = IrValueParameterSymbolImpl(descriptor)
val defaultValueCopy = defaultValue?.let { originalDefault -> val defaultValueCopy = defaultValue?.let { originalDefault ->
factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) { factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) {
expression = originalDefault.expression.deepCopyWithVariables().also { expression = originalDefault.expression.deepCopyWithVariables().also {
@@ -147,7 +141,6 @@ fun IrValueParameter.copyTo(
name, index, type, varargElementType, isCrossinline = isCrossinline, name, index, type, varargElementType, isCrossinline = isCrossinline,
isNoinline = isNoinline, isHidden = false, isAssignable = isAssignable isNoinline = isNoinline, isHidden = false, isAssignable = isAssignable
).also { ).also {
descriptor.bind(it)
it.parent = irFunction it.parent = irFunction
it.defaultValue = defaultValueCopy it.defaultValue = defaultValueCopy
it.copyAnnotationsFrom(this) it.copyAnnotationsFrom(this)
@@ -167,10 +160,9 @@ fun IrTypeParameter.copyToWithoutSuperTypes(
fun IrFunction.copyReceiverParametersFrom(from: IrFunction, substitutionMap: Map<IrTypeParameterSymbol, IrType>) { fun IrFunction.copyReceiverParametersFrom(from: IrFunction, substitutionMap: Map<IrTypeParameterSymbol, IrType>) {
dispatchReceiverParameter = from.dispatchReceiverParameter?.run { dispatchReceiverParameter = from.dispatchReceiverParameter?.run {
val newDescriptor = WrappedReceiverParameterDescriptor()
factory.createValueParameter( factory.createValueParameter(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrValueParameterSymbolImpl(newDescriptor), IrValueParameterSymbolImpl(),
name, index, name, index,
type.substitute(substitutionMap), type.substitute(substitutionMap),
varargElementType?.substitute(substitutionMap), varargElementType?.substitute(substitutionMap),
@@ -178,7 +170,6 @@ fun IrFunction.copyReceiverParametersFrom(from: IrFunction, substitutionMap: Map
isHidden, isAssignable isHidden, isAssignable
).also { parameter -> ).also { parameter ->
parameter.parent = this@copyReceiverParametersFrom parameter.parent = this@copyReceiverParametersFrom
newDescriptor.bind(this)
} }
} }
extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this) extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this)
@@ -428,11 +419,10 @@ fun IrClass.createParameterDeclarations() {
fun IrFunction.createDispatchReceiverParameter(origin: IrDeclarationOrigin? = null) { fun IrFunction.createDispatchReceiverParameter(origin: IrDeclarationOrigin? = null) {
assert(dispatchReceiverParameter == null) assert(dispatchReceiverParameter == null)
val newDescriptor = WrappedReceiverParameterDescriptor()
dispatchReceiverParameter = factory.createValueParameter( dispatchReceiverParameter = factory.createValueParameter(
startOffset, endOffset, startOffset, endOffset,
origin ?: parentAsClass.origin, origin ?: parentAsClass.origin,
IrValueParameterSymbolImpl(newDescriptor), IrValueParameterSymbolImpl(),
Name.special("<this>"), Name.special("<this>"),
-1, -1,
parentAsClass.defaultType, parentAsClass.defaultType,
@@ -443,7 +433,6 @@ fun IrFunction.createDispatchReceiverParameter(origin: IrDeclarationOrigin? = nu
isAssignable = false isAssignable = false
).apply { ).apply {
parent = this@createDispatchReceiverParameter parent = this@createDispatchReceiverParameter
newDescriptor.bind(this)
} }
} }
@@ -469,11 +458,11 @@ val IrFunction.allParametersCount: Int
private class FakeOverrideBuilderForLowerings : FakeOverrideBuilderStrategy() { private class FakeOverrideBuilderForLowerings : FakeOverrideBuilderStrategy() {
override fun linkFunctionFakeOverride(declaration: IrFakeOverrideFunction) { override fun linkFunctionFakeOverride(declaration: IrFakeOverrideFunction) {
declaration.acquireSymbol(IrSimpleFunctionSymbolImpl(WrappedSimpleFunctionDescriptor())) declaration.acquireSymbol(IrSimpleFunctionSymbolImpl())
} }
override fun linkPropertyFakeOverride(declaration: IrFakeOverrideProperty) { override fun linkPropertyFakeOverride(declaration: IrFakeOverrideProperty) {
val propertySymbol = IrPropertySymbolImpl(WrappedPropertyDescriptor()) val propertySymbol = IrPropertySymbolImpl()
declaration.getter?.let { it.correspondingPropertySymbol = propertySymbol } declaration.getter?.let { it.correspondingPropertySymbol = propertySymbol }
declaration.setter?.let { it.correspondingPropertySymbol = propertySymbol } declaration.setter?.let { it.correspondingPropertySymbol = propertySymbol }
@@ -509,11 +498,10 @@ fun IrFactory.createStaticFunctionWithReceivers(
copyMetadata: Boolean = true, copyMetadata: Boolean = true,
typeParametersFromContext: List<IrTypeParameter> = listOf() typeParametersFromContext: List<IrTypeParameter> = listOf()
): IrSimpleFunction { ): IrSimpleFunction {
val descriptor = WrappedSimpleFunctionDescriptor()
return createFunction( return createFunction(
oldFunction.startOffset, oldFunction.endOffset, oldFunction.startOffset, oldFunction.endOffset,
origin, origin,
IrSimpleFunctionSymbolImpl(descriptor), IrSimpleFunctionSymbolImpl(),
name, name,
visibility, visibility,
modality, modality,
@@ -528,7 +516,6 @@ fun IrFactory.createStaticFunctionWithReceivers(
isInfix = oldFunction is IrSimpleFunction && oldFunction.isInfix, isInfix = oldFunction is IrSimpleFunction && oldFunction.isInfix,
containerSource = oldFunction.containerSource, containerSource = oldFunction.containerSource,
).apply { ).apply {
descriptor.bind(this)
parent = irParent parent = irParent
val newTypeParametersFromContext = copyAndRenameConflictingTypeParametersFrom( val newTypeParametersFromContext = copyAndRenameConflictingTypeParametersFrom(
@@ -21,15 +21,12 @@ import org.jetbrains.kotlin.types.Variance
@PublishedApi @PublishedApi
internal fun IrFactory.buildClass(builder: IrClassBuilder): IrClass = with(builder) { internal fun IrFactory.buildClass(builder: IrClassBuilder): IrClass = with(builder) {
val wrappedDescriptor = WrappedClassDescriptor()
createClass( createClass(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrClassSymbolImpl(wrappedDescriptor), IrClassSymbolImpl(),
name, kind, visibility, modality, name, kind, visibility, modality,
isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun
).also { )
wrappedDescriptor.bind(it)
}
} }
inline fun IrFactory.buildClass(builder: IrClassBuilder.() -> Unit) = inline fun IrFactory.buildClass(builder: IrClassBuilder.() -> Unit) =
@@ -40,14 +37,12 @@ inline fun IrFactory.buildClass(builder: IrClassBuilder.() -> Unit) =
@PublishedApi @PublishedApi
internal fun IrFactory.buildField(builder: IrFieldBuilder): IrField = with(builder) { internal fun IrFactory.buildField(builder: IrFieldBuilder): IrField = with(builder) {
val wrappedDescriptor = WrappedFieldDescriptor()
createField( createField(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrFieldSymbolImpl(wrappedDescriptor), IrFieldSymbolImpl(),
name, type, visibility, isFinal, isExternal, isStatic, name, type, visibility, isFinal, isExternal, isStatic,
).also { ).also {
it.metadata = metadata it.metadata = metadata
wrappedDescriptor.bind(it)
} }
} }
@@ -75,17 +70,13 @@ fun IrClass.addField(fieldName: String, fieldType: IrType, fieldVisibility: Desc
@PublishedApi @PublishedApi
internal fun IrFactory.buildProperty(builder: IrPropertyBuilder): IrProperty = with(builder) { internal fun IrFactory.buildProperty(builder: IrPropertyBuilder): IrProperty = with(builder) {
val wrappedDescriptor = WrappedPropertyDescriptor()
createProperty( createProperty(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrPropertySymbolImpl(wrappedDescriptor), IrPropertySymbolImpl(),
name, visibility, modality, name, visibility, modality,
isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride,
containerSource, containerSource,
).also { )
wrappedDescriptor.bind(it)
}
} }
inline fun IrFactory.buildProperty(builder: IrPropertyBuilder.() -> Unit) = inline fun IrFactory.buildProperty(builder: IrPropertyBuilder.() -> Unit) =
@@ -113,31 +104,25 @@ inline fun IrProperty.addGetter(builder: IrFunctionBuilder.() -> Unit = {}): IrS
@PublishedApi @PublishedApi
internal fun IrFactory.buildFunction(builder: IrFunctionBuilder): IrSimpleFunction = with(builder) { internal fun IrFactory.buildFunction(builder: IrFunctionBuilder): IrSimpleFunction = with(builder) {
val wrappedDescriptor = WrappedSimpleFunctionDescriptor()
createFunction( createFunction(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrSimpleFunctionSymbolImpl(wrappedDescriptor), IrSimpleFunctionSymbolImpl(),
name, visibility, modality, returnType, name, visibility, modality, returnType,
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride, isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride,
containerSource, containerSource,
).also { )
wrappedDescriptor.bind(it)
}
} }
@PublishedApi @PublishedApi
internal fun IrFactory.buildConstructor(builder: IrFunctionBuilder): IrConstructor = with(builder) { internal fun IrFactory.buildConstructor(builder: IrFunctionBuilder): IrConstructor = with(builder) {
val wrappedDescriptor = WrappedClassConstructorDescriptor()
return createConstructor( return createConstructor(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrConstructorSymbolImpl(wrappedDescriptor), IrConstructorSymbolImpl(),
Name.special("<init>"), Name.special("<init>"),
visibility, returnType, visibility, returnType,
isInline = isInline, isExternal = isExternal, isPrimary = isPrimary, isExpect = isExpect, isInline = isInline, isExternal = isExternal, isPrimary = isPrimary, isExpect = isExpect,
containerSource = containerSource containerSource = containerSource
).also { )
wrappedDescriptor.bind(it)
}
} }
inline fun IrFactory.buildFun(builder: IrFunctionBuilder.() -> Unit): IrSimpleFunction = inline fun IrFactory.buildFun(builder: IrFunctionBuilder.() -> Unit): IrSimpleFunction =
@@ -207,28 +192,24 @@ fun <D> buildReceiverParameter(
startOffset: Int = parent.startOffset, startOffset: Int = parent.startOffset,
endOffset: Int = parent.endOffset endOffset: Int = parent.endOffset
): IrValueParameter ): IrValueParameter
where D : IrDeclaration, D : IrDeclarationParent = WrappedReceiverParameterDescriptor().let { wrappedDescriptor -> where D : IrDeclaration, D : IrDeclarationParent =
parent.factory.createValueParameter( parent.factory.createValueParameter(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrValueParameterSymbolImpl(wrappedDescriptor), IrValueParameterSymbolImpl(),
RECEIVER_PARAMETER_NAME, -1, type, null, isCrossinline = false, isNoinline = false, RECEIVER_PARAMETER_NAME, -1, type, null, isCrossinline = false, isNoinline = false,
isHidden = false, isAssignable = false isHidden = false, isAssignable = false
).also { ).also {
wrappedDescriptor.bind(it)
it.parent = parent it.parent = parent
} }
}
@PublishedApi @PublishedApi
internal fun IrFactory.buildValueParameter(builder: IrValueParameterBuilder, parent: IrDeclarationParent): IrValueParameter = internal fun IrFactory.buildValueParameter(builder: IrValueParameterBuilder, parent: IrDeclarationParent): IrValueParameter =
with(builder) { with(builder) {
val wrappedDescriptor = WrappedValueParameterDescriptor()
return createValueParameter( return createValueParameter(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrValueParameterSymbolImpl(wrappedDescriptor), IrValueParameterSymbolImpl(),
name, index, type, varargElementType, isCrossInline, isNoinline, isHidden, isAssignable name, index, type, varargElementType, isCrossInline, isNoinline, isHidden, isAssignable
).also { ).also {
wrappedDescriptor.bind(it)
it.parent = parent it.parent = parent
} }
} }
@@ -283,13 +264,11 @@ fun IrSimpleFunction.addExtensionReceiver(type: IrType, origin: IrDeclarationOri
@PublishedApi @PublishedApi
internal fun IrFactory.buildTypeParameter(builder: IrTypeParameterBuilder, parent: IrDeclarationParent): IrTypeParameter = internal fun IrFactory.buildTypeParameter(builder: IrTypeParameterBuilder, parent: IrDeclarationParent): IrTypeParameter =
with(builder) { with(builder) {
val wrappedDescriptor = WrappedTypeParameterDescriptor()
createTypeParameter( createTypeParameter(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrTypeParameterSymbolImpl(wrappedDescriptor), IrTypeParameterSymbolImpl(),
name, index, isReified, variance name, index, isReified, variance
).also { ).also {
wrappedDescriptor.bind(it)
it.superTypes = superTypes it.superTypes = superTypes
it.parent = parent it.parent = parent
} }
@@ -330,13 +309,11 @@ fun buildVariable(
isConst: Boolean = false, isConst: Boolean = false,
isLateinit: Boolean = false, isLateinit: Boolean = false,
): IrVariable { ): IrVariable {
val wrappedDescriptor = WrappedVariableDescriptor()
return IrVariableImpl( return IrVariableImpl(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrVariableSymbolImpl(wrappedDescriptor), IrVariableSymbolImpl(),
name, type, isVar, isConst, isLateinit name, type, isVar, isConst, isLateinit
).also { ).also {
wrappedDescriptor.bind(it)
if (parent != null) { if (parent != null) {
it.parent = parent it.parent = parent
} }
@@ -54,6 +54,10 @@ private class DescriptorlessIrFileSymbol : IrFileSymbol {
override val descriptor: PackageFragmentDescriptor override val descriptor: PackageFragmentDescriptor
get() = error("Operation is unsupported") get() = error("Operation is unsupported")
@ObsoleteDescriptorBasedAPI
override val hasDescriptor: Boolean
get() = error("Operation is unsupported")
private var _owner: IrFile? = null private var _owner: IrFile? = null
override val owner get() = _owner!! override val owner get() = _owner!!
@@ -95,14 +95,12 @@ class JvmSharedVariablesManager(
typeArguments.forEachIndexed(::putTypeArgument) typeArguments.forEachIndexed(::putTypeArgument)
} }
return with(originalDeclaration) { return with(originalDeclaration) {
val descriptor = WrappedVariableDescriptor()
IrVariableImpl( IrVariableImpl(
startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor), name, refType, startOffset, endOffset, origin, IrVariableSymbolImpl(), name, refType,
isVar = false, // writes are remapped to field stores isVar = false, // writes are remapped to field stores
isConst = false, // const vals could not possibly require ref wrappers isConst = false, // const vals could not possibly require ref wrappers
isLateinit = false isLateinit = false
).apply { ).apply {
descriptor.bind(this)
initializer = refConstructorCall initializer = refConstructorCall
} }
} }
@@ -84,13 +84,11 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
} }
private fun buildEnumEntry(enumClass: IrClass, entryName: String): IrEnumEntry { private fun buildEnumEntry(enumClass: IrClass, entryName: String): IrEnumEntry {
val descriptor = WrappedEnumEntryDescriptor()
return IrEnumEntryImpl( return IrEnumEntryImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB, UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB,
IrEnumEntrySymbolImpl(descriptor), IrEnumEntrySymbolImpl(),
Name.identifier(entryName) Name.identifier(entryName)
).apply { ).apply {
descriptor.bind(this)
parent = enumClass parent = enumClass
enumClass.addChild(this) enumClass.addChild(this)
} }
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.backend.common.phaser.makeIrModulePhase
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.config.JvmAnalysisFlags import org.jetbrains.kotlin.config.JvmAnalysisFlags
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Modality
@@ -31,7 +30,6 @@ import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
import org.jetbrains.kotlin.fileClasses.JvmSimpleFileClassInfo import org.jetbrains.kotlin.fileClasses.JvmSimpleFileClassInfo
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.ir.util.IdSignature import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.NaiveSourceBasedFileEntryImpl import org.jetbrains.kotlin.ir.util.NaiveSourceBasedFileEntryImpl
@@ -82,17 +80,14 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
private fun createFileClass(irFile: IrFile, fileClassMembers: List<IrDeclaration>): IrClass { private fun createFileClass(irFile: IrFile, fileClassMembers: List<IrDeclaration>): IrClass {
val fileEntry = irFile.fileEntry val fileEntry = irFile.fileEntry
val fileClassInfo: JvmFileClassInfo? val fileClassInfo: JvmFileClassInfo?
val descriptor: ClassDescriptor
when (fileEntry) { when (fileEntry) {
is PsiSourceManager.PsiFileEntry -> { is PsiSourceManager.PsiFileEntry -> {
val ktFile = context.psiSourceManager.getKtFile(fileEntry) val ktFile = context.psiSourceManager.getKtFile(fileEntry)
?: throw AssertionError("Unexpected file entry: $fileEntry") ?: throw AssertionError("Unexpected file entry: $fileEntry")
fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(ktFile) fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(ktFile)
descriptor = WrappedClassDescriptor()
} }
is NaiveSourceBasedFileEntryImpl -> { is NaiveSourceBasedFileEntryImpl -> {
fileClassInfo = JvmSimpleFileClassInfo(PackagePartClassUtils.getPackagePartFqName(irFile.fqName, fileEntry.name), false) fileClassInfo = JvmSimpleFileClassInfo(PackagePartClassUtils.getPackagePartFqName(irFile.fqName, fileEntry.name), false)
descriptor = WrappedClassDescriptor()
} }
else -> error("unknown kind of file entry: $fileEntry") else -> error("unknown kind of file entry: $fileEntry")
} }
@@ -101,13 +96,12 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
0, fileEntry.maxOffset, 0, fileEntry.maxOffset,
if (!isMultifilePart || context.state.languageVersionSettings.getFlag(JvmAnalysisFlags.inheritMultifileParts)) if (!isMultifilePart || context.state.languageVersionSettings.getFlag(JvmAnalysisFlags.inheritMultifileParts))
IrDeclarationOrigin.FILE_CLASS else IrDeclarationOrigin.SYNTHETIC_FILE_CLASS, IrDeclarationOrigin.FILE_CLASS else IrDeclarationOrigin.SYNTHETIC_FILE_CLASS,
symbol = IrClassSymbolImpl(descriptor), symbol = IrClassSymbolImpl(),
name = fileClassInfo.fileClassFqName.shortName(), name = fileClassInfo.fileClassFqName.shortName(),
kind = ClassKind.CLASS, kind = ClassKind.CLASS,
visibility = if (!isMultifilePart) DescriptorVisibilities.PUBLIC else JavaDescriptorVisibilities.PACKAGE_VISIBILITY, visibility = if (!isMultifilePart) DescriptorVisibilities.PUBLIC else JavaDescriptorVisibilities.PACKAGE_VISIBILITY,
modality = Modality.FINAL modality = Modality.FINAL
).apply { ).apply {
descriptor.bind(this)
superTypes = listOf(context.irBuiltIns.anyType) superTypes = listOf(context.irBuiltIns.anyType)
parent = irFile parent = irFile
declarations.addAll(fileClassMembers) declarations.addAll(fileClassMembers)
@@ -425,7 +425,7 @@ private inline fun IrClass.addAnonymousInitializer(builder: IrFunctionBuilder.()
returnType = defaultType returnType = defaultType
IrAnonymousInitializerImpl( IrAnonymousInitializerImpl(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrAnonymousInitializerSymbolImpl(WrappedClassDescriptor()) IrAnonymousInitializerSymbolImpl()
) )
}.also { anonymousInitializer -> }.also { anonymousInitializer ->
declarations.add(anonymousInitializer) declarations.add(anonymousInitializer)
@@ -54,19 +54,17 @@ class WasmSharedVariablesManager(val context: JsCommonBackendContext, val builtI
putValueArgument(0, initializer) putValueArgument(0, initializer)
} }
val descriptor = WrappedVariableDescriptor()
return IrVariableImpl( return IrVariableImpl(
originalDeclaration.startOffset, originalDeclaration.startOffset,
originalDeclaration.endOffset, originalDeclaration.endOffset,
originalDeclaration.origin, originalDeclaration.origin,
IrVariableSymbolImpl(descriptor), IrVariableSymbolImpl(),
originalDeclaration.name, originalDeclaration.name,
irCall.type, irCall.type,
false, false,
false, false,
false false
).also { ).also {
descriptor.bind(it)
it.parent = originalDeclaration.parent it.parent = originalDeclaration.parent
it.initializer = irCall it.initializer = irCall
} }
@@ -165,8 +163,7 @@ class WasmSharedVariablesManager(val context: JsCommonBackendContext, val builtI
} }
private fun createClosureBoxPropertyDeclaration(): IrField { private fun createClosureBoxPropertyDeclaration(): IrField {
val descriptor = WrappedFieldDescriptor() val symbol = IrFieldSymbolImpl()
val symbol = IrFieldSymbolImpl(descriptor)
val fieldName = Name.identifier("v") val fieldName = Name.identifier("v")
return context.irFactory.createField( return context.irFactory.createField(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
@@ -180,15 +177,13 @@ class WasmSharedVariablesManager(val context: JsCommonBackendContext, val builtI
isExternal = false, isExternal = false,
isStatic = false, isStatic = false,
).also { ).also {
descriptor.bind(it)
it.parent = closureBoxClassDeclaration it.parent = closureBoxClassDeclaration
closureBoxClassDeclaration.declarations += it closureBoxClassDeclaration.declarations += it
} }
} }
private fun createClosureBoxConstructorDeclaration(): IrConstructor { private fun createClosureBoxConstructorDeclaration(): IrConstructor {
val descriptor = WrappedClassConstructorDescriptor() val symbol = IrConstructorSymbolImpl()
val symbol = IrConstructorSymbolImpl(descriptor)
val declaration = context.irFactory.createConstructor( val declaration = context.irFactory.createConstructor(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, JsLoweredDeclarationOrigin.JS_CLOSURE_BOX_CLASS_DECLARATION, symbol, UNDEFINED_OFFSET, UNDEFINED_OFFSET, JsLoweredDeclarationOrigin.JS_CLOSURE_BOX_CLASS_DECLARATION, symbol,
@@ -196,7 +191,6 @@ class WasmSharedVariablesManager(val context: JsCommonBackendContext, val builtI
isInline = false, isExternal = false, isPrimary = true, isExpect = false isInline = false, isExternal = false, isPrimary = true, isExpect = false
) )
descriptor.bind(declaration)
declaration.parent = closureBoxClassDeclaration declaration.parent = closureBoxClassDeclaration
val parameterDeclaration = createClosureBoxConstructorParameterDeclaration(declaration) val parameterDeclaration = createClosureBoxConstructorParameterDeclaration(declaration)
@@ -377,7 +377,7 @@ private fun StatementGenerator.createFunctionForSuspendConversion(
} }
adapterFunctionDescriptor.bind(irAdapterFun) adapterFunctionDescriptor.bind(irAdapterFun)
context.symbolTable.enterScope(adapterFunctionDescriptor) context.symbolTable.enterScope(irAdapterFun)
fun createValueParameter(name: String, index: Int, type: IrType): IrValueParameter { fun createValueParameter(name: String, index: Int, type: IrType): IrValueParameter {
val descriptor = WrappedValueParameterDescriptor() val descriptor = WrappedValueParameterDescriptor()
@@ -434,7 +434,7 @@ private fun StatementGenerator.createFunctionForSuspendConversion(
} }
} }
context.symbolTable.leaveScope(adapterFunctionDescriptor) context.symbolTable.leaveScope(irAdapterFun)
return irAdapterFun return irAdapterFun
} }
@@ -340,7 +340,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
).also { irAdapterFun -> ).also { irAdapterFun ->
adapterFunctionDescriptor.bind(irAdapterFun) adapterFunctionDescriptor.bind(irAdapterFun)
context.symbolTable.withScope(adapterFunctionDescriptor) { context.symbolTable.withScope(irAdapterFun) {
irAdapterFun.metadata = DescriptorMetadataSource.Function(adapteeDescriptor) irAdapterFun.metadata = DescriptorMetadataSource.Function(adapteeDescriptor)
irAdapterFun.dispatchReceiverParameter = null irAdapterFun.dispatchReceiverParameter = null
@@ -194,7 +194,7 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
} }
irFunction.metadata = DescriptorMetadataSource.Function(descriptor) irFunction.metadata = DescriptorMetadataSource.Function(descriptor)
symbolTable.withScope(descriptor) { symbolTable.withScope(irFunction) {
generateOverridenSymbols(irFunction, descriptor.overriddenDescriptors) generateOverridenSymbols(irFunction, descriptor.overriddenDescriptors)
generateScopedTypeParameterDeclarations(irFunction, descriptor.propertyIfAccessor.typeParameters) generateScopedTypeParameterDeclarations(irFunction, descriptor.propertyIfAccessor.typeParameters)
generateValueParameterDeclarations(irFunction, descriptor, defaultArgumentFactory) generateValueParameterDeclarations(irFunction, descriptor, defaultArgumentFactory)
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrErrorDeclaration import org.jetbrains.kotlin.ir.declarations.IrErrorDeclaration
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrSymbol
@OptIn(ObsoleteDescriptorBasedAPI::class) @OptIn(ObsoleteDescriptorBasedAPI::class)
class IrErrorDeclarationImpl( class IrErrorDeclarationImpl(
@@ -61,12 +61,10 @@ class Scope(val scopeOwnerSymbol: IrSymbol) {
endOffset: Int = UNDEFINED_OFFSET endOffset: Int = UNDEFINED_OFFSET
): IrVariable { ): IrVariable {
val name = Name.identifier(getNameForTemporary(nameHint)) val name = Name.identifier(getNameForTemporary(nameHint))
val descriptor = WrappedVariableDescriptor()
return IrVariableImpl( return IrVariableImpl(
startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor), name, startOffset, endOffset, origin, IrVariableSymbolImpl(), name,
irType, isMutable, isConst = false, isLateinit = false irType, isMutable, isConst = false, isLateinit = false
).apply { ).apply {
descriptor.bind(this)
parent = getLocalDeclarationParent() parent = getLocalDeclarationParent()
} }
} }
@@ -35,7 +35,7 @@ interface IrMetadataSourceOwner : IrElement {
var metadata: MetadataSource? var metadata: MetadataSource?
} }
interface IrDeclaration : IrStatement, IrMutableAnnotationContainer { interface IrDeclaration : IrStatement, IrSymbolOwner, IrMutableAnnotationContainer {
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
val descriptor: DeclarationDescriptor val descriptor: DeclarationDescriptor
@@ -48,7 +48,7 @@ interface IrDeclaration : IrStatement, IrMutableAnnotationContainer {
abstract class IrDeclarationBase : IrElementBase(), IrDeclaration abstract class IrDeclarationBase : IrElementBase(), IrDeclaration
interface IrSymbolDeclaration<out S : IrSymbol> : IrDeclaration, IrSymbolOwner { interface IrSymbolDeclaration<out S : IrSymbol> : IrDeclaration {
override val symbol: S override val symbol: S
} }
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.ir.declarations package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -30,4 +31,7 @@ abstract class IrErrorDeclaration : IrDeclarationBase() {
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) { override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
// no children // no children
} }
override val symbol: IrSymbol
get() = error("Should never be called")
} }
@@ -58,7 +58,7 @@ class IrLazyConstructor(
override var typeParameters: List<IrTypeParameter> by lazyVar { override var typeParameters: List<IrTypeParameter> by lazyVar {
typeTranslator.buildWithScope(this) { typeTranslator.buildWithScope(this) {
stubGenerator.symbolTable.withScope(descriptor) { stubGenerator.symbolTable.withScope(this) {
val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size
val allConstructorTypeParameters = descriptor.typeParameters val allConstructorTypeParameters = descriptor.typeParameters
allConstructorTypeParameters.subList(classTypeParametersCount, allConstructorTypeParameters.size).mapTo(ArrayList()) { allConstructorTypeParameters.subList(classTypeParametersCount, allConstructorTypeParameters.size).mapTo(ArrayList()) {
@@ -66,7 +66,7 @@ class IrLazyFunction(
override var typeParameters: List<IrTypeParameter> by lazyVar { override var typeParameters: List<IrTypeParameter> by lazyVar {
typeTranslator.buildWithScope(this) { typeTranslator.buildWithScope(this) {
stubGenerator.symbolTable.withScope(descriptor) { stubGenerator.symbolTable.withScope(this) {
val propertyIfAccessor = descriptor.propertyIfAccessor val propertyIfAccessor = descriptor.propertyIfAccessor
propertyIfAccessor.typeParameters.mapTo(arrayListOf()) { typeParameterDescriptor -> propertyIfAccessor.typeParameters.mapTo(arrayListOf()) { typeParameterDescriptor ->
if (descriptor != propertyIfAccessor) { if (descriptor != propertyIfAccessor) {
@@ -17,6 +17,10 @@ abstract class IrDelegatingSymbol<S : IrBindableSymbol<D, B>, B : IrSymbolOwner,
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
override val descriptor: D get() = delegate.descriptor override val descriptor: D get() = delegate.descriptor
@ObsoleteDescriptorBasedAPI
override val hasDescriptor: Boolean
get() = delegate.hasDescriptor
override val isBound: Boolean get() = delegate.isBound override val isBound: Boolean get() = delegate.isBound
override val signature: IdSignature? override val signature: IdSignature?
@@ -30,6 +30,9 @@ interface IrSymbol {
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
val descriptor: DeclarationDescriptor val descriptor: DeclarationDescriptor
@ObsoleteDescriptorBasedAPI
val hasDescriptor: Boolean
val isBound: Boolean val isBound: Boolean
val signature: IdSignature? val signature: IdSignature?
@@ -16,6 +16,9 @@ class DescriptorlessExternalPackageFragmentSymbol : IrExternalPackageFragmentSym
override val descriptor: PackageFragmentDescriptor override val descriptor: PackageFragmentDescriptor
get() = error("Operation is unsupported") get() = error("Operation is unsupported")
override val hasDescriptor: Boolean
get() = error("Operation is unsupported")
private var _owner: IrExternalPackageFragment? = null private var _owner: IrExternalPackageFragment? = null
override val owner get() = _owner!! override val owner get() = _owner!!
@@ -28,14 +28,16 @@ import org.jetbrains.kotlin.ir.util.render
@OptIn(ObsoleteDescriptorBasedAPI::class) @OptIn(ObsoleteDescriptorBasedAPI::class)
abstract class IrSymbolBase<out D : DeclarationDescriptor>( abstract class IrSymbolBase<out D : DeclarationDescriptor>(
private val _descriptor: D private val _descriptor: D?
) : IrSymbol { ) : IrSymbol {
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
@Suppress("UNCHECKED_CAST")
override val descriptor: D override val descriptor: D
get() = if (isBound && _descriptor is WrappedDeclarationDescriptor<*>) get() = _descriptor ?: (owner as IrDeclaration).toIrBasedDescriptor() as D
(owner as IrDeclaration).toIrBasedDescriptor() as D
else @ObsoleteDescriptorBasedAPI
_descriptor override val hasDescriptor: Boolean
get() = _descriptor != null
override fun toString(): String { override fun toString(): String {
if (isBound) return owner.render() if (isBound) return owner.render()
@@ -43,15 +45,15 @@ abstract class IrSymbolBase<out D : DeclarationDescriptor>(
} }
} }
abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D) : abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D?) :
IrBindableSymbol<D, B>, IrSymbolBase<D>(descriptor) { IrBindableSymbol<D, B>, IrSymbolBase<D>(descriptor) {
init { init {
assert(isOriginalDescriptor(descriptor)) { assert(descriptor == null || isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor.original}" "Substituted descriptor $descriptor for ${descriptor!!.original}"
} }
if (descriptor !is WrappedDeclarationDescriptor<*>) { if (descriptor !is WrappedDeclarationDescriptor<*>) {
val containingDeclaration = descriptor.containingDeclaration val containingDeclaration = descriptor?.containingDeclaration
assert(containingDeclaration == null || isOriginalDescriptor(containingDeclaration)) { assert(containingDeclaration == null || isOriginalDescriptor(containingDeclaration)) {
"Substituted containing declaration: $containingDeclaration\nfor descriptor: $descriptor" "Substituted containing declaration: $containingDeclaration\nfor descriptor: $descriptor"
} }
@@ -92,41 +94,41 @@ class IrExternalPackageFragmentSymbolImpl(descriptor: PackageFragmentDescriptor)
IrExternalPackageFragmentSymbol IrExternalPackageFragmentSymbol
@OptIn(ObsoleteDescriptorBasedAPI::class) @OptIn(ObsoleteDescriptorBasedAPI::class)
class IrAnonymousInitializerSymbolImpl(descriptor: ClassDescriptor) : class IrAnonymousInitializerSymbolImpl(descriptor: ClassDescriptor? = null) :
IrBindableSymbolBase<ClassDescriptor, IrAnonymousInitializer>(descriptor), IrBindableSymbolBase<ClassDescriptor, IrAnonymousInitializer>(descriptor),
IrAnonymousInitializerSymbol { IrAnonymousInitializerSymbol {
constructor(irClassSymbol: IrClassSymbol) : this(irClassSymbol.descriptor) constructor(irClassSymbol: IrClassSymbol) : this(irClassSymbol.descriptor)
} }
class IrClassSymbolImpl(descriptor: ClassDescriptor) : class IrClassSymbolImpl(descriptor: ClassDescriptor? = null) :
IrBindableSymbolBase<ClassDescriptor, IrClass>(descriptor), IrBindableSymbolBase<ClassDescriptor, IrClass>(descriptor),
IrClassSymbol IrClassSymbol
class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor) : class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor? = null) :
IrBindableSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor), IrBindableSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor),
IrEnumEntrySymbol IrEnumEntrySymbol
class IrFieldSymbolImpl(descriptor: PropertyDescriptor) : class IrFieldSymbolImpl(descriptor: PropertyDescriptor? = null) :
IrBindableSymbolBase<PropertyDescriptor, IrField>(descriptor), IrBindableSymbolBase<PropertyDescriptor, IrField>(descriptor),
IrFieldSymbol IrFieldSymbol
class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor) : class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor? = null) :
IrBindableSymbolBase<TypeParameterDescriptor, IrTypeParameter>(descriptor), IrBindableSymbolBase<TypeParameterDescriptor, IrTypeParameter>(descriptor),
IrTypeParameterSymbol IrTypeParameterSymbol
class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor) : class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor? = null) :
IrBindableSymbolBase<ParameterDescriptor, IrValueParameter>(descriptor), IrBindableSymbolBase<ParameterDescriptor, IrValueParameter>(descriptor),
IrValueParameterSymbol IrValueParameterSymbol
class IrVariableSymbolImpl(descriptor: VariableDescriptor) : class IrVariableSymbolImpl(descriptor: VariableDescriptor? = null) :
IrBindableSymbolBase<VariableDescriptor, IrVariable>(descriptor), IrBindableSymbolBase<VariableDescriptor, IrVariable>(descriptor),
IrVariableSymbol IrVariableSymbol
class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor) : class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor? = null) :
IrBindableSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor), IrBindableSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor),
IrSimpleFunctionSymbol IrSimpleFunctionSymbol
class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) : class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor? = null) :
IrBindableSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor), IrBindableSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor),
IrConstructorSymbol IrConstructorSymbol
@@ -134,17 +136,17 @@ class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor), IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor),
IrReturnableBlockSymbol IrReturnableBlockSymbol
class IrPropertySymbolImpl(descriptor: PropertyDescriptor) : class IrPropertySymbolImpl(descriptor: PropertyDescriptor? = null) :
IrBindableSymbolBase<PropertyDescriptor, IrProperty>(descriptor), IrBindableSymbolBase<PropertyDescriptor, IrProperty>(descriptor),
IrPropertySymbol IrPropertySymbol
class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAccessors) : class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAccessors? = null) :
IrBindableSymbolBase<VariableDescriptorWithAccessors, IrLocalDelegatedProperty>(descriptor), IrBindableSymbolBase<VariableDescriptorWithAccessors, IrLocalDelegatedProperty>(descriptor),
IrLocalDelegatedPropertySymbol IrLocalDelegatedPropertySymbol
class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor) : class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor? = null) :
IrBindableSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor), IrBindableSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor),
IrTypeAliasSymbol IrTypeAliasSymbol
class IrScriptSymbolImpl(descriptor: ScriptDescriptor) : class IrScriptSymbolImpl(descriptor: ScriptDescriptor? = null) :
IrScriptSymbol, IrBindableSymbolBase<ScriptDescriptor, IrScript>(descriptor) IrScriptSymbol, IrBindableSymbolBase<ScriptDescriptor, IrScript>(descriptor)
@@ -15,15 +15,17 @@ import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.ir.util.render
abstract class IrPublicSymbolBase<out D : DeclarationDescriptor> @OptIn(ObsoleteDescriptorBasedAPI::class) constructor( abstract class IrPublicSymbolBase<out D : DeclarationDescriptor> @OptIn(ObsoleteDescriptorBasedAPI::class) constructor(
private val _descriptor: D, override val signature: IdSignature,
override val signature: IdSignature private val _descriptor: D?
) : IrSymbol { ) : IrSymbol {
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
@Suppress("UNCHECKED_CAST")
override val descriptor: D override val descriptor: D
get() = if (isBound && _descriptor is WrappedDeclarationDescriptor<*>) get() = _descriptor ?: (owner as IrDeclaration).toIrBasedDescriptor() as D
(owner as IrDeclaration).toIrBasedDescriptor() as D
else @ObsoleteDescriptorBasedAPI
_descriptor override val hasDescriptor: Boolean
get() = _descriptor != null
override fun toString(): String { override fun toString(): String {
if (isBound) return owner.render() if (isBound) return owner.render()
@@ -31,12 +33,12 @@ abstract class IrPublicSymbolBase<out D : DeclarationDescriptor> @OptIn(Obsolete
} }
} }
abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D, sig: IdSignature) : abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(sig: IdSignature, descriptor: D?) :
IrBindableSymbol<D, B>, IrPublicSymbolBase<D>(descriptor, sig) { IrBindableSymbol<D, B>, IrPublicSymbolBase<D>(sig, descriptor) {
init { init {
assert(isOriginalDescriptor(descriptor)) { assert(descriptor == null || isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor.original}" "Substituted descriptor $descriptor for ${descriptor!!.original}"
} }
assert(sig.isPublic) assert(sig.isPublic)
} }
@@ -49,7 +51,8 @@ abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrS
private var _owner: B? = null private var _owner: B? = null
override val owner: B override val owner: B
get() = _owner ?: throw IllegalStateException("Symbol for $signature is unbound") get() = _owner ?:
throw IllegalStateException("Symbol for $signature is unbound")
override fun bind(owner: B) { override fun bind(owner: B) {
if (_owner == null) { if (_owner == null) {
@@ -63,26 +66,26 @@ abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrS
get() = _owner != null get() = _owner != null
} }
class IrClassPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) : class IrClassPublicSymbolImpl(sig: IdSignature, descriptor: ClassDescriptor? = null) :
IrBindablePublicSymbolBase<ClassDescriptor, IrClass>(descriptor, sig), IrBindablePublicSymbolBase<ClassDescriptor, IrClass>(sig, descriptor),
IrClassSymbol IrClassSymbol
class IrEnumEntryPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) : class IrEnumEntryPublicSymbolImpl(sig: IdSignature, descriptor: ClassDescriptor? = null) :
IrBindablePublicSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor, sig), IrBindablePublicSymbolBase<ClassDescriptor, IrEnumEntry>(sig, descriptor),
IrEnumEntrySymbol IrEnumEntrySymbol
class IrSimpleFunctionPublicSymbolImpl(descriptor: FunctionDescriptor, sig: IdSignature) : class IrSimpleFunctionPublicSymbolImpl(sig: IdSignature, descriptor: FunctionDescriptor? = null) :
IrBindablePublicSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor, sig), IrBindablePublicSymbolBase<FunctionDescriptor, IrSimpleFunction>(sig, descriptor),
IrSimpleFunctionSymbol IrSimpleFunctionSymbol
class IrConstructorPublicSymbolImpl(descriptor: ClassConstructorDescriptor, sig: IdSignature) : class IrConstructorPublicSymbolImpl(sig: IdSignature, descriptor: ClassConstructorDescriptor? = null) :
IrBindablePublicSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor, sig), IrBindablePublicSymbolBase<ClassConstructorDescriptor, IrConstructor>(sig, descriptor),
IrConstructorSymbol IrConstructorSymbol
class IrPropertyPublicSymbolImpl(descriptor: PropertyDescriptor, sig: IdSignature) : class IrPropertyPublicSymbolImpl(sig: IdSignature, descriptor: PropertyDescriptor? = null) :
IrBindablePublicSymbolBase<PropertyDescriptor, IrProperty>(descriptor, sig), IrBindablePublicSymbolBase<PropertyDescriptor, IrProperty>(sig, descriptor),
IrPropertySymbol IrPropertySymbol
class IrTypeAliasPublicSymbolImpl(descriptor: TypeAliasDescriptor, sig: IdSignature) : class IrTypeAliasPublicSymbolImpl(sig: IdSignature, descriptor: TypeAliasDescriptor? = null) :
IrBindablePublicSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor, sig), IrBindablePublicSymbolBase<TypeAliasDescriptor, IrTypeAlias>(sig, descriptor),
IrTypeAliasSymbol IrTypeAliasSymbol
@@ -168,15 +168,13 @@ abstract class DataClassMembersGenerator(
val irIntType = context.irBuiltIns.intType val irIntType = context.irBuiltIns.intType
val resultVarDescriptor = WrappedVariableDescriptor()
val irResultVar = IrVariableImpl( val irResultVar = IrVariableImpl(
startOffset, endOffset, startOffset, endOffset,
IrDeclarationOrigin.DEFINED, IrDeclarationOrigin.DEFINED,
IrVariableSymbolImpl(resultVarDescriptor), IrVariableSymbolImpl(),
Name.identifier("result"), irIntType, Name.identifier("result"), irIntType,
isVar = true, isConst = false, isLateinit = false isVar = true, isConst = false, isLateinit = false
).also { ).also {
resultVarDescriptor.bind(it)
it.parent = irFunction it.parent = irFunction
it.initializer = getHashCodeOfProperty(properties[0]) it.initializer = getHashCodeOfProperty(properties[0])
} }
@@ -77,7 +77,7 @@ class DeclarationStubGenerator(
if (symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true) { if (symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true) {
return generateStubBySymbol(symbol, symbol.descriptor) return generateStubBySymbol(symbol, symbol.descriptor)
} }
val descriptor = if (symbol.descriptor is WrappedDeclarationDescriptor<*>) val descriptor = if (!symbol.hasDescriptor || symbol.descriptor is WrappedDeclarationDescriptor<*>)
findDescriptorBySignature( findDescriptorBySignature(
symbol.signature symbol.signature
?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}") ?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}")
@@ -46,23 +46,19 @@ interface ReferenceSymbolTable {
fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol
fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol fun referenceClassFromLinker(sig: IdSignature): IrClassSymbol
fun referenceConstructorFromLinker(descriptor: ClassConstructorDescriptor, sig: IdSignature): IrConstructorSymbol fun referenceConstructorFromLinker(sig: IdSignature): IrConstructorSymbol
fun referenceEnumEntryFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrEnumEntrySymbol fun referenceEnumEntryFromLinker(sig: IdSignature): IrEnumEntrySymbol
fun referenceFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrFieldSymbol fun referenceFieldFromLinker(sig: IdSignature): IrFieldSymbol
fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol fun referencePropertyFromLinker(sig: IdSignature): IrPropertySymbol
fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol fun referenceSimpleFunctionFromLinker(sig: IdSignature): IrSimpleFunctionSymbol
fun referenceTypeParameterFromLinker(classifier: TypeParameterDescriptor, sig: IdSignature): IrTypeParameterSymbol fun referenceTypeParameterFromLinker(sig: IdSignature): IrTypeParameterSymbol
fun referenceTypeAliasFromLinker(descriptor: TypeAliasDescriptor, sig: IdSignature): IrTypeAliasSymbol fun referenceTypeAliasFromLinker(sig: IdSignature): IrTypeAliasSymbol
@ObsoleteDescriptorBasedAPI
fun enterScope(owner: DeclarationDescriptor)
fun enterScope(owner: IrSymbol)
fun enterScope(owner: IrDeclaration) fun enterScope(owner: IrDeclaration)
@ObsoleteDescriptorBasedAPI fun leaveScope(owner: IrSymbol)
fun leaveScope(owner: DeclarationDescriptor)
fun leaveScope(owner: IrDeclaration) fun leaveScope(owner: IrDeclaration)
} }
@@ -79,7 +75,7 @@ class SymbolTable(
val unboundSymbols = linkedSetOf<S>() val unboundSymbols = linkedSetOf<S>()
abstract fun get(d: D): S? abstract fun get(d: D): S?
abstract fun set(d: D, s: S) abstract fun set(s: S)
abstract fun get(sig: IdSignature): S? abstract fun get(sig: IdSignature): S?
inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B { inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
@@ -91,7 +87,7 @@ class SymbolTable(
val existing = get(d0) val existing = get(d0)
val symbol = if (existing == null) { val symbol = if (existing == null) {
val new = createSymbol() val new = createSymbol()
set(d0, new) set(new)
new new
} else { } else {
unboundSymbols.remove(existing) unboundSymbols.remove(existing)
@@ -106,11 +102,12 @@ class SymbolTable(
val symbol = if (existing == null) { val symbol = if (existing == null) {
createSymbol() createSymbol()
} else { } else {
throw AssertionError("Symbol for $sig already exists") unboundSymbols.remove(existing)
existing
} }
val result = createOwner(symbol) val result = createOwner(symbol)
// TODO: try to get rid of this // TODO: try to get rid of this
set(symbol.descriptor, symbol) set(symbol)
return result return result
} }
@@ -123,7 +120,7 @@ class SymbolTable(
val existing = get(d0) val existing = get(d0)
val symbol = if (existing == null) { val symbol = if (existing == null) {
val new = createSymbol() val new = createSymbol()
set(d0, new) set(new)
new new
} else { } else {
if (!existing.isBound) unboundSymbols.remove(existing) if (!existing.isBound) unboundSymbols.remove(existing)
@@ -132,16 +129,16 @@ class SymbolTable(
return if (symbol.isBound) symbol.owner else createOwner(symbol) return if (symbol.isBound) symbol.owner else createOwner(symbol)
} }
inline fun declare(sig: IdSignature, d: D, createSymbol: () -> S, createOwner: (S) -> B): B { inline fun declare(sig: IdSignature, d: D?, createSymbol: () -> S, createOwner: (S) -> B): B {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
val d0 = d.original as D val d0 = d?.original as D
assert(d0 === d) { assert(d0 === d) {
"Non-original descriptor in declaration: $d\n\tExpected: $d0" "Non-original descriptor in declaration: $d\n\tExpected: $d0"
} }
val existing = get(sig) val existing = get(sig)
val symbol = if (existing == null) { val symbol = if (existing == null) {
val new = createSymbol() val new = createSymbol()
set(d0, new) set(new)
new new
} else { } else {
unboundSymbols.remove(existing) unboundSymbols.remove(existing)
@@ -162,7 +159,7 @@ class SymbolTable(
assert(unboundSymbols.add(new)) { assert(unboundSymbols.add(new)) {
"Symbol for $new was already referenced" "Symbol for $new was already referenced"
} }
set(d0, new) set(new)
return new return new
} }
return s return s
@@ -175,7 +172,7 @@ class SymbolTable(
assert(unboundSymbols.add(new)) { assert(unboundSymbols.add(new)) {
"Symbol for ${new.signature} was already referenced" "Symbol for ${new.signature} was already referenced"
} }
set(new.descriptor, new) set(new)
new new
} }
} }
@@ -207,11 +204,12 @@ class SymbolTable(
} }
} }
override fun set(d: D, s: S) { @OptIn(ObsoleteDescriptorBasedAPI::class)
override fun set(s: S) {
s.signature?.let { s.signature?.let {
idSigToSymbol[it] = s idSigToSymbol[it] = s
} ?: run { } ?: if (s.hasDescriptor) {
descriptorToSymbol[d] = s descriptorToSymbol[s.descriptor] = s
} }
} }
@@ -228,7 +226,7 @@ class SymbolTable(
private inner class ScopedSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>> private inner class ScopedSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>>
: SymbolTableBase<D, B, S>() { : SymbolTableBase<D, B, S>() {
inner class Scope(val owner: DeclarationDescriptor, val parent: Scope?) { inner class Scope(val owner: IrSymbol, val parent: Scope?) {
private val descriptorToSymbol = linkedMapOf<D, S>() private val descriptorToSymbol = linkedMapOf<D, S>()
private val idSigToSymbol = linkedMapOf<IdSignature, S>() private val idSigToSymbol = linkedMapOf<IdSignature, S>()
@@ -255,12 +253,14 @@ class SymbolTable(
fun getLocal(d: D) = descriptorToSymbol[d] fun getLocal(d: D) = descriptorToSymbol[d]
@OptIn(ObsoleteDescriptorBasedAPI::class)
operator fun set(d: D, s: S) { operator fun set(d: D, s: S) {
s.signature?.let { s.signature?.let {
require(d is TypeParameterDescriptor) require(d is TypeParameterDescriptor)
idSigToSymbol[it] = s idSigToSymbol[it] = s
} ?: run { } ?: run {
descriptorToSymbol[d] = s assert(s.hasDescriptor)
descriptorToSymbol[s.descriptor] = s
} }
} }
@@ -286,9 +286,10 @@ class SymbolTable(
return scope[d] return scope[d]
} }
override fun set(d: D, s: S) { @OptIn(ObsoleteDescriptorBasedAPI::class)
override fun set(s: S) {
val scope = currentScope ?: throw AssertionError("No active scope") val scope = currentScope ?: throw AssertionError("No active scope")
scope[d] = s scope[s.descriptor] = s
} }
override fun get(sig: IdSignature): S? { override fun get(sig: IdSignature): S? {
@@ -310,13 +311,11 @@ class SymbolTable(
scope[descriptor] = symbol scope[descriptor] = symbol
} }
@ObsoleteDescriptorBasedAPI fun enterScope(owner: IrSymbol) {
fun enterScope(owner: DeclarationDescriptor) {
currentScope = Scope(owner, currentScope) currentScope = Scope(owner, currentScope)
} }
@ObsoleteDescriptorBasedAPI fun leaveScope(owner: IrSymbol) {
fun leaveScope(owner: DeclarationDescriptor) {
currentScope?.owner.let { currentScope?.owner.let {
assert(it == owner) { "Unexpected leaveScope: owner=$owner, currentScope.owner=$it" } assert(it == owner) { "Unexpected leaveScope: owner=$owner, currentScope.owner=$it" }
} }
@@ -324,6 +323,7 @@ class SymbolTable(
currentScope = currentScope?.parent currentScope = currentScope?.parent
if (currentScope != null && unboundSymbols.isNotEmpty()) { if (currentScope != null && unboundSymbols.isNotEmpty()) {
@OptIn(ObsoleteDescriptorBasedAPI::class)
throw AssertionError("Local scope contains unbound symbols: ${unboundSymbols.joinToString { it.descriptor.toString() }}") throw AssertionError("Local scope contains unbound symbols: ${unboundSymbols.joinToString { it.descriptor.toString() }}")
} }
} }
@@ -406,7 +406,7 @@ class SymbolTable(
} }
private fun createClassSymbol(descriptor: ClassDescriptor): IrClassSymbol { private fun createClassSymbol(descriptor: ClassDescriptor): IrClassSymbol {
return signaturer.composeSignature(descriptor)?.let { IrClassPublicSymbolImpl(descriptor, it) } ?: IrClassSymbolImpl(descriptor) return signaturer.composeSignature(descriptor)?.let { IrClassPublicSymbolImpl(it, descriptor) } ?: IrClassSymbolImpl(descriptor)
} }
fun declareClass( fun declareClass(
@@ -439,7 +439,7 @@ class SymbolTable(
fun declareClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature, factory: (IrClassSymbol) -> IrClass): IrClass { fun declareClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature, factory: (IrClassSymbol) -> IrClass): IrClass {
return classSymbolTable.run { return classSymbolTable.run {
if (sig.isPublic) { if (sig.isPublic) {
declare(sig, descriptor, { IrClassPublicSymbolImpl(descriptor, sig) }, factory) declare(sig, descriptor, { IrClassPublicSymbolImpl(sig, descriptor) }, factory)
} else { } else {
declare(descriptor, { IrClassSymbolImpl(descriptor) }, factory) declare(descriptor, { IrClassSymbolImpl(descriptor) }, factory)
} }
@@ -452,16 +452,16 @@ class SymbolTable(
fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? = fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? =
classSymbolTable.get(sig) classSymbolTable.get(sig)
override fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol = override fun referenceClassFromLinker(sig: IdSignature): IrClassSymbol =
classSymbolTable.run { classSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(descriptor, sig) } if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(sig) }
else referenced(descriptor) { IrClassSymbolImpl(descriptor) } else IrClassSymbolImpl()
} }
val unboundClasses: Set<IrClassSymbol> get() = classSymbolTable.unboundSymbols val unboundClasses: Set<IrClassSymbol> get() = classSymbolTable.unboundSymbols
private fun createConstructorSymbol(descriptor: ClassConstructorDescriptor): IrConstructorSymbol { private fun createConstructorSymbol(descriptor: ClassConstructorDescriptor): IrConstructorSymbol {
return signaturer.composeSignature(descriptor)?.let { IrConstructorPublicSymbolImpl(descriptor, it) } ?: IrConstructorSymbolImpl( return signaturer.composeSignature(descriptor)?.let { IrConstructorPublicSymbolImpl(it, descriptor) } ?: IrConstructorSymbolImpl(
descriptor descriptor
) )
} }
@@ -508,23 +508,23 @@ class SymbolTable(
): IrConstructor { ): IrConstructor {
return constructorSymbolTable.run { return constructorSymbolTable.run {
if (sig.isPublic) { if (sig.isPublic) {
declare(sig, descriptor, { IrConstructorPublicSymbolImpl(descriptor, sig) }, constructorFactory) declare(sig, descriptor, { IrConstructorPublicSymbolImpl(sig, descriptor) }, constructorFactory)
} else { } else {
declare(descriptor, { IrConstructorSymbolImpl(descriptor) }, constructorFactory) declare(descriptor, { IrConstructorSymbolImpl(descriptor) }, constructorFactory)
} }
} }
} }
override fun referenceConstructorFromLinker(descriptor: ClassConstructorDescriptor, sig: IdSignature): IrConstructorSymbol = override fun referenceConstructorFromLinker(sig: IdSignature): IrConstructorSymbol =
constructorSymbolTable.run { constructorSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrConstructorPublicSymbolImpl(descriptor, sig) } if (sig.isPublic) referenced(sig) { IrConstructorPublicSymbolImpl(sig) }
else referenced(descriptor) { IrConstructorSymbolImpl(descriptor) } else IrConstructorSymbolImpl()
} }
val unboundConstructors: Set<IrConstructorSymbol> get() = constructorSymbolTable.unboundSymbols val unboundConstructors: Set<IrConstructorSymbol> get() = constructorSymbolTable.unboundSymbols
private fun createEnumEntrySymbol(descriptor: ClassDescriptor): IrEnumEntrySymbol { private fun createEnumEntrySymbol(descriptor: ClassDescriptor): IrEnumEntrySymbol {
return signaturer.composeEnumEntrySignature(descriptor)?.let { IrEnumEntryPublicSymbolImpl(descriptor, it) } return signaturer.composeEnumEntrySignature(descriptor)?.let { IrEnumEntryPublicSymbolImpl(it, descriptor) }
?: IrEnumEntrySymbolImpl(descriptor) ?: IrEnumEntrySymbolImpl(descriptor)
} }
@@ -557,7 +557,7 @@ class SymbolTable(
): IrEnumEntry { ): IrEnumEntry {
return enumEntrySymbolTable.run { return enumEntrySymbolTable.run {
if (sig.isPublic) { if (sig.isPublic) {
declare(sig, descriptor, { IrEnumEntryPublicSymbolImpl(descriptor, sig) }, factory) declare(sig, descriptor, { IrEnumEntryPublicSymbolImpl(sig, descriptor) }, factory)
} else { } else {
declare(descriptor, { IrEnumEntrySymbolImpl(descriptor) }, factory) declare(descriptor, { IrEnumEntrySymbolImpl(descriptor) }, factory)
} }
@@ -567,10 +567,10 @@ class SymbolTable(
override fun referenceEnumEntry(descriptor: ClassDescriptor) = override fun referenceEnumEntry(descriptor: ClassDescriptor) =
enumEntrySymbolTable.referenced(descriptor) { createEnumEntrySymbol(descriptor) } enumEntrySymbolTable.referenced(descriptor) { createEnumEntrySymbol(descriptor) }
override fun referenceEnumEntryFromLinker(descriptor: ClassDescriptor, sig: IdSignature) = override fun referenceEnumEntryFromLinker(sig: IdSignature) =
enumEntrySymbolTable.run { enumEntrySymbolTable.run {
if (sig.isPublic) referenced(sig) { IrEnumEntryPublicSymbolImpl(descriptor, sig) } else if (sig.isPublic) referenced(sig) { IrEnumEntryPublicSymbolImpl(sig) }
referenced(descriptor) { IrEnumEntrySymbolImpl(descriptor) } else IrEnumEntrySymbolImpl()
} }
val unboundEnumEntries: Set<IrEnumEntrySymbol> get() = enumEntrySymbolTable.unboundSymbols val unboundEnumEntries: Set<IrEnumEntrySymbol> get() = enumEntrySymbolTable.unboundSymbols
@@ -615,6 +615,18 @@ class SymbolTable(
initializer = irInitializer initializer = irInitializer
} }
fun declareField(
sig: IdSignature,
symbolFactory: () -> IrFieldSymbol,
propertyFactory: (IrFieldSymbol) -> IrField
): IrField {
return fieldSymbolTable.declare(
sig,
symbolFactory,
propertyFactory
)
}
fun declareFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrFieldSymbol) -> IrField): IrField { fun declareFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrFieldSymbol) -> IrField): IrField {
return fieldSymbolTable.run { return fieldSymbolTable.run {
require(sig.isLocal) require(sig.isLocal)
@@ -625,10 +637,10 @@ class SymbolTable(
override fun referenceField(descriptor: PropertyDescriptor) = override fun referenceField(descriptor: PropertyDescriptor) =
fieldSymbolTable.referenced(descriptor) { createFieldSymbol(descriptor) } fieldSymbolTable.referenced(descriptor) { createFieldSymbol(descriptor) }
override fun referenceFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature) = override fun referenceFieldFromLinker(sig: IdSignature) =
fieldSymbolTable.run { fieldSymbolTable.run {
require(sig.isLocal) require(sig.isLocal)
referenced(descriptor) { IrFieldSymbolImpl(descriptor) } IrFieldSymbolImpl()
} }
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
@@ -641,7 +653,7 @@ class SymbolTable(
propertyTable.getOrPut(descriptor, generate) propertyTable.getOrPut(descriptor, generate)
private fun createPropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol { private fun createPropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol {
return signaturer.composeSignature(descriptor)?.let { IrPropertyPublicSymbolImpl(descriptor, it) } ?: IrPropertySymbolImpl( return signaturer.composeSignature(descriptor)?.let { IrPropertyPublicSymbolImpl(it, descriptor) } ?: IrPropertySymbolImpl(
descriptor descriptor
) )
@@ -694,7 +706,7 @@ class SymbolTable(
fun declarePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrPropertySymbol) -> IrProperty): IrProperty { fun declarePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrPropertySymbol) -> IrProperty): IrProperty {
return propertySymbolTable.run { return propertySymbolTable.run {
if (sig.isPublic) { if (sig.isPublic) {
declare(sig, descriptor, { IrPropertyPublicSymbolImpl(descriptor, sig) }, factory) declare(sig, descriptor, { IrPropertyPublicSymbolImpl(sig, descriptor) }, factory)
} else { } else {
declare(descriptor, { IrPropertySymbolImpl(descriptor) }, factory) declare(descriptor, { IrPropertySymbolImpl(descriptor) }, factory)
} }
@@ -707,16 +719,16 @@ class SymbolTable(
fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? = fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? =
propertySymbolTable.get(sig) propertySymbolTable.get(sig)
override fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol = override fun referencePropertyFromLinker(sig: IdSignature): IrPropertySymbol =
propertySymbolTable.run { propertySymbolTable.run {
if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(descriptor, sig) } if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(sig) }
else referenced(descriptor) { IrPropertySymbolImpl(descriptor) } else IrPropertySymbolImpl()
} }
val unboundProperties: Set<IrPropertySymbol> get() = propertySymbolTable.unboundSymbols val unboundProperties: Set<IrPropertySymbol> get() = propertySymbolTable.unboundSymbols
private fun createTypeAliasSymbol(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol { private fun createTypeAliasSymbol(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol {
return signaturer.composeSignature(descriptor)?.let { IrTypeAliasPublicSymbolImpl(descriptor, it) } ?: IrTypeAliasSymbolImpl( return signaturer.composeSignature(descriptor)?.let { IrTypeAliasPublicSymbolImpl(it, descriptor) } ?: IrTypeAliasSymbolImpl(
descriptor descriptor
) )
} }
@@ -731,17 +743,17 @@ class SymbolTable(
): IrTypeAlias { ): IrTypeAlias {
return typeAliasSymbolTable.run { return typeAliasSymbolTable.run {
if (sig.isPublic) { if (sig.isPublic) {
declare(sig, descriptor, { IrTypeAliasPublicSymbolImpl(descriptor, sig) }, factory) declare(sig, descriptor, { IrTypeAliasPublicSymbolImpl(sig, descriptor) }, factory)
} else { } else {
declare(descriptor, { IrTypeAliasSymbolImpl(descriptor) }, factory) declare(descriptor, { IrTypeAliasSymbolImpl(descriptor) }, factory)
} }
} }
} }
override fun referenceTypeAliasFromLinker(descriptor: TypeAliasDescriptor, sig: IdSignature) = override fun referenceTypeAliasFromLinker(sig: IdSignature) =
typeAliasSymbolTable.run { typeAliasSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrTypeAliasPublicSymbolImpl(descriptor, sig) } else if (sig.isPublic) referenced(sig) { IrTypeAliasPublicSymbolImpl(sig) }
referenced(descriptor) { IrTypeAliasSymbolImpl(descriptor) } else IrTypeAliasSymbolImpl()
} }
fun declareTypeAlias(descriptor: TypeAliasDescriptor, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias = fun declareTypeAlias(descriptor: TypeAliasDescriptor, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias =
@@ -761,7 +773,7 @@ class SymbolTable(
val unboundTypeAliases: Set<IrTypeAliasSymbol> get() = typeAliasSymbolTable.unboundSymbols val unboundTypeAliases: Set<IrTypeAliasSymbol> get() = typeAliasSymbolTable.unboundSymbols
private fun createSimpleFunctionSymbol(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol { private fun createSimpleFunctionSymbol(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol {
return signaturer.composeSignature(descriptor)?.let { IrSimpleFunctionPublicSymbolImpl(descriptor, it) } return signaturer.composeSignature(descriptor)?.let { IrSimpleFunctionPublicSymbolImpl(it, descriptor) }
?: IrSimpleFunctionSymbolImpl(descriptor) ?: IrSimpleFunctionSymbolImpl(descriptor)
} }
@@ -796,15 +808,15 @@ class SymbolTable(
} }
fun declareSimpleFunctionFromLinker( fun declareSimpleFunctionFromLinker(
descriptor: FunctionDescriptor, descriptor: FunctionDescriptor?,
sig: IdSignature, sig: IdSignature,
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
): IrSimpleFunction { ): IrSimpleFunction {
return simpleFunctionSymbolTable.run { return simpleFunctionSymbolTable.run {
if (sig.isPublic) { if (sig.isPublic) {
declare(sig, descriptor, { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) }, functionFactory) declare(sig, descriptor, { IrSimpleFunctionPublicSymbolImpl(sig, descriptor) }, functionFactory)
} else { } else {
declare(descriptor, { IrSimpleFunctionSymbolImpl(descriptor) }, functionFactory) declare(descriptor!!, { IrSimpleFunctionSymbolImpl(descriptor) }, functionFactory)
} }
} }
} }
@@ -815,10 +827,10 @@ class SymbolTable(
fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? = fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? =
simpleFunctionSymbolTable.get(sig) simpleFunctionSymbolTable.get(sig)
override fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol { override fun referenceSimpleFunctionFromLinker(sig: IdSignature): IrSimpleFunctionSymbol {
return simpleFunctionSymbolTable.run { return simpleFunctionSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) } else if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(sig) }
referenced(descriptor) { IrSimpleFunctionSymbolImpl(descriptor) } else IrSimpleFunctionSymbolImpl()
} }
} }
@@ -850,6 +862,15 @@ class SymbolTable(
typeParameterFactory typeParameterFactory
) )
fun declareGlobalTypeParameter(
sig: IdSignature,
symbolFactory: () -> IrTypeParameterSymbol,
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter
): IrTypeParameter {
require(sig.isLocal)
return globalTypeParameterSymbolTable.declare(sig, symbolFactory, typeParameterFactory)
}
fun declareGlobalTypeParameterFromLinker( fun declareGlobalTypeParameterFromLinker(
descriptor: TypeParameterDescriptor, descriptor: TypeParameterDescriptor,
sig: IdSignature, sig: IdSignature,
@@ -878,6 +899,15 @@ class SymbolTable(
typeParameterFactory typeParameterFactory
) )
fun declareScopedTypeParameter(
sig: IdSignature,
symbolFactory: () -> IrTypeParameterSymbol,
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter
): IrTypeParameter {
require(sig.isLocal)
return typeParameterFactory(symbolFactory())
}
fun declareScopedTypeParameterFromLinker( fun declareScopedTypeParameterFromLinker(
descriptor: TypeParameterDescriptor, descriptor: TypeParameterDescriptor,
sig: IdSignature, sig: IdSignature,
@@ -927,10 +957,9 @@ class SymbolTable(
createTypeParameterSymbol(classifier) createTypeParameterSymbol(classifier)
} }
override fun referenceTypeParameterFromLinker(classifier: TypeParameterDescriptor, sig: IdSignature): IrTypeParameterSymbol { override fun referenceTypeParameterFromLinker(sig: IdSignature): IrTypeParameterSymbol {
require(sig.isLocal) require(sig.isLocal)
return scopedTypeParameterSymbolTable.get(classifier) return IrTypeParameterSymbolImpl()
?: globalTypeParameterSymbolTable.referenced(classifier) { IrTypeParameterSymbolImpl(classifier) }
} }
fun declareVariable( fun declareVariable(
@@ -992,24 +1021,20 @@ class SymbolTable(
throw AssertionError("Undefined local delegated property referenced: $descriptor") throw AssertionError("Undefined local delegated property referenced: $descriptor")
} }
@ObsoleteDescriptorBasedAPI override fun enterScope(owner: IrSymbol) {
override fun enterScope(owner: DeclarationDescriptor) {
scopedSymbolTables.forEach { it.enterScope(owner) } scopedSymbolTables.forEach { it.enterScope(owner) }
} }
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun enterScope(owner: IrDeclaration) { override fun enterScope(owner: IrDeclaration) {
enterScope(owner.descriptor) enterScope(owner.symbol)
} }
@ObsoleteDescriptorBasedAPI override fun leaveScope(owner: IrSymbol) {
override fun leaveScope(owner: DeclarationDescriptor) {
scopedSymbolTables.forEach { it.leaveScope(owner) } scopedSymbolTables.forEach { it.leaveScope(owner) }
} }
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun leaveScope(owner: IrDeclaration) { override fun leaveScope(owner: IrDeclaration) {
leaveScope(owner.descriptor) leaveScope(owner.symbol)
} }
fun referenceValue(value: ValueDescriptor): IrValueSymbol = fun referenceValue(value: ValueDescriptor): IrValueSymbol =
@@ -1070,32 +1095,31 @@ class SymbolTable(
} }
} }
@ObsoleteDescriptorBasedAPI inline fun <T> SymbolTable.withScope(owner: IrSymbol, block: SymbolTable.() -> T): T {
inline fun <T, D : DeclarationDescriptor> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
enterScope(owner) enterScope(owner)
val result = block(owner) val result = block()
leaveScope(owner) leaveScope(owner)
return result return result
} }
inline fun <T, D : IrDeclaration> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T { inline fun <T> SymbolTable.withScope(owner: IrDeclaration, block: SymbolTable.() -> T): T {
enterScope(owner) enterScope(owner)
val result = block(owner) val result = block()
leaveScope(owner) leaveScope(owner)
return result return result
} }
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
inline fun <T, D : DeclarationDescriptor> ReferenceSymbolTable.withReferenceScope(owner: D, block: ReferenceSymbolTable.(D) -> T): T { inline fun <T> ReferenceSymbolTable.withReferenceScope(owner: IrSymbol, block: ReferenceSymbolTable.() -> T): T {
enterScope(owner) enterScope(owner)
val result = block(owner) val result = block()
leaveScope(owner) leaveScope(owner)
return result return result
} }
inline fun <T, D : IrDeclaration> ReferenceSymbolTable.withReferenceScope(owner: D, block: ReferenceSymbolTable.(D) -> T): T { inline fun <T> ReferenceSymbolTable.withReferenceScope(owner: IrDeclaration, block: ReferenceSymbolTable.() -> T): T {
enterScope(owner) enterScope(owner)
val result = block(owner) val result = block()
leaveScope(owner) leaveScope(owner)
return result return result
} }
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.declarations.IrConstructor
@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.backend.common.serialization.GlobalDeclarationTable
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy import org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy
import org.jetbrains.kotlin.ir.overrides.IrOverridingUtil import org.jetbrains.kotlin.ir.overrides.IrOverridingUtil
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
@@ -113,7 +111,7 @@ class FakeOverrideBuilder(
// But to create and link that symbol we should already have the signature computed. // But to create and link that symbol we should already have the signature computed.
// To break this loop we use temp symbol in correspondingProperty. // To break this loop we use temp symbol in correspondingProperty.
val tempSymbol = IrPropertySymbolImpl(WrappedPropertyDescriptor()).also { val tempSymbol = IrPropertySymbolImpl().also {
it.bind(declaration as IrProperty) it.bind(declaration as IrProperty)
} }
declaration.getter?.let { declaration.getter?.let {
@@ -142,9 +140,9 @@ class FakeOverrideBuilder(
private fun declareFunctionFakeOverride(declaration: IrFakeOverrideFunction, signature: IdSignature) { private fun declareFunctionFakeOverride(declaration: IrFakeOverrideFunction, signature: IdSignature) {
val parent = declaration.parentAsClass val parent = declaration.parentAsClass
val symbol = linker.tryReferencingSimpleFunctionByLocalSignature(parent, signature) val symbol = linker.tryReferencingSimpleFunctionByLocalSignature(parent, signature)
val descriptor = symbol?.descriptor ?: WrappedSimpleFunctionDescriptor() ?: symbolTable.referenceSimpleFunctionFromLinker(signature)
symbolTable.declareSimpleFunctionFromLinker(descriptor, signature) { symbolTable.declareSimpleFunction(signature, { symbol }) {
assert(it === symbol || symbol == null) assert(it === symbol)
declaration.acquireSymbol(it) declaration.acquireSymbol(it)
} }
} }
@@ -152,9 +150,9 @@ class FakeOverrideBuilder(
private fun declarePropertyFakeOverride(declaration: IrFakeOverrideProperty, signature: IdSignature) { private fun declarePropertyFakeOverride(declaration: IrFakeOverrideProperty, signature: IdSignature) {
val parent = declaration.parentAsClass val parent = declaration.parentAsClass
val symbol = linker.tryReferencingPropertyByLocalSignature(parent, signature) val symbol = linker.tryReferencingPropertyByLocalSignature(parent, signature)
val descriptor = symbol?.descriptor ?: WrappedPropertyDescriptor() ?: symbolTable.referencePropertyFromLinker(signature)
symbolTable.declarePropertyFromLinker(descriptor, signature) { symbolTable.declareProperty(signature, { symbol }) {
assert(it === symbol || symbol == null) assert(it === symbol)
declaration.acquireSymbol(it) declaration.acquireSymbol(it)
} }
} }
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.symbols.impl.IrPublicSymbolBase import org.jetbrains.kotlin.ir.symbols.impl.IrPublicSymbolBase
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.* import org.jetbrains.kotlin.ir.types.impl.*
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
@@ -1009,21 +1010,17 @@ abstract class IrFileDeserializer(
val result = symbolTable.run { val result = symbolTable.run {
if (isGlobal) { if (isGlobal) {
val p = deserializeIrSymbolToDeclare(proto.base.symbol) val p = deserializeIrSymbolToDeclare(proto.base.symbol)
val symbol = p.first val symbol = p.first as IrTypeParameterSymbol
sig = p.second sig = p.second
val descriptor = (symbol as IrTypeParameterSymbol).descriptor declareGlobalTypeParameter(sig, { symbol }, factory)
declareGlobalTypeParameterFromLinker(descriptor, sig, factory)
} else { } else {
val symbolData = BinarySymbolData val symbolData = BinarySymbolData
.decode(proto.base.symbol) .decode(proto.base.symbol)
sig = deserializeIdSignature(symbolData.signatureId) sig = deserializeIdSignature(symbolData.signatureId)
val descriptor = WrappedTypeParameterDescriptor() declareScopedTypeParameter(sig, { IrTypeParameterSymbolImpl() }, factory)
declareScopedTypeParameterFromLinker(descriptor, sig, factory)
} }
} }
(result.descriptor as? WrappedTypeParameterDescriptor)?.bind(result)
// make sure this symbol is known to linker // make sure this symbol is known to linker
referenceIrSymbol(result.symbol, sig) referenceIrSymbol(result.symbol, sig)
result.annotations += deserializeAnnotations(proto.base.annotationList) result.annotations += deserializeAnnotations(proto.base.annotationList)
@@ -1059,7 +1056,7 @@ abstract class IrFileDeserializer(
withDeserializedIrDeclarationBase(proto.base) { symbol, signature, startOffset, endOffset, origin, fcode -> withDeserializedIrDeclarationBase(proto.base) { symbol, signature, startOffset, endOffset, origin, fcode ->
val flags = ClassFlags.decode(fcode) val flags = ClassFlags.decode(fcode)
symbolTable.declareClassFromLinker((symbol as IrClassSymbol).descriptor, signature) { symbolTable.declareClass(signature, { symbol as IrClassSymbol }) {
irFactory.createClass( irFactory.createClass(
startOffset, endOffset, origin, startOffset, endOffset, origin,
it, it,
@@ -1086,15 +1083,14 @@ abstract class IrFileDeserializer(
thisReceiver = deserializeIrValueParameter(proto.thisReceiver, -1) thisReceiver = deserializeIrValueParameter(proto.thisReceiver, -1)
(descriptor as? WrappedClassDescriptor)?.bind(this)
fakeOverrideBuilder.enqueueClass(this, signature) fakeOverrideBuilder.enqueueClass(this, signature)
} }
} }
private fun deserializeIrTypeAlias(proto: ProtoTypeAlias): IrTypeAlias = private fun deserializeIrTypeAlias(proto: ProtoTypeAlias): IrTypeAlias =
withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, fcode -> withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, fcode ->
symbolTable.declareTypeAliasFromLinker((symbol as IrTypeAliasSymbol).descriptor, uniqId) { require(symbol is IrTypeAliasSymbol)
symbolTable.declareTypeAlias(uniqId, { symbol }) {
val flags = TypeAliasFlags.decode(fcode) val flags = TypeAliasFlags.decode(fcode)
val nameType = BinaryNameAndType.decode(proto.nameType) val nameType = BinaryNameAndType.decode(proto.nameType)
irFactory.createTypeAlias( irFactory.createTypeAlias(
@@ -1108,8 +1104,6 @@ abstract class IrFileDeserializer(
) )
}.usingParent { }.usingParent {
typeParameters = deserializeTypeParameters(proto.typeParameterList, true) typeParameters = deserializeTypeParameters(proto.typeParameterList, true)
(descriptor as? WrappedTypeAliasDescriptor)?.bind(this)
} }
} }
@@ -1204,7 +1198,7 @@ abstract class IrFileDeserializer(
proto: ProtoFunctionBase, proto: ProtoFunctionBase,
block: (IrFunctionSymbol, IdSignature, Int, Int, IrDeclarationOrigin, Long) -> T block: (IrFunctionSymbol, IdSignature, Int, Int, IrDeclarationOrigin, Long) -> T
): T = withDeserializedIrDeclarationBase(proto.base) { symbol, idSig, startOffset, endOffset, origin, fcode -> ): T = withDeserializedIrDeclarationBase(proto.base) { symbol, idSig, startOffset, endOffset, origin, fcode ->
symbolTable.withScope(symbol.descriptor) { symbolTable.withScope(symbol) {
block(symbol as IrFunctionSymbol, idSig, startOffset, endOffset, origin, fcode).usingParent { block(symbol as IrFunctionSymbol, idSig, startOffset, endOffset, origin, fcode).usingParent {
typeParameters = deserializeTypeParameters(proto.typeParameterList, false) typeParameters = deserializeTypeParameters(proto.typeParameterList, false)
val nameType = BinaryNameAndType.decode(proto.nameType) val nameType = BinaryNameAndType.decode(proto.nameType)
@@ -1227,7 +1221,7 @@ abstract class IrFileDeserializer(
private fun deserializeIrFunction(proto: ProtoFunction): IrSimpleFunction { private fun deserializeIrFunction(proto: ProtoFunction): IrSimpleFunction {
return withDeserializedIrFunctionBase(proto.base) { symbol, idSig, startOffset, endOffset, origin, fcode -> return withDeserializedIrFunctionBase(proto.base) { symbol, idSig, startOffset, endOffset, origin, fcode ->
val flags = FunctionFlags.decode(fcode) val flags = FunctionFlags.decode(fcode)
symbolTable.declareSimpleFunctionFromLinker(symbol.descriptor, idSig) { symbolTable.declareSimpleFunction(idSig, { symbol as IrSimpleFunctionSymbol }) {
val nameType = BinaryNameAndType.decode(proto.base.nameType) val nameType = BinaryNameAndType.decode(proto.base.nameType)
irFactory.createFunction( irFactory.createFunction(
startOffset, endOffset, origin, startOffset, endOffset, origin,
@@ -1275,15 +1269,13 @@ abstract class IrFileDeserializer(
private fun deserializeIrEnumEntry(proto: ProtoEnumEntry): IrEnumEntry = private fun deserializeIrEnumEntry(proto: ProtoEnumEntry): IrEnumEntry =
withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, _ -> withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, _ ->
symbolTable.declareEnumEntryFromLinker((symbol as IrEnumEntrySymbol).descriptor, uniqId) { symbolTable.declareEnumEntry(uniqId, { symbol as IrEnumEntrySymbol }) {
irFactory.createEnumEntry(startOffset, endOffset, origin, it, deserializeName(proto.name)) irFactory.createEnumEntry(startOffset, endOffset, origin, it, deserializeName(proto.name))
}.apply { }.apply {
if (proto.hasCorrespondingClass()) if (proto.hasCorrespondingClass())
correspondingClass = deserializeIrClass(proto.correspondingClass) correspondingClass = deserializeIrClass(proto.correspondingClass)
if (proto.hasInitializer()) if (proto.hasInitializer())
initializerExpression = irFactory.createExpressionBody(deserializeExpressionBody(proto.initializer)) initializerExpression = irFactory.createExpressionBody(deserializeExpressionBody(proto.initializer))
(descriptor as? WrappedEnumEntryDescriptor)?.bind(this)
} }
} }
@@ -1292,16 +1284,15 @@ abstract class IrFileDeserializer(
irFactory.createAnonymousInitializer(startOffset, endOffset, origin, symbol as IrAnonymousInitializerSymbol).apply { irFactory.createAnonymousInitializer(startOffset, endOffset, origin, symbol as IrAnonymousInitializerSymbol).apply {
// body = deserializeBlockBody(proto.body.blockBody, startOffset, endOffset) // body = deserializeBlockBody(proto.body.blockBody, startOffset, endOffset)
body = deserializeStatementBody(proto.body) as IrBlockBody body = deserializeStatementBody(proto.body) as IrBlockBody
(descriptor as? WrappedClassDescriptor)?.bind(parentsStack.peek() as IrClass)
} }
} }
private fun deserializeIrConstructor(proto: ProtoConstructor): IrConstructor = private fun deserializeIrConstructor(proto: ProtoConstructor): IrConstructor =
withDeserializedIrFunctionBase(proto.base) { symbol, idSig, startOffset, endOffset, origin, fcode -> withDeserializedIrFunctionBase(proto.base) { symbol, idSig, startOffset, endOffset, origin, fcode ->
require(symbol is IrConstructorSymbol)
val flags = FunctionFlags.decode(fcode) val flags = FunctionFlags.decode(fcode)
val nameType = BinaryNameAndType.decode(proto.base.nameType) val nameType = BinaryNameAndType.decode(proto.base.nameType)
symbolTable.declareConstructorFromLinker((symbol as IrConstructorSymbol).descriptor, idSig) { symbolTable.declareConstructor(idSig, { symbol }) {
irFactory.createConstructor( irFactory.createConstructor(
startOffset, endOffset, origin, startOffset, endOffset, origin,
it, it,
@@ -1313,8 +1304,6 @@ abstract class IrFileDeserializer(
flags.isPrimary, flags.isPrimary,
flags.isExpect flags.isExpect
) )
}.apply {
(descriptor as? WrappedClassConstructorDescriptor)?.bind(this)
} }
} }
@@ -1322,10 +1311,11 @@ abstract class IrFileDeserializer(
private fun deserializeIrField(proto: ProtoField): IrField = private fun deserializeIrField(proto: ProtoField): IrField =
withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, fcode -> withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, fcode ->
require(symbol is IrFieldSymbol)
val nameType = BinaryNameAndType.decode(proto.nameType) val nameType = BinaryNameAndType.decode(proto.nameType)
val type = deserializeIrType(nameType.typeIndex) val type = deserializeIrType(nameType.typeIndex)
val flags = FieldFlags.decode(fcode) val flags = FieldFlags.decode(fcode)
symbolTable.declareFieldFromLinker((symbol as IrFieldSymbol).descriptor, uniqId) { symbolTable.declareField(uniqId, { symbol }) {
irFactory.createField( irFactory.createField(
startOffset, endOffset, origin, startOffset, endOffset, origin,
it, it,
@@ -1342,8 +1332,6 @@ abstract class IrFileDeserializer(
initializer = irFactory.createExpressionBody(deserializeExpressionBody(proto.initializer)) initializer = irFactory.createExpressionBody(deserializeExpressionBody(proto.initializer))
} }
} }
(descriptor as? WrappedFieldDescriptor)?.bind(this)
} }
} }
@@ -1369,8 +1357,9 @@ abstract class IrFileDeserializer(
private fun deserializeIrProperty(proto: ProtoProperty): IrProperty = private fun deserializeIrProperty(proto: ProtoProperty): IrProperty =
withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, fcode -> withDeserializedIrDeclarationBase(proto.base) { symbol, uniqId, startOffset, endOffset, origin, fcode ->
require(symbol is IrPropertySymbol)
val flags = PropertyFlags.decode(fcode) val flags = PropertyFlags.decode(fcode)
symbolTable.declarePropertyFromLinker((symbol as IrPropertySymbol).descriptor, uniqId) { symbolTable.declareProperty(uniqId, { symbol }) {
irFactory.createProperty( irFactory.createProperty(
startOffset, endOffset, origin, startOffset, endOffset, origin,
it, it,
@@ -502,21 +502,21 @@ abstract class KotlinIrLinker(
private fun referenceDeserializedSymbol(symbolKind: BinarySymbolData.SymbolKind, idSig: IdSignature): IrSymbol = symbolTable.run { private fun referenceDeserializedSymbol(symbolKind: BinarySymbolData.SymbolKind, idSig: IdSignature): IrSymbol = symbolTable.run {
when (symbolKind) { when (symbolKind) {
BinarySymbolData.SymbolKind.ANONYMOUS_INIT_SYMBOL -> IrAnonymousInitializerSymbolImpl(WrappedClassDescriptor()) BinarySymbolData.SymbolKind.ANONYMOUS_INIT_SYMBOL -> IrAnonymousInitializerSymbolImpl()
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClassFromLinker(WrappedClassDescriptor(), idSig) BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClassFromLinker(idSig)
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructorFromLinker(WrappedClassConstructorDescriptor(), idSig) BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructorFromLinker(idSig)
BinarySymbolData.SymbolKind.TYPE_PARAMETER_SYMBOL -> referenceTypeParameterFromLinker(WrappedTypeParameterDescriptor(), idSig) BinarySymbolData.SymbolKind.TYPE_PARAMETER_SYMBOL -> referenceTypeParameterFromLinker(idSig)
BinarySymbolData.SymbolKind.ENUM_ENTRY_SYMBOL -> referenceEnumEntryFromLinker(WrappedEnumEntryDescriptor(), idSig) BinarySymbolData.SymbolKind.ENUM_ENTRY_SYMBOL -> referenceEnumEntryFromLinker(idSig)
BinarySymbolData.SymbolKind.STANDALONE_FIELD_SYMBOL -> referenceFieldFromLinker(WrappedFieldDescriptor(), idSig) BinarySymbolData.SymbolKind.STANDALONE_FIELD_SYMBOL -> referenceFieldFromLinker(idSig)
BinarySymbolData.SymbolKind.FIELD_SYMBOL -> referenceFieldFromLinker(WrappedPropertyDescriptor(), idSig) BinarySymbolData.SymbolKind.FIELD_SYMBOL -> referenceFieldFromLinker(idSig)
BinarySymbolData.SymbolKind.FUNCTION_SYMBOL -> referenceSimpleFunctionFromLinker(WrappedSimpleFunctionDescriptor(), idSig) BinarySymbolData.SymbolKind.FUNCTION_SYMBOL -> referenceSimpleFunctionFromLinker(idSig)
BinarySymbolData.SymbolKind.TYPEALIAS_SYMBOL -> referenceTypeAliasFromLinker(WrappedTypeAliasDescriptor(), idSig) BinarySymbolData.SymbolKind.TYPEALIAS_SYMBOL -> referenceTypeAliasFromLinker(idSig)
BinarySymbolData.SymbolKind.PROPERTY_SYMBOL -> referencePropertyFromLinker(WrappedPropertyDescriptor(), idSig) BinarySymbolData.SymbolKind.PROPERTY_SYMBOL -> referencePropertyFromLinker(idSig)
BinarySymbolData.SymbolKind.VARIABLE_SYMBOL -> IrVariableSymbolImpl(WrappedVariableDescriptor()) BinarySymbolData.SymbolKind.VARIABLE_SYMBOL -> IrVariableSymbolImpl()
BinarySymbolData.SymbolKind.VALUE_PARAMETER_SYMBOL -> IrValueParameterSymbolImpl(WrappedValueParameterDescriptor()) BinarySymbolData.SymbolKind.VALUE_PARAMETER_SYMBOL -> IrValueParameterSymbolImpl()
BinarySymbolData.SymbolKind.RECEIVER_PARAMETER_SYMBOL -> IrValueParameterSymbolImpl(WrappedReceiverParameterDescriptor()) BinarySymbolData.SymbolKind.RECEIVER_PARAMETER_SYMBOL -> IrValueParameterSymbolImpl()
BinarySymbolData.SymbolKind.LOCAL_DELEGATED_PROPERTY_SYMBOL -> BinarySymbolData.SymbolKind.LOCAL_DELEGATED_PROPERTY_SYMBOL ->
IrLocalDelegatedPropertySymbolImpl(WrappedVariableDescriptorWithAccessor()) IrLocalDelegatedPropertySymbolImpl()
else -> error("Unexpected classifier symbol kind: $symbolKind for signature $idSig") else -> error("Unexpected classifier symbol kind: $symbolKind for signature $idSig")
} }
} }
@@ -553,6 +553,8 @@ abstract class KotlinIrLinker(
protected open fun platformSpecificSymbol(symbol: IrSymbol): Boolean = false protected open fun platformSpecificSymbol(symbol: IrSymbol): Boolean = false
private fun tryResolveCustomDeclaration(symbol: IrSymbol): IrDeclaration? { private fun tryResolveCustomDeclaration(symbol: IrSymbol): IrDeclaration? {
if (!symbol.hasDescriptor) return null
val descriptor = symbol.descriptor val descriptor = symbol.descriptor
if (descriptor is WrappedDeclarationDescriptor<*>) return null if (descriptor is WrappedDeclarationDescriptor<*>) return null
@@ -66,7 +66,7 @@ open class SerializerIrGenerator(
lateinit var prop: IrProperty lateinit var prop: IrProperty
// how to (auto)create backing field and getter/setter? // how to (auto)create backing field and getter/setter?
compilerContext.symbolTable.withReferenceScope(irClass.descriptor) { compilerContext.symbolTable.withReferenceScope(irClass) {
prop = generateSimplePropertyWithBackingField(desc, irClass) prop = generateSimplePropertyWithBackingField(desc, irClass)
// TODO: Do not use descriptors here // TODO: Do not use descriptors here
@@ -84,7 +84,7 @@ open class SerializerIrGenerator(
} }
anonymousInit.buildWithScope { initIrBody -> anonymousInit.buildWithScope { initIrBody ->
compilerContext.symbolTable.withReferenceScope(initIrBody.descriptor) { compilerContext.symbolTable.withReferenceScope(initIrBody) {
initIrBody.body = initIrBody.body =
DeclarationIrBuilder(compilerContext, initIrBody.symbol, initIrBody.startOffset, initIrBody.endOffset).irBlockBody { DeclarationIrBuilder(compilerContext, initIrBody.symbol, initIrBody.startOffset, initIrBody.endOffset).irBlockBody {
val localDesc = irTemporary( val localDesc = irTemporary(