[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:
committed by
Space Team
parent
0067eb85da
commit
4986cb14aa
+3
-1
@@ -85,7 +85,9 @@ class IrBuiltInsOverDescriptors(
|
||||
override val operatorsPackageFragment: IrExternalPackageFragment =
|
||||
IrExternalPackageFragmentImpl(symbolTable.referenceExternalPackageFragment(packageFragmentDescriptor), KOTLIN_INTERNAL_IR_FQN)
|
||||
|
||||
private fun ClassDescriptor.toIrSymbol() = symbolTable.referenceClass(this)
|
||||
private fun ClassDescriptor.toIrSymbol(): IrClassSymbol {
|
||||
return symbolTable.referenceClass(this)
|
||||
}
|
||||
private fun KotlinType.toIrType() = typeTranslator.translateType(this)
|
||||
|
||||
private fun defineOperator(
|
||||
|
||||
+2
-2
@@ -200,7 +200,7 @@ class IrDescriptorBasedFunctionFactory(
|
||||
|
||||
override fun typeParameterDescriptor(index: Int, factory: (IrTypeParameterSymbol) -> IrTypeParameter): IrTypeParameterSymbol {
|
||||
val descriptor = classDescriptor.declaredTypeParameters[index]
|
||||
return symbolTable.declareGlobalTypeParameter(offset, offset, classOrigin, descriptor, factory).symbol
|
||||
return symbolTable.descriptorExtension.declareGlobalTypeParameter(descriptor, factory).symbol
|
||||
}
|
||||
|
||||
override fun classReceiverParameterDescriptor(): ReceiverParameterDescriptor {
|
||||
@@ -444,7 +444,7 @@ class IrDescriptorBasedFunctionFactory(
|
||||
}
|
||||
|
||||
fun createFakeOverrideProperty(descriptor: PropertyDescriptor): IrProperty {
|
||||
return symbolTable.declareProperty(offset, offset, memberOrigin, descriptor) {
|
||||
return symbolTable.declareProperty(descriptor) {
|
||||
irFactory.createProperty(
|
||||
startOffset = offset,
|
||||
endOffset = offset,
|
||||
|
||||
@@ -82,7 +82,7 @@ internal class ClassGenerator(
|
||||
it.toIrType()
|
||||
}
|
||||
|
||||
irClass.thisReceiver = context.symbolTable.declareValueParameter(
|
||||
irClass.thisReceiver = context.symbolTable.descriptorExtension.declareValueParameter(
|
||||
startOffset, endOffset,
|
||||
IrDeclarationOrigin.INSTANCE_RECEIVER,
|
||||
classDescriptor.thisAsReceiverParameter,
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
||||
from: List<TypeParameterDescriptor>
|
||||
) {
|
||||
generateTypeParameterDeclarations(irTypeParametersOwner, from) { startOffset, endOffset, typeParameterDescriptor ->
|
||||
context.symbolTable.declareScopedTypeParameter(
|
||||
context.symbolTable.descriptorExtension.declareScopedTypeParameter(
|
||||
startOffset,
|
||||
endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
|
||||
+2
-2
@@ -263,7 +263,7 @@ internal class DelegatedPropertyGenerator(
|
||||
): IrLocalDelegatedProperty {
|
||||
val kPropertyType = getKPropertyTypeForLocalDelegatedProperty(variableDescriptor)
|
||||
|
||||
val irLocalDelegatedProperty = context.symbolTable.declareLocalDelegatedProperty(
|
||||
val irLocalDelegatedProperty = context.symbolTable.descriptorExtension.declareLocalDelegatedProperty(
|
||||
ktProperty.startOffsetSkippingComments, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
|
||||
variableDescriptor,
|
||||
variableDescriptor.type.toIrType()
|
||||
@@ -314,7 +314,7 @@ internal class DelegatedPropertyGenerator(
|
||||
val delegateType = getDelegatedPropertyDelegateType(variableDescriptor, ktDelegate)
|
||||
val delegateDescriptor = createLocalPropertyDelegatedDescriptor(variableDescriptor, delegateType, kPropertyType)
|
||||
|
||||
return context.symbolTable.declareVariable(
|
||||
return context.symbolTable.descriptorExtension.declareVariable(
|
||||
ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||
delegateDescriptor, delegateDescriptor.type.toIrType()
|
||||
).also { irVariable ->
|
||||
|
||||
+1
-1
@@ -434,7 +434,7 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
origin = IrDeclarationOrigin.DESTRUCTURED_OBJECT_PARAMETER
|
||||
}
|
||||
}
|
||||
return context.symbolTable.declareValueParameter(
|
||||
return context.symbolTable.descriptorExtension.declareValueParameter(
|
||||
ktElement?.pureStartOffset ?: irOwnerElement.startOffset,
|
||||
ktElement?.pureEndOffset ?: irOwnerElement.endOffset,
|
||||
origin,
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ internal class PropertyGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
propertyDescriptor: PropertyDescriptor,
|
||||
generateInitializer: (IrField) -> IrExpressionBody?
|
||||
): IrField =
|
||||
context.symbolTable.declareField(
|
||||
context.symbolTable.descriptorExtension.declareField(
|
||||
ktPropertyElement.startOffsetSkippingComments, ktPropertyElement.endOffset,
|
||||
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
|
||||
propertyDescriptor, propertyDescriptor.type.toIrType(),
|
||||
|
||||
+1
-1
@@ -579,7 +579,7 @@ internal class ReflectionReferencesGenerator(statementGenerator: StatementGenera
|
||||
} else null
|
||||
if (!symbol.isBound) {
|
||||
val offset = UNDEFINED_OFFSET
|
||||
context.symbolTable.declareProperty(offset, offset, IrDeclarationOrigin.SYNTHETIC_JAVA_PROPERTY_DELEGATE, descriptor) {
|
||||
context.symbolTable.descriptorExtension.declareProperty(descriptor) {
|
||||
context.irFactory.createProperty(
|
||||
startOffset = offset,
|
||||
endOffset = offset,
|
||||
|
||||
@@ -293,7 +293,7 @@ internal class ScriptGenerator(declarationGenerator: DeclarationGenerator) : Dec
|
||||
}
|
||||
|
||||
private fun ParameterDescriptor.toIrValueParameter(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin) =
|
||||
context.symbolTable.declareValueParameter(
|
||||
context.symbolTable.descriptorExtension.declareValueParameter(
|
||||
startOffset, endOffset, origin,
|
||||
this,
|
||||
type.toIrType(),
|
||||
|
||||
+3
-3
@@ -48,7 +48,7 @@ internal class StandaloneDeclarationGenerator(private val context: GeneratorCont
|
||||
from: List<TypeParameterDescriptor>
|
||||
) {
|
||||
generateTypeParameterDeclarations(irTypeParametersOwner, from) { startOffset, endOffset, typeParameterDescriptor ->
|
||||
symbolTable.declareScopedTypeParameter(startOffset, endOffset, IrDeclarationOrigin.DEFINED, typeParameterDescriptor)
|
||||
symbolTable.descriptorExtension.declareScopedTypeParameter(startOffset, endOffset, IrDeclarationOrigin.DEFINED, typeParameterDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ internal class StandaloneDeclarationGenerator(private val context: GeneratorCont
|
||||
it.toIrType()
|
||||
}
|
||||
|
||||
irClass.thisReceiver = context.symbolTable.declareValueParameter(
|
||||
irClass.thisReceiver = context.symbolTable.descriptorExtension.declareValueParameter(
|
||||
startOffset, endOffset,
|
||||
IrDeclarationOrigin.INSTANCE_RECEIVER,
|
||||
descriptor.thisAsReceiverParameter,
|
||||
@@ -134,7 +134,7 @@ internal class StandaloneDeclarationGenerator(private val context: GeneratorCont
|
||||
}
|
||||
|
||||
protected fun declareParameter(descriptor: ParameterDescriptor, ktElement: KtPureElement?, irOwnerElement: IrElement): IrValueParameter {
|
||||
return symbolTable.declareValueParameter(
|
||||
return symbolTable.descriptorExtension.declareValueParameter(
|
||||
ktElement?.pureStartOffset ?: irOwnerElement.startOffset,
|
||||
ktElement?.pureEndOffset ?: irOwnerElement.endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ internal class TryCatchExpressionGenerator(statementGenerator: StatementGenerato
|
||||
|
||||
val irCatch = IrCatchImpl(
|
||||
ktCatchClause.startOffsetSkippingComments, ktCatchClause.endOffset,
|
||||
context.symbolTable.declareVariable(
|
||||
context.symbolTable.descriptorExtension.declareVariable(
|
||||
ktCatchParameter.startOffsetSkippingComments, ktCatchParameter.endOffset,
|
||||
IrDeclarationOrigin.CATCH_PARAMETER,
|
||||
catchParameterDescriptor, catchParameterDescriptor.type.toIrType()
|
||||
|
||||
+2
-1
@@ -51,6 +51,7 @@ class FragmentCompilerSymbolTableDecorator(
|
||||
return super.referenceValueParameter(descriptor)
|
||||
}
|
||||
|
||||
|
||||
override fun referenceValue(value: ValueDescriptor): IrValueSymbol {
|
||||
val fi = fragmentInfo ?: return super.referenceValue(value)
|
||||
|
||||
@@ -71,4 +72,4 @@ class FragmentCompilerSymbolTableDecorator(
|
||||
|
||||
return super.referenceValue(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -42,7 +42,7 @@ open class FragmentDeclarationGenerator(
|
||||
Modality.FINAL
|
||||
)
|
||||
}.buildWithScope { irClass ->
|
||||
irClass.thisReceiver = context.symbolTable.declareValueParameter(
|
||||
irClass.thisReceiver = context.symbolTable.descriptorExtension.declareValueParameter(
|
||||
startOffset, endOffset,
|
||||
IrDeclarationOrigin.INSTANCE_RECEIVER,
|
||||
classDescriptor.thisAsReceiverParameter,
|
||||
@@ -128,14 +128,14 @@ open class FragmentDeclarationGenerator(
|
||||
// of IR generation. The replacement is delayed because the JVM
|
||||
// specific infrastructure (i.e. "SharedVariableContext") is not yet
|
||||
// instantiated: PSI2IR is kept backend agnostic.
|
||||
return context.symbolTable.declareValueParameter(
|
||||
return context.symbolTable.descriptorExtension.declareValueParameter(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
if (shouldPromoteToSharedVariable(parameterInfo)) IrDeclarationOrigin.SHARED_VARIABLE_IN_EVALUATOR_FRAGMENT else IrDeclarationOrigin.DEFINED,
|
||||
descriptor,
|
||||
descriptor.type.toIrType(),
|
||||
descriptor.varargElementType?.toIrType(),
|
||||
null,
|
||||
name = null,
|
||||
isAssignable = parameterInfo.isLValue
|
||||
)
|
||||
}
|
||||
@@ -157,4 +157,4 @@ open class FragmentDeclarationGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,12 @@ package org.jetbrains.kotlin.ir
|
||||
* However, more correct and universal way is to store all necessary information inside IR elements themselves
|
||||
* and do not use descriptors as some intermediate storage. It's planned to remove all descriptor usages from IR in future.
|
||||
*/
|
||||
@Target(
|
||||
AnnotationTarget.CLASS,
|
||||
AnnotationTarget.PROPERTY,
|
||||
AnnotationTarget.VALUE_PARAMETER,
|
||||
AnnotationTarget.FUNCTION,
|
||||
AnnotationTarget.TYPEALIAS
|
||||
)
|
||||
@RequiresOptIn(message = "Please use IR declaration properties and not its descriptor properties", level = RequiresOptIn.Level.ERROR)
|
||||
annotation class ObsoleteDescriptorBasedAPI
|
||||
annotation class ObsoleteDescriptorBasedAPI
|
||||
|
||||
@@ -141,9 +141,7 @@ abstract class DeclarationStubGenerator(
|
||||
}
|
||||
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareProperty(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original, descriptor.isDelegated
|
||||
) {
|
||||
return symbolTable.descriptorExtension.declareProperty(descriptor.original) {
|
||||
IrLazyProperty(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
@@ -294,7 +292,7 @@ abstract class DeclarationStubGenerator(
|
||||
return referenced.owner
|
||||
}
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareEnumEntry(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||
return symbolTable.declareEnumEntry(descriptor) {
|
||||
IrLazyEnumEntryImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
@@ -309,7 +307,7 @@ abstract class DeclarationStubGenerator(
|
||||
return referenced.owner
|
||||
}
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||
return symbolTable.descriptorExtension.declareGlobalTypeParameter(descriptor) {
|
||||
IrLazyTypeParameter(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
|
||||
+498
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
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.descriptors.IrBasedClassDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
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.utils.threadLocal
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
typealias DescriptorBasedReferenceSymbolTableExtension = ReferenceSymbolTableExtension<
|
||||
ClassDescriptor, TypeAliasDescriptor, ScriptDescriptor, FunctionDescriptor, ClassConstructorDescriptor,
|
||||
PropertyDescriptor, ValueParameterDescriptor, TypeParameterDescriptor
|
||||
>
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
class DescriptorSymbolTableExtension(table: SymbolTable) : SymbolTableExtension<
|
||||
DeclarationDescriptor, ClassDescriptor, TypeAliasDescriptor, ScriptDescriptor, FunctionDescriptor,
|
||||
ClassConstructorDescriptor, PropertyDescriptor, ParameterDescriptor, TypeParameterDescriptor>(table)
|
||||
{
|
||||
private val irFactory: IrFactory
|
||||
get() = table.irFactory
|
||||
|
||||
private val nameProvider: NameProvider
|
||||
get() = table.nameProvider
|
||||
|
||||
private val signatureComposer: IdSignatureComposer
|
||||
get() = table.signaturer
|
||||
|
||||
private val externalPackageFragmentSlice: SymbolTableSlice<PackageFragmentDescriptor, IrExternalPackageFragment, IrExternalPackageFragmentSymbol> = SymbolTableSlice.Flat(lock)
|
||||
|
||||
private val valueParameterSlice: SymbolTableSlice.Scoped<ParameterDescriptor, IrValueParameter, IrValueParameterSymbol> by threadLocal {
|
||||
SymbolTableSlice.Scoped(lock)
|
||||
}
|
||||
|
||||
private val variableSlice: SymbolTableSlice.Scoped<VariableDescriptor, IrVariable, IrVariableSymbol> by threadLocal {
|
||||
SymbolTableSlice.Scoped(lock)
|
||||
}
|
||||
|
||||
private val localDelegatedPropertySlice: SymbolTableSlice.Scoped<VariableDescriptorWithAccessors, IrLocalDelegatedProperty, IrLocalDelegatedPropertySymbol> by threadLocal {
|
||||
SymbolTableSlice.Scoped(lock)
|
||||
}
|
||||
|
||||
override fun MutableList<SymbolTableSlice.Scoped<*, *, *>>.initializeScopedSlices() {
|
||||
add(valueParameterSlice)
|
||||
add(variableSlice)
|
||||
add(localDelegatedPropertySlice)
|
||||
}
|
||||
|
||||
// ------------------------------------ signature ------------------------------------
|
||||
|
||||
override fun calculateSignature(declaration: DeclarationDescriptor): IdSignature? {
|
||||
return signatureComposer.composeSignature(declaration)
|
||||
}
|
||||
|
||||
override fun calculateEnumEntrySignature(declaration: ClassDescriptor): IdSignature? {
|
||||
return signatureComposer.composeEnumEntrySignature(declaration)
|
||||
}
|
||||
|
||||
override fun calculateFieldSignature(declaration: PropertyDescriptor): IdSignature? {
|
||||
return signatureComposer.composeFieldSignature(declaration)
|
||||
}
|
||||
|
||||
// ------------------------------------ script ------------------------------------
|
||||
|
||||
override fun defaultScriptFactory(startOffset: Int, endOffset: Int, script: ScriptDescriptor, symbol: IrScriptSymbol): IrScript {
|
||||
return IrScriptImpl(symbol, nameProvider.nameForDeclaration(script), irFactory, startOffset, endOffset)
|
||||
}
|
||||
|
||||
override fun createScriptSymbol(descriptor: ScriptDescriptor, signature: IdSignature?): IrScriptSymbol {
|
||||
return IrScriptSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
// ------------------------------------ class ------------------------------------
|
||||
|
||||
override fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol {
|
||||
return if (descriptor is IrBasedClassDescriptor) {
|
||||
descriptor.owner.symbol
|
||||
} else {
|
||||
super.referenceClass(descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
fun declareClassFromLinker(descriptor: ClassDescriptor, signature: IdSignature, classFactory: (IrClassSymbol) -> IrClass): IrClass {
|
||||
return declareFromLinker(
|
||||
descriptor,
|
||||
signature,
|
||||
SymbolTable::declareClass,
|
||||
::declareClass,
|
||||
::createClassSymbol,
|
||||
classFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun createPublicClassSymbol(descriptor: ClassDescriptor, signature: IdSignature): IrClassSymbol {
|
||||
return IrClassPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateClassSymbol(descriptor: ClassDescriptor): IrClassSymbol {
|
||||
return IrClassSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
// ------------------------------------ constructor ------------------------------------
|
||||
|
||||
fun declareConstructorFromLinker(
|
||||
descriptor: ClassConstructorDescriptor,
|
||||
signature: IdSignature,
|
||||
constructorFactory: (IrConstructorSymbol) -> IrConstructor,
|
||||
): IrConstructor {
|
||||
return declareFromLinker(
|
||||
descriptor,
|
||||
signature,
|
||||
SymbolTable::declareConstructor,
|
||||
::declareConstructor,
|
||||
::createConstructorSymbol,
|
||||
constructorFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun createPublicConstructorSymbol(descriptor: ClassConstructorDescriptor, signature: IdSignature): IrConstructorSymbol {
|
||||
return IrConstructorPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateConstructorSymbol(descriptor: ClassConstructorDescriptor): IrConstructorSymbol {
|
||||
return IrConstructorSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
// ------------------------------------ enum entry ------------------------------------
|
||||
|
||||
fun declareEnumEntryFromLinker(
|
||||
descriptor: ClassDescriptor,
|
||||
signature: IdSignature,
|
||||
factory: (IrEnumEntrySymbol) -> IrEnumEntry,
|
||||
): IrEnumEntry {
|
||||
return declareFromLinker(
|
||||
descriptor,
|
||||
signature,
|
||||
SymbolTable::declareEnumEntry,
|
||||
::declareEnumEntry,
|
||||
::createEnumEntrySymbol,
|
||||
factory
|
||||
)
|
||||
}
|
||||
|
||||
override fun createPublicEnumEntrySymbol(descriptor: ClassDescriptor, signature: IdSignature): IrEnumEntrySymbol {
|
||||
return IrEnumEntryPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateEnumEntrySymbol(descriptor: ClassDescriptor): IrEnumEntrySymbol {
|
||||
return IrEnumEntrySymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
override fun defaultEnumEntryFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
enumEntry: ClassDescriptor,
|
||||
symbol: IrEnumEntrySymbol,
|
||||
): IrEnumEntry {
|
||||
return irFactory.createEnumEntry(startOffset, endOffset, origin, nameProvider.nameForDeclaration(enumEntry), symbol)
|
||||
}
|
||||
|
||||
// ------------------------------------ field ------------------------------------
|
||||
|
||||
override fun createPublicFieldSymbol(descriptor: PropertyDescriptor, signature: IdSignature): IrFieldSymbol {
|
||||
return IrFieldPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateFieldSymbol(descriptor: PropertyDescriptor): IrFieldSymbol {
|
||||
return IrFieldSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
override fun defaultFieldFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: PropertyDescriptor,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility?,
|
||||
symbol: IrFieldSymbol,
|
||||
): IrField {
|
||||
return irFactory.createField(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = nameProvider.nameForDeclaration(descriptor),
|
||||
visibility = visibility ?: symbol.descriptor.visibility,
|
||||
symbol = symbol,
|
||||
type = type,
|
||||
isFinal = !symbol.descriptor.isVar,
|
||||
isStatic = symbol.descriptor.dispatchReceiverParameter == null,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
).apply {
|
||||
metadata = DescriptorMetadataSource.Property(symbol.descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------ property ------------------------------------
|
||||
|
||||
fun declarePropertyFromLinker(
|
||||
descriptor: PropertyDescriptor,
|
||||
signature: IdSignature,
|
||||
propertyFactory: (IrPropertySymbol) -> IrProperty,
|
||||
): IrProperty {
|
||||
return declareFromLinker(
|
||||
descriptor,
|
||||
signature,
|
||||
SymbolTable::declareProperty,
|
||||
::declareProperty,
|
||||
::createPropertySymbol,
|
||||
propertyFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun createPublicPropertySymbol(descriptor: PropertyDescriptor, signature: IdSignature): IrPropertySymbol {
|
||||
return IrPropertyPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivatePropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol {
|
||||
return IrPropertySymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
override fun defaultPropertyFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: PropertyDescriptor,
|
||||
isDelegated: Boolean,
|
||||
symbol: IrPropertySymbol,
|
||||
): IrProperty {
|
||||
return irFactory.createProperty(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = nameProvider.nameForDeclaration(descriptor),
|
||||
visibility = descriptor.visibility,
|
||||
modality = descriptor.modality,
|
||||
symbol = symbol,
|
||||
isVar = descriptor.isVar,
|
||||
isConst = descriptor.isConst,
|
||||
isLateinit = descriptor.isLateInit,
|
||||
isDelegated = isDelegated,
|
||||
isExternal = descriptor.isEffectivelyExternal(),
|
||||
isExpect = descriptor.isExpect,
|
||||
isFakeOverride = descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE,
|
||||
).apply {
|
||||
metadata = DescriptorMetadataSource.Property(symbol.descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------ typealias ------------------------------------
|
||||
|
||||
override fun createPublicTypeAliasSymbol(descriptor: TypeAliasDescriptor, signature: IdSignature): IrTypeAliasSymbol {
|
||||
return IrTypeAliasPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateTypeAliasSymbol(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol {
|
||||
return IrTypeAliasSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
// ------------------------------------ function ------------------------------------
|
||||
|
||||
fun declareSimpleFunctionFromLinker(
|
||||
descriptor: FunctionDescriptor,
|
||||
signature: IdSignature,
|
||||
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction,
|
||||
): IrSimpleFunction {
|
||||
return declareFromLinker(
|
||||
descriptor,
|
||||
signature,
|
||||
SymbolTable::declareSimpleFunction,
|
||||
::declareSimpleFunction,
|
||||
::createFunctionSymbol,
|
||||
functionFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun createPublicFunctionSymbol(descriptor: FunctionDescriptor, signature: IdSignature): IrSimpleFunctionSymbol {
|
||||
return IrSimpleFunctionPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateFunctionSymbol(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol {
|
||||
return IrSimpleFunctionSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
// ------------------------------------ type parameter ------------------------------------
|
||||
|
||||
override fun createPublicTypeParameterSymbol(descriptor: TypeParameterDescriptor, signature: IdSignature): IrTypeParameterSymbol {
|
||||
return IrTypeParameterPublicSymbolImpl(signature, descriptor)
|
||||
}
|
||||
|
||||
override fun createPrivateTypeParameterSymbol(descriptor: TypeParameterDescriptor): IrTypeParameterSymbol {
|
||||
return IrTypeParameterSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
override fun defaultTypeParameterFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: TypeParameterDescriptor,
|
||||
symbol: IrTypeParameterSymbol,
|
||||
): IrTypeParameter {
|
||||
return irFactory.createTypeParameter(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = nameProvider.nameForDeclaration(descriptor),
|
||||
symbol = symbol,
|
||||
variance = symbol.descriptor.variance,
|
||||
index = symbol.descriptor.index,
|
||||
isReified = symbol.descriptor.isReified
|
||||
)
|
||||
}
|
||||
|
||||
// ------------------------------------ package fragment ------------------------------------
|
||||
|
||||
fun referenceExternalPackageFragment(descriptor: PackageFragmentDescriptor): IrExternalPackageFragmentSymbol =
|
||||
externalPackageFragmentSlice.referenced(descriptor) { IrExternalPackageFragmentSymbolImpl(descriptor) }
|
||||
|
||||
fun declareExternalPackageFragment(descriptor: PackageFragmentDescriptor): IrExternalPackageFragment {
|
||||
return externalPackageFragmentSlice.declare(
|
||||
descriptor,
|
||||
{ IrExternalPackageFragmentSymbolImpl(descriptor) },
|
||||
{ IrExternalPackageFragmentImpl(it, descriptor.fqName) }
|
||||
)
|
||||
}
|
||||
|
||||
fun declareExternalPackageFragmentIfNotExists(descriptor: PackageFragmentDescriptor): IrExternalPackageFragment {
|
||||
return externalPackageFragmentSlice.declareIfNotExists(
|
||||
descriptor,
|
||||
{ IrExternalPackageFragmentSymbolImpl(descriptor) },
|
||||
{ IrExternalPackageFragmentImpl(it, descriptor.fqName) }
|
||||
)
|
||||
}
|
||||
|
||||
// ------------------------------------ anonymous initializer ------------------------------------
|
||||
|
||||
fun declareAnonymousInitializer(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: ClassDescriptor
|
||||
): IrAnonymousInitializer =
|
||||
irFactory.createAnonymousInitializer(
|
||||
startOffset, endOffset, origin,
|
||||
IrAnonymousInitializerSymbolImpl(descriptor)
|
||||
)
|
||||
|
||||
// ------------------------------------ value parameter ------------------------------------
|
||||
|
||||
fun declareValueParameter(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: ParameterDescriptor,
|
||||
type: IrType,
|
||||
varargElementType: IrType? = null,
|
||||
name: Name? = null,
|
||||
index: Int? = null,
|
||||
isAssignable: Boolean = false,
|
||||
valueParameterFactory: (IrValueParameterSymbol) -> IrValueParameter = {
|
||||
irFactory.createValueParameter(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = name ?: nameProvider.nameForDeclaration(descriptor),
|
||||
type = type,
|
||||
isAssignable = isAssignable,
|
||||
symbol = it,
|
||||
index = index ?: descriptor.indexOrMinusOne,
|
||||
varargElementType = varargElementType,
|
||||
isCrossinline = descriptor.isCrossinline,
|
||||
isNoinline = descriptor.isNoinline,
|
||||
isHidden = false,
|
||||
)
|
||||
}
|
||||
): IrValueParameter =
|
||||
valueParameterSlice.declareLocal(
|
||||
descriptor,
|
||||
{ IrValueParameterSymbolImpl(descriptor) },
|
||||
valueParameterFactory
|
||||
)
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun introduceValueParameter(irValueParameter: IrValueParameter) {
|
||||
valueParameterSlice.introduceLocal(irValueParameter.descriptor, irValueParameter.symbol)
|
||||
}
|
||||
|
||||
override fun referenceValueParameter(descriptor: ParameterDescriptor): IrValueParameterSymbol {
|
||||
return valueParameterSlice.referenced(descriptor) {
|
||||
error("Undefined parameter referenced: $descriptor\n${valueParameterSlice.dump()}")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: convert to extension
|
||||
fun referenceValue(value: ValueDescriptor): IrValueSymbol {
|
||||
return when (value) {
|
||||
is ParameterDescriptor -> valueParameterSlice.referenced(value) { error("Undefined parameter referenced: $value") }
|
||||
is VariableDescriptor -> variableSlice.referenced(value) { error("Undefined variable referenced: $value") }
|
||||
else -> error("Unexpected value descriptor: $value")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------ variable ------------------------------------
|
||||
|
||||
fun declareVariable(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: VariableDescriptor,
|
||||
type: IrType,
|
||||
): IrVariable =
|
||||
variableSlice.declareLocal(
|
||||
descriptor,
|
||||
{ IrVariableSymbolImpl(descriptor) }
|
||||
) {
|
||||
IrVariableImpl(
|
||||
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type,
|
||||
descriptor.isVar, descriptor.isConst, descriptor.isLateInit
|
||||
)
|
||||
}
|
||||
|
||||
fun declareVariable(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: VariableDescriptor,
|
||||
type: IrType,
|
||||
irInitializerExpression: IrExpression?
|
||||
): IrVariable =
|
||||
declareVariable(startOffset, endOffset, origin, descriptor, type).apply {
|
||||
initializer = irInitializerExpression
|
||||
}
|
||||
|
||||
// ------------------------------------ local delegated property ------------------------------------
|
||||
|
||||
fun declareLocalDelegatedProperty(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: VariableDescriptorWithAccessors,
|
||||
type: IrType
|
||||
): IrLocalDelegatedProperty {
|
||||
return localDelegatedPropertySlice.declareLocal(
|
||||
descriptor,
|
||||
{ IrLocalDelegatedPropertySymbolImpl(descriptor) },
|
||||
) {
|
||||
irFactory.createLocalDelegatedProperty(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = nameProvider.nameForDeclaration(descriptor),
|
||||
symbol = it,
|
||||
type = type,
|
||||
isVar = descriptor.isVar
|
||||
)
|
||||
}.apply {
|
||||
metadata = DescriptorMetadataSource.LocalDelegatedProperty(descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
fun referenceLocalDelegatedProperty(descriptor: VariableDescriptorWithAccessors): IrLocalDelegatedPropertySymbol =
|
||||
localDelegatedPropertySlice.referenced(descriptor) {
|
||||
error("Undefined local delegated property referenced: $descriptor")
|
||||
}
|
||||
|
||||
// ------------------------------------ utilities ------------------------------------
|
||||
|
||||
private inline fun <D : DeclarationDescriptor, Symbol : IrBindableSymbol<*, SymbolOwner>, SymbolOwner : IrSymbolOwner> declareFromLinker(
|
||||
descriptor: D,
|
||||
signature: IdSignature,
|
||||
declareBySignature: SymbolTable.(IdSignature, () -> Symbol, OwnerFactory<Symbol, SymbolOwner>) -> SymbolOwner,
|
||||
declareByDescriptor: (D, OwnerFactory<Symbol, SymbolOwner>) -> SymbolOwner,
|
||||
crossinline symbolFactory: SymbolFactory<D, Symbol>,
|
||||
noinline ownerFactory: OwnerFactory<Symbol, SymbolOwner>
|
||||
): SymbolOwner {
|
||||
return if (signature.isPubliclyVisible) {
|
||||
table.declareBySignature(signature, { symbolFactory(descriptor, signature) }, ownerFactory)
|
||||
} else {
|
||||
declareByDescriptor(descriptor, ownerFactory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.linkage.IrProvider
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
|
||||
@@ -22,6 +23,7 @@ class ExternalDependenciesGenerator(
|
||||
private val symbolTable: SymbolTable,
|
||||
private val irProviders: List<IrProvider>
|
||||
) {
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun generateUnboundSymbolsAsDependencies() {
|
||||
// There should be at most one DeclarationStubGenerator (none in closed world?)
|
||||
irProviders.filterIsInstance<DeclarationStubGenerator>().singleOrNull()?.run { unboundSymbolGeneration = true }
|
||||
@@ -30,7 +32,7 @@ class ExternalDependenciesGenerator(
|
||||
var unbound = emptySet<IrSymbol>()
|
||||
do {
|
||||
val prevUnbound = unbound
|
||||
unbound = symbolTable.allUnbound
|
||||
unbound = symbolTable.descriptorExtension.allUnboundSymbols
|
||||
for (symbol in unbound) {
|
||||
// Symbol could get bound as a side effect of deserializing other symbols.
|
||||
if (!symbol.isBound) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
|
||||
interface ReferenceSymbolTable {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol
|
||||
fun referenceClass(signature: IdSignature): IrClassSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceScript(descriptor: ScriptDescriptor): IrScriptSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceConstructor(descriptor: ClassConstructorDescriptor): IrConstructorSymbol
|
||||
fun referenceConstructor(signature: IdSignature): IrConstructorSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceEnumEntry(descriptor: ClassDescriptor): IrEnumEntrySymbol
|
||||
fun referenceEnumEntry(signature: IdSignature): IrEnumEntrySymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceField(descriptor: PropertyDescriptor): IrFieldSymbol
|
||||
fun referenceField(signature: IdSignature): IrFieldSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol
|
||||
fun referenceProperty(signature: IdSignature): IrPropertySymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol
|
||||
fun referenceSimpleFunction(signature: IdSignature): IrSimpleFunctionSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceDeclaredFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceValueParameter(descriptor: ParameterDescriptor): IrValueParameterSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol
|
||||
fun referenceTypeParameter(signature: IdSignature): IrTypeParameterSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceScopedTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol
|
||||
fun referenceTypeAlias(signature: IdSignature): IrTypeAliasSymbol
|
||||
|
||||
fun enterScope(symbol: IrSymbol)
|
||||
fun enterScope(owner: IrDeclaration)
|
||||
|
||||
fun leaveScope(symbol: IrSymbol)
|
||||
fun leaveScope(owner: IrDeclaration)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,695 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.ir.IrLock
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.utils.threadLocal
|
||||
|
||||
abstract class ReferenceSymbolTableExtension<Class, TypeAlias, Script, Function, Constructor, Property, ValueParameter, TypeParameter> {
|
||||
abstract fun referenceScript(descriptor: Script): IrScriptSymbol
|
||||
abstract fun referenceClass(descriptor: Class): IrClassSymbol
|
||||
abstract fun referenceConstructor(descriptor: Constructor): IrConstructorSymbol
|
||||
abstract fun referenceEnumEntry(descriptor: Class): IrEnumEntrySymbol
|
||||
abstract fun referenceField(descriptor: Property): IrFieldSymbol
|
||||
abstract fun referenceProperty(descriptor: Property): IrPropertySymbol
|
||||
abstract fun referenceSimpleFunction(descriptor: Function): IrSimpleFunctionSymbol
|
||||
abstract fun referenceDeclaredFunction(descriptor: Function): IrSimpleFunctionSymbol
|
||||
abstract fun referenceValueParameter(descriptor: ValueParameter): IrValueParameterSymbol
|
||||
abstract fun referenceTypeParameter(classifier: TypeParameter): IrTypeParameterSymbol
|
||||
abstract fun referenceScopedTypeParameter(classifier: TypeParameter): IrTypeParameterSymbol
|
||||
abstract fun referenceTypeAlias(descriptor: TypeAlias): IrTypeAliasSymbol
|
||||
}
|
||||
|
||||
typealias SymbolFactory<Declaration, Symbol> = (Declaration, IdSignature?) -> Symbol
|
||||
typealias OwnerFactory<Symbol, SymbolOwner> = (Symbol) -> SymbolOwner
|
||||
|
||||
abstract class SymbolTableExtension<
|
||||
Declaration, Class, TypeAlias, Script, Function, Constructor,
|
||||
Property, ValueParameter, TypeParameter,
|
||||
>(
|
||||
val table: SymbolTable,
|
||||
) : ReferenceSymbolTableExtension<Class, TypeAlias, Script, Function, Constructor, Property, ValueParameter, TypeParameter>()
|
||||
where Class : Declaration,
|
||||
TypeAlias : Declaration,
|
||||
Script : Declaration,
|
||||
Function : Declaration,
|
||||
Constructor : Declaration,
|
||||
Property : Declaration,
|
||||
ValueParameter : Declaration,
|
||||
TypeParameter : Declaration {
|
||||
protected val lock: IrLock
|
||||
get() = table.lock
|
||||
|
||||
private val scriptSlice: SymbolTableSlice.Flat<Script, IrScript, IrScriptSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val classSlice: SymbolTableSlice.Flat<Class, IrClass, IrClassSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val constructorSlice: SymbolTableSlice.Flat<Constructor, IrConstructor, IrConstructorSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val enumEntrySlice: SymbolTableSlice.Flat<Class, IrEnumEntry, IrEnumEntrySymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val fieldSlice: SymbolTableSlice.Flat<Property, IrField, IrFieldSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val functionSlice: SymbolTableSlice.Flat<Function, IrSimpleFunction, IrSimpleFunctionSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val propertySlice: SymbolTableSlice.Flat<Property, IrProperty, IrPropertySymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val typeAliasSlice: SymbolTableSlice.Flat<TypeAlias, IrTypeAlias, IrTypeAliasSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
private val globalTypeParameterSlice: SymbolTableSlice.Flat<TypeParameter, IrTypeParameter, IrTypeParameterSymbol> =
|
||||
SymbolTableSlice.Flat(lock)
|
||||
|
||||
private val scopedTypeParameterSlice: SymbolTableSlice.Scoped<TypeParameter, IrTypeParameter, IrTypeParameterSymbol> by threadLocal {
|
||||
SymbolTableSlice.Scoped(lock)
|
||||
}
|
||||
|
||||
protected abstract fun MutableList<SymbolTableSlice.Scoped<*, *, *>>.initializeScopedSlices()
|
||||
|
||||
private val scopedSlices: List<SymbolTableSlice.Scoped<*, *, *>> by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
buildList {
|
||||
add(scopedTypeParameterSlice)
|
||||
initializeScopedSlices()
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------ signature ------------------------------------
|
||||
|
||||
protected abstract fun calculateSignature(declaration: Declaration): IdSignature?
|
||||
protected abstract fun calculateEnumEntrySignature(declaration: Class): IdSignature?
|
||||
protected abstract fun calculateFieldSignature(declaration: Property): IdSignature?
|
||||
|
||||
// ------------------------------------ script ------------------------------------
|
||||
|
||||
fun declareScript(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
descriptor: Script,
|
||||
): IrScript {
|
||||
return declare(
|
||||
descriptor,
|
||||
scriptSlice,
|
||||
SymbolTable::declareScript,
|
||||
symbolFactory = { createScriptSymbol(descriptor, it) },
|
||||
ownerFactory = { defaultScriptFactory(startOffset, endOffset, descriptor, it) }
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceScript(descriptor: Script): IrScriptSymbol {
|
||||
return scriptSlice.referenced(descriptor) { createScriptSymbol(descriptor, signature = null) }
|
||||
}
|
||||
|
||||
protected abstract fun defaultScriptFactory(startOffset: Int, endOffset: Int, script: Script, symbol: IrScriptSymbol): IrScript
|
||||
|
||||
protected abstract fun createScriptSymbol(descriptor: Script, signature: IdSignature?): IrScriptSymbol
|
||||
|
||||
// ------------------------------------ script ------------------------------------
|
||||
|
||||
fun declareClass(descriptor: Class, classFactory: (IrClassSymbol) -> IrClass): IrClass {
|
||||
return declare(
|
||||
descriptor,
|
||||
classSlice,
|
||||
SymbolTable::declareClass,
|
||||
{ createClassSymbol(descriptor, it) },
|
||||
classFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun declareClassIfNotExists(descriptor: Class, classFactory: (IrClassSymbol) -> IrClass): IrClass {
|
||||
return declareIfNotExist(
|
||||
descriptor,
|
||||
classSlice,
|
||||
SymbolTable::declareClassIfNotExists,
|
||||
{ createClassSymbol(descriptor, it) },
|
||||
classFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceClass(descriptor: Class): IrClassSymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
classSlice,
|
||||
SymbolTable::referenceClassImpl,
|
||||
::createClassSymbol,
|
||||
::createPublicClassSymbol,
|
||||
::createPrivateClassSymbol
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createClassSymbol(descriptor: Class, signature: IdSignature?): IrClassSymbol {
|
||||
return signature?.let { createPublicClassSymbol(descriptor, signature) } ?: createPrivateClassSymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicClassSymbol(descriptor: Class, signature: IdSignature): IrClassSymbol
|
||||
protected abstract fun createPrivateClassSymbol(descriptor: Class): IrClassSymbol
|
||||
|
||||
// ------------------------------------ constructor ------------------------------------
|
||||
|
||||
fun declareConstructor(descriptor: Constructor, constructorFactory: (IrConstructorSymbol) -> IrConstructor): IrConstructor {
|
||||
return declare(
|
||||
descriptor,
|
||||
constructorSlice,
|
||||
SymbolTable::declareConstructor,
|
||||
{ createConstructorSymbol(descriptor, it) },
|
||||
constructorFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun declareConstructorIfNotExists(
|
||||
descriptor: Constructor,
|
||||
constructorFactory: (IrConstructorSymbol) -> IrConstructor,
|
||||
): IrConstructor {
|
||||
return declareIfNotExist(
|
||||
descriptor,
|
||||
constructorSlice,
|
||||
SymbolTable::declareConstructorIfNotExists,
|
||||
{ createConstructorSymbol(descriptor, it) },
|
||||
constructorFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceConstructor(descriptor: Constructor): IrConstructorSymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
constructorSlice,
|
||||
SymbolTable::referenceConstructorImpl,
|
||||
::createConstructorSymbol,
|
||||
::createPublicConstructorSymbol,
|
||||
::createPrivateConstructorSymbol
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createConstructorSymbol(descriptor: Constructor, signature: IdSignature?): IrConstructorSymbol {
|
||||
return signature?.let { createPublicConstructorSymbol(descriptor, signature) } ?: createPrivateConstructorSymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicConstructorSymbol(descriptor: Constructor, signature: IdSignature): IrConstructorSymbol
|
||||
protected abstract fun createPrivateConstructorSymbol(descriptor: Constructor): IrConstructorSymbol
|
||||
|
||||
// ------------------------------------ enum entry ------------------------------------
|
||||
|
||||
fun declareEnumEntry(descriptor: Class, enumEntryFactory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry {
|
||||
return declare(
|
||||
descriptor,
|
||||
enumEntrySlice,
|
||||
SymbolTable::declareEnumEntry,
|
||||
{ createEnumEntrySymbol(descriptor, it) },
|
||||
enumEntryFactory,
|
||||
::calculateEnumEntrySignature
|
||||
)
|
||||
}
|
||||
|
||||
fun declareEnumEntry(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: Class): IrEnumEntry {
|
||||
return declareEnumEntry(
|
||||
descriptor
|
||||
) { enumEntrySymbol -> defaultEnumEntryFactory(startOffset, endOffset, origin, descriptor, enumEntrySymbol) }
|
||||
}
|
||||
|
||||
fun declareEnumEntryIfNotExists(descriptor: Class, enumEntryFactory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry {
|
||||
return declareIfNotExist(
|
||||
descriptor,
|
||||
enumEntrySlice,
|
||||
SymbolTable::declareEnumEntryIfNotExists,
|
||||
{ createEnumEntrySymbol(descriptor, it) },
|
||||
enumEntryFactory,
|
||||
::calculateEnumEntrySignature
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceEnumEntry(descriptor: Class): IrEnumEntrySymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
enumEntrySlice,
|
||||
SymbolTable::referenceEnumEntryImpl,
|
||||
::createEnumEntrySymbol,
|
||||
::createPublicEnumEntrySymbol,
|
||||
::createPrivateEnumEntrySymbol,
|
||||
::calculateEnumEntrySignature
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createEnumEntrySymbol(descriptor: Class, signature: IdSignature?): IrEnumEntrySymbol {
|
||||
return signature?.let { createPublicEnumEntrySymbol(descriptor, signature) } ?: createPrivateEnumEntrySymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicEnumEntrySymbol(descriptor: Class, signature: IdSignature): IrEnumEntrySymbol
|
||||
protected abstract fun createPrivateEnumEntrySymbol(descriptor: Class): IrEnumEntrySymbol
|
||||
|
||||
protected abstract fun defaultEnumEntryFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
enumEntry: Class,
|
||||
symbol: IrEnumEntrySymbol,
|
||||
): IrEnumEntry
|
||||
|
||||
// ------------------------------------ field ------------------------------------
|
||||
|
||||
fun declareField(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: Property,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility? = null,
|
||||
fieldFactory: (IrFieldSymbol) -> IrField = {
|
||||
defaultFieldFactory(
|
||||
startOffset,
|
||||
endOffset,
|
||||
origin,
|
||||
descriptor,
|
||||
type,
|
||||
visibility,
|
||||
it
|
||||
)
|
||||
},
|
||||
): IrField {
|
||||
return declare(
|
||||
descriptor,
|
||||
fieldSlice,
|
||||
SymbolTable::declareField,
|
||||
{ createFieldSymbol(descriptor, it) },
|
||||
fieldFactory,
|
||||
::calculateFieldSignature
|
||||
)
|
||||
}
|
||||
|
||||
fun declareField(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: Property,
|
||||
type: IrType,
|
||||
irInitializer: IrExpressionBody?,
|
||||
): IrField {
|
||||
return declareField(startOffset, endOffset, origin, descriptor, type).apply {
|
||||
initializer = irInitializer
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceField(descriptor: Property): IrFieldSymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
fieldSlice,
|
||||
SymbolTable::referenceFieldImpl,
|
||||
::createFieldSymbol,
|
||||
::createPublicFieldSymbol,
|
||||
::createPrivateFieldSymbol,
|
||||
::calculateFieldSignature
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createFieldSymbol(descriptor: Property, signature: IdSignature?): IrFieldSymbol {
|
||||
return signature?.let { createPublicFieldSymbol(descriptor, signature) } ?: createPrivateFieldSymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicFieldSymbol(descriptor: Property, signature: IdSignature): IrFieldSymbol
|
||||
protected abstract fun createPrivateFieldSymbol(descriptor: Property): IrFieldSymbol
|
||||
|
||||
protected abstract fun defaultFieldFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: Property,
|
||||
type: IrType,
|
||||
visibility: DescriptorVisibility?,
|
||||
symbol: IrFieldSymbol,
|
||||
): IrField
|
||||
|
||||
// ------------------------------------ property ------------------------------------
|
||||
|
||||
fun declareProperty(descriptor: Property, propertyFactory: (IrPropertySymbol) -> IrProperty): IrProperty {
|
||||
return declare(
|
||||
descriptor,
|
||||
propertySlice,
|
||||
SymbolTable::declareProperty,
|
||||
{ createPropertySymbol(descriptor, it) },
|
||||
propertyFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun declareProperty(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: Property,
|
||||
isDelegated: Boolean,/* = descriptor.isDelegated*/
|
||||
): IrProperty {
|
||||
return declareProperty(descriptor) { propertySymbol ->
|
||||
defaultPropertyFactory(startOffset, endOffset, origin, descriptor, isDelegated, propertySymbol)
|
||||
}
|
||||
}
|
||||
|
||||
fun declarePropertyIfNotExists(descriptor: Property, propertyFactory: (IrPropertySymbol) -> IrProperty): IrProperty {
|
||||
return declareIfNotExist(
|
||||
descriptor,
|
||||
propertySlice,
|
||||
SymbolTable::declarePropertyIfNotExists,
|
||||
{ createPropertySymbol(descriptor, it) },
|
||||
propertyFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceProperty(descriptor: Property): IrPropertySymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
propertySlice,
|
||||
SymbolTable::referencePropertyImpl,
|
||||
::createPropertySymbol,
|
||||
::createPublicPropertySymbol,
|
||||
::createPrivatePropertySymbol
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createPropertySymbol(descriptor: Property, signature: IdSignature?): IrPropertySymbol {
|
||||
return signature?.let { createPublicPropertySymbol(descriptor, signature) } ?: createPrivatePropertySymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicPropertySymbol(descriptor: Property, signature: IdSignature): IrPropertySymbol
|
||||
protected abstract fun createPrivatePropertySymbol(descriptor: Property): IrPropertySymbol
|
||||
|
||||
protected abstract fun defaultPropertyFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: Property,
|
||||
isDelegated: Boolean,
|
||||
symbol: IrPropertySymbol,
|
||||
): IrProperty
|
||||
|
||||
// ------------------------------------ typealias ------------------------------------
|
||||
|
||||
fun declareTypeAlias(descriptor: TypeAlias, typeAliasFactory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias {
|
||||
return declare(
|
||||
descriptor,
|
||||
typeAliasSlice,
|
||||
SymbolTable::declareTypeAlias,
|
||||
{ createTypeAliasSymbol(descriptor, it) },
|
||||
typeAliasFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun declareTypeAliasIfNotExists(descriptor: TypeAlias, typeAliasFactory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias {
|
||||
return declareIfNotExist(
|
||||
descriptor,
|
||||
typeAliasSlice,
|
||||
SymbolTable::declareTypeAliasIfNotExists,
|
||||
{ createTypeAliasSymbol(descriptor, it) },
|
||||
typeAliasFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceTypeAlias(descriptor: TypeAlias): IrTypeAliasSymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
typeAliasSlice,
|
||||
SymbolTable::referenceTypeAliasImpl,
|
||||
::createTypeAliasSymbol,
|
||||
::createPublicTypeAliasSymbol,
|
||||
::createPrivateTypeAliasSymbol
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createTypeAliasSymbol(descriptor: TypeAlias, signature: IdSignature?): IrTypeAliasSymbol {
|
||||
return signature?.let { createPublicTypeAliasSymbol(descriptor, signature) } ?: createPrivateTypeAliasSymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicTypeAliasSymbol(descriptor: TypeAlias, signature: IdSignature): IrTypeAliasSymbol
|
||||
protected abstract fun createPrivateTypeAliasSymbol(descriptor: TypeAlias): IrTypeAliasSymbol
|
||||
|
||||
// ------------------------------------ function ------------------------------------
|
||||
|
||||
fun declareSimpleFunction(descriptor: Function, functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction): IrSimpleFunction {
|
||||
return declare(
|
||||
descriptor,
|
||||
functionSlice,
|
||||
SymbolTable::declareSimpleFunction,
|
||||
{ createFunctionSymbol(descriptor, it) },
|
||||
functionFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun declareSimpleFunctionIfNotExists(
|
||||
descriptor: Function,
|
||||
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction,
|
||||
): IrSimpleFunction {
|
||||
return declareIfNotExist(
|
||||
descriptor,
|
||||
functionSlice,
|
||||
SymbolTable::declareSimpleFunctionIfNotExists,
|
||||
{ createFunctionSymbol(descriptor, it) },
|
||||
functionFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceSimpleFunction(descriptor: Function): IrSimpleFunctionSymbol {
|
||||
return reference(
|
||||
descriptor,
|
||||
functionSlice,
|
||||
SymbolTable::referenceSimpleFunctionImpl,
|
||||
::createFunctionSymbol,
|
||||
::createPublicFunctionSymbol,
|
||||
::createPrivateFunctionSymbol
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceDeclaredFunction(descriptor: Function): IrSimpleFunctionSymbol {
|
||||
fun throwError(): Nothing = error("Function is not declared: $descriptor")
|
||||
|
||||
return reference(
|
||||
descriptor,
|
||||
functionSlice,
|
||||
SymbolTable::referenceSimpleFunctionImpl,
|
||||
{ _, _ -> throwError() },
|
||||
{ _, _ -> throwError() },
|
||||
{ throwError() },
|
||||
)
|
||||
}
|
||||
|
||||
protected fun createFunctionSymbol(descriptor: Function, signature: IdSignature?): IrSimpleFunctionSymbol {
|
||||
return signature?.let { createPublicFunctionSymbol(descriptor, signature) } ?: createPrivateFunctionSymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicFunctionSymbol(descriptor: Function, signature: IdSignature): IrSimpleFunctionSymbol
|
||||
protected abstract fun createPrivateFunctionSymbol(descriptor: Function): IrSimpleFunctionSymbol
|
||||
|
||||
// ------------------------------------ type parameter ------------------------------------
|
||||
|
||||
fun declareGlobalTypeParameter(
|
||||
descriptor: TypeParameter,
|
||||
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter,
|
||||
): IrTypeParameter {
|
||||
return declare(
|
||||
descriptor,
|
||||
globalTypeParameterSlice,
|
||||
SymbolTable::declareGlobalTypeParameter,
|
||||
{ createTypeParameterSymbol(descriptor, it) },
|
||||
typeParameterFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun declareGlobalTypeParameter(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: TypeParameter,
|
||||
): IrTypeParameter {
|
||||
return declareGlobalTypeParameter(descriptor) {
|
||||
defaultTypeParameterFactory(startOffset, endOffset, origin, descriptor, it)
|
||||
}
|
||||
}
|
||||
|
||||
fun declareScopedTypeParameter(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: TypeParameter,
|
||||
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = {
|
||||
defaultTypeParameterFactory(startOffset, endOffset, origin, descriptor, it)
|
||||
},
|
||||
): IrTypeParameter {
|
||||
// TODO: looks little suspicious
|
||||
// Is it correct that we never create scoped type parameters by signatures?
|
||||
return scopedTypeParameterSlice.declare(
|
||||
descriptor,
|
||||
{ createTypeParameterSymbol(descriptor, calculateSignature(descriptor)) },
|
||||
typeParameterFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceTypeParameter(classifier: TypeParameter): IrTypeParameterSymbol {
|
||||
scopedTypeParameterSlice.get(classifier)?.let { return it }
|
||||
return reference(
|
||||
classifier,
|
||||
globalTypeParameterSlice,
|
||||
SymbolTable::referenceTypeParameterImpl,
|
||||
::createTypeParameterSymbol,
|
||||
::createPublicTypeParameterSymbol,
|
||||
::createPrivateTypeParameterSymbol
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceScopedTypeParameter(classifier: TypeParameter): IrTypeParameterSymbol {
|
||||
return scopedTypeParameterSlice.referenced(classifier) { createTypeParameterSymbol(classifier, calculateSignature(classifier)) }
|
||||
}
|
||||
|
||||
protected fun createTypeParameterSymbol(descriptor: TypeParameter, signature: IdSignature?): IrTypeParameterSymbol {
|
||||
return signature?.let { createPublicTypeParameterSymbol(descriptor, signature) } ?: createPrivateTypeParameterSymbol(descriptor)
|
||||
}
|
||||
|
||||
protected abstract fun createPublicTypeParameterSymbol(descriptor: TypeParameter, signature: IdSignature): IrTypeParameterSymbol
|
||||
protected abstract fun createPrivateTypeParameterSymbol(descriptor: TypeParameter): IrTypeParameterSymbol
|
||||
|
||||
protected abstract fun defaultTypeParameterFactory(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: TypeParameter,
|
||||
symbol: IrTypeParameterSymbol,
|
||||
): IrTypeParameter
|
||||
|
||||
// ------------------------------------ value parameter ------------------------------------
|
||||
|
||||
override fun referenceValueParameter(descriptor: ValueParameter): IrValueParameterSymbol {
|
||||
error("There is no default implementation for any symbol table extension")
|
||||
}
|
||||
|
||||
// ------------------------------------ scopes ------------------------------------
|
||||
|
||||
fun enterScope(symbol: IrSymbol) {
|
||||
scopedSlices.forEach { it.enterScope(symbol) }
|
||||
}
|
||||
|
||||
fun enterScope(owner: IrDeclaration) {
|
||||
enterScope(owner.symbol)
|
||||
}
|
||||
|
||||
fun leaveScope(symbol: IrSymbol) {
|
||||
scopedSlices.forEach { it.leaveScope(symbol) }
|
||||
}
|
||||
|
||||
fun leaveScope(owner: IrDeclaration) {
|
||||
leaveScope(owner.symbol)
|
||||
}
|
||||
|
||||
// ------------------------------------ utilities ------------------------------------
|
||||
|
||||
/**
|
||||
* This function is quite messy and doesn't have good contract of what exactly is traversed.
|
||||
* Basic idea is it traverse symbols which can be reasonable referered from other module
|
||||
*
|
||||
* Be careful when using it, and avoid it, except really need.
|
||||
*
|
||||
* TODO: add some OptIn
|
||||
*/
|
||||
fun forEachDeclarationSymbol(block: (IrSymbol) -> Unit) {
|
||||
table.forEachDeclarationSymbol(block)
|
||||
|
||||
scriptSlice.forEachSymbol { block(it) }
|
||||
classSlice.forEachSymbol { block(it) }
|
||||
constructorSlice.forEachSymbol { block(it) }
|
||||
enumEntrySlice.forEachSymbol { block(it) }
|
||||
fieldSlice.forEachSymbol { block(it) }
|
||||
functionSlice.forEachSymbol { block(it) }
|
||||
propertySlice.forEachSymbol { block(it) }
|
||||
typeAliasSlice.forEachSymbol { block(it) }
|
||||
globalTypeParameterSlice.forEachSymbol { block(it) }
|
||||
}
|
||||
|
||||
val allUnboundSymbols: Set<IrSymbol>
|
||||
get() = buildSet {
|
||||
fun addUnbound(slice: SymbolTableSlice<*, *, *>) {
|
||||
slice.unboundSymbols.filterTo(this) { !it.isBound }
|
||||
}
|
||||
addAll(table.allUnboundSymbols)
|
||||
|
||||
addUnbound(scriptSlice)
|
||||
addUnbound(classSlice)
|
||||
addUnbound(constructorSlice)
|
||||
addUnbound(enumEntrySlice)
|
||||
addUnbound(fieldSlice)
|
||||
addUnbound(functionSlice)
|
||||
addUnbound(propertySlice)
|
||||
addUnbound(typeAliasSlice)
|
||||
addUnbound(globalTypeParameterSlice)
|
||||
}
|
||||
|
||||
private inline fun <D : Declaration, Symbol : IrBindableSymbol<*, SymbolOwner>, SymbolOwner : IrSymbolOwner> declare(
|
||||
descriptor: D,
|
||||
slice: SymbolTableSlice<D, SymbolOwner, Symbol>,
|
||||
declareBySignature: SymbolTable.(IdSignature, () -> Symbol, OwnerFactory<Symbol, SymbolOwner>) -> SymbolOwner,
|
||||
crossinline symbolFactory: (IdSignature?) -> Symbol,
|
||||
noinline ownerFactory: OwnerFactory<Symbol, SymbolOwner>,
|
||||
specificCalculateSignature: (D) -> IdSignature? = { calculateSignature(it) }
|
||||
): SymbolOwner {
|
||||
return declare(
|
||||
descriptor,
|
||||
slice,
|
||||
declareBySignature,
|
||||
SymbolTableSlice<D, SymbolOwner, Symbol>::declare,
|
||||
symbolFactory,
|
||||
ownerFactory,
|
||||
specificCalculateSignature
|
||||
)
|
||||
}
|
||||
|
||||
private inline fun <D : Declaration, Symbol : IrBindableSymbol<*, SymbolOwner>, SymbolOwner : IrSymbolOwner> declareIfNotExist(
|
||||
descriptor: D,
|
||||
slice: SymbolTableSlice<D, SymbolOwner, Symbol>,
|
||||
declareBySignature: SymbolTable.(IdSignature, () -> Symbol, OwnerFactory<Symbol, SymbolOwner>) -> SymbolOwner,
|
||||
crossinline symbolFactory: (IdSignature?) -> Symbol,
|
||||
noinline ownerFactory: OwnerFactory<Symbol, SymbolOwner>,
|
||||
specificCalculateSignature: (D) -> IdSignature? = { calculateSignature(it) }
|
||||
): SymbolOwner {
|
||||
return declare(
|
||||
descriptor,
|
||||
slice,
|
||||
declareBySignature,
|
||||
SymbolTableSlice<D, SymbolOwner, Symbol>::declareIfNotExists,
|
||||
symbolFactory,
|
||||
ownerFactory,
|
||||
specificCalculateSignature
|
||||
)
|
||||
}
|
||||
|
||||
private inline fun <D : Declaration, Symbol : IrBindableSymbol<*, SymbolOwner>, SymbolOwner : IrSymbolOwner> declare(
|
||||
descriptor: D,
|
||||
slice: SymbolTableSlice<D, SymbolOwner, Symbol>,
|
||||
declareBySignature: SymbolTable.(IdSignature, () -> Symbol, OwnerFactory<Symbol, SymbolOwner>) -> SymbolOwner,
|
||||
declareByDeclaration: SymbolTableSlice<D, SymbolOwner, Symbol>.(D, () -> Symbol, OwnerFactory<Symbol, SymbolOwner>) -> SymbolOwner,
|
||||
crossinline symbolFactory: (IdSignature?) -> Symbol,
|
||||
noinline ownerFactory: OwnerFactory<Symbol, SymbolOwner>,
|
||||
specificCalculateSignature: (D) -> IdSignature?
|
||||
): SymbolOwner {
|
||||
return when (val signature = specificCalculateSignature(descriptor)) {
|
||||
null -> slice.declareByDeclaration(descriptor, { symbolFactory(signature) }, ownerFactory)
|
||||
else -> table.declareBySignature(signature, { symbolFactory(signature) }, ownerFactory)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <D : Declaration, Symbol : IrBindableSymbol<*, SymbolOwner>, SymbolOwner : IrSymbolOwner> reference(
|
||||
descriptor: D,
|
||||
slice: SymbolTableSlice<D, SymbolOwner, Symbol>,
|
||||
referenceBySignature: SymbolTable.(IdSignature, () -> Symbol, () -> Symbol) -> Symbol,
|
||||
crossinline symbolFactory: (D, IdSignature?) -> Symbol,
|
||||
crossinline publicSymbolFactory: (D, IdSignature) -> Symbol,
|
||||
crossinline privateSymbolFactory: (D) -> Symbol,
|
||||
specificCalculateSignature: (D) -> IdSignature? = { calculateSignature(it) }
|
||||
): Symbol {
|
||||
return when (val signature = specificCalculateSignature(descriptor)) {
|
||||
null -> slice.referenced(descriptor) { symbolFactory(descriptor, signature) }
|
||||
else -> table.referenceBySignature(
|
||||
signature,
|
||||
{ publicSymbolFactory(descriptor, signature) },
|
||||
{ privateSymbolFactory(descriptor) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrLock
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.symbols.IrBindableSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
|
||||
abstract class SymbolTableSlice<Key, SymbolOwner, Symbol>(val lock: IrLock)
|
||||
where SymbolOwner : IrSymbolOwner,
|
||||
Symbol : IrBindableSymbol<*, SymbolOwner> {
|
||||
/**
|
||||
* With the partial linkage turned on it's hard to predict whether a newly created [IrSymbol] that is added to the [SymbolTable]
|
||||
* via one of referenceXXX() calls will or won't be bound to some declaration. The latter may happen in certain cases,
|
||||
* for example when the symbol refers from an IR expression to a non-top level declaration that was removed in newer version
|
||||
* of Kotlin library (KLIB). Unless such symbol is registered as "probably unbound" it remains invisible for the linkage process.
|
||||
*
|
||||
* The optimization that allows to reference symbols without registering them as "probably unbound" is fragile. It's better
|
||||
* to avoid calling any referenceXXX(reg = false) functions. Instead, wherever it is s suitable it is recommended to use one
|
||||
* of the appropriate declareXXX() calls.
|
||||
*
|
||||
* For the future: Consider implementing the optimization once again for the new "flat" ID signatures.
|
||||
*/
|
||||
val unboundSymbols = linkedSetOf<Symbol>()
|
||||
|
||||
abstract fun get(key: Key): Symbol?
|
||||
abstract fun set(key: Key, symbol: Symbol)
|
||||
|
||||
inline fun declare(key: Key, createSymbol: () -> Symbol, createOwner: (Symbol) -> SymbolOwner): SymbolOwner {
|
||||
synchronized(lock) {
|
||||
val existing = get(key)
|
||||
val symbol = if (existing == null) {
|
||||
createSymbol().also { set(key, it) }
|
||||
} else {
|
||||
unboundSymbols.remove(existing)
|
||||
existing
|
||||
}
|
||||
return createOwnerSafe(symbol, createOwner)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun referenced(key: Key, orElse: () -> Symbol): Symbol {
|
||||
synchronized(lock) {
|
||||
return get(key) ?: run {
|
||||
val new = orElse()
|
||||
assert(unboundSymbols.add(new)) { "Symbol for ${new.signature} was already referenced" }
|
||||
set(key, new)
|
||||
new
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun declareIfNotExists(
|
||||
key: Key,
|
||||
createSymbol: () -> Symbol,
|
||||
createOwner: (Symbol) -> SymbolOwner,
|
||||
): SymbolOwner {
|
||||
synchronized(lock) {
|
||||
val existing = get(key)
|
||||
val symbol = if (existing == null) {
|
||||
// checkOriginal(descriptor) // TODO: remove?
|
||||
val new = createSymbol()
|
||||
set(key, new)
|
||||
new
|
||||
} else {
|
||||
if (existing.isBound) {
|
||||
unboundSymbols.remove(existing)
|
||||
return existing.owner
|
||||
}
|
||||
existing
|
||||
}
|
||||
return createOwnerSafe(symbol, createOwner)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add PrivateToInline
|
||||
@PublishedApi
|
||||
internal inline fun createOwnerSafe(symbol: Symbol, createOwner: (Symbol) -> SymbolOwner): SymbolOwner {
|
||||
val owner = createOwner(symbol)
|
||||
require(symbol.isBound)
|
||||
require(symbol.owner === owner) {
|
||||
"Attempt to rebind an IR symbol or to re-create its owner: old owner ${symbol.owner.render()}, new owner ${owner.render()}"
|
||||
}
|
||||
return owner
|
||||
}
|
||||
|
||||
class Flat<Key, SymbolOwner, Symbol>(lock: IrLock) : SymbolTableSlice<Key, SymbolOwner, Symbol>(lock)
|
||||
where SymbolOwner : IrSymbolOwner, Symbol : IrBindableSymbol<*, SymbolOwner> {
|
||||
private val signatureToSymbol = hashMapOf<Key, Symbol>()
|
||||
|
||||
override fun get(key: Key): Symbol? {
|
||||
return signatureToSymbol[key]
|
||||
}
|
||||
|
||||
override fun set(key: Key, symbol: Symbol) {
|
||||
signatureToSymbol[key] = symbol
|
||||
}
|
||||
|
||||
// TODO: add some OptIn
|
||||
internal fun forEachSymbol(block: (IrSymbol) -> Unit) {
|
||||
signatureToSymbol.forEach { (_, symbol) -> block(symbol) }
|
||||
}
|
||||
}
|
||||
|
||||
class Scoped<Key, SymbolOwner, Symbol>(lock: IrLock) : SymbolTableSlice<Key, SymbolOwner, Symbol>(lock)
|
||||
where SymbolOwner : IrSymbolOwner, Symbol : IrBindableSymbol<*, SymbolOwner> {
|
||||
|
||||
override fun set(key: Key, symbol: Symbol) {
|
||||
val scope = currentScope ?: noScope()
|
||||
scope[key] = symbol
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
// TODO: add PrivateForInline
|
||||
internal var currentScope: SliceScope<Key, Symbol>? = null
|
||||
private set
|
||||
|
||||
override fun get(key: Key): Symbol? {
|
||||
return currentScope?.get(key)
|
||||
}
|
||||
|
||||
inline fun declareLocal(key: Key, createSymbol: () -> Symbol, createOwner: (Symbol) -> SymbolOwner): SymbolOwner {
|
||||
val scope = currentScope ?: noScope()
|
||||
val symbol = scope.getLocal(key) ?: createSymbol().also { scope[key] = it }
|
||||
return createOwnerSafe(symbol, createOwner)
|
||||
}
|
||||
|
||||
fun introduceLocal(descriptor: Key, symbol: Symbol) {
|
||||
val scope = currentScope ?: noScope()
|
||||
scope[descriptor]?.let { error("$descriptor is already bound to $it") }
|
||||
scope[descriptor] = symbol
|
||||
}
|
||||
|
||||
fun enterScope(owner: IrSymbol) {
|
||||
currentScope = SliceScope(owner, currentScope)
|
||||
}
|
||||
|
||||
fun leaveScope(owner: IrSymbol) {
|
||||
currentScope?.owner.let {
|
||||
require(it == owner) { "Unexpected leaveScope: owner=$owner, currentScope.owner=$it" }
|
||||
}
|
||||
|
||||
currentScope = currentScope?.parent
|
||||
|
||||
if (currentScope != null && unboundSymbols.isNotEmpty()) {
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
error("Local scope contains unbound symbols: ${unboundSymbols.joinToString { it.descriptor.toString() }}")
|
||||
}
|
||||
}
|
||||
|
||||
fun dump(): String {
|
||||
return currentScope?.dump() ?: "<none>"
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
// TODO: add PrivateForInline
|
||||
internal fun noScope(): Nothing = error("No active scope")
|
||||
|
||||
@PublishedApi
|
||||
// TODO: add PrivateForInline
|
||||
internal class SliceScope<Key, Symbol>(val owner: IrSymbol, val parent: SliceScope<Key, Symbol>?) {
|
||||
private val signatureToSymbol = hashMapOf<Key, Symbol>()
|
||||
|
||||
operator fun get(descriptor: Key): Symbol? {
|
||||
return signatureToSymbol[descriptor] ?: parent?.get(descriptor)
|
||||
}
|
||||
|
||||
fun getLocal(descriptor: Key): Symbol? {
|
||||
return signatureToSymbol[descriptor]
|
||||
}
|
||||
|
||||
operator fun set(descriptor: Key, symbol: Symbol) {
|
||||
signatureToSymbol[descriptor] = symbol
|
||||
}
|
||||
|
||||
fun dumpTo(stringBuilder: StringBuilder): StringBuilder {
|
||||
return stringBuilder.also {
|
||||
it.append("owner=")
|
||||
it.append(owner)
|
||||
it.append("; ")
|
||||
signatureToSymbol.keys.joinTo(prefix = "[", postfix = "]", buffer = it)
|
||||
it.append('\n')
|
||||
parent?.dumpTo(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun dump(): String = dumpTo(StringBuilder()).toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.backend.common.serialization.KotlinIrLinker
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.allUnbound
|
||||
import org.jetbrains.kotlin.ir.util.irMessageLogger
|
||||
|
||||
// N.B. Checks for absence of unbound symbols only when unbound symbols are not allowed.
|
||||
@@ -18,14 +17,14 @@ fun KotlinIrLinker.checkNoUnboundSymbols(symbolTable: SymbolTable, whenDetected:
|
||||
|
||||
// N.B. Always checks for absence of unbound symbols. The condition whether this check should be applied is controlled outside.
|
||||
fun IrMessageLogger.checkNoUnboundSymbols(symbolTable: SymbolTable, whenDetected: String) {
|
||||
val unboundSymbols = symbolTable.allUnbound
|
||||
val unboundSymbols = symbolTable.descriptorExtension.allUnboundSymbols
|
||||
if (unboundSymbols.isNotEmpty())
|
||||
UnexpectedUnboundIrSymbols(unboundSymbols, whenDetected).raiseIssue(this)
|
||||
}
|
||||
|
||||
// N.B. Always checks for absence of unbound symbols. The condition whether this check should be applied is controlled outside.
|
||||
fun CompilerConfiguration.checkNoUnboundSymbols(symbolTable: SymbolTable, whenDetected: String) {
|
||||
val unboundSymbols = symbolTable.allUnbound
|
||||
val unboundSymbols = symbolTable.descriptorExtension.allUnboundSymbols
|
||||
if (unboundSymbols.isNotEmpty())
|
||||
UnexpectedUnboundIrSymbols(unboundSymbols, whenDetected).raiseIssue(irMessageLogger)
|
||||
}
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageLogger
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.allUnbound
|
||||
|
||||
fun createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig: PartialLinkageConfig,
|
||||
@@ -73,7 +72,7 @@ internal class PartialLinkageSupportForLinkerImpl(
|
||||
|
||||
private fun generateStubsAndPatchUsagesInternal(symbolTable: SymbolTable, patchIrTree: () -> Unit) {
|
||||
// Generate stubs.
|
||||
for (symbol in symbolTable.allUnbound) {
|
||||
for (symbol in symbolTable.descriptorExtension.allUnboundSymbols) {
|
||||
stubGenerator.getDeclaration(symbol)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -145,7 +145,7 @@ class CurrentModuleWithICDeserializer(
|
||||
|
||||
override fun init(delegate: IrModuleDeserializer) {
|
||||
val knownBuiltIns = irBuiltIns.knownBuiltins.map { (it as IrSymbolOwner).symbol }.toSet()
|
||||
symbolTable.forEachDeclarationSymbol {
|
||||
symbolTable.descriptorExtension.forEachDeclarationSymbol {
|
||||
assert(it.isPublicApi)
|
||||
if (it.descriptor.isDirtyDescriptor()) { // public && non-deserialized should be dirty symbol
|
||||
if (it !in knownBuiltIns) {
|
||||
@@ -172,4 +172,4 @@ class CurrentModuleWithICDeserializer(
|
||||
override fun fileDeserializers(): Collection<IrFileDeserializer> {
|
||||
return delegate.fileDeserializers()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,12 +7,12 @@ package org.jetbrains.kotlin.test.backend.handlers
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.AbstractIrLazyFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.util.DeserializableClass
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.allUnbound
|
||||
import org.jetbrains.kotlin.ir.util.resolveFakeOverride
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
@@ -24,13 +24,14 @@ import org.jetbrains.kotlin.test.services.TestServices
|
||||
class IrInlineBodiesHandler(testServices: TestServices) : AbstractIrHandler(testServices) {
|
||||
val declaredInlineFunctionSignatures = mutableSetOf<IdSignature>()
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
info.processAllIrModuleFragments(module) { irModule, _ ->
|
||||
irModule.acceptChildrenVoid(InlineFunctionsCollector())
|
||||
irModule.acceptChildrenVoid(InlineCallBodiesCheck(firEnabled = module.frontendKind == FrontendKinds.FIR))
|
||||
}
|
||||
|
||||
assertions.assertTrue((info as IrBackendInput.JvmIrBackendInput).backendInput.symbolTable.allUnbound.isEmpty())
|
||||
assertions.assertTrue((info as IrBackendInput.JvmIrBackendInput).backendInput.symbolTable.descriptorExtension.allUnboundSymbols.isEmpty())
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
|
||||
+1
-1
@@ -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) }
|
||||
|
||||
+3
-1
@@ -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)
|
||||
|
||||
+4
-4
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user