diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDeclarations.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDeclarations.kt index 614ef1cf05a..30859ffb09f 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDeclarations.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDeclarations.kt @@ -16,26 +16,16 @@ package org.jetbrains.kotlin.backend.common -import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.IrElement -import org.jetbrains.kotlin.ir.declarations.IrVariable -import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor import org.jetbrains.kotlin.ir.expressions.IrLoop -import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols -import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper -import org.jetbrains.kotlin.ir.util.DeepCopyTypeRemapper -import org.jetbrains.kotlin.ir.util.DescriptorsRemapper +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.acceptVoid @Suppress("UNCHECKED_CAST") @OptIn(ObsoleteDescriptorBasedAPI::class) fun T.deepCopyWithVariables(): T { - val descriptorsRemapper = object : DescriptorsRemapper { - override fun remapDeclaredVariable(descriptor: VariableDescriptor) = WrappedVariableDescriptor() - } - - val symbolsRemapper = DeepCopySymbolRemapper(descriptorsRemapper) + val symbolsRemapper = DeepCopySymbolRemapper(NullDescriptorsRemapper) acceptVoid(symbolsRemapper) val typesRemapper = DeepCopyTypeRemapper(symbolsRemapper) @@ -45,12 +35,6 @@ fun T.deepCopyWithVariables(): T { override fun getNonTransformedLoop(irLoop: IrLoop): IrLoop { return irLoop } - - override fun visitVariable(declaration: IrVariable): IrVariable { - val variable = super.visitVariable(declaration) - variable.descriptor.let { if (it is WrappedVariableDescriptor) it.bind(variable) } - return variable - } }, null ) as T diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrInlineUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrInlineUtils.kt index efbdfc2fe6e..44671ca21a8 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrInlineUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrInlineUtils.kt @@ -6,11 +6,9 @@ package org.jetbrains.kotlin.backend.common.ir import org.jetbrains.kotlin.backend.common.lower.VariableRemapper -import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.ir.IrStatement +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl import org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl @@ -83,12 +81,6 @@ private fun IrBody.move( // TODO use a generic inliner (e.g. JS/Native's FunctionInlining.Inliner) // Inline simple function calls without type parameters, default parameters, or varargs. fun IrFunction.inline(target: IrDeclarationParent, arguments: List = listOf()): IrReturnableBlock = - IrReturnableBlockImpl(startOffset, endOffset, returnType, IrReturnableBlockSymbolImpl(getNewWrappedDescriptor()), null, symbol).apply { + IrReturnableBlockImpl(startOffset, endOffset, returnType, IrReturnableBlockSymbolImpl(), null, symbol).apply { statements += body!!.move(this@inline, target, symbol, valueParameters.zip(arguments).toMap()).statements - } - -fun IrFunction.getNewWrappedDescriptor(): FunctionDescriptor = when (this) { - is IrConstructor -> WrappedClassConstructorDescriptor().apply { bind(this@getNewWrappedDescriptor) } - is IrSimpleFunction -> WrappedSimpleFunctionDescriptor().apply { bind(this@getNewWrappedDescriptor) } - else -> error("Unknown IrFunction kind: $this") -} + } \ No newline at end of file diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FinallyBlocksLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FinallyBlocksLowering.kt index 2faee457a37..b2f7bb156b6 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FinallyBlocksLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/FinallyBlocksLowering.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildVariable import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFunction -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol @@ -175,7 +174,7 @@ class FinallyBlocksLowering(val context: CommonBackendContext, private val throw currentTryScope.jumps.getOrPut(jump) { val type = (jump as? Return)?.target?.owner?.returnType(context) ?: value.type jump.toString() - val symbol = IrReturnableBlockSymbolImpl(WrappedSimpleFunctionDescriptor()) + val symbol = IrReturnableBlockSymbolImpl() with(currentTryScope) { irBuilder.run { val inlinedFinally = irInlineFinally(symbol, type, expression, finallyExpression) @@ -234,7 +233,7 @@ class FinallyBlocksLowering(val context: CommonBackendContext, private val throw using(TryScope(syntheticTry, transformedFinallyExpression, this)) { val fallThroughType = aTry.type - val fallThroughSymbol = IrReturnableBlockSymbolImpl(WrappedSimpleFunctionDescriptor()) + val fallThroughSymbol = IrReturnableBlockSymbolImpl() val transformedResult = aTry.tryResult.transform(transformer, null) val returnedResult = irReturn(fallThroughSymbol, transformedResult) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt index 370e2487544..1a29f8e91c9 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.common.lower.inline import org.jetbrains.kotlin.backend.common.* import org.jetbrains.kotlin.backend.common.ir.Symbols -import org.jetbrains.kotlin.backend.common.ir.getNewWrappedDescriptor import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings @@ -178,7 +177,7 @@ class FunctionInlining( val evaluationStatements = evaluateArguments(callSite, copiedCallee) val statements = (copiedCallee.body as IrBlockBody).statements - val irReturnableBlockSymbol = IrReturnableBlockSymbolImpl(callee.getNewWrappedDescriptor()) + val irReturnableBlockSymbol = IrReturnableBlockSymbolImpl() val endOffset = callee.endOffset /* creates irBuilder appending to the end of the given returnable block: thus why we initialize * irBuilder with (..., endOffset, endOffset). 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 8aad58f9fc7..e3f8c554f92 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 @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns -import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor import org.jetbrains.kotlin.ir.expressions.IrConst import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrGetValue 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 4163b08212b..386a61c9a71 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 @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrEnumEntryImpl import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedEnumEntryDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue 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 0fd8355829f..501929fb039 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 @@ -20,7 +20,6 @@ import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.declarations.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.* -import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.* diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SuspendLambdaLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SuspendLambdaLowering.kt index b9c7b3ab7d7..1567e4b763f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SuspendLambdaLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SuspendLambdaLowering.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.backend.jvm.lower -import com.intellij.lang.jvm.source.JvmDeclarationSearch import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.ir.* @@ -27,12 +26,9 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.declarations.* import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol -import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid @@ -41,7 +37,6 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames -import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin internal val suspendLambdaPhase = makeIrFilePhase( ::SuspendLambdaLowering, 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 bf34d2870f7..ffc989df5fb 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 @@ -28,10 +28,10 @@ import org.jetbrains.kotlin.ir.builders.irGet import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.IrValueParameter -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtElement @@ -358,41 +358,26 @@ private fun StatementGenerator.createFunctionForSuspendConversion( val suspendFunReturnType = suspendFunType.arguments.last().type val irSuspendFunReturnType = suspendFunReturnType.toIrType() - val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor() - - val irAdapterFun = context.symbolTable.declareSimpleFunction( - adapterFunctionDescriptor - ) { irAdapterSymbol -> - context.irFactory.createFunction( - startOffset, endOffset, - IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION, - irAdapterSymbol, - Name.identifier(scope.inventNameForTemporary("suspendConversion")), - DescriptorVisibilities.LOCAL, Modality.FINAL, - irSuspendFunReturnType, - isInline = false, isExternal = false, isTailrec = false, - isSuspend = true, - isOperator = false, isInfix = false, isExpect = false, isFakeOverride = false - ) - } - adapterFunctionDescriptor.bind(irAdapterFun) + val irAdapterFun = context.irFactory.createFunction( + startOffset, endOffset, + IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION, + IrSimpleFunctionSymbolImpl(), + Name.identifier(scope.inventNameForTemporary("suspendConversion")), + DescriptorVisibilities.LOCAL, Modality.FINAL, + irSuspendFunReturnType, + isInline = false, isExternal = false, isTailrec = false, + isSuspend = true, + isOperator = false, isInfix = false, isExpect = false, isFakeOverride = false + ) context.symbolTable.enterScope(irAdapterFun) - fun createValueParameter(name: String, index: Int, type: IrType): IrValueParameter { - val descriptor = WrappedValueParameterDescriptor() - return context.symbolTable.declareValueParameter( - startOffset, endOffset, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION, descriptor, type - ) { - context.irFactory.createValueParameter( - startOffset, endOffset, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION, - it, Name.identifier(name), index, type, varargElementType = null, isCrossinline = false, isNoinline = false, - isHidden = false, isAssignable = false - ) - }.also { - descriptor.bind(it) - } - } + fun createValueParameter(name: String, index: Int, type: IrType): IrValueParameter = + context.irFactory.createValueParameter( + startOffset, endOffset, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION, IrValueParameterSymbolImpl(), + Name.identifier(name), index, type, varargElementType = null, isCrossinline = false, isNoinline = false, + isHidden = false, isAssignable = false + ) irAdapterFun.extensionReceiverParameter = createValueParameter("callee", -1, funType.toIrType()) irAdapterFun.valueParameters = suspendFunType.arguments 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 2af97bb01de..7abed0ee355 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 @@ -25,14 +25,14 @@ import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.IrValueParameter -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.util.referenceClassifier import org.jetbrains.kotlin.ir.util.referenceFunction import org.jetbrains.kotlin.ir.util.withScope @@ -313,49 +313,41 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St callBuilder: CallBuilder, callableReferenceType: KotlinType ): IrSimpleFunction { - val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor() - val hasSuspendConversion = !adapteeDescriptor.isSuspend && callableReferenceType.isKSuspendFunctionType - return context.symbolTable.declareSimpleFunction( - adapterFunctionDescriptor - ) { irAdapterSymbol -> - context.irFactory.createFunction( - startOffset, endOffset, - IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE, - irAdapterSymbol, - adapteeDescriptor.name, - DescriptorVisibilities.LOCAL, - Modality.FINAL, - ktExpectedReturnType.toIrType(), - isInline = adapteeDescriptor.isInline, // TODO ? - isExternal = false, - isTailrec = false, - isSuspend = adapteeDescriptor.isSuspend || hasSuspendConversion, - isOperator = adapteeDescriptor.isOperator, // TODO ? - isInfix = adapteeDescriptor.isInfix, - isExpect = false, - isFakeOverride = false - ).also { irAdapterFun -> - adapterFunctionDescriptor.bind(irAdapterFun) + return context.irFactory.createFunction( + startOffset, endOffset, + IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE, + IrSimpleFunctionSymbolImpl(), + adapteeDescriptor.name, + DescriptorVisibilities.LOCAL, + Modality.FINAL, + ktExpectedReturnType.toIrType(), + isInline = adapteeDescriptor.isInline, // TODO ? + isExternal = false, + isTailrec = false, + isSuspend = adapteeDescriptor.isSuspend || hasSuspendConversion, + isOperator = adapteeDescriptor.isOperator, // TODO ? + isInfix = adapteeDescriptor.isInfix, + isExpect = false, + isFakeOverride = false + ).also { irAdapterFun -> + context.symbolTable.withScope(irAdapterFun) { + irAdapterFun.metadata = DescriptorMetadataSource.Function(adapteeDescriptor) - context.symbolTable.withScope(irAdapterFun) { - irAdapterFun.metadata = DescriptorMetadataSource.Function(adapteeDescriptor) + irAdapterFun.dispatchReceiverParameter = null - irAdapterFun.dispatchReceiverParameter = null + val boundReceiver = callBuilder.original.selectBoundReceiver() + if (boundReceiver != null) { + irAdapterFun.extensionReceiverParameter = + createAdapterParameter(startOffset, endOffset, Name.identifier("receiver"), -1, boundReceiver.type) + } else { + irAdapterFun.extensionReceiverParameter = null + } - val boundReceiver = callBuilder.original.selectBoundReceiver() - if (boundReceiver != null) { - irAdapterFun.extensionReceiverParameter = - createAdapterParameter(startOffset, endOffset, Name.identifier("receiver"), -1, boundReceiver.type) - } else { - irAdapterFun.extensionReceiverParameter = null - } - - irAdapterFun.valueParameters += ktExpectedParameterTypes.mapIndexed { index, ktExpectedParameterType -> - createAdapterParameter(startOffset, endOffset, Name.identifier("p$index"), index, ktExpectedParameterType) - } + irAdapterFun.valueParameters += ktExpectedParameterTypes.mapIndexed { index, ktExpectedParameterType -> + createAdapterParameter(startOffset, endOffset, Name.identifier("p$index"), index, ktExpectedParameterType) } } } @@ -371,24 +363,16 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St } } - private fun createAdapterParameter(startOffset: Int, endOffset: Int, name: Name, index: Int, type: KotlinType): IrValueParameter { - val descriptor = WrappedValueParameterDescriptor() - return context.symbolTable.declareValueParameter( - startOffset, endOffset, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE, descriptor, type.toIrType() - ) { irAdapterParameterSymbol -> - context.irFactory.createValueParameter( - startOffset, endOffset, - IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE, - irAdapterParameterSymbol, - name, - index, - type.toIrType(), - varargElementType = null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false - ).also { irAdapterValueParameter -> - descriptor.bind(irAdapterValueParameter) - } - } - } + private fun createAdapterParameter(startOffset: Int, endOffset: Int, name: Name, index: Int, type: KotlinType): IrValueParameter = + context.irFactory.createValueParameter( + startOffset, endOffset, + IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE, + IrValueParameterSymbolImpl(), + name, + index, + type.toIrType(), + varargElementType = null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false + ) fun generateCallableReference( ktElement: KtElement, 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 1150f452f08..c469c1a3e2a 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 @@ -22,15 +22,18 @@ import org.jetbrains.kotlin.ir.declarations.IrFactory 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.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall -import org.jetbrains.kotlin.ir.symbols.IrSymbol @OptIn(ObsoleteDescriptorBasedAPI::class) class IrErrorDeclarationImpl( override val startOffset: Int, override val endOffset: Int, - override val descriptor: DeclarationDescriptor + private val _descriptor: DeclarationDescriptor? ) : IrErrorDeclaration() { + override val descriptor: DeclarationDescriptor + get() = _descriptor ?: this.toIrBasedDescriptor() + override var origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED override val factory: IrFactory diff --git a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt index cf68503e852..f1939e4a0ae 100644 --- a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt +++ b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt @@ -83,7 +83,7 @@ object IrFactoryImpl : IrFactory { override fun createErrorDeclaration( startOffset: Int, endOffset: Int, - descriptor: DeclarationDescriptor, + descriptor: DeclarationDescriptor?, ): IrErrorDeclaration = IrErrorDeclarationImpl(startOffset, endOffset, descriptor) diff --git a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt index 99a4b43a3e7..21fe68874af 100644 --- a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt +++ b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall @@ -138,7 +137,6 @@ class IrFakeOverrideFunctionImpl( assert(_symbol == null) { "$this already has symbol _symbol" } _symbol = symbol symbol.bind(this) - (symbol.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this) return this } } diff --git a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt index d00b6d301ff..ec97784ef1a 100644 --- a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt +++ b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrPropertyImpl.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol @@ -122,7 +121,6 @@ class IrFakeOverridePropertyImpl( assert(_symbol == null) { "$this already has symbol _symbol" } _symbol = symbol symbol.bind(this) - (symbol.descriptor as? WrappedPropertyDescriptor)?.bind(this) return this } } diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt index 2864d65eb5c..e474cc26e43 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt @@ -24,14 +24,18 @@ import org.jetbrains.kotlin.ir.declarations.IrErrorDeclaration import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ErrorCarrier import org.jetbrains.kotlin.ir.declarations.stageController +import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall @OptIn(ObsoleteDescriptorBasedAPI::class) internal class PersistentIrErrorDeclaration( override val startOffset: Int, override val endOffset: Int, - override val descriptor: DeclarationDescriptor + private val _descriptor: DeclarationDescriptor? ) : PersistentIrDeclarationBase, IrErrorDeclaration(), ErrorCarrier { + override val descriptor: DeclarationDescriptor + get() = _descriptor ?: this.toIrBasedDescriptor() + override var lastModified: Int = stageController.currentStage override var loweredUpTo: Int = stageController.currentStage override var values: Array? = null diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt index 13fa08ea6a0..1cbbd63941c 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt @@ -83,7 +83,7 @@ object PersistentIrFactory : IrFactory { override fun createErrorDeclaration( startOffset: Int, endOffset: Int, - descriptor: DeclarationDescriptor, + descriptor: DeclarationDescriptor?, ): IrErrorDeclaration = PersistentIrErrorDeclaration(startOffset, endOffset, descriptor) diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt index bfde5aca37f..6802894d21e 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt @@ -12,8 +12,6 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionCarrier -import org.jetbrains.kotlin.ir.descriptors.IrBasedSimpleFunctionDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall @@ -245,7 +243,6 @@ internal class PersistentIrFakeOverrideFunction( assert(_symbol == null) { "$this already has symbol _symbol" } _symbol = symbol symbol.bind(this) - (symbol.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this) return this } } diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt index 9e0fbdd6765..12407ba9537 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.PropertyCarrier -import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol @@ -173,7 +172,6 @@ internal class PersistentIrFakeOverrideProperty( assert(_symbol == null) { "$this already has symbol _symbol" } _symbol = symbol symbol.bind(this) - (symbol.descriptor as? WrappedPropertyDescriptor)?.bind(this) return this } } 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 f1d7bd93eab..e92a6f28739 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 @@ -16,15 +16,12 @@ package org.jetbrains.kotlin.ir.builders -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.IrDeclaration import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.impl.* diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt index 89e67e51841..2735fa12fc8 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt @@ -70,7 +70,7 @@ interface IrFactory { fun createErrorDeclaration( startOffset: Int, endOffset: Int, - descriptor: DeclarationDescriptor, + descriptor: DeclarationDescriptor? = null, ): IrErrorDeclaration fun createField( diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt index 7452739012e..c85caf34316 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource import org.jetbrains.kotlin.storage.LockBasedStorageManager +import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* /* Descriptors that serve purely as a view into IR structures. @@ -112,6 +113,7 @@ fun IrDeclaration.toIrBasedDescriptor(): DeclarationDescriptor = when (this) { is IrProperty -> toIrBasedDescriptor() is IrField -> toIrBasedDescriptor() is IrTypeAlias -> toIrBasedDescriptor() + is IrErrorDeclaration -> toIrBasedDescriptor() else -> error("Unknown declaration kind") } @@ -658,6 +660,27 @@ open class IrBasedClassDescriptor(owner: IrClass) : ClassDescriptor, IrBasedDecl fun IrClass.toIrBasedDescriptor() = IrBasedClassDescriptor(this) +class LazyTypeConstructor( + val classDescriptor: ClassDescriptor, + val parametersBuilder: () -> List, + val superTypesBuilder: () -> List, + storageManager: StorageManager +) : AbstractClassTypeConstructor(storageManager) { + val parameters_ by lazy { parametersBuilder() } + val superTypes_ by lazy { superTypesBuilder() } + + override fun getParameters() = parameters_ + + override fun computeSupertypes() = superTypes_ + + override fun isDenotable() = true + + override fun getDeclarationDescriptor() = classDescriptor + + override val supertypeLoopChecker: SupertypeLoopChecker + get() = SupertypeLoopChecker.EMPTY +} + open class IrBasedEnumEntryDescriptor(owner: IrEnumEntry) : ClassDescriptor, IrBasedDeclarationDescriptor(owner) { override fun getName() = owner.name @@ -1037,6 +1060,25 @@ open class IrBasedFieldDescriptor(owner: IrField) : PropertyDescriptor, IrBasedD fun IrField.toIrBasedDescriptor() = IrBasedFieldDescriptor(this) +class IrBasedErrorDescriptor(owner: IrErrorDeclaration) : IrBasedDeclarationDescriptor(owner) { + override fun getName(): Name = error("IrBasedErrorDescriptor.getName: Should not be reached") + + override fun getOriginal(): DeclarationDescriptorWithSource = + error("IrBasedErrorDescriptor.getOriginal: Should not be reached") + + override fun getContainingDeclaration(): DeclarationDescriptor = + error("IrBasedErrorDescriptor.getContainingDeclaration: Should not be reached") + + override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R { + error("IrBasedErrorDescriptor.accept: Should not be reached") + } + + override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { + } +} + +fun IrErrorDeclaration.toIrBasedDescriptor() = IrBasedErrorDescriptor(this) + @OptIn(ObsoleteDescriptorBasedAPI::class) private fun getContainingDeclaration(declaration: IrDeclaration): DeclarationDescriptor { val parent = declaration.parent diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt index bc2dd3b00db..a69cae6c09b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt @@ -273,8 +273,6 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa isAssignable = false ) - if (vDescriptor is WrappedReceiverParameterDescriptor) vDescriptor.bind(vDeclaration) - return vDeclaration } @@ -339,7 +337,6 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa isAssignable = false ) vDeclaration.parent = fDeclaration - if (vDescriptor is WrappedValueParameterDescriptor) vDescriptor.bind(vDeclaration) fDeclaration.valueParameters += vDeclaration } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/WrappedDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/WrappedDescriptors.kt deleted file mode 100644 index 27be9b26ef3..00000000000 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/WrappedDescriptors.kt +++ /dev/null @@ -1,1197 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.ir.descriptors - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl -import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor -import org.jetbrains.kotlin.ir.IrElement -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI -import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.types.classifierOrFail -import org.jetbrains.kotlin.ir.types.toKotlinType -import org.jetbrains.kotlin.ir.types.typeConstructorParameters -import org.jetbrains.kotlin.ir.util.* -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.constants.* -import org.jetbrains.kotlin.resolve.descriptorUtil.classId -import org.jetbrains.kotlin.resolve.descriptorUtil.module -import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter -import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource -import org.jetbrains.kotlin.storage.LockBasedStorageManager -import org.jetbrains.kotlin.storage.StorageManager -import org.jetbrains.kotlin.types.* - -@OptIn(ObsoleteDescriptorBasedAPI::class) -abstract class WrappedDeclarationDescriptor : DeclarationDescriptorWithSource { - override val annotations: Annotations - get() = annotationsFromOwner - - override fun getSource(): SourceElement = SourceElement.NO_SOURCE - - private val annotationsFromOwner by lazy { - val ownerAnnotations = (owner as? IrAnnotationContainer)?.annotations ?: return@lazy Annotations.EMPTY - Annotations.create(ownerAnnotations.map { it.toAnnotationDescriptor() }) - } - - private fun IrConstructorCall.toAnnotationDescriptor(): AnnotationDescriptor { - assert(symbol.owner.parentAsClass.isAnnotationClass) { - "Expected call to constructor of annotation class but was: ${this.dump()}" - } - return AnnotationDescriptorImpl( - symbol.owner.parentAsClass.defaultType.toKotlinType(), - symbol.owner.valueParameters.map { it.name to getValueArgument(it.index) } - .filter { it.second != null } - .associate { it.first to it.second!!.toConstantValue() }, - /*TODO*/ SourceElement.NO_SOURCE - ) - } - - private fun IrElement.toConstantValue(): ConstantValue<*> { - return when { - this is IrConst<*> -> when (kind) { - IrConstKind.Null -> NullValue() - IrConstKind.Boolean -> BooleanValue(value as Boolean) - IrConstKind.Char -> CharValue(value as Char) - IrConstKind.Byte -> ByteValue(value as Byte) - IrConstKind.Short -> ShortValue(value as Short) - IrConstKind.Int -> IntValue(value as Int) - IrConstKind.Long -> LongValue(value as Long) - IrConstKind.String -> StringValue(value as String) - IrConstKind.Float -> FloatValue(value as Float) - IrConstKind.Double -> DoubleValue(value as Double) - } - - this is IrVararg -> { - val elements = elements.map { if (it is IrSpreadElement) error("$it is not expected") else it.toConstantValue() } - ArrayValue(elements) { moduleDescriptor -> - // TODO: substitute. - moduleDescriptor.builtIns.array.defaultType - } - } - - this is IrGetEnumValue -> EnumValue(symbol.owner.parentAsClass.descriptor.classId!!, symbol.owner.name) - - this is IrClassReference -> KClassValue(classType.classifierOrFail.descriptor.classId!!, /*TODO*/0) - - this is IrConstructorCall -> AnnotationValue(this.toAnnotationDescriptor()) - - else -> error("$this is not expected: ${this.dump()}") - } - } - - private var _owner: T? = null - - var owner: T - get() { - return _owner ?: error("$this is not bound") - } - private set(value) { - _owner?.let { error("$this is already bound to ${it.dump()}") } - _owner = value - } - - fun bind(declaration: T) { - owner = declaration - } - - fun isBound(): Boolean = _owner != null -} - -abstract class WrappedCallableDescriptor : CallableDescriptor, WrappedDeclarationDescriptor() { - override fun getOriginal() = this - - override fun substitute(substitutor: TypeSubstitutor): CallableDescriptor = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun getOverriddenDescriptors(): Collection { - TODO("not implemented") - } - - override fun getSource() = SourceElement.NO_SOURCE - - override fun getExtensionReceiverParameter(): ReceiverParameterDescriptor? = null - - override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = null - - override fun getTypeParameters(): List { - TODO("not implemented") - } - - override fun getReturnType(): KotlinType? { - TODO("not implemented") - } - - override fun getValueParameters(): List { - TODO("not implemented") - } - - override fun hasStableParameterNames(): Boolean { - TODO("not implemented") - } - - override fun hasSynthesizedParameterNames() = false - - override fun getVisibility(): DescriptorVisibility { - TODO("not implemented") - } - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R { - TODO("not implemented") - } - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - TODO("not implemented") - } - - override fun getUserData(key: CallableDescriptor.UserDataKey?): V? = null -} - -// TODO: (Roman Artemev) do not create this kind of descriptor for dispatch receiver parameters -// WrappedReceiverParameterDescriptor should be used instead -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedValueParameterDescriptor : ValueParameterDescriptor, WrappedCallableDescriptor() { - - override val index get() = owner.index - override val isCrossinline get() = owner.isCrossinline - override val isNoinline get() = owner.isNoinline - override val varargElementType get() = owner.varargElementType?.toKotlinType() - override fun isConst() = false - override fun isVar() = false - - override fun getContainingDeclaration() = (owner.parent as IrFunction).descriptor - override fun getType() = owner.type.toKotlinType() - override fun getName() = owner.name - override fun declaresDefaultValue() = owner.defaultValue != null - override fun getCompileTimeInitializer(): ConstantValue<*>? = null - - override fun copy(newOwner: CallableDescriptor, newName: Name, newIndex: Int) = object : WrappedValueParameterDescriptor() { - override fun getContainingDeclaration() = newOwner as FunctionDescriptor - override fun getName() = newName - override val index = newIndex - }.also { it.bind(owner) } - - - override fun getOverriddenDescriptors(): Collection = emptyList() - override fun getTypeParameters(): List = emptyList() - override fun getValueParameters(): List = emptyList() - - override fun getOriginal() = this - - override fun substitute(substitutor: TypeSubstitutor): ValueParameterDescriptor = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun getReturnType(): KotlinType? = owner.type.toKotlinType() - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D) = - visitor!!.visitValueParameterDescriptor(this, data)!! - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitValueParameterDescriptor(this, null) - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedReceiverParameterDescriptor : ReceiverParameterDescriptor, WrappedCallableDescriptor() { - - override fun getValue(): ReceiverValue { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun getContainingDeclaration(): DeclarationDescriptor = - (owner.parent as? IrFunction)?.descriptor ?: (owner.parent as IrClass).descriptor - - override fun getType() = owner.type.toKotlinType() - override fun getName() = owner.name - - override fun copy(newOwner: DeclarationDescriptor) = object : WrappedReceiverParameterDescriptor() { - override fun getContainingDeclaration() = newOwner - }.also { it.bind(owner) } - - override fun getOverriddenDescriptors(): Collection = emptyList() - - override fun getOriginal() = this - - override fun substitute(substitutor: TypeSubstitutor): ReceiverParameterDescriptor { - TODO("") - } - - override fun getReturnType(): KotlinType? = owner.type.toKotlinType() - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D) = - visitor!!.visitReceiverParameterDescriptor(this, data)!! - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitReceiverParameterDescriptor(this, null) - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedTypeParameterDescriptor : TypeParameterDescriptor, WrappedDeclarationDescriptor() { - override fun getName() = owner.name - - override fun isReified() = owner.isReified - - override fun getVariance() = owner.variance - - override fun getUpperBounds() = owner.superTypes.map { it.toKotlinType() } - - private val _typeConstructor: TypeConstructor by lazy { - object : AbstractTypeConstructor(LockBasedStorageManager.NO_LOCKS) { - override fun computeSupertypes() = upperBounds - - override val supertypeLoopChecker = SupertypeLoopChecker.EMPTY - - override fun getParameters(): List = emptyList() - - override fun isFinal() = false - - override fun isDenotable() = true - - override fun getDeclarationDescriptor() = this@WrappedTypeParameterDescriptor - - override fun getBuiltIns() = module.builtIns - } - } - - override fun getTypeConstructor() = _typeConstructor - - override fun getOriginal() = this - - override fun getSource() = SourceElement.NO_SOURCE - - override fun getIndex() = owner.index - - override fun isCapturedFromOuterDeclaration() = false - - private val _defaultType: SimpleType by lazy { - KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( - Annotations.EMPTY, typeConstructor, emptyList(), false, - LazyScopeAdapter { - TypeIntersectionScope.create( - "Scope for type parameter " + name.asString(), - upperBounds - ) - } - ) - } - - override fun getDefaultType() = _defaultType - - override fun getStorageManager() = LockBasedStorageManager.NO_LOCKS - - override fun getContainingDeclaration() = (owner.parent as IrDeclaration).descriptor - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R = - visitor!!.visitTypeParameterDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitTypeParameterDescriptor(this, null) - } - -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedVariableDescriptor : VariableDescriptor, WrappedCallableDescriptor() { - - override fun getContainingDeclaration() = (owner.parent as IrDeclaration).descriptor - override fun getType() = owner.type.toKotlinType() - override fun getReturnType() = getType() - override fun getName() = owner.name - override fun isConst() = owner.isConst - override fun isVar() = owner.isVar - override fun isLateInit() = owner.isLateinit - - override fun getCompileTimeInitializer(): ConstantValue<*>? { - TODO("") - } - - override fun getOverriddenDescriptors(): Collection { - TODO("Not Implemented") - } - - override fun getOriginal() = this - - override fun substitute(substitutor: TypeSubstitutor): VariableDescriptor { - TODO("") - } - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R = - visitor!!.visitVariableDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitVariableDescriptor(this, null) - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedVariableDescriptorWithAccessor : VariableDescriptorWithAccessors, - WrappedCallableDescriptor() { - override fun getName(): Name = owner.name - - override fun substitute(substitutor: TypeSubstitutor): VariableDescriptor { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun isVar() = owner.isVar - - override fun getCompileTimeInitializer(): ConstantValue<*>? { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun getType(): KotlinType = owner.type.toKotlinType() - - override fun isConst(): Boolean = false - - override fun getContainingDeclaration() = (owner.parent as IrFunction).descriptor - - override fun isLateInit(): Boolean = false - - override val getter: VariableAccessorDescriptor? - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. - override val setter: VariableAccessorDescriptor? - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. - override val isDelegated: Boolean = true - -} - -// We make all wrapped function descriptors instances of DescriptorWithContainerSource, and use .parentClassId to -// check whether declaration is deserialized. See IrInlineCodegen.descriptorIsDeserialized -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedSimpleFunctionDescriptor : - SimpleFunctionDescriptor, DescriptorWithContainerSource, WrappedCallableDescriptor() { - - override fun getOverriddenDescriptors() = owner.overriddenSymbols.map { it.descriptor } - - override fun getContainingDeclaration(): DeclarationDescriptor = getContainingDeclaration(owner) - - override fun getModality() = owner.modality - override fun getName() = owner.name - override fun getVisibility() = owner.visibility - override fun getReturnType() = owner.returnType.toKotlinType() - - override fun getDispatchReceiverParameter() = owner.dispatchReceiverParameter?.run { - (containingDeclaration as ClassDescriptor).thisAsReceiverParameter - } - - override fun getExtensionReceiverParameter() = owner.extensionReceiverParameter?.let { - if (it.isHidden) null else - it.descriptor as? ReceiverParameterDescriptor - } - override fun getTypeParameters() = owner.typeParameters.map { it.descriptor } - override fun getValueParameters() = owner.valueParameters - .asSequence() - .filter { !it.isHidden } - .mapNotNull { it.descriptor as? ValueParameterDescriptor } - .toMutableList() - - override fun isExternal() = owner.isExternal - override fun isSuspend() = owner.isSuspend - override fun isTailrec() = owner.isTailrec - override fun isInline() = owner.isInline - - override fun isExpect() = false - override fun isActual() = false - override fun isInfix() = false - override fun isOperator() = false - - override val containerSource: DeserializedContainerSource? - get() = owner.containerSource - - override fun getOriginal() = this - override fun substitute(substitutor: TypeSubstitutor): SimpleFunctionDescriptor { - TODO("") - } - - override fun setOverriddenDescriptors(overriddenDescriptors: MutableCollection) { - TODO("not implemented") - } - - override fun getKind() = - if (owner.origin == IrDeclarationOrigin.FAKE_OVERRIDE) CallableMemberDescriptor.Kind.FAKE_OVERRIDE - else CallableMemberDescriptor.Kind.SYNTHESIZED - - override fun copy( - newOwner: DeclarationDescriptor?, - modality: Modality?, - visibility: DescriptorVisibility?, - kind: CallableMemberDescriptor.Kind?, - copyOverrides: Boolean - ): Nothing { - TODO("not implemented") - } - - override fun isHiddenToOvercomeSignatureClash(): Boolean = false - override fun isHiddenForResolutionEverywhereBesideSupercalls(): Boolean = false - - override fun getInitialSignatureDescriptor(): FunctionDescriptor? = null - - override fun getUserData(key: CallableDescriptor.UserDataKey?): V? = null - - override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder { - TODO("not implemented") - } - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D) = - visitor!!.visitFunctionDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitFunctionDescriptor(this, null) - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedClassConstructorDescriptor : ClassConstructorDescriptor, WrappedCallableDescriptor() { - override fun getContainingDeclaration() = (owner.parent as IrClass).descriptor - - override fun getDispatchReceiverParameter() = owner.dispatchReceiverParameter?.run { - (containingDeclaration.containingDeclaration as ClassDescriptor).thisAsReceiverParameter - } - - override fun getTypeParameters() = - (owner.constructedClass.typeParameters + owner.typeParameters).map { it.descriptor } - - override fun getValueParameters() = owner.valueParameters.asSequence() - .mapNotNull { it.descriptor as? ValueParameterDescriptor } - .toMutableList() - - override fun getOriginal() = this - - override fun substitute(substitutor: TypeSubstitutor): ClassConstructorDescriptor { - TODO("not implemented") - } - - override fun copy( - newOwner: DeclarationDescriptor, - modality: Modality, - visibility: DescriptorVisibility, - kind: CallableMemberDescriptor.Kind, - copyOverrides: Boolean - ): ClassConstructorDescriptor { - throw UnsupportedOperationException() - } - - override fun getModality() = Modality.FINAL - - - override fun setOverriddenDescriptors(overriddenDescriptors: MutableCollection) { - TODO("not implemented") - } - - override fun getKind() = CallableMemberDescriptor.Kind.SYNTHESIZED - - override fun getConstructedClass() = (owner.parent as IrClass).descriptor - - override fun getName() = owner.name - - override fun getOverriddenDescriptors(): MutableCollection = mutableListOf() - - override fun getInitialSignatureDescriptor(): FunctionDescriptor? = null - - override fun getVisibility() = owner.visibility - - override fun isHiddenToOvercomeSignatureClash(): Boolean { - TODO("not implemented") - } - - override fun isOperator() = false - - override fun isInline() = owner.isInline - - override fun isHiddenForResolutionEverywhereBesideSupercalls(): Boolean { - TODO("not implemented") - } - - override fun getReturnType() = owner.returnType.toKotlinType() - - override fun isPrimary() = owner.isPrimary - - override fun isExpect() = false - - override fun isTailrec() = false - - override fun isActual() = false - - override fun isInfix() = false - - override fun isSuspend() = false - - override fun getUserData(key: CallableDescriptor.UserDataKey?): V? = null - - override fun isExternal() = owner.isExternal - - override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder { - TODO("not implemented") - } - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R = - visitor!!.visitConstructorDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitConstructorDescriptor(this, null) - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedClassDescriptor : ClassDescriptor, WrappedDeclarationDescriptor() { - override fun getName() = owner.name - - override fun getMemberScope(typeArguments: MutableList) = MemberScope.Empty - - override fun getMemberScope(typeSubstitution: TypeSubstitution) = MemberScope.Empty - - override fun getUnsubstitutedMemberScope() = MemberScope.Empty - - override fun getUnsubstitutedInnerClassesScope() = MemberScope.Empty - - override fun getStaticScope() = MemberScope.Empty - - override fun getConstructors() = - owner.declarations.filterIsInstance().filter { !it.origin.isSynthetic }.map { it.descriptor }.toList() - - override fun getContainingDeclaration() = (owner.parent as IrSymbolOwner).symbol.descriptor - - private val _defaultType: SimpleType by lazy { - TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope, KotlinTypeFactory.EMPTY_REFINED_TYPE_FACTORY) - } - - override fun getDefaultType(): SimpleType = _defaultType - - override fun getKind() = owner.kind - - override fun getModality() = owner.modality - - override fun getCompanionObjectDescriptor() = owner.declarations.filterIsInstance().firstOrNull { it.isCompanion }?.descriptor - - override fun getVisibility() = owner.visibility - - override fun isCompanionObject() = owner.isCompanion - - override fun isData() = owner.isData - - override fun isInline() = owner.isInline - - override fun isFun() = owner.isFun - - override fun isValue() = owner.isInline - - override fun getThisAsReceiverParameter() = owner.thisReceiver?.descriptor as ReceiverParameterDescriptor - - override fun getUnsubstitutedPrimaryConstructor() = - owner.declarations.filterIsInstance().singleOrNull { it.isPrimary }?.descriptor - - override fun getDeclaredTypeParameters() = owner.typeParameters.map { it.descriptor } - - override fun getSealedSubclasses(): Collection { - TODO("not implemented") - } - - override fun getOriginal() = this - - override fun isExpect() = false - - override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun isActual() = false - - private val _typeConstructor: TypeConstructor by lazy { - LazyTypeConstructor( - this, - ::collectTypeParameters, - { owner.superTypes.map { it.toKotlinType() } }, - LockBasedStorageManager.NO_LOCKS - ) - } - - private fun collectTypeParameters(): List = - owner.typeConstructorParameters - .map { it.descriptor } - .toList() - - override fun getTypeConstructor(): TypeConstructor = _typeConstructor - - override fun isInner() = owner.isInner - - override fun isExternal() = owner.isExternal - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R = - visitor!!.visitClassDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitClassDescriptor(this, null) - } - - override fun getDefaultFunctionTypeForSamInterface(): SimpleType? { - TODO("not implemented") - } - - override fun isDefinitelyNotSamInterface(): Boolean { - return owner.descriptor.isDefinitelyNotSamInterface - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedScriptDescriptor : ScriptDescriptor, WrappedDeclarationDescriptor() { - override fun getName() = owner.name - - override fun getMemberScope(typeArguments: MutableList) = MemberScope.Empty - - override fun getMemberScope(typeSubstitution: TypeSubstitution) = MemberScope.Empty - - override fun getUnsubstitutedMemberScope() = MemberScope.Empty - - override fun getUnsubstitutedInnerClassesScope() = MemberScope.Empty - - override fun getStaticScope() = MemberScope.Empty - - override fun getSource(): SourceElement = SourceElement.NO_SOURCE - - override fun getConstructors() = - owner.statements.filterIsInstance().filter { !it.origin.isSynthetic }.map { it.descriptor }.toList() - - override fun getContainingDeclaration() = (owner.parent as IrSymbolOwner).symbol.descriptor - - private val _defaultType: SimpleType by lazy { - TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope, KotlinTypeFactory.EMPTY_REFINED_TYPE_FACTORY) - } - - override fun getDefaultType(): SimpleType = _defaultType - - override fun getKind() = TODO() - - override fun getModality() = TODO() - - override fun getCompanionObjectDescriptor() = owner.statements.filterIsInstance().firstOrNull { it.isCompanion }?.descriptor - - override fun getVisibility() = TODO() - - override fun isCompanionObject() = false - - override fun isData() = false - - override fun isInline() = false - - override fun isFun() = false - - override fun isValue() = false - - override fun getThisAsReceiverParameter() = owner.thisReceiver.descriptor as ReceiverParameterDescriptor - - override fun getUnsubstitutedPrimaryConstructor() = TODO() - - override fun getDeclaredTypeParameters() = TODO() - - override fun getSealedSubclasses(): Collection { - TODO("not implemented") - } - - override fun getOriginal() = this - - override fun isExpect() = false - - override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun isInner(): Boolean { - TODO("Not yet implemented") - } - - override fun isActual() = false - - override fun isExternal(): Boolean { - TODO("Not yet implemented") - } - - override fun getTypeConstructor(): TypeConstructor = TODO() - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R = - visitor!!.visitClassDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitClassDescriptor(this, null) - } - - override fun getDefaultFunctionTypeForSamInterface(): SimpleType? { - TODO("not yet implemented") - } - - override fun isDefinitelyNotSamInterface(): Boolean { - TODO("Not yet implemented") - } - - override fun getPriority(): Int { - TODO("Not yet implemented") - } - - override fun getExplicitConstructorParameters(): MutableList { - TODO("Not yet implemented") - } - - override fun getImplicitReceiversParameters(): MutableList { - TODO("Not yet implemented") - } - - override fun getScriptProvidedPropertiesParameters(): MutableList { - TODO("Not yet implemented") - } - - override fun getImplicitReceivers(): MutableList { - TODO("Not yet implemented") - } - - override fun getScriptProvidedProperties(): MutableList { - TODO("Not yet implemented") - } - - override fun getResultValue(): PropertyDescriptor? { - TODO("Not yet implemented") - } -} - -class LazyTypeConstructor( - val classDescriptor: ClassDescriptor, - val parametersBuilder: () -> List, - val superTypesBuilder: () -> List, - storageManager: StorageManager -) : AbstractClassTypeConstructor(storageManager) { - val parameters_ by lazy { parametersBuilder() } - val superTypes_ by lazy { superTypesBuilder() } - - override fun getParameters() = parameters_ - - override fun computeSupertypes() = superTypes_ - - override fun isDenotable() = true - - override fun getDeclarationDescriptor() = classDescriptor - - override val supertypeLoopChecker: SupertypeLoopChecker - get() = SupertypeLoopChecker.EMPTY -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedEnumEntryDescriptor : ClassDescriptor, WrappedDeclarationDescriptor() { - override fun getName() = owner.name - - override fun getMemberScope(typeArguments: MutableList) = MemberScope.Empty - - override fun getMemberScope(typeSubstitution: TypeSubstitution) = MemberScope.Empty - - override fun getUnsubstitutedMemberScope() = MemberScope.Empty - - override fun getUnsubstitutedInnerClassesScope() = MemberScope.Empty - - override fun getStaticScope() = MemberScope.Empty - - override fun getSource() = SourceElement.NO_SOURCE - - override fun getConstructors() = - getCorrespondingClass().declarations.asSequence().filterIsInstance().map { it.descriptor }.toList() - - private fun getCorrespondingClass() = owner.correspondingClass ?: (owner.parent as IrClass) - - override fun getContainingDeclaration() = (owner.parent as IrSymbolOwner).symbol.descriptor - - - private val _defaultType: SimpleType by lazy { - TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope, KotlinTypeFactory.EMPTY_REFINED_TYPE_FACTORY) - } - - override fun getDefaultType(): SimpleType = _defaultType - - override fun getKind() = ClassKind.ENUM_ENTRY - - override fun getModality() = Modality.FINAL - - override fun getCompanionObjectDescriptor() = null - - override fun getVisibility() = DescriptorVisibilities.DEFAULT_VISIBILITY - - override fun isCompanionObject() = false - - override fun isData() = false - - override fun isInline() = false - - override fun isFun() = false - - override fun isValue() = false - - override fun getThisAsReceiverParameter() = (owner.parent as IrClass).descriptor.thisAsReceiverParameter - - override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? { - TODO("not implemented") - } - - override fun getDeclaredTypeParameters(): List = emptyList() - - override fun getSealedSubclasses(): Collection { - TODO("not implemented") - } - - override fun getOriginal() = this - - override fun isExpect() = false - - override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun isActual() = false - - private val _typeConstructor: TypeConstructor by lazy { - ClassTypeConstructorImpl( - this, - emptyList(), - getCorrespondingClass().superTypes.map { it.toKotlinType() }, - LockBasedStorageManager.NO_LOCKS - ) - } - - override fun getTypeConstructor(): TypeConstructor = _typeConstructor - - override fun isInner() = false - - override fun isExternal() = false - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R = - visitor!!.visitClassDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitClassDescriptor(this, null) - } - - override fun getDefaultFunctionTypeForSamInterface(): SimpleType? = null - - override fun isDefinitelyNotSamInterface() = true -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedPropertyDescriptor : - PropertyDescriptor, DescriptorWithContainerSource, WrappedDeclarationDescriptor() { - override fun getModality() = owner.modality - - override fun setOverriddenDescriptors(overriddenDescriptors: MutableCollection) { - TODO("not implemented") - } - - override fun getKind() = CallableMemberDescriptor.Kind.SYNTHESIZED - - override fun getName() = owner.name - - override fun getSource() = SourceElement.NO_SOURCE - - override fun hasSynthesizedParameterNames(): Boolean { - TODO("not implemented") - } - - override fun getOverriddenDescriptors(): MutableCollection = mutableListOf() - - override fun copy( - newOwner: DeclarationDescriptor?, - modality: Modality?, - visibility: DescriptorVisibility?, - kind: CallableMemberDescriptor.Kind?, - copyOverrides: Boolean - ): CallableMemberDescriptor { - TODO("not implemented") - } - - override fun getValueParameters(): MutableList = mutableListOf() - - override fun getCompileTimeInitializer(): ConstantValue<*>? { - return null - } - - override fun isSetterProjectedOut(): Boolean { - TODO("not implemented") - } - - override fun getAccessors(): List = listOfNotNull(getter, setter) - - override fun getTypeParameters(): List = getter?.typeParameters.orEmpty() - - override fun getVisibility() = owner.visibility - - override val setter: PropertySetterDescriptor? get() = owner.setter?.descriptor as? PropertySetterDescriptor - - override val containerSource: DeserializedContainerSource? - get() = owner.containerSource - - override fun getOriginal() = this - - override fun isExpect() = false - - override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun isActual() = false - - override fun getReturnType() = (owner.getter?.returnType ?: owner.backingField?.type!!).toKotlinType() - - override fun hasStableParameterNames() = false - - override fun getType(): KotlinType = returnType - - override fun isVar() = owner.isVar - - override fun getDispatchReceiverParameter() = owner.getter?.dispatchReceiverParameter?.descriptor as? ReceiverParameterDescriptor - - override fun isConst() = owner.isConst - - override fun getContainingDeclaration(): DeclarationDescriptor = getContainingDeclaration(owner) - - override fun isLateInit() = owner.isLateinit - - override fun getExtensionReceiverParameter() = owner.getter?.extensionReceiverParameter?.descriptor as? ReceiverParameterDescriptor - - override fun isExternal() = owner.isExternal - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D) = - visitor!!.visitPropertyDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitPropertyDescriptor(this, null) - } - - override val getter: PropertyGetterDescriptor? get() = owner.getter?.descriptor as? PropertyGetterDescriptor - - override fun newCopyBuilder(): CallableMemberDescriptor.CopyBuilder { - TODO("not implemented") - } - - override val isDelegated get() = owner.isDelegated - - override fun getBackingField(): FieldDescriptor? { - TODO("not implemented") - } - - override fun getDelegateField(): FieldDescriptor? { - TODO("not implemented") - } - - override fun getUserData(key: CallableDescriptor.UserDataKey?): V? = null -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -abstract class WrappedPropertyAccessorDescriptor : WrappedSimpleFunctionDescriptor(), PropertyAccessorDescriptor { - override fun isDefault(): Boolean = false - - override fun getOriginal(): WrappedPropertyAccessorDescriptor = this - - override fun getOverriddenDescriptors() = super.getOverriddenDescriptors().map { it as PropertyAccessorDescriptor } - - override fun getCorrespondingProperty(): PropertyDescriptor = owner.correspondingPropertySymbol!!.descriptor - - override val correspondingVariable: VariableDescriptorWithAccessors get() = correspondingProperty -} - -class WrappedPropertyGetterDescriptor : - WrappedPropertyAccessorDescriptor(), PropertyGetterDescriptor { - override fun getOverriddenDescriptors() = super.getOverriddenDescriptors().map { it as PropertyGetterDescriptor } - - override fun getOriginal(): WrappedPropertyGetterDescriptor = this -} - -class WrappedPropertySetterDescriptor : - WrappedPropertyAccessorDescriptor(), PropertySetterDescriptor { - override fun getOverriddenDescriptors() = super.getOverriddenDescriptors().map { it as PropertySetterDescriptor } - - override fun getOriginal(): WrappedPropertySetterDescriptor = this -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedTypeAliasDescriptor : WrappedDeclarationDescriptor(), TypeAliasDescriptor { - - override val underlyingType: SimpleType - get() = throw UnsupportedOperationException("Unexpected use of WrappedTypeAliasDescriptor $this") - - override val constructors: Collection - get() = throw UnsupportedOperationException("Unexpected use of WrappedTypeAliasDescriptor $this") - - override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters = - throw UnsupportedOperationException("Wrapped descriptors should not be substituted") - - override fun getDefaultType(): SimpleType = - throw UnsupportedOperationException("Unexpected use of WrappedTypeAliasDescriptor $this") - - override fun getTypeConstructor(): TypeConstructor = - throw UnsupportedOperationException("Unexpected use of WrappedTypeAliasDescriptor $this") - - override val expandedType: SimpleType - get() = owner.expandedType.toKotlinType() as SimpleType - - override val classDescriptor: ClassDescriptor? - get() = expandedType.constructor.declarationDescriptor as ClassDescriptor? - - override fun getOriginal(): TypeAliasDescriptor = this - - override fun isInner(): Boolean = false - - override fun getDeclaredTypeParameters(): List = owner.typeParameters.map { it.descriptor } - - override fun getContainingDeclaration(): DeclarationDescriptor = getContainingDeclaration(owner) - - override fun getName(): Name = owner.name - - override fun getModality(): Modality = Modality.FINAL - - override fun getSource(): SourceElement = SourceElement.NO_SOURCE - - override fun getVisibility(): DescriptorVisibility = owner.visibility - - override fun isExpect(): Boolean = false - - override fun isActual(): Boolean = owner.isActual - - override fun isExternal(): Boolean = false - - override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R = - visitor.visitTypeAliasDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor) { - visitor.visitTypeAliasDescriptor(this, null) - } -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -open class WrappedFieldDescriptor : PropertyDescriptor, WrappedDeclarationDescriptor() { - override fun getModality() = if (owner.isFinal) Modality.FINAL else Modality.OPEN - - override fun setOverriddenDescriptors(overriddenDescriptors: MutableCollection) { - TODO("not implemented") - } - - override fun getKind() = CallableMemberDescriptor.Kind.SYNTHESIZED - - override fun getName() = owner.name - - override fun getSource() = SourceElement.NO_SOURCE - - override fun hasSynthesizedParameterNames() = false - - override fun getOverriddenDescriptors(): MutableCollection = mutableListOf() - - override fun copy( - newOwner: DeclarationDescriptor?, - modality: Modality?, - visibility: DescriptorVisibility?, - kind: CallableMemberDescriptor.Kind?, - copyOverrides: Boolean - ): CallableMemberDescriptor { - TODO("not implemented") - } - - override fun getValueParameters(): MutableList = mutableListOf() - - override fun getCompileTimeInitializer(): ConstantValue<*>? { - TODO("not implemented") - } - - override fun isSetterProjectedOut(): Boolean { - TODO("not implemented") - } - - override fun getAccessors(): MutableList = mutableListOf() - - override fun getTypeParameters(): List = emptyList() - - override fun getVisibility() = owner.visibility - - override val setter: PropertySetterDescriptor? get() = null - - override fun getOriginal() = this - - override fun isExpect() = false - - override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor = - throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") - - override fun isActual() = false - - override fun getReturnType() = owner.type.toKotlinType() - - override fun hasStableParameterNames(): Boolean { - TODO("not implemented") - } - - override fun getType(): KotlinType = owner.type.toKotlinType() - - override fun isVar() = !owner.isFinal - - override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = - if (owner.isStatic) null else (owner.parentAsClass.thisReceiver?.descriptor as ReceiverParameterDescriptor) - - override fun isConst() = false - - override fun getContainingDeclaration() = (owner.parent as IrSymbolOwner).symbol.descriptor - - override fun isLateInit() = owner.correspondingPropertySymbol?.owner?.isLateinit ?: false - - override fun getExtensionReceiverParameter(): ReceiverParameterDescriptor? = - owner.correspondingPropertySymbol?.owner?.descriptor?.extensionReceiverParameter - - override fun isExternal() = owner.isExternal - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D) = - visitor!!.visitPropertyDescriptor(this, data) - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - visitor!!.visitPropertyDescriptor(this, null) - } - - override val getter: PropertyGetterDescriptor? get() = null - - override fun newCopyBuilder(): CallableMemberDescriptor.CopyBuilder { - TODO("not implemented") - } - - override val isDelegated get() = false - - // Following functions are used in error reporting when rendering annotations on properties - override fun getBackingField(): FieldDescriptor? = null // TODO - override fun getDelegateField(): FieldDescriptor? = null // TODO - - override fun getUserData(key: CallableDescriptor.UserDataKey?): V? = null -} - -class WrappedErrorDescriptor : WrappedDeclarationDescriptor() { - override fun getName(): Name = error("WrappedErrorDescriptor.getName: Should not be reached") - - override fun getOriginal(): DeclarationDescriptorWithSource = - error("WrappedErrorDescriptor.getOriginal: Should not be reached") - - override fun getContainingDeclaration(): DeclarationDescriptor? = - error("WrappedErrorDescriptor.getContainingDeclaration: Should not be reached") - - override fun accept(visitor: DeclarationDescriptorVisitor?, data: D): R { - error("WrappedErrorDescriptor.accept: Should not be reached") - } - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) { - } - -} - -@OptIn(ObsoleteDescriptorBasedAPI::class) -private fun getContainingDeclaration(declaration: IrDeclarationWithName): DeclarationDescriptor { - val parent = declaration.parent - val parentDescriptor = (parent as IrSymbolOwner).symbol.descriptor - return if (parent is IrClass && parent.isFileClass) { - // JVM IR adds facade classes for IR of functions/properties loaded both from sources and dependencies. However, these shouldn't - // exist in the descriptor hierarchy, since this is what the old backend (dealing with descriptors) expects. - parentDescriptor.containingDeclaration!! - } else { - parentDescriptor - } -} 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 f9df09539f2..ad023bbf91d 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 @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.ir.symbols.impl import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock import org.jetbrains.kotlin.ir.symbols.* @@ -52,8 +51,8 @@ abstract class IrBindableSymbolBase) { - val containingDeclaration = descriptor?.containingDeclaration + if (descriptor != null) { + val containingDeclaration = descriptor.containingDeclaration assert(containingDeclaration == null || isOriginalDescriptor(containingDeclaration)) { "Substituted containing declaration: $containingDeclaration\nfor descriptor: $descriptor" } @@ -61,9 +60,8 @@ abstract class IrBindableSymbolBase || - // TODO fix declaring/referencing value parameters: compute proper original descriptor - descriptor is ValueParameterDescriptor && isOriginalDescriptor(descriptor.containingDeclaration) || + // TODO fix declaring/referencing value parameters: compute proper original descriptor + descriptor is ValueParameterDescriptor && isOriginalDescriptor(descriptor.containingDeclaration) || descriptor == descriptor.original private var _owner: B? = null @@ -132,7 +130,7 @@ class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor? = null) : IrBindableSymbolBase(descriptor), IrConstructorSymbol -class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) : +class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor? = null) : IrBindableSymbolBase(descriptor), IrReturnableBlockSymbol 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 c9798905aa4..1c842fbf547 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 @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.ir.symbols.impl import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.util.IdSignature @@ -44,15 +43,13 @@ abstract class IrBindablePublicSymbolBase || - // TODO fix declaring/referencing value parameters: compute proper original descriptor - descriptor is ValueParameterDescriptor && isOriginalDescriptor(descriptor.containingDeclaration) || + // TODO fix declaring/referencing value parameters: compute proper original descriptor + descriptor is ValueParameterDescriptor && isOriginalDescriptor(descriptor.containingDeclaration) || descriptor == descriptor.original private var _owner: B? = null 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) { if (_owner == null) { 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 4d9d464a383..88ce9378197 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 @@ -74,10 +74,12 @@ class DeclarationStubGenerator( override fun getDeclaration(symbol: IrSymbol): IrDeclaration? { // Special case: generating field for an already generated property. - if (symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true) { - return generateStubBySymbol(symbol, symbol.descriptor) - } - val descriptor = if (!symbol.hasDescriptor || symbol.descriptor is WrappedDeclarationDescriptor<*>) + // -- this used to be done via a trick (ab)using WrappedDescriptors. Not clear if this code should ever be invoked, + // and if so, how it can be reproduced without them. +// if (symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true) { +// return generateStubBySymbol(symbol, symbol.descriptor) +// } + val descriptor = if (!symbol.hasDescriptor) findDescriptorBySignature( symbol.signature ?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}") @@ -85,9 +87,7 @@ class DeclarationStubGenerator( else symbol.descriptor if (descriptor == null) return null - return generateStubBySymbol(symbol, descriptor).also { - symbol.descriptor.bind(it) - } + return generateStubBySymbol(symbol, descriptor) } fun generateOrGetEmptyExternalPackageFragmentStub(descriptor: PackageFragmentDescriptor): IrExternalPackageFragment { @@ -377,22 +377,4 @@ class DeclarationStubGenerator( } return candidates.firstOrNull { symbolTable.signaturer.composeSignature(it) == signature } } - - private fun DeclarationDescriptor.bind(declaration: IrDeclaration) { - when (this) { - is WrappedValueParameterDescriptor -> bind(declaration as IrValueParameter) - is WrappedReceiverParameterDescriptor -> bind(declaration as IrValueParameter) - is WrappedTypeParameterDescriptor -> bind(declaration as IrTypeParameter) - is WrappedVariableDescriptor -> bind(declaration as IrVariable) - is WrappedVariableDescriptorWithAccessor -> bind(declaration as IrLocalDelegatedProperty) - is WrappedSimpleFunctionDescriptor -> bind(declaration as IrSimpleFunction) - is WrappedClassConstructorDescriptor -> bind(declaration as IrConstructor) - is WrappedClassDescriptor -> bind(declaration as IrClass) - is WrappedEnumEntryDescriptor -> bind(declaration as IrEnumEntry) - is WrappedPropertyDescriptor -> (declaration as? IrProperty)?.let { bind(it) } - is WrappedTypeAliasDescriptor -> bind(declaration as IrTypeAlias) - is WrappedFieldDescriptor -> bind(declaration as IrField) - else -> {} - } - } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt index 9fb87ab940b..671a132170b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.ir.util -import org.jetbrains.kotlin.descriptors.ScriptDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI @@ -15,7 +14,6 @@ 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.IrAnonymousInitializerSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrScriptSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt index f37a0ad690a..98ca0ad4909 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt @@ -159,7 +159,7 @@ open class DeepCopySymbolRemapper( override fun visitBlock(expression: IrBlock) { if (expression is IrReturnableBlock) { remapSymbol(returnableBlocks, expression) { - IrReturnableBlockSymbolImpl(expression.descriptor) + IrReturnableBlockSymbolImpl() } } expression.acceptChildrenVoid(this) 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 f03ce87f68e..f7186dd703c 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 @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl import org.jetbrains.kotlin.ir.declarations.impl.IrScriptImpl import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable -import org.jetbrains.kotlin.ir.descriptors.* import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.* @@ -20,7 +19,6 @@ import org.jetbrains.kotlin.ir.symbols.impl.* import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource interface ReferenceSymbolTable { fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol @@ -184,20 +182,11 @@ class SymbolTable( protected open fun signature(descriptor: D): IdSignature? = signaturer.composeSignature(descriptor) override fun get(d: D): S? { - return if (d !is WrappedDeclarationDescriptor<*>) { - val sig = signature(d) - if (sig != null) { - idSigToSymbol[sig] - } else { - descriptorToSymbol[d] - } + val sig = signature(d) + return if (sig != null) { + idSigToSymbol[sig] } else { - if (d.isBound()) { - @Suppress("UNCHECKED_CAST") - d.owner.symbol as S - } else { - descriptorToSymbol[d] - } + descriptorToSymbol[d] } } @@ -236,13 +225,9 @@ class SymbolTable( } operator fun get(d: D): S? { - return if (d !is WrappedDeclarationDescriptor<*>) { - val sig = signaturer.composeSignature(d) - if (sig != null) { - getByIdSignature(sig) - } else { - getByDescriptor(d) - } + val sig = signaturer.composeSignature(d) + return if (sig != null) { + getByIdSignature(sig) } else { getByDescriptor(d) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/originalDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/originalDescriptors.kt index 9dceb95f7e5..69c954d2d74 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/originalDescriptors.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/originalDescriptors.kt @@ -9,11 +9,10 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.ir.descriptors.IrBasedTypeParameterDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedTypeParameterDescriptor val TypeParameterDescriptor.originalTypeParameter: TypeParameterDescriptor get() = - if (this is WrappedTypeParameterDescriptor || this is IrBasedTypeParameterDescriptor) { + if (this is IrBasedTypeParameterDescriptor) { original } else { when (val container = containingDeclaration.original) { 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 7302170b9ca..dccd507249f 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 @@ -1046,9 +1046,6 @@ abstract class IrFileDeserializer( ).apply { if (proto.hasDefaultValue()) defaultValue = irFactory.createExpressionBody(deserializeExpressionBody(proto.defaultValue)) - - (descriptor as? WrappedValueParameterDescriptor)?.bind(this) - (descriptor as? WrappedReceiverParameterDescriptor)?.bind(this) } } @@ -1110,9 +1107,7 @@ abstract class IrFileDeserializer( private fun deserializeErrorDeclaration(proto: ProtoErrorDeclaration): IrErrorDeclaration { require(allowErrorNodes) { "IrErrorDeclaration found but error code is not allowed" } val coordinates = BinaryCoordinates.decode(proto.coordinates) - val descriptor = WrappedErrorDescriptor() - return irFactory.createErrorDeclaration(coordinates.startOffset, coordinates.endOffset, descriptor).also { - descriptor.bind(it) + return irFactory.createErrorDeclaration(coordinates.startOffset, coordinates.endOffset).also { it.parent = parentsStack.peek()!! } } @@ -1241,8 +1236,6 @@ abstract class IrFileDeserializer( ) }.apply { overriddenSymbols = proto.overriddenList.map { deserializeIrSymbolAndRemap(it) as IrSimpleFunctionSymbol } - - (descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this) } } } @@ -1262,8 +1255,6 @@ abstract class IrFileDeserializer( ).apply { if (proto.hasInitializer()) initializer = deserializeExpression(proto.initializer) - - (descriptor as? WrappedVariableDescriptor)?.bind(this) } } @@ -1350,8 +1341,6 @@ abstract class IrFileDeserializer( getter = deserializeIrFunction(proto.getter) if (proto.hasSetter()) setter = deserializeIrFunction(proto.setter) - - (descriptor as? WrappedVariableDescriptorWithAccessor)?.bind(this) } } @@ -1387,17 +1376,9 @@ abstract class IrFileDeserializer( } if (proto.hasBackingField()) { backingField = deserializeIrField(proto.backingField).also { - // A property symbol and its field symbol share the same descriptor. - // Unfortunately symbol deserialization doesn't know anything about that. - // So we can end up with two wrapped property descriptors for property and its field. - // In that case we need to bind the field's one here. - if (descriptor != it.descriptor) - (it.descriptor as? WrappedPropertyDescriptor)?.bind(this) it.correspondingPropertySymbol = symbol } } - - (descriptor as? WrappedPropertyDescriptor)?.bind(this) } } diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt index 44d3fe1f054..434cae774d3 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrModuleDeserializer.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns -import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.util.IdSignature import org.jetbrains.kotlin.library.IrLibrary @@ -42,7 +41,7 @@ abstract class IrModuleDeserializer(val moduleDescriptor: ModuleDescriptor) { open fun declareIrSymbol(symbol: IrSymbol) { val signature = symbol.signature require(signature != null) { "Symbol is not public API: ${symbol.descriptor}" } - assert(symbol.descriptor !is WrappedDeclarationDescriptor<*>) + assert(symbol.hasDescriptor) deserializeIrSymbol(signature, symbol.kind()) } @@ -69,7 +68,7 @@ abstract class IrModuleDeserializer(val moduleDescriptor: ModuleDescriptor) { // Used to resolve built in symbols like `kotlin.ir.internal.*` or `kotlin.FunctionN` class IrModuleDeserializerWithBuiltIns( - private val builtIns: IrBuiltIns, + builtIns: IrBuiltIns, private val functionFactory: IrAbstractFunctionFactory, private val delegate: IrModuleDeserializer ) : IrModuleDeserializer(delegate.moduleDescriptor) { 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 467afb94473..62574d45b92 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 @@ -556,8 +556,6 @@ abstract class KotlinIrLinker( if (!symbol.hasDescriptor) return null val descriptor = symbol.descriptor - - if (descriptor is WrappedDeclarationDescriptor<*>) return null if (descriptor is CallableMemberDescriptor) { if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { // skip fake overrides @@ -578,7 +576,6 @@ abstract class KotlinIrLinker( if (!symbol.isPublicApi) { val descriptor = symbol.descriptor - if (descriptor is WrappedDeclarationDescriptor<*>) return null if (!platformSpecificSymbol(symbol)) { if (descriptor.module !== currentModule) return null } diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/signature/IdSignatureDescriptor.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/signature/IdSignatureDescriptor.kt index c97fcfef86a..059f80b18bf 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/signature/IdSignatureDescriptor.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/signature/IdSignatureDescriptor.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.backend.common.serialization.signature import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor import org.jetbrains.kotlin.ir.util.IdSignature import org.jetbrains.kotlin.ir.util.IdSignatureComposer import org.jetbrains.kotlin.ir.util.KotlinMangler @@ -109,14 +108,12 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa private val composer by lazy { createSignatureBuilder() } override fun composeSignature(descriptor: DeclarationDescriptor): IdSignature? { - if (descriptor is WrappedDeclarationDescriptor<*>) return null return if (mangler.run { descriptor.isExported() }) { composer.buildSignature(descriptor) } else null } override fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? { - if (descriptor is WrappedDeclarationDescriptor<*>) return null return if (mangler.run { descriptor.isExportEnumEntry() }) { composer.buildSignature(descriptor) } else null diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt index b3140b4e942..9e424ed2334 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/ir/ComposeLikeGenerationExtension.kt @@ -31,7 +31,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol @@ -149,12 +148,11 @@ class ComposeLikeDefaultArgumentRewriter( declaration.valueParameters.forEach { param -> newParameters.add( if (param.defaultValue != null) { - val descriptor = WrappedValueParameterDescriptor() val result = IrValueParameterImpl( param.startOffset, param.endOffset, param.origin, - IrValueParameterSymbolImpl(descriptor), + IrValueParameterSymbolImpl(), param.name, index = param.index, type = defaultParameterType(param), @@ -167,7 +165,6 @@ class ComposeLikeDefaultArgumentRewriter( it.defaultValue = param.defaultValue it.parent = declaration } - descriptor.bind(result) parameterMapping[param] = result result } else param