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