[IR] Extract descriptor part from SymbolTable into separate component

After this change SymbolTable (and ReferenceSymbolTable) contains only
  methods with IdSignatures. All descriptors-related methods are moved
  into DescriptorSymbolTableExtension, which automatically delegates to
  the SymbolTable if needed

At this moment there are cross-references between SymbolTable, because
  descriptor API is still actively used across backends. So SymbolTable
  is accessible in some place then descriptor extension will be accessible
  too

DescriptorSymbolTableExtension is an implementation of abstract SymbolTableExtension
  which allows to implement different kinds of storages, e.g. FIR based
  (it probably will be needed for FIR2IR)
This commit is contained in:
Dmitriy Novozhilov
2023-07-07 10:37:08 +03:00
committed by Space Team
parent 0067eb85da
commit 4986cb14aa
30 changed files with 2117 additions and 1040 deletions
@@ -371,7 +371,7 @@ internal class BuiltInFictitiousFunctionIrClassFactory(
isExpect = descriptor.isExpect,
isFakeOverride = true)
}
val property = symbolTable.declareProperty(offset, offset, memberOrigin, descriptor, propertyFactory = propertyDeclare)
val property = symbolTable.declareProperty(descriptor, propertyFactory = propertyDeclare)
property.parent = this
property.getter = descriptor.getter?.let { g -> createFakeOverrideFunction(g, property.symbol) }
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
import org.jetbrains.kotlin.fir.pipeline.convertToIrAndActualize
import org.jetbrains.kotlin.fir.signaturer.Ir2FirManglerAdapter
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
@@ -103,8 +104,9 @@ internal fun PhaseContext.fir2Ir(
"`${irModuleFragment.name}` must be Name.special, since it's required by KlibMetadataModuleDescriptorFactoryImpl.createDescriptorOptionalBuiltIns()"
}
@OptIn(ObsoleteDescriptorBasedAPI::class)
val usedPackages = buildSet {
components.symbolTable.forEachDeclarationSymbol {
components.symbolTable.descriptorExtension.forEachDeclarationSymbol {
val p = it.owner as? IrDeclaration ?: return@forEachDeclarationSymbol
val fragment = (p.getPackageFragment() as? IrExternalPackageFragment) ?: return@forEachDeclarationSymbol
add(fragment.packageFqName)
@@ -94,7 +94,7 @@ internal interface DescriptorToIrTranslationMixin {
}
}
irConstructor.valueParameters += constructorDescriptor.valueParameters.map { valueParameterDescriptor ->
symbolTable.declareValueParameter(
symbolTable.descriptorExtension.declareValueParameter(
SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.DEFINED,
valueParameterDescriptor,
valueParameterDescriptor.type.toIrType()).also {
@@ -127,10 +127,10 @@ internal interface DescriptorToIrTranslationMixin {
symbolTable.withScope(irFunction) {
irFunction.returnType = functionDescriptor.returnType!!.toIrType()
irFunction.valueParameters += functionDescriptor.valueParameters.map {
symbolTable.declareValueParameter(SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.DEFINED, it, it.type.toIrType())
symbolTable.descriptorExtension.declareValueParameter(SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.DEFINED, it, it.type.toIrType())
}
irFunction.dispatchReceiverParameter = functionDescriptor.dispatchReceiverParameter?.let {
symbolTable.declareValueParameter(SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.DEFINED, it, it.type.toIrType())
symbolTable.descriptorExtension.declareValueParameter(SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.DEFINED, it, it.type.toIrType())
}
irFunction.generateAnnotations()
}
@@ -182,4 +182,4 @@ internal fun IrSymbol.findCStructDescriptor(): ClassDescriptor? =
internal fun DeclarationDescriptor.findCStructDescriptor(): ClassDescriptor? =
parentsWithSelf.filterIsInstance<ClassDescriptor>().firstOrNull {
it.inheritsFromCStructVar() || it.annotations.hasAnnotation(RuntimeNames.managedType)
}
}
@@ -96,7 +96,7 @@ internal class CEnumClassGenerator(
?: error("No `value` property in ${irClass.name}")
val irProperty = createProperty(propertyDescriptor)
symbolTable.withScope(irProperty) {
irProperty.backingField = symbolTable.declareField(
irProperty.backingField = symbolTable.descriptorExtension.declareField(
SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
propertyDescriptor, propertyDescriptor.type.toIrType(), DescriptorVisibilities.PRIVATE
).also {
@@ -148,7 +148,7 @@ internal class CStructVarClassGenerator(
val managedValType = managedVal.getter!!.returnType
managedVal.backingField = symbolTable.declareField(
managedVal.backingField = symbolTable.descriptorExtension.declareField(
SYNTHETIC_OFFSET,
SYNTHETIC_OFFSET,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,