diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ExternalPackageParentPatcher.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ExternalPackageParentPatcher.kt new file mode 100644 index 00000000000..274b3a2069d --- /dev/null +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ExternalPackageParentPatcher.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2020 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.fir.backend + +import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator +import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid +import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid + +// TODO: could be a lowering +internal class ExternalPackageParentPatcher(private val stubGenerator: DeclarationStubGenerator) : IrElementVisitorVoid { + override fun visitElement(element: IrElement) { + element.acceptChildrenVoid(this) + } + + override fun visitMemberAccess(expression: IrMemberAccessExpression<*>) { + super.visitMemberAccess(expression) + val callee = expression.symbol.owner as? IrDeclaration ?: return + if (callee.parent is IrExternalPackageFragment) { + @OptIn(ObsoleteDescriptorBasedAPI::class) + val parentClass = stubGenerator.generateOrGetFacadeClass(callee.descriptor) ?: return + callee.parent = parentClass + when (callee) { + is IrProperty -> handleProperty(callee, parentClass) + is IrSimpleFunction -> callee.correspondingPropertySymbol?.owner?.let { handleProperty(it, parentClass) } + } + } + } + + private fun handleProperty(property: IrProperty, newParent: IrClass) { + property.parent = newParent + property.getter?.parent = newParent + property.setter?.parent = newParent + property.backingField?.parent = newParent + } +} \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt index 47d67dad90b..3b8ba3a879a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt @@ -21,15 +21,15 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedEnumEntryDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedTypeAliasDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedTypeParameterDescriptor import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrEnumEntrySymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrTypeAliasSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.util.IdSignature @@ -177,13 +177,11 @@ class Fir2IrClassifierStorage( return irClass } - private fun declareIrTypeAlias(signature: IdSignature?, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias { - if (signature == null) { - val descriptor = WrappedTypeAliasDescriptor() - return symbolTable.declareTypeAlias(descriptor, factory).apply { descriptor.bind(this) } - } - return symbolTable.declareTypeAlias(signature, { Fir2IrTypeAliasSymbol(signature) }, factory) - } + private fun declareIrTypeAlias(signature: IdSignature?, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias = + if (signature == null) + factory(IrTypeAliasSymbolImpl()) + else + symbolTable.declareTypeAlias(signature, { Fir2IrTypeAliasSymbol(signature) }, factory) fun registerTypeAlias( typeAlias: FirTypeAlias, @@ -211,13 +209,11 @@ class Fir2IrClassifierStorage( internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias] - private fun declareIrClass(signature: IdSignature?, factory: (IrClassSymbol) -> IrClass): IrClass { - if (signature == null) { - val descriptor = WrappedClassDescriptor() - return symbolTable.declareClass(descriptor, factory).apply { descriptor.bind(this) } - } - return symbolTable.declareClass(signature, { Fir2IrClassSymbol(signature) }, factory) - } + private fun declareIrClass(signature: IdSignature?, factory: (IrClassSymbol) -> IrClass): IrClass = + if (signature == null) + factory(IrClassSymbolImpl()) + else + symbolTable.declareClass(signature, { Fir2IrClassSymbol(signature) }, factory) fun registerIrClass( regularClass: FirRegularClass, @@ -305,20 +301,15 @@ class Fir2IrClassifierStorage( typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT ): IrTypeParameter { require(index >= 0) - val descriptor = WrappedTypeParameterDescriptor() val origin = IrDeclarationOrigin.DEFINED val irTypeParameter = with(typeParameter) { convertWithOffsets { startOffset, endOffset -> - symbolTable.declareGlobalTypeParameter(startOffset, endOffset, origin, descriptor) { symbol -> - irFactory.createTypeParameter( - startOffset, endOffset, origin, symbol, - name, if (index < 0) 0 else index, - isReified, - variance - ).apply { - descriptor.bind(this) - } - } + irFactory.createTypeParameter( + startOffset, endOffset, origin, IrTypeParameterSymbolImpl(), + name, if (index < 0) 0 else index, + isReified, + variance + ) } } @@ -375,13 +366,11 @@ class Fir2IrClassifierStorage( internal fun getCachedIrEnumEntry(enumEntry: FirEnumEntry): IrEnumEntry? = enumEntryCache[enumEntry] - private fun declareIrEnumEntry(signature: IdSignature?, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry { - if (signature == null) { - val descriptor = WrappedEnumEntryDescriptor() - return symbolTable.declareEnumEntry(0, 0, IrDeclarationOrigin.DEFINED, descriptor, factory).apply { descriptor.bind(this) } - } - return symbolTable.declareEnumEntry(signature, { Fir2IrEnumEntrySymbol(signature) }, factory) - } + private fun declareIrEnumEntry(signature: IdSignature?, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry = + if (signature == null) + factory(IrEnumEntrySymbolImpl()) + else + symbolTable.declareEnumEntry(signature, { Fir2IrEnumEntrySymbol(signature) }, factory) fun createIrEnumEntry( enumEntry: FirEnumEntry, diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index 00f385371b7..58134b80893 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -22,8 +22,8 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns -import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi2ir.PsiSourceManager @@ -318,14 +318,7 @@ class Fir2IrConverter( externalDependenciesGenerator.generateUnboundSymbolsAsDependencies() val stubGenerator = irProviders.filterIsInstance().first() - for (descriptor in symbolTable.wrappedTopLevelCallableDescriptors()) { - val parentClass = stubGenerator.generateOrGetFacadeClass(descriptor as WrappedDeclarationDescriptor<*>) - val owner = descriptor.owner - owner.parent = parentClass ?: continue - if (owner is IrProperty) { - owner.backingField?.parent = parentClass - } - } + irModuleFragment.acceptVoid(ExternalPackageParentPatcher(stubGenerator)) evaluateConstants(irModuleFragment) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 9dbdbebf48e..f2b35fd9b4c 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -44,6 +44,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrSyntheticBodyKind import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl import org.jetbrains.kotlin.ir.symbols.* +import org.jetbrains.kotlin.ir.symbols.impl.* import org.jetbrains.kotlin.ir.types.IrErrorType import org.jetbrains.kotlin.ir.types.IrSimpleType import org.jetbrains.kotlin.ir.types.IrType @@ -264,20 +265,14 @@ class Fir2IrDeclarationStorage( type: IrType, parent: IrFunction ): IrValueParameter { - val descriptor = WrappedValueParameterDescriptor() - return symbolTable.declareValueParameter( - startOffset, endOffset, origin, descriptor, type - ) { symbol -> - irFactory.createValueParameter( - startOffset, endOffset, IrDeclarationOrigin.DEFINED, symbol, - Name.special(""), 0, type, - varargElementType = null, - isCrossinline = false, isNoinline = false, - isHidden = false, isAssignable = false - ).apply { - this.parent = parent - descriptor.bind(this) - } + return irFactory.createValueParameter( + startOffset, endOffset, IrDeclarationOrigin.DEFINED, IrValueParameterSymbolImpl(), + Name.special(""), 0, type, + varargElementType = null, + isCrossinline = false, isNoinline = false, + isHidden = false, isAssignable = false + ).apply { + this.parent = parent } } @@ -404,13 +399,12 @@ class Fir2IrDeclarationStorage( signature: IdSignature?, containerSource: DeserializedContainerSource?, factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction - ): IrSimpleFunction { + ): IrSimpleFunction = if (signature == null) { - val descriptor = WrappedSimpleFunctionDescriptor() - return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) } + factory(IrSimpleFunctionSymbolImpl()) + } else { + symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory) } - return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory) - } fun getOrCreateIrFunction( function: FirSimpleFunction, @@ -516,13 +510,12 @@ class Fir2IrDeclarationStorage( } } - private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor { - if (signature == null) { - val descriptor = WrappedClassConstructorDescriptor() - return symbolTable.declareConstructor(descriptor, factory).apply { descriptor.bind(this) } - } - return symbolTable.declareConstructor(signature, { Fir2IrConstructorSymbol(signature) }, factory) - } + private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor = + if (signature == null) + factory(IrConstructorSymbolImpl()) + else + symbolTable.declareConstructor(signature, { Fir2IrConstructorSymbol(signature) }, factory) + fun createIrConstructor( constructor: FirConstructor, @@ -555,17 +548,12 @@ class Fir2IrDeclarationStorage( private fun declareIrAccessor( signature: IdSignature?, containerSource: DeserializedContainerSource?, - isGetter: Boolean, factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction - ): IrSimpleFunction { - if (signature == null) { - val descriptor = - if (isGetter) WrappedPropertyGetterDescriptor() - else WrappedPropertySetterDescriptor() - return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) } - } - return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory) - } + ): IrSimpleFunction = + if (signature == null) + factory(IrSimpleFunctionSymbolImpl()) + else + symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory) internal fun createIrPropertyAccessor( propertyAccessor: FirPropertyAccessor?, @@ -586,8 +574,7 @@ class Fir2IrDeclarationStorage( val containerSource = (correspondingProperty as? IrProperty)?.containerSource return declareIrAccessor( signature, - containerSource, - isGetter = !isSetter + containerSource ) { symbol -> val accessorReturnType = if (isSetter) irBuiltIns.unitType else propertyType val visibility = propertyAccessor?.visibility?.let { @@ -685,15 +672,11 @@ class Fir2IrDeclarationStorage( signature: IdSignature?, containerSource: DeserializedContainerSource?, factory: (IrPropertySymbol) -> IrProperty - ): IrProperty { - if (signature == null) { - val descriptor = WrappedPropertyDescriptor() - return symbolTable.declareProperty(0, 0, IrDeclarationOrigin.DEFINED, descriptor, isDelegated = false, factory).apply { - descriptor.bind(this) - } - } - return symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature, containerSource) }, factory) - } + ): IrProperty = + if (signature == null) + factory(IrPropertySymbolImpl()) + else + symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature, containerSource) }, factory) fun getOrCreateIrProperty( property: FirProperty, @@ -859,28 +842,21 @@ class Fir2IrDeclarationStorage( field: FirField, origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB ): IrField { - val descriptor = WrappedFieldDescriptor() val type = field.returnTypeRef.toIrType() return field.convertWithOffsets { startOffset, endOffset -> - symbolTable.declareField( - startOffset, endOffset, - origin, descriptor, type - ) { symbol -> - irFactory.createField( - startOffset, endOffset, origin, symbol, - field.name, type, components.visibilityConverter.convertToDescriptorVisibility(field.visibility), - isFinal = field.modality == Modality.FINAL, - isExternal = false, - isStatic = field.isStatic - ).apply { - field.initializer?.let { - val expression = visitor.convertToIrExpression(it) - expression.type = type - initializer = irFactory.createExpressionBody(expression) - } - descriptor.bind(this) - fieldCache[field] = this + irFactory.createField( + startOffset, endOffset, origin, IrFieldSymbolImpl(), + field.name, type, components.visibilityConverter.convertToDescriptorVisibility(field.visibility), + isFinal = field.modality == Modality.FINAL, + isExternal = false, + isStatic = field.isStatic + ).apply { + field.initializer?.let { + val expression = visitor.convertToIrExpression(it) + expression.type = type + initializer = irFactory.createExpressionBody(expression) } + fieldCache[field] = this } } } @@ -891,33 +867,27 @@ class Fir2IrDeclarationStorage( useStubForDefaultValueStub: Boolean = true, typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT ): IrValueParameter { - val descriptor = WrappedValueParameterDescriptor() val origin = IrDeclarationOrigin.DEFINED val type = valueParameter.returnTypeRef.toIrType() val irParameter = valueParameter.convertWithOffsets { startOffset, endOffset -> - symbolTable.declareValueParameter( - startOffset, endOffset, origin, descriptor, type - ) { symbol -> - irFactory.createValueParameter( - startOffset, endOffset, origin, symbol, - valueParameter.name, index, type, - if (!valueParameter.isVararg) null - else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext), - isCrossinline = valueParameter.isCrossinline, isNoinline = valueParameter.isNoinline, - isHidden = false, isAssignable = false - ).apply { - descriptor.bind(this) - if (valueParameter.defaultValue.let { - it != null && (useStubForDefaultValueStub || it !is FirExpressionStub) - } - ) { - this.defaultValue = factory.createExpressionBody( - IrErrorExpressionImpl( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, - "Stub expression for default value of ${valueParameter.name}" - ) - ) + irFactory.createValueParameter( + startOffset, endOffset, origin, IrValueParameterSymbolImpl(), + valueParameter.name, index, type, + if (!valueParameter.isVararg) null + else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext), + isCrossinline = valueParameter.isCrossinline, isNoinline = valueParameter.isNoinline, + isHidden = false, isAssignable = false + ).apply { + if (valueParameter.defaultValue.let { + it != null && (useStubForDefaultValueStub || it !is FirExpressionStub) } + ) { + this.defaultValue = factory.createExpressionBody( + IrErrorExpressionImpl( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, + "Stub expression for default value of ${valueParameter.name}" + ) + ) } } } @@ -937,17 +907,11 @@ class Fir2IrDeclarationStorage( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, name: Name, type: IrType, isVar: Boolean, isConst: Boolean, isLateinit: Boolean - ): IrVariable { - val descriptor = WrappedVariableDescriptor() - return symbolTable.declareVariable(startOffset, endOffset, origin, descriptor, type) { symbol -> - IrVariableImpl( - startOffset, endOffset, origin, symbol, name, type, - isVar, isConst, isLateinit - ).apply { - descriptor.bind(this) - } - } - } + ): IrVariable = + IrVariableImpl( + startOffset, endOffset, origin, IrVariableSymbolImpl(), name, type, + isVar, isConst, isLateinit + ) fun createIrVariable(variable: FirVariable<*>, irParent: IrDeclarationParent, givenOrigin: IrDeclarationOrigin? = null): IrVariable { val type = variable.returnTypeRef.toIrType() @@ -974,12 +938,15 @@ class Fir2IrDeclarationStorage( val type = property.returnTypeRef.toIrType() val origin = IrDeclarationOrigin.DEFINED val irProperty = property.convertWithOffsets { startOffset, endOffset -> - val descriptor = WrappedVariableDescriptorWithAccessor() - symbolTable.declareLocalDelegatedProperty(startOffset, endOffset, origin, descriptor, type) { - irFactory.createLocalDelegatedProperty(startOffset, endOffset, origin, it, property.name, type, property.isVar).apply { - descriptor.bind(this) - } - } + irFactory.createLocalDelegatedProperty( + startOffset, + endOffset, + origin, + IrLocalDelegatedPropertySymbolImpl(), + property.name, + type, + property.isVar + ) }.apply { parent = irParent metadata = FirMetadataSource.Property(property) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt index 79e66bca164..4633c6c2675 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt @@ -20,8 +20,6 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrBlock import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrGetValue @@ -30,6 +28,8 @@ 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.impl.IrSimpleFunctionSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrSimpleType import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.isUnit @@ -187,59 +187,55 @@ internal class AdapterGenerator( ): IrSimpleFunction { val returnType = type.arguments.last().typeOrNull!! val parameterTypes = type.arguments.dropLast(1).map { it.typeOrNull!! } - val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor() - return symbolTable.declareSimpleFunction(adapterFunctionDescriptor) { irAdapterSymbol -> - irFactory.createFunction( - startOffset, endOffset, - IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE, - irAdapterSymbol, - adaptee.name, - DescriptorVisibilities.LOCAL, - Modality.FINAL, - returnType, - isInline = firAdaptee.isInline, - isExternal = firAdaptee.isExternal, - isTailrec = firAdaptee.isTailRec, - isSuspend = firAdaptee.isSuspend || type.isSuspendFunction(), - isOperator = firAdaptee.isOperator, - isInfix = firAdaptee.isInfix, - isExpect = firAdaptee.isExpect, - isFakeOverride = false - ).also { irAdapterFunction -> - adapterFunctionDescriptor.bind(irAdapterFunction) - irAdapterFunction.metadata = FirMetadataSource.Function(firAdaptee) + return irFactory.createFunction( + startOffset, endOffset, + IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE, + IrSimpleFunctionSymbolImpl(), + adaptee.name, + DescriptorVisibilities.LOCAL, + Modality.FINAL, + returnType, + isInline = firAdaptee.isInline, + isExternal = firAdaptee.isExternal, + isTailrec = firAdaptee.isTailRec, + isSuspend = firAdaptee.isSuspend || type.isSuspendFunction(), + isOperator = firAdaptee.isOperator, + isInfix = firAdaptee.isInfix, + isExpect = firAdaptee.isExpect, + isFakeOverride = false + ).also { irAdapterFunction -> + irAdapterFunction.metadata = FirMetadataSource.Function(firAdaptee) - symbolTable.enterScope(irAdapterFunction) - irAdapterFunction.dispatchReceiverParameter = null - val boundReceiver = boundDispatchReceiver ?: boundExtensionReceiver - when { - boundReceiver == null -> - irAdapterFunction.extensionReceiverParameter = null - boundDispatchReceiver != null && boundExtensionReceiver != null -> - error("Bound callable references can't have both receivers: ${callableReferenceAccess.render()}") - else -> - irAdapterFunction.extensionReceiverParameter = - createAdapterParameter( - irAdapterFunction, - Name.identifier("receiver"), - index = UNDEFINED_PARAMETER_INDEX, - boundReceiver.type, - IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE - ) - } - irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType -> - createAdapterParameter( - irAdapterFunction, - Name.identifier("p$index"), - index, - parameterType, - IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE - ) - } - symbolTable.leaveScope(irAdapterFunction) - - irAdapterFunction.parent = conversionScope.parent()!! + symbolTable.enterScope(irAdapterFunction) + irAdapterFunction.dispatchReceiverParameter = null + val boundReceiver = boundDispatchReceiver ?: boundExtensionReceiver + when { + boundReceiver == null -> + irAdapterFunction.extensionReceiverParameter = null + boundDispatchReceiver != null && boundExtensionReceiver != null -> + error("Bound callable references can't have both receivers: ${callableReferenceAccess.render()}") + else -> + irAdapterFunction.extensionReceiverParameter = + createAdapterParameter( + irAdapterFunction, + Name.identifier("receiver"), + index = UNDEFINED_PARAMETER_INDEX, + boundReceiver.type, + IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE + ) } + irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType -> + createAdapterParameter( + irAdapterFunction, + Name.identifier("p$index"), + index, + parameterType, + IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE + ) + } + symbolTable.leaveScope(irAdapterFunction) + + irAdapterFunction.parent = conversionScope.parent()!! } } @@ -249,31 +245,23 @@ internal class AdapterGenerator( index: Int, type: IrType, origin: IrDeclarationOrigin - ): IrValueParameter { - val startOffset = adapterFunction.startOffset - val endOffset = adapterFunction.endOffset - val descriptor = WrappedValueParameterDescriptor() - return symbolTable.declareValueParameter( - startOffset, endOffset, origin, descriptor, type - ) { irAdapterParameterSymbol -> - irFactory.createValueParameter( - startOffset, endOffset, - origin, - irAdapterParameterSymbol, - name, - index, - type, - varargElementType = null, - isCrossinline = false, - isNoinline = false, - isHidden = false, - isAssignable = false - ).also { irAdapterValueParameter -> - descriptor.bind(irAdapterValueParameter) - irAdapterValueParameter.parent = adapterFunction - } + ): IrValueParameter = + irFactory.createValueParameter( + adapterFunction.startOffset, + adapterFunction.endOffset, + origin, + IrValueParameterSymbolImpl(), + name, + index, + type, + varargElementType = null, + isCrossinline = false, + isNoinline = false, + isHidden = false, + isAssignable = false + ).also { irAdapterValueParameter -> + irAdapterValueParameter.parent = adapterFunction } - } private fun IrValueDeclaration.toIrGetValue(startOffset: Int, endOffset: Int): IrGetValue = IrGetValueImpl(startOffset, endOffset, this.type, this.symbol) @@ -446,55 +434,51 @@ internal class AdapterGenerator( ): IrSimpleFunction { val returnType = type.arguments.last().typeOrNull!! val parameterTypes = type.arguments.dropLast(1).map { it.typeOrNull!! } - val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor() - return symbolTable.declareSimpleFunction(adapterFunctionDescriptor) { irAdapterSymbol -> - irFactory.createFunction( - startOffset, endOffset, - IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION, - irAdapterSymbol, - // TODO: need a better way to avoid name clash - Name.identifier("suspendConversion"), - DescriptorVisibilities.LOCAL, - Modality.FINAL, - returnType, - isInline = false, - isExternal = false, - isTailrec = false, - isSuspend = true, - isOperator = false, - isInfix = false, - isExpect = false, - isFakeOverride = false - ).also { irAdapterFunction -> - adapterFunctionDescriptor.bind(irAdapterFunction) - symbolTable.enterScope(irAdapterFunction) - irAdapterFunction.extensionReceiverParameter = createAdapterParameter( + return irFactory.createFunction( + startOffset, endOffset, + IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION, + IrSimpleFunctionSymbolImpl(), + // TODO: need a better way to avoid name clash + Name.identifier("suspendConversion"), + DescriptorVisibilities.LOCAL, + Modality.FINAL, + returnType, + isInline = false, + isExternal = false, + isTailrec = false, + isSuspend = true, + isOperator = false, + isInfix = false, + isExpect = false, + isFakeOverride = false + ).also { irAdapterFunction -> + symbolTable.enterScope(irAdapterFunction) + irAdapterFunction.extensionReceiverParameter = createAdapterParameter( + irAdapterFunction, + Name.identifier("callee"), + UNDEFINED_PARAMETER_INDEX, + argumentType, + IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION + ) + irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType -> + createAdapterParameter( irAdapterFunction, - Name.identifier("callee"), - UNDEFINED_PARAMETER_INDEX, - argumentType, + Name.identifier("p$index"), + index, + parameterType, IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION ) - irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType -> - createAdapterParameter( - irAdapterFunction, - Name.identifier("p$index"), - index, - parameterType, - IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION - ) - } - irAdapterFunction.body = irFactory.createBlockBody(startOffset, endOffset) { - val irCall = createAdapteeCallForArgument(startOffset, endOffset, irAdapterFunction, invokeSymbol) - if (returnType.isUnit()) { - statements.add(irCall) - } else { - statements.add(IrReturnImpl(startOffset, endOffset, irBuiltIns.nothingType, irAdapterFunction.symbol, irCall)) - } - } - symbolTable.leaveScope(irAdapterFunction) - irAdapterFunction.parent = conversionScope.parent()!! } + irAdapterFunction.body = irFactory.createBlockBody(startOffset, endOffset) { + val irCall = createAdapteeCallForArgument(startOffset, endOffset, irAdapterFunction, invokeSymbol) + if (returnType.isUnit()) { + statements.add(irCall) + } else { + statements.add(IrReturnImpl(startOffset, endOffset, irBuiltIns.nothingType, irAdapterFunction.symbol, irCall)) + } + } + symbolTable.leaveScope(irAdapterFunction) + irAdapterFunction.parent = conversionScope.parent()!! } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt index 2284aa8c562..aa43ea3c266 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt @@ -49,7 +49,6 @@ internal class ClassMemberGenerator( if (irPrimaryConstructor != null) { with(declarationStorage) { enterScope(irPrimaryConstructor) - irPrimaryConstructor.valueParameters.forEach { symbolTable.introduceValueParameter(it) } irPrimaryConstructor.putParametersInScope(primaryConstructor) convertFunctionContent(irPrimaryConstructor, primaryConstructor, containingClass = klass) } @@ -86,7 +85,6 @@ internal class ClassMemberGenerator( // Scope for primary constructor should be entered before class declaration processing with(declarationStorage) { enterScope(irFunction) - irFunction.valueParameters.forEach { symbolTable.introduceValueParameter(it) } irFunction.putParametersInScope(firFunction) } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt index 6e59e9879e3..c928347c9f6 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt @@ -30,8 +30,8 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.IrGeneratorContextBase import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator @@ -98,16 +98,14 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) { } } - fun generateDispatchReceiverParameter(irFunction: IrFunction, valueParameterDescriptor: WrappedValueParameterDescriptor) = + fun generateDispatchReceiverParameter(irFunction: IrFunction) = irFunction.declareThisReceiverParameter( components.symbolTable, irClass.defaultType, origin, UNDEFINED_OFFSET, UNDEFINED_OFFSET - ).apply { - valueParameterDescriptor.bind(this) - } + ) private val FirSimpleFunction.matchesEqualsSignature: Boolean @@ -223,7 +221,6 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) { returnType: IrType, otherParameterNeeded: Boolean = false ): IrFunction { - val thisReceiverDescriptor = WrappedValueParameterDescriptor() val firFunction = buildSimpleFunction { origin = FirDeclarationOrigin.Synthetic this.name = name @@ -273,7 +270,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) { } }.apply { parent = irClass - dispatchReceiverParameter = generateDispatchReceiverParameter(this, thisReceiverDescriptor) + dispatchReceiverParameter = generateDispatchReceiverParameter(this) components.irBuiltIns.anyClass.descriptor.unsubstitutedMemberScope .getContributedFunctions(this.name, NoLookupLocation.FROM_BACKEND) .singleOrNull { function -> function.name == this.name } @@ -283,20 +280,13 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) { } } - private fun createSyntheticIrParameter(irFunction: IrFunction, name: Name, type: IrType, index: Int = 0): IrValueParameter { - val descriptor = WrappedValueParameterDescriptor() - return components.symbolTable.declareValueParameter( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor, type - ) { symbol -> - components.irFactory.createValueParameter( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, symbol, name, index, type, null, - isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false - ) - }.apply { + private fun createSyntheticIrParameter(irFunction: IrFunction, name: Name, type: IrType, index: Int = 0): IrValueParameter = + components.irFactory.createValueParameter( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, IrValueParameterSymbolImpl(), name, index, type, null, + isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false + ).apply { parent = irFunction - descriptor.bind(this) } - } } companion object { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt index b9e07aa0410..2c28c04b4e2 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import kotlin.properties.ReadWriteProperty -interface AbstractFir2IrLazyDeclaration : +interface AbstractFir2IrLazyDeclaration : IrDeclaration, IrDeclarationParent, Fir2IrComponents { val fir: F diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/symbols/Fir2IrBindableSymbol.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/symbols/Fir2IrBindableSymbol.kt index 560b35bda54..21bed117bba 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/symbols/Fir2IrBindableSymbol.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/symbols/Fir2IrBindableSymbol.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.symbols.IrBindableSymbol import org.jetbrains.kotlin.ir.util.IdSignature import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource -abstract class Fir2IrBindableSymbol( +abstract class Fir2IrBindableSymbol( override val signature: IdSignature, private val containerSource: DeserializedContainerSource? = null ) : IrBindableSymbol { @@ -34,31 +34,9 @@ abstract class Fir2IrBindableSymbol WrappedEnumEntryDescriptor().apply { bind(owner) } - is IrClass -> WrappedClassDescriptor().apply { bind(owner) } - is IrConstructor -> WrappedClassConstructorDescriptor().apply { bind(owner) } - is IrSimpleFunction -> when { - owner.name.isSpecial && owner.name.asString().startsWith(GETTER_PREFIX) -> - WrappedPropertyGetterDescriptor() - owner.name.isSpecial && owner.name.asString().startsWith(SETTER_PREFIX) -> - WrappedPropertySetterDescriptor() - else -> - WrappedSimpleFunctionDescriptor() - }.apply { bind(owner) } - is IrVariable -> WrappedVariableDescriptor().apply { bind(owner) } - is IrValueParameter -> WrappedValueParameterDescriptor().apply { bind(owner) } - is IrTypeParameter -> WrappedTypeParameterDescriptor().apply { bind(owner) } - is IrProperty -> WrappedPropertyDescriptor().apply { bind(owner) } - is IrField -> WrappedFieldDescriptor().apply { bind(owner) } - is IrTypeAlias -> WrappedTypeAliasDescriptor().apply { bind(owner) } - else -> throw IllegalStateException("Unsupported owner in Fir2IrBindableSymbol: $owner") - } - + override val descriptor: D @Suppress("UNCHECKED_CAST") - result as D - } + get() = owner.toIrBasedDescriptor() as D @ObsoleteDescriptorBasedAPI override val hasDescriptor: Boolean 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 16d5a30ae20..99a4b43a3e7 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 @@ -11,6 +11,7 @@ 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 import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol @@ -130,7 +131,7 @@ class IrFakeOverrideFunctionImpl( @ObsoleteDescriptorBasedAPI override val descriptor - get() = _symbol?.descriptor ?: WrappedSimpleFunctionDescriptor() + get() = _symbol?.descriptor ?: this.toIrBasedDescriptor() @OptIn(ObsoleteDescriptorBasedAPI::class) override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction { 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 17725e92fe7..d00b6d301ff 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 @@ -22,6 +22,7 @@ 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 import org.jetbrains.kotlin.name.Name @@ -114,7 +115,7 @@ class IrFakeOverridePropertyImpl( @ObsoleteDescriptorBasedAPI override val descriptor - get() = _symbol?.descriptor ?: WrappedPropertyDescriptor() + get() = _symbol?.descriptor ?: this.toIrBasedDescriptor() @OptIn(ObsoleteDescriptorBasedAPI::class) override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty { 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 c512b193050..bfde5aca37f 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,7 +12,9 @@ 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 import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol @@ -236,7 +238,7 @@ internal class PersistentIrFakeOverrideFunction( @ObsoleteDescriptorBasedAPI override val descriptor - get() = _symbol?.descriptor ?: WrappedSimpleFunctionDescriptor() + get() = _symbol?.descriptor ?: this.toIrBasedDescriptor() @OptIn(ObsoleteDescriptorBasedAPI::class) override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction { 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 a88ac15d1b6..9e0fbdd6765 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 @@ -24,6 +24,7 @@ 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 import org.jetbrains.kotlin.name.Name @@ -165,7 +166,7 @@ internal class PersistentIrFakeOverrideProperty( @ObsoleteDescriptorBasedAPI override val descriptor - get() = _symbol?.descriptor ?: WrappedPropertyDescriptor() + get() = _symbol?.descriptor ?: this.toIrBasedDescriptor() @OptIn(ObsoleteDescriptorBasedAPI::class) override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty { 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 988b01e0e34..f03ce87f68e 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,9 +12,7 @@ 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.WrappedDeclarationDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor -import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor +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.* @@ -1046,34 +1044,6 @@ class SymbolTable( throw IllegalArgumentException("Unexpected value descriptor: $value") } - @OptIn(ObsoleteDescriptorBasedAPI::class) - fun wrappedTopLevelCallableDescriptors(): Set { - val result = mutableSetOf() - for (descriptor in simpleFunctionSymbolTable.descriptorToSymbol.keys) { - if (descriptor is WrappedSimpleFunctionDescriptor && descriptor.owner.parent is IrPackageFragment) { - result.add(descriptor) - } - } - for (symbol in simpleFunctionSymbolTable.idSigToSymbol.values) { - val descriptor = symbol.descriptor - if (descriptor is WrappedSimpleFunctionDescriptor && symbol.owner.parent is IrPackageFragment) { - result.add(descriptor) - } - } - for (descriptor in propertySymbolTable.descriptorToSymbol.keys) { - if (descriptor is WrappedPropertyDescriptor && descriptor.owner.parent is IrPackageFragment) { - result.add(descriptor) - } - } - for (symbol in propertySymbolTable.idSigToSymbol.values) { - val descriptor = symbol.descriptor - if (descriptor is WrappedPropertyDescriptor && symbol.owner.parent is IrPackageFragment) { - result.add(descriptor) - } - } - return result - } - private inline fun > FlatSymbolTable.forEachPublicSymbolImpl( block: (IrSymbol) -> Unit ) { 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 e780a8e418c..9dceb95f7e5 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 @@ -8,11 +8,12 @@ package org.jetbrains.kotlin.ir.util 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) { + if (this is WrappedTypeParameterDescriptor || this is IrBasedTypeParameterDescriptor) { original } else { when (val container = containingDeclaration.original) {