IR: removing WrappedDescriptors from symbols

This commit is contained in:
Georgy Bronnikov
2020-11-30 12:36:50 +03:00
parent 989d4350b1
commit d714adacae
32 changed files with 266 additions and 282 deletions
@@ -61,12 +61,10 @@ class Scope(val scopeOwnerSymbol: IrSymbol) {
endOffset: Int = UNDEFINED_OFFSET
): IrVariable {
val name = Name.identifier(getNameForTemporary(nameHint))
val descriptor = WrappedVariableDescriptor()
return IrVariableImpl(
startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor), name,
startOffset, endOffset, origin, IrVariableSymbolImpl(), name,
irType, isMutable, isConst = false, isLateinit = false
).apply {
descriptor.bind(this)
parent = getLocalDeclarationParent()
}
}
@@ -35,7 +35,7 @@ interface IrMetadataSourceOwner : IrElement {
var metadata: MetadataSource?
}
interface IrDeclaration : IrStatement, IrMutableAnnotationContainer {
interface IrDeclaration : IrStatement, IrSymbolOwner, IrMutableAnnotationContainer {
@ObsoleteDescriptorBasedAPI
val descriptor: DeclarationDescriptor
@@ -48,7 +48,7 @@ interface IrDeclaration : IrStatement, IrMutableAnnotationContainer {
abstract class IrDeclarationBase : IrElementBase(), IrDeclaration
interface IrSymbolDeclaration<out S : IrSymbol> : IrDeclaration, IrSymbolOwner {
interface IrSymbolDeclaration<out S : IrSymbol> : IrDeclaration {
override val symbol: S
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -30,4 +31,7 @@ abstract class IrErrorDeclaration : IrDeclarationBase() {
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
// no children
}
override val symbol: IrSymbol
get() = error("Should never be called")
}
@@ -58,7 +58,7 @@ class IrLazyConstructor(
override var typeParameters: List<IrTypeParameter> by lazyVar {
typeTranslator.buildWithScope(this) {
stubGenerator.symbolTable.withScope(descriptor) {
stubGenerator.symbolTable.withScope(this) {
val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size
val allConstructorTypeParameters = descriptor.typeParameters
allConstructorTypeParameters.subList(classTypeParametersCount, allConstructorTypeParameters.size).mapTo(ArrayList()) {
@@ -66,7 +66,7 @@ class IrLazyFunction(
override var typeParameters: List<IrTypeParameter> by lazyVar {
typeTranslator.buildWithScope(this) {
stubGenerator.symbolTable.withScope(descriptor) {
stubGenerator.symbolTable.withScope(this) {
val propertyIfAccessor = descriptor.propertyIfAccessor
propertyIfAccessor.typeParameters.mapTo(arrayListOf()) { typeParameterDescriptor ->
if (descriptor != propertyIfAccessor) {
@@ -17,6 +17,10 @@ abstract class IrDelegatingSymbol<S : IrBindableSymbol<D, B>, B : IrSymbolOwner,
@ObsoleteDescriptorBasedAPI
override val descriptor: D get() = delegate.descriptor
@ObsoleteDescriptorBasedAPI
override val hasDescriptor: Boolean
get() = delegate.hasDescriptor
override val isBound: Boolean get() = delegate.isBound
override val signature: IdSignature?
@@ -30,6 +30,9 @@ interface IrSymbol {
@ObsoleteDescriptorBasedAPI
val descriptor: DeclarationDescriptor
@ObsoleteDescriptorBasedAPI
val hasDescriptor: Boolean
val isBound: Boolean
val signature: IdSignature?
@@ -16,6 +16,9 @@ class DescriptorlessExternalPackageFragmentSymbol : IrExternalPackageFragmentSym
override val descriptor: PackageFragmentDescriptor
get() = error("Operation is unsupported")
override val hasDescriptor: Boolean
get() = error("Operation is unsupported")
private var _owner: IrExternalPackageFragment? = null
override val owner get() = _owner!!
@@ -28,14 +28,16 @@ import org.jetbrains.kotlin.ir.util.render
@OptIn(ObsoleteDescriptorBasedAPI::class)
abstract class IrSymbolBase<out D : DeclarationDescriptor>(
private val _descriptor: D
private val _descriptor: D?
) : IrSymbol {
@ObsoleteDescriptorBasedAPI
@Suppress("UNCHECKED_CAST")
override val descriptor: D
get() = if (isBound && _descriptor is WrappedDeclarationDescriptor<*>)
(owner as IrDeclaration).toIrBasedDescriptor() as D
else
_descriptor
get() = _descriptor ?: (owner as IrDeclaration).toIrBasedDescriptor() as D
@ObsoleteDescriptorBasedAPI
override val hasDescriptor: Boolean
get() = _descriptor != null
override fun toString(): String {
if (isBound) return owner.render()
@@ -43,15 +45,15 @@ abstract class IrSymbolBase<out D : DeclarationDescriptor>(
}
}
abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D) :
abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D?) :
IrBindableSymbol<D, B>, IrSymbolBase<D>(descriptor) {
init {
assert(isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor.original}"
assert(descriptor == null || isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor!!.original}"
}
if (descriptor !is WrappedDeclarationDescriptor<*>) {
val containingDeclaration = descriptor.containingDeclaration
val containingDeclaration = descriptor?.containingDeclaration
assert(containingDeclaration == null || isOriginalDescriptor(containingDeclaration)) {
"Substituted containing declaration: $containingDeclaration\nfor descriptor: $descriptor"
}
@@ -92,41 +94,41 @@ class IrExternalPackageFragmentSymbolImpl(descriptor: PackageFragmentDescriptor)
IrExternalPackageFragmentSymbol
@OptIn(ObsoleteDescriptorBasedAPI::class)
class IrAnonymousInitializerSymbolImpl(descriptor: ClassDescriptor) :
class IrAnonymousInitializerSymbolImpl(descriptor: ClassDescriptor? = null) :
IrBindableSymbolBase<ClassDescriptor, IrAnonymousInitializer>(descriptor),
IrAnonymousInitializerSymbol {
constructor(irClassSymbol: IrClassSymbol) : this(irClassSymbol.descriptor)
}
class IrClassSymbolImpl(descriptor: ClassDescriptor) :
class IrClassSymbolImpl(descriptor: ClassDescriptor? = null) :
IrBindableSymbolBase<ClassDescriptor, IrClass>(descriptor),
IrClassSymbol
class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor) :
class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor? = null) :
IrBindableSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor),
IrEnumEntrySymbol
class IrFieldSymbolImpl(descriptor: PropertyDescriptor) :
class IrFieldSymbolImpl(descriptor: PropertyDescriptor? = null) :
IrBindableSymbolBase<PropertyDescriptor, IrField>(descriptor),
IrFieldSymbol
class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor) :
class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor? = null) :
IrBindableSymbolBase<TypeParameterDescriptor, IrTypeParameter>(descriptor),
IrTypeParameterSymbol
class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor) :
class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor? = null) :
IrBindableSymbolBase<ParameterDescriptor, IrValueParameter>(descriptor),
IrValueParameterSymbol
class IrVariableSymbolImpl(descriptor: VariableDescriptor) :
class IrVariableSymbolImpl(descriptor: VariableDescriptor? = null) :
IrBindableSymbolBase<VariableDescriptor, IrVariable>(descriptor),
IrVariableSymbol
class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor) :
class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor? = null) :
IrBindableSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor),
IrSimpleFunctionSymbol
class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) :
class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor? = null) :
IrBindableSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor),
IrConstructorSymbol
@@ -134,17 +136,17 @@ class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor),
IrReturnableBlockSymbol
class IrPropertySymbolImpl(descriptor: PropertyDescriptor) :
class IrPropertySymbolImpl(descriptor: PropertyDescriptor? = null) :
IrBindableSymbolBase<PropertyDescriptor, IrProperty>(descriptor),
IrPropertySymbol
class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAccessors) :
class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAccessors? = null) :
IrBindableSymbolBase<VariableDescriptorWithAccessors, IrLocalDelegatedProperty>(descriptor),
IrLocalDelegatedPropertySymbol
class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor) :
class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor? = null) :
IrBindableSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor),
IrTypeAliasSymbol
class IrScriptSymbolImpl(descriptor: ScriptDescriptor) :
class IrScriptSymbolImpl(descriptor: ScriptDescriptor? = null) :
IrScriptSymbol, IrBindableSymbolBase<ScriptDescriptor, IrScript>(descriptor)
@@ -15,15 +15,17 @@ import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.render
abstract class IrPublicSymbolBase<out D : DeclarationDescriptor> @OptIn(ObsoleteDescriptorBasedAPI::class) constructor(
private val _descriptor: D,
override val signature: IdSignature
override val signature: IdSignature,
private val _descriptor: D?
) : IrSymbol {
@ObsoleteDescriptorBasedAPI
@Suppress("UNCHECKED_CAST")
override val descriptor: D
get() = if (isBound && _descriptor is WrappedDeclarationDescriptor<*>)
(owner as IrDeclaration).toIrBasedDescriptor() as D
else
_descriptor
get() = _descriptor ?: (owner as IrDeclaration).toIrBasedDescriptor() as D
@ObsoleteDescriptorBasedAPI
override val hasDescriptor: Boolean
get() = _descriptor != null
override fun toString(): String {
if (isBound) return owner.render()
@@ -31,12 +33,12 @@ abstract class IrPublicSymbolBase<out D : DeclarationDescriptor> @OptIn(Obsolete
}
}
abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D, sig: IdSignature) :
IrBindableSymbol<D, B>, IrPublicSymbolBase<D>(descriptor, sig) {
abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(sig: IdSignature, descriptor: D?) :
IrBindableSymbol<D, B>, IrPublicSymbolBase<D>(sig, descriptor) {
init {
assert(isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor.original}"
assert(descriptor == null || isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor!!.original}"
}
assert(sig.isPublic)
}
@@ -49,7 +51,8 @@ abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrS
private var _owner: B? = null
override val owner: B
get() = _owner ?: throw IllegalStateException("Symbol for $signature is unbound")
get() = _owner ?:
throw IllegalStateException("Symbol for $signature is unbound")
override fun bind(owner: B) {
if (_owner == null) {
@@ -63,26 +66,26 @@ abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrS
get() = _owner != null
}
class IrClassPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) :
IrBindablePublicSymbolBase<ClassDescriptor, IrClass>(descriptor, sig),
class IrClassPublicSymbolImpl(sig: IdSignature, descriptor: ClassDescriptor? = null) :
IrBindablePublicSymbolBase<ClassDescriptor, IrClass>(sig, descriptor),
IrClassSymbol
class IrEnumEntryPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) :
IrBindablePublicSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor, sig),
class IrEnumEntryPublicSymbolImpl(sig: IdSignature, descriptor: ClassDescriptor? = null) :
IrBindablePublicSymbolBase<ClassDescriptor, IrEnumEntry>(sig, descriptor),
IrEnumEntrySymbol
class IrSimpleFunctionPublicSymbolImpl(descriptor: FunctionDescriptor, sig: IdSignature) :
IrBindablePublicSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor, sig),
class IrSimpleFunctionPublicSymbolImpl(sig: IdSignature, descriptor: FunctionDescriptor? = null) :
IrBindablePublicSymbolBase<FunctionDescriptor, IrSimpleFunction>(sig, descriptor),
IrSimpleFunctionSymbol
class IrConstructorPublicSymbolImpl(descriptor: ClassConstructorDescriptor, sig: IdSignature) :
IrBindablePublicSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor, sig),
class IrConstructorPublicSymbolImpl(sig: IdSignature, descriptor: ClassConstructorDescriptor? = null) :
IrBindablePublicSymbolBase<ClassConstructorDescriptor, IrConstructor>(sig, descriptor),
IrConstructorSymbol
class IrPropertyPublicSymbolImpl(descriptor: PropertyDescriptor, sig: IdSignature) :
IrBindablePublicSymbolBase<PropertyDescriptor, IrProperty>(descriptor, sig),
class IrPropertyPublicSymbolImpl(sig: IdSignature, descriptor: PropertyDescriptor? = null) :
IrBindablePublicSymbolBase<PropertyDescriptor, IrProperty>(sig, descriptor),
IrPropertySymbol
class IrTypeAliasPublicSymbolImpl(descriptor: TypeAliasDescriptor, sig: IdSignature) :
IrBindablePublicSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor, sig),
class IrTypeAliasPublicSymbolImpl(sig: IdSignature, descriptor: TypeAliasDescriptor? = null) :
IrBindablePublicSymbolBase<TypeAliasDescriptor, IrTypeAlias>(sig, descriptor),
IrTypeAliasSymbol
@@ -168,15 +168,13 @@ abstract class DataClassMembersGenerator(
val irIntType = context.irBuiltIns.intType
val resultVarDescriptor = WrappedVariableDescriptor()
val irResultVar = IrVariableImpl(
startOffset, endOffset,
IrDeclarationOrigin.DEFINED,
IrVariableSymbolImpl(resultVarDescriptor),
IrVariableSymbolImpl(),
Name.identifier("result"), irIntType,
isVar = true, isConst = false, isLateinit = false
).also {
resultVarDescriptor.bind(it)
it.parent = irFunction
it.initializer = getHashCodeOfProperty(properties[0])
}
@@ -77,7 +77,7 @@ class DeclarationStubGenerator(
if (symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true) {
return generateStubBySymbol(symbol, symbol.descriptor)
}
val descriptor = if (symbol.descriptor is WrappedDeclarationDescriptor<*>)
val descriptor = if (!symbol.hasDescriptor || symbol.descriptor is WrappedDeclarationDescriptor<*>)
findDescriptorBySignature(
symbol.signature
?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}")
@@ -46,23 +46,19 @@ interface ReferenceSymbolTable {
fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol
fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol
fun referenceConstructorFromLinker(descriptor: ClassConstructorDescriptor, sig: IdSignature): IrConstructorSymbol
fun referenceEnumEntryFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrEnumEntrySymbol
fun referenceFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrFieldSymbol
fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol
fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol
fun referenceTypeParameterFromLinker(classifier: TypeParameterDescriptor, sig: IdSignature): IrTypeParameterSymbol
fun referenceTypeAliasFromLinker(descriptor: TypeAliasDescriptor, sig: IdSignature): IrTypeAliasSymbol
@ObsoleteDescriptorBasedAPI
fun enterScope(owner: DeclarationDescriptor)
fun referenceClassFromLinker(sig: IdSignature): IrClassSymbol
fun referenceConstructorFromLinker(sig: IdSignature): IrConstructorSymbol
fun referenceEnumEntryFromLinker(sig: IdSignature): IrEnumEntrySymbol
fun referenceFieldFromLinker(sig: IdSignature): IrFieldSymbol
fun referencePropertyFromLinker(sig: IdSignature): IrPropertySymbol
fun referenceSimpleFunctionFromLinker(sig: IdSignature): IrSimpleFunctionSymbol
fun referenceTypeParameterFromLinker(sig: IdSignature): IrTypeParameterSymbol
fun referenceTypeAliasFromLinker(sig: IdSignature): IrTypeAliasSymbol
fun enterScope(owner: IrSymbol)
fun enterScope(owner: IrDeclaration)
@ObsoleteDescriptorBasedAPI
fun leaveScope(owner: DeclarationDescriptor)
fun leaveScope(owner: IrSymbol)
fun leaveScope(owner: IrDeclaration)
}
@@ -79,7 +75,7 @@ class SymbolTable(
val unboundSymbols = linkedSetOf<S>()
abstract fun get(d: D): S?
abstract fun set(d: D, s: S)
abstract fun set(s: S)
abstract fun get(sig: IdSignature): S?
inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
@@ -91,7 +87,7 @@ class SymbolTable(
val existing = get(d0)
val symbol = if (existing == null) {
val new = createSymbol()
set(d0, new)
set(new)
new
} else {
unboundSymbols.remove(existing)
@@ -106,11 +102,12 @@ class SymbolTable(
val symbol = if (existing == null) {
createSymbol()
} else {
throw AssertionError("Symbol for $sig already exists")
unboundSymbols.remove(existing)
existing
}
val result = createOwner(symbol)
// TODO: try to get rid of this
set(symbol.descriptor, symbol)
set(symbol)
return result
}
@@ -123,7 +120,7 @@ class SymbolTable(
val existing = get(d0)
val symbol = if (existing == null) {
val new = createSymbol()
set(d0, new)
set(new)
new
} else {
if (!existing.isBound) unboundSymbols.remove(existing)
@@ -132,16 +129,16 @@ class SymbolTable(
return if (symbol.isBound) symbol.owner else createOwner(symbol)
}
inline fun declare(sig: IdSignature, d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
inline fun declare(sig: IdSignature, d: D?, createSymbol: () -> S, createOwner: (S) -> B): B {
@Suppress("UNCHECKED_CAST")
val d0 = d.original as D
val d0 = d?.original as D
assert(d0 === d) {
"Non-original descriptor in declaration: $d\n\tExpected: $d0"
}
val existing = get(sig)
val symbol = if (existing == null) {
val new = createSymbol()
set(d0, new)
set(new)
new
} else {
unboundSymbols.remove(existing)
@@ -162,7 +159,7 @@ class SymbolTable(
assert(unboundSymbols.add(new)) {
"Symbol for $new was already referenced"
}
set(d0, new)
set(new)
return new
}
return s
@@ -175,7 +172,7 @@ class SymbolTable(
assert(unboundSymbols.add(new)) {
"Symbol for ${new.signature} was already referenced"
}
set(new.descriptor, new)
set(new)
new
}
}
@@ -207,11 +204,12 @@ class SymbolTable(
}
}
override fun set(d: D, s: S) {
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun set(s: S) {
s.signature?.let {
idSigToSymbol[it] = s
} ?: run {
descriptorToSymbol[d] = s
} ?: if (s.hasDescriptor) {
descriptorToSymbol[s.descriptor] = s
}
}
@@ -228,7 +226,7 @@ class SymbolTable(
private inner class ScopedSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>>
: SymbolTableBase<D, B, S>() {
inner class Scope(val owner: DeclarationDescriptor, val parent: Scope?) {
inner class Scope(val owner: IrSymbol, val parent: Scope?) {
private val descriptorToSymbol = linkedMapOf<D, S>()
private val idSigToSymbol = linkedMapOf<IdSignature, S>()
@@ -255,12 +253,14 @@ class SymbolTable(
fun getLocal(d: D) = descriptorToSymbol[d]
@OptIn(ObsoleteDescriptorBasedAPI::class)
operator fun set(d: D, s: S) {
s.signature?.let {
require(d is TypeParameterDescriptor)
idSigToSymbol[it] = s
} ?: run {
descriptorToSymbol[d] = s
assert(s.hasDescriptor)
descriptorToSymbol[s.descriptor] = s
}
}
@@ -286,9 +286,10 @@ class SymbolTable(
return scope[d]
}
override fun set(d: D, s: S) {
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun set(s: S) {
val scope = currentScope ?: throw AssertionError("No active scope")
scope[d] = s
scope[s.descriptor] = s
}
override fun get(sig: IdSignature): S? {
@@ -310,13 +311,11 @@ class SymbolTable(
scope[descriptor] = symbol
}
@ObsoleteDescriptorBasedAPI
fun enterScope(owner: DeclarationDescriptor) {
fun enterScope(owner: IrSymbol) {
currentScope = Scope(owner, currentScope)
}
@ObsoleteDescriptorBasedAPI
fun leaveScope(owner: DeclarationDescriptor) {
fun leaveScope(owner: IrSymbol) {
currentScope?.owner.let {
assert(it == owner) { "Unexpected leaveScope: owner=$owner, currentScope.owner=$it" }
}
@@ -324,6 +323,7 @@ class SymbolTable(
currentScope = currentScope?.parent
if (currentScope != null && unboundSymbols.isNotEmpty()) {
@OptIn(ObsoleteDescriptorBasedAPI::class)
throw AssertionError("Local scope contains unbound symbols: ${unboundSymbols.joinToString { it.descriptor.toString() }}")
}
}
@@ -406,7 +406,7 @@ class SymbolTable(
}
private fun createClassSymbol(descriptor: ClassDescriptor): IrClassSymbol {
return signaturer.composeSignature(descriptor)?.let { IrClassPublicSymbolImpl(descriptor, it) } ?: IrClassSymbolImpl(descriptor)
return signaturer.composeSignature(descriptor)?.let { IrClassPublicSymbolImpl(it, descriptor) } ?: IrClassSymbolImpl(descriptor)
}
fun declareClass(
@@ -439,7 +439,7 @@ class SymbolTable(
fun declareClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature, factory: (IrClassSymbol) -> IrClass): IrClass {
return classSymbolTable.run {
if (sig.isPublic) {
declare(sig, descriptor, { IrClassPublicSymbolImpl(descriptor, sig) }, factory)
declare(sig, descriptor, { IrClassPublicSymbolImpl(sig, descriptor) }, factory)
} else {
declare(descriptor, { IrClassSymbolImpl(descriptor) }, factory)
}
@@ -452,16 +452,16 @@ class SymbolTable(
fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? =
classSymbolTable.get(sig)
override fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol =
override fun referenceClassFromLinker(sig: IdSignature): IrClassSymbol =
classSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(descriptor, sig) }
else referenced(descriptor) { IrClassSymbolImpl(descriptor) }
if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(sig) }
else IrClassSymbolImpl()
}
val unboundClasses: Set<IrClassSymbol> get() = classSymbolTable.unboundSymbols
private fun createConstructorSymbol(descriptor: ClassConstructorDescriptor): IrConstructorSymbol {
return signaturer.composeSignature(descriptor)?.let { IrConstructorPublicSymbolImpl(descriptor, it) } ?: IrConstructorSymbolImpl(
return signaturer.composeSignature(descriptor)?.let { IrConstructorPublicSymbolImpl(it, descriptor) } ?: IrConstructorSymbolImpl(
descriptor
)
}
@@ -508,23 +508,23 @@ class SymbolTable(
): IrConstructor {
return constructorSymbolTable.run {
if (sig.isPublic) {
declare(sig, descriptor, { IrConstructorPublicSymbolImpl(descriptor, sig) }, constructorFactory)
declare(sig, descriptor, { IrConstructorPublicSymbolImpl(sig, descriptor) }, constructorFactory)
} else {
declare(descriptor, { IrConstructorSymbolImpl(descriptor) }, constructorFactory)
}
}
}
override fun referenceConstructorFromLinker(descriptor: ClassConstructorDescriptor, sig: IdSignature): IrConstructorSymbol =
override fun referenceConstructorFromLinker(sig: IdSignature): IrConstructorSymbol =
constructorSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrConstructorPublicSymbolImpl(descriptor, sig) }
else referenced(descriptor) { IrConstructorSymbolImpl(descriptor) }
if (sig.isPublic) referenced(sig) { IrConstructorPublicSymbolImpl(sig) }
else IrConstructorSymbolImpl()
}
val unboundConstructors: Set<IrConstructorSymbol> get() = constructorSymbolTable.unboundSymbols
private fun createEnumEntrySymbol(descriptor: ClassDescriptor): IrEnumEntrySymbol {
return signaturer.composeEnumEntrySignature(descriptor)?.let { IrEnumEntryPublicSymbolImpl(descriptor, it) }
return signaturer.composeEnumEntrySignature(descriptor)?.let { IrEnumEntryPublicSymbolImpl(it, descriptor) }
?: IrEnumEntrySymbolImpl(descriptor)
}
@@ -557,7 +557,7 @@ class SymbolTable(
): IrEnumEntry {
return enumEntrySymbolTable.run {
if (sig.isPublic) {
declare(sig, descriptor, { IrEnumEntryPublicSymbolImpl(descriptor, sig) }, factory)
declare(sig, descriptor, { IrEnumEntryPublicSymbolImpl(sig, descriptor) }, factory)
} else {
declare(descriptor, { IrEnumEntrySymbolImpl(descriptor) }, factory)
}
@@ -567,10 +567,10 @@ class SymbolTable(
override fun referenceEnumEntry(descriptor: ClassDescriptor) =
enumEntrySymbolTable.referenced(descriptor) { createEnumEntrySymbol(descriptor) }
override fun referenceEnumEntryFromLinker(descriptor: ClassDescriptor, sig: IdSignature) =
override fun referenceEnumEntryFromLinker(sig: IdSignature) =
enumEntrySymbolTable.run {
if (sig.isPublic) referenced(sig) { IrEnumEntryPublicSymbolImpl(descriptor, sig) } else
referenced(descriptor) { IrEnumEntrySymbolImpl(descriptor) }
if (sig.isPublic) referenced(sig) { IrEnumEntryPublicSymbolImpl(sig) }
else IrEnumEntrySymbolImpl()
}
val unboundEnumEntries: Set<IrEnumEntrySymbol> get() = enumEntrySymbolTable.unboundSymbols
@@ -615,6 +615,18 @@ class SymbolTable(
initializer = irInitializer
}
fun declareField(
sig: IdSignature,
symbolFactory: () -> IrFieldSymbol,
propertyFactory: (IrFieldSymbol) -> IrField
): IrField {
return fieldSymbolTable.declare(
sig,
symbolFactory,
propertyFactory
)
}
fun declareFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrFieldSymbol) -> IrField): IrField {
return fieldSymbolTable.run {
require(sig.isLocal)
@@ -625,10 +637,10 @@ class SymbolTable(
override fun referenceField(descriptor: PropertyDescriptor) =
fieldSymbolTable.referenced(descriptor) { createFieldSymbol(descriptor) }
override fun referenceFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature) =
override fun referenceFieldFromLinker(sig: IdSignature) =
fieldSymbolTable.run {
require(sig.isLocal)
referenced(descriptor) { IrFieldSymbolImpl(descriptor) }
IrFieldSymbolImpl()
}
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
@@ -641,7 +653,7 @@ class SymbolTable(
propertyTable.getOrPut(descriptor, generate)
private fun createPropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol {
return signaturer.composeSignature(descriptor)?.let { IrPropertyPublicSymbolImpl(descriptor, it) } ?: IrPropertySymbolImpl(
return signaturer.composeSignature(descriptor)?.let { IrPropertyPublicSymbolImpl(it, descriptor) } ?: IrPropertySymbolImpl(
descriptor
)
@@ -694,7 +706,7 @@ class SymbolTable(
fun declarePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrPropertySymbol) -> IrProperty): IrProperty {
return propertySymbolTable.run {
if (sig.isPublic) {
declare(sig, descriptor, { IrPropertyPublicSymbolImpl(descriptor, sig) }, factory)
declare(sig, descriptor, { IrPropertyPublicSymbolImpl(sig, descriptor) }, factory)
} else {
declare(descriptor, { IrPropertySymbolImpl(descriptor) }, factory)
}
@@ -707,16 +719,16 @@ class SymbolTable(
fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? =
propertySymbolTable.get(sig)
override fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol =
override fun referencePropertyFromLinker(sig: IdSignature): IrPropertySymbol =
propertySymbolTable.run {
if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(descriptor, sig) }
else referenced(descriptor) { IrPropertySymbolImpl(descriptor) }
if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(sig) }
else IrPropertySymbolImpl()
}
val unboundProperties: Set<IrPropertySymbol> get() = propertySymbolTable.unboundSymbols
private fun createTypeAliasSymbol(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol {
return signaturer.composeSignature(descriptor)?.let { IrTypeAliasPublicSymbolImpl(descriptor, it) } ?: IrTypeAliasSymbolImpl(
return signaturer.composeSignature(descriptor)?.let { IrTypeAliasPublicSymbolImpl(it, descriptor) } ?: IrTypeAliasSymbolImpl(
descriptor
)
}
@@ -731,17 +743,17 @@ class SymbolTable(
): IrTypeAlias {
return typeAliasSymbolTable.run {
if (sig.isPublic) {
declare(sig, descriptor, { IrTypeAliasPublicSymbolImpl(descriptor, sig) }, factory)
declare(sig, descriptor, { IrTypeAliasPublicSymbolImpl(sig, descriptor) }, factory)
} else {
declare(descriptor, { IrTypeAliasSymbolImpl(descriptor) }, factory)
}
}
}
override fun referenceTypeAliasFromLinker(descriptor: TypeAliasDescriptor, sig: IdSignature) =
override fun referenceTypeAliasFromLinker(sig: IdSignature) =
typeAliasSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrTypeAliasPublicSymbolImpl(descriptor, sig) } else
referenced(descriptor) { IrTypeAliasSymbolImpl(descriptor) }
if (sig.isPublic) referenced(sig) { IrTypeAliasPublicSymbolImpl(sig) }
else IrTypeAliasSymbolImpl()
}
fun declareTypeAlias(descriptor: TypeAliasDescriptor, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias =
@@ -761,7 +773,7 @@ class SymbolTable(
val unboundTypeAliases: Set<IrTypeAliasSymbol> get() = typeAliasSymbolTable.unboundSymbols
private fun createSimpleFunctionSymbol(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol {
return signaturer.composeSignature(descriptor)?.let { IrSimpleFunctionPublicSymbolImpl(descriptor, it) }
return signaturer.composeSignature(descriptor)?.let { IrSimpleFunctionPublicSymbolImpl(it, descriptor) }
?: IrSimpleFunctionSymbolImpl(descriptor)
}
@@ -796,15 +808,15 @@ class SymbolTable(
}
fun declareSimpleFunctionFromLinker(
descriptor: FunctionDescriptor,
descriptor: FunctionDescriptor?,
sig: IdSignature,
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
): IrSimpleFunction {
return simpleFunctionSymbolTable.run {
if (sig.isPublic) {
declare(sig, descriptor, { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) }, functionFactory)
declare(sig, descriptor, { IrSimpleFunctionPublicSymbolImpl(sig, descriptor) }, functionFactory)
} else {
declare(descriptor, { IrSimpleFunctionSymbolImpl(descriptor) }, functionFactory)
declare(descriptor!!, { IrSimpleFunctionSymbolImpl(descriptor) }, functionFactory)
}
}
}
@@ -815,10 +827,10 @@ class SymbolTable(
fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? =
simpleFunctionSymbolTable.get(sig)
override fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol {
override fun referenceSimpleFunctionFromLinker(sig: IdSignature): IrSimpleFunctionSymbol {
return simpleFunctionSymbolTable.run {
if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) } else
referenced(descriptor) { IrSimpleFunctionSymbolImpl(descriptor) }
if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(sig) }
else IrSimpleFunctionSymbolImpl()
}
}
@@ -850,6 +862,15 @@ class SymbolTable(
typeParameterFactory
)
fun declareGlobalTypeParameter(
sig: IdSignature,
symbolFactory: () -> IrTypeParameterSymbol,
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter
): IrTypeParameter {
require(sig.isLocal)
return globalTypeParameterSymbolTable.declare(sig, symbolFactory, typeParameterFactory)
}
fun declareGlobalTypeParameterFromLinker(
descriptor: TypeParameterDescriptor,
sig: IdSignature,
@@ -878,6 +899,15 @@ class SymbolTable(
typeParameterFactory
)
fun declareScopedTypeParameter(
sig: IdSignature,
symbolFactory: () -> IrTypeParameterSymbol,
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter
): IrTypeParameter {
require(sig.isLocal)
return typeParameterFactory(symbolFactory())
}
fun declareScopedTypeParameterFromLinker(
descriptor: TypeParameterDescriptor,
sig: IdSignature,
@@ -927,10 +957,9 @@ class SymbolTable(
createTypeParameterSymbol(classifier)
}
override fun referenceTypeParameterFromLinker(classifier: TypeParameterDescriptor, sig: IdSignature): IrTypeParameterSymbol {
override fun referenceTypeParameterFromLinker(sig: IdSignature): IrTypeParameterSymbol {
require(sig.isLocal)
return scopedTypeParameterSymbolTable.get(classifier)
?: globalTypeParameterSymbolTable.referenced(classifier) { IrTypeParameterSymbolImpl(classifier) }
return IrTypeParameterSymbolImpl()
}
fun declareVariable(
@@ -992,24 +1021,20 @@ class SymbolTable(
throw AssertionError("Undefined local delegated property referenced: $descriptor")
}
@ObsoleteDescriptorBasedAPI
override fun enterScope(owner: DeclarationDescriptor) {
override fun enterScope(owner: IrSymbol) {
scopedSymbolTables.forEach { it.enterScope(owner) }
}
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun enterScope(owner: IrDeclaration) {
enterScope(owner.descriptor)
enterScope(owner.symbol)
}
@ObsoleteDescriptorBasedAPI
override fun leaveScope(owner: DeclarationDescriptor) {
override fun leaveScope(owner: IrSymbol) {
scopedSymbolTables.forEach { it.leaveScope(owner) }
}
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun leaveScope(owner: IrDeclaration) {
leaveScope(owner.descriptor)
leaveScope(owner.symbol)
}
fun referenceValue(value: ValueDescriptor): IrValueSymbol =
@@ -1070,32 +1095,31 @@ class SymbolTable(
}
}
@ObsoleteDescriptorBasedAPI
inline fun <T, D : DeclarationDescriptor> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
inline fun <T> SymbolTable.withScope(owner: IrSymbol, block: SymbolTable.() -> T): T {
enterScope(owner)
val result = block(owner)
val result = block()
leaveScope(owner)
return result
}
inline fun <T, D : IrDeclaration> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
inline fun <T> SymbolTable.withScope(owner: IrDeclaration, block: SymbolTable.() -> T): T {
enterScope(owner)
val result = block(owner)
val result = block()
leaveScope(owner)
return result
}
@ObsoleteDescriptorBasedAPI
inline fun <T, D : DeclarationDescriptor> ReferenceSymbolTable.withReferenceScope(owner: D, block: ReferenceSymbolTable.(D) -> T): T {
inline fun <T> ReferenceSymbolTable.withReferenceScope(owner: IrSymbol, block: ReferenceSymbolTable.() -> T): T {
enterScope(owner)
val result = block(owner)
val result = block()
leaveScope(owner)
return result
}
inline fun <T, D : IrDeclaration> ReferenceSymbolTable.withReferenceScope(owner: D, block: ReferenceSymbolTable.(D) -> T): T {
inline fun <T> ReferenceSymbolTable.withReferenceScope(owner: IrDeclaration, block: ReferenceSymbolTable.() -> T): T {
enterScope(owner)
val result = block(owner)
val result = block()
leaveScope(owner)
return result
}
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.IrConstructor