IR: restore reading common Klib from JVM
Adapt to changes in linker
This commit is contained in:
@@ -19,13 +19,13 @@ import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
|
||||
class IrLazyClass(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrClassSymbol,
|
||||
override val descriptor: ClassDescriptor,
|
||||
override val name: Name,
|
||||
override val kind: ClassKind,
|
||||
override var visibility: Visibility,
|
||||
@@ -43,35 +43,10 @@ class IrLazyClass(
|
||||
IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
IrClass {
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrClassSymbol,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
TypeTranslator: TypeTranslator
|
||||
) :
|
||||
this(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name, symbol.descriptor.kind,
|
||||
symbol.descriptor.visibility, symbol.descriptor.modality,
|
||||
isCompanion = symbol.descriptor.isCompanionObject,
|
||||
isInner = symbol.descriptor.isInner,
|
||||
isData = symbol.descriptor.isData,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
isInline = symbol.descriptor.isInline,
|
||||
isExpect = symbol.descriptor.isExpect,
|
||||
isFun = symbol.descriptor.isFun,
|
||||
stubGenerator = stubGenerator,
|
||||
typeTranslator = TypeTranslator
|
||||
)
|
||||
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
override val descriptor: ClassDescriptor get() = symbol.descriptor
|
||||
|
||||
override var thisReceiver: IrValueParameter? by lazyVar {
|
||||
typeTranslator.buildWithScope(this) {
|
||||
descriptor.thisAsReceiverParameter.generateReceiverParameterStub().apply { parent = this@IrLazyClass }
|
||||
|
||||
+1
-22
@@ -16,13 +16,13 @@ import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.withScope
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
|
||||
class IrLazyConstructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrConstructorSymbol,
|
||||
override val descriptor: ClassConstructorDescriptor,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
isInline: Boolean,
|
||||
@@ -39,25 +39,6 @@ class IrLazyConstructor(
|
||||
),
|
||||
IrConstructor {
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrConstructorSymbol,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
TypeTranslator: TypeTranslator
|
||||
) : this(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name,
|
||||
symbol.descriptor.visibility,
|
||||
isInline = symbol.descriptor.isInline,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
isPrimary = symbol.descriptor.isPrimary,
|
||||
isExpect = symbol.descriptor.isExpect,
|
||||
stubGenerator = stubGenerator,
|
||||
typeTranslator = TypeTranslator
|
||||
)
|
||||
|
||||
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||
typeTranslator.buildWithScope(this) {
|
||||
stubGenerator.symbolTable.withScope(descriptor) {
|
||||
@@ -74,8 +55,6 @@ class IrLazyConstructor(
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitConstructor(this, data)
|
||||
}
|
||||
+1
-1
@@ -33,6 +33,7 @@ class IrLazyEnumEntryImpl(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrEnumEntrySymbol,
|
||||
override val descriptor: ClassDescriptor,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
typeTranslator: TypeTranslator
|
||||
) : IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
@@ -42,7 +43,6 @@ class IrLazyEnumEntryImpl(
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
override val descriptor: ClassDescriptor get() = symbol.descriptor
|
||||
override val name: Name = symbol.descriptor.name
|
||||
|
||||
override var correspondingClass: IrClass? = null
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||
@@ -22,13 +21,13 @@ import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
|
||||
class IrLazyField(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrFieldSymbol,
|
||||
override val descriptor: PropertyDescriptor,
|
||||
override val name: Name,
|
||||
override val visibility: Visibility,
|
||||
override val isFinal: Boolean,
|
||||
@@ -40,25 +39,6 @@ class IrLazyField(
|
||||
) : IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
IrField {
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrFieldSymbol,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
typeTranslator: TypeTranslator
|
||||
) : this(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name,
|
||||
symbol.descriptor.visibility,
|
||||
isFinal = !symbol.descriptor.isVar,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
isStatic = symbol.descriptor.dispatchReceiverParameter == null,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
stubGenerator = stubGenerator,
|
||||
typeTranslator = typeTranslator
|
||||
)
|
||||
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
@@ -69,8 +49,6 @@ class IrLazyField(
|
||||
?: mutableListOf()
|
||||
}
|
||||
|
||||
override val descriptor: PropertyDescriptor = symbol.descriptor
|
||||
|
||||
override var overriddenSymbols: List<IrFieldSymbol> by lazyVar {
|
||||
symbol.descriptor.overriddenDescriptors.map {
|
||||
stubGenerator.generateFieldStub(it.original).symbol
|
||||
|
||||
+1
-25
@@ -23,6 +23,7 @@ class IrLazyFunction(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrSimpleFunctionSymbol,
|
||||
override val descriptor: FunctionDescriptor,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
override val modality: Modality,
|
||||
@@ -39,31 +40,6 @@ class IrLazyFunction(
|
||||
IrLazyFunctionBase(startOffset, endOffset, origin, name, visibility, isInline, isExternal, isExpect, stubGenerator, typeTranslator),
|
||||
IrSimpleFunction {
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrSimpleFunctionSymbol,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
TypeTranslator: TypeTranslator
|
||||
) : this(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name,
|
||||
symbol.descriptor.visibility,
|
||||
symbol.descriptor.modality,
|
||||
isInline = symbol.descriptor.isInline,
|
||||
isExternal = symbol.descriptor.isExternal,
|
||||
isTailrec = symbol.descriptor.isTailrec,
|
||||
isSuspend = symbol.descriptor.isSuspend,
|
||||
isExpect = symbol.descriptor.isExpect,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
isOperator = symbol.descriptor.isOperator,
|
||||
stubGenerator = stubGenerator,
|
||||
typeTranslator = TypeTranslator
|
||||
)
|
||||
|
||||
override val descriptor: FunctionDescriptor = symbol.descriptor
|
||||
|
||||
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||
typeTranslator.buildWithScope(this) {
|
||||
stubGenerator.symbolTable.withScope(descriptor) {
|
||||
|
||||
+1
-28
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.resolve.hasBackingField
|
||||
|
||||
class IrLazyProperty(
|
||||
@@ -27,6 +26,7 @@ class IrLazyProperty(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrPropertySymbol,
|
||||
override val descriptor: PropertyDescriptor,
|
||||
override val name: Name,
|
||||
override val visibility: Visibility,
|
||||
override val modality: Modality,
|
||||
@@ -44,30 +44,6 @@ class IrLazyProperty(
|
||||
IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
IrProperty {
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrPropertySymbol,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
typeTranslator: TypeTranslator,
|
||||
bindingContext: BindingContext?
|
||||
) : this(
|
||||
startOffset, endOffset, origin,
|
||||
symbol,
|
||||
symbol.descriptor.name, symbol.descriptor.visibility, symbol.descriptor.modality,
|
||||
isVar = symbol.descriptor.isVar,
|
||||
isConst = symbol.descriptor.isConst,
|
||||
isLateinit = symbol.descriptor.isLateInit,
|
||||
isDelegated = @Suppress("DEPRECATION") symbol.descriptor.isDelegated,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
isExpect = symbol.descriptor.isExpect,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
stubGenerator = stubGenerator,
|
||||
typeTranslator = typeTranslator,
|
||||
bindingContext = bindingContext
|
||||
)
|
||||
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
@@ -75,9 +51,6 @@ class IrLazyProperty(
|
||||
private val hasBackingField: Boolean =
|
||||
descriptor.hasBackingField(bindingContext) || stubGenerator.extensions.isPropertyWithPlatformField(descriptor)
|
||||
|
||||
override val descriptor: PropertyDescriptor
|
||||
get() = symbol.descriptor
|
||||
|
||||
override var backingField: IrField? by lazyVar {
|
||||
if (hasBackingField) {
|
||||
stubGenerator.generateFieldStub(descriptor).apply {
|
||||
|
||||
+1
-3
@@ -25,6 +25,7 @@ class IrLazyTypeAlias(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrTypeAliasSymbol,
|
||||
override val descriptor: TypeAliasDescriptor,
|
||||
override val name: Name,
|
||||
override val visibility: Visibility,
|
||||
override val isActual: Boolean,
|
||||
@@ -38,9 +39,6 @@ class IrLazyTypeAlias(
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
override val descriptor: TypeAliasDescriptor
|
||||
get() = symbol.descriptor
|
||||
|
||||
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||
descriptor.declaredTypeParameters.mapTo(arrayListOf()) {
|
||||
stubGenerator.generateOrGetTypeParameterStub(it)
|
||||
|
||||
+1
-19
@@ -24,6 +24,7 @@ class IrLazyTypeParameter(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val symbol: IrTypeParameterSymbol,
|
||||
override val descriptor: TypeParameterDescriptor,
|
||||
override val name: Name,
|
||||
override val index: Int,
|
||||
override val isReified: Boolean,
|
||||
@@ -34,25 +35,6 @@ class IrLazyTypeParameter(
|
||||
IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
IrTypeParameter {
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrTypeParameterSymbol,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
TypeTranslator: TypeTranslator
|
||||
) :
|
||||
this(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name,
|
||||
symbol.descriptor.index,
|
||||
symbol.descriptor.isReified,
|
||||
symbol.descriptor.variance,
|
||||
stubGenerator, TypeTranslator
|
||||
)
|
||||
|
||||
override val descriptor: TypeParameterDescriptor get() = symbol.descriptor
|
||||
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
@@ -31,13 +30,14 @@ import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class DeclarationStubGenerator(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val symbolTable: SymbolTable,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
val extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY
|
||||
@@ -68,12 +68,19 @@ class DeclarationStubGenerator(
|
||||
constantValueGenerator.typeTranslator = typeTranslator
|
||||
}
|
||||
|
||||
override fun getDeclaration(symbol: IrSymbol): IrDeclaration? = when {
|
||||
override fun getDeclaration(symbol: IrSymbol): IrDeclaration? {
|
||||
// Special case: generating field for an already generated property.
|
||||
symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true ->
|
||||
generateStubBySymbol(symbol)
|
||||
symbol.descriptor is WrappedDeclarationDescriptor<*> -> null
|
||||
else -> generateStubBySymbol(symbol)
|
||||
if (symbol is IrFieldSymbol && (symbol.descriptor as? WrappedPropertyDescriptor)?.isBound() == true) {
|
||||
return generateStubBySymbol(symbol, symbol.descriptor)
|
||||
}
|
||||
val descriptor = if (symbol.descriptor is WrappedDeclarationDescriptor<*>)
|
||||
findDescriptorBySignature(symbol.signature)
|
||||
else
|
||||
symbol.descriptor
|
||||
if (descriptor == null) return null
|
||||
return generateStubBySymbol(symbol, descriptor).also {
|
||||
symbol.descriptor.bind(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun generateOrGetEmptyExternalPackageFragmentStub(descriptor: PackageFragmentDescriptor): IrExternalPackageFragment {
|
||||
@@ -117,13 +124,13 @@ class DeclarationStubGenerator(
|
||||
throw AssertionError("Unexpected member descriptor: $descriptor")
|
||||
}
|
||||
|
||||
private fun generateStubBySymbol(symbol: IrSymbol): IrDeclaration = when (symbol) {
|
||||
private fun generateStubBySymbol(symbol: IrSymbol, descriptor: DeclarationDescriptor): IrDeclaration = when (symbol) {
|
||||
is IrFieldSymbol ->
|
||||
generateFieldStub(symbol.descriptor)
|
||||
generateFieldStub(descriptor as PropertyDescriptor)
|
||||
is IrTypeParameterSymbol ->
|
||||
generateOrGetTypeParameterStub(symbol.descriptor)
|
||||
generateOrGetTypeParameterStub(descriptor as TypeParameterDescriptor)
|
||||
else ->
|
||||
generateMemberStub(symbol.descriptor)
|
||||
generateMemberStub(descriptor)
|
||||
}
|
||||
|
||||
private fun computeOrigin(descriptor: DeclarationDescriptor): IrDeclarationOrigin =
|
||||
@@ -143,7 +150,15 @@ class DeclarationStubGenerator(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original,
|
||||
isDelegated = @Suppress("DEPRECATION") descriptor.isDelegated
|
||||
) {
|
||||
IrLazyProperty(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator, bindingContext)
|
||||
IrLazyProperty(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.visibility, descriptor.modality,
|
||||
descriptor.isVar, descriptor.isConst, descriptor.isLateInit,
|
||||
@Suppress("DEPRECATION") descriptor.isDelegated, descriptor.isEffectivelyExternal(), descriptor.isExpect,
|
||||
isFakeOverride = (origin == IrDeclarationOrigin.FAKE_OVERRIDE),
|
||||
stubGenerator = this, typeTranslator = typeTranslator, bindingContext = bindingContext
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +174,16 @@ class DeclarationStubGenerator(
|
||||
else computeOrigin(descriptor)
|
||||
|
||||
return symbolTable.declareField(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original, descriptor.type.toIrType()) {
|
||||
IrLazyField(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyField(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.visibility,
|
||||
isFinal = !descriptor.isVar,
|
||||
isExternal = descriptor.isEffectivelyExternal(),
|
||||
isStatic = (descriptor.dispatchReceiverParameter == null),
|
||||
isFakeOverride = (origin == IrDeclarationOrigin.FAKE_OVERRIDE),
|
||||
stubGenerator = this, typeTranslator = typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +213,14 @@ class DeclarationStubGenerator(
|
||||
origin,
|
||||
descriptor.original
|
||||
) {
|
||||
IrLazyFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyFunction(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.visibility, descriptor.modality,
|
||||
descriptor.isInline, descriptor.isExternal, descriptor.isTailrec, descriptor.isSuspend, descriptor.isExpect,
|
||||
isFakeOverride = (origin == IrDeclarationOrigin.FAKE_OVERRIDE), isOperator = descriptor.isOperator,
|
||||
stubGenerator = this, typeTranslator = typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +234,13 @@ class DeclarationStubGenerator(
|
||||
return symbolTable.declareConstructor(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original
|
||||
) {
|
||||
IrLazyConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyConstructor(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.visibility,
|
||||
descriptor.isInline, descriptor.isEffectivelyExternal(), descriptor.isPrimary, descriptor.isExpect,
|
||||
this, typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +270,20 @@ class DeclarationStubGenerator(
|
||||
}
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||
IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyClass(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.kind, descriptor.visibility, descriptor.modality,
|
||||
isCompanion = descriptor.isCompanionObject,
|
||||
isInner = descriptor.isInner,
|
||||
isData = descriptor.isData,
|
||||
isExternal = descriptor.isEffectivelyExternal(),
|
||||
isInline = descriptor.isInline,
|
||||
isExpect = descriptor.isExpect,
|
||||
isFun = descriptor.isFun,
|
||||
stubGenerator = this,
|
||||
typeTranslator = typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +294,11 @@ class DeclarationStubGenerator(
|
||||
}
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareEnumEntry(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||
IrLazyEnumEntryImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyEnumEntryImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
this, typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +309,15 @@ class DeclarationStubGenerator(
|
||||
}
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||
IrLazyTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyTypeParameter(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name,
|
||||
descriptor.index,
|
||||
descriptor.isReified,
|
||||
descriptor.variance,
|
||||
this, typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +328,14 @@ class DeclarationStubGenerator(
|
||||
}
|
||||
val origin = computeOrigin(descriptor)
|
||||
return symbolTable.declareScopedTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
|
||||
IrLazyTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
|
||||
IrLazyTypeParameter(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, descriptor,
|
||||
descriptor.name,
|
||||
descriptor.index,
|
||||
descriptor.isReified,
|
||||
descriptor.variance,
|
||||
this, typeTranslator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,9 +348,57 @@ class DeclarationStubGenerator(
|
||||
return symbolTable.declareTypeAlias(descriptor) {
|
||||
IrLazyTypeAlias(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
|
||||
it, it.descriptor.name, it.descriptor.visibility, it.descriptor.isActual,
|
||||
it, descriptor,
|
||||
descriptor.name, descriptor.visibility, descriptor.isActual,
|
||||
this, typeTranslator
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findDescriptorBySignature(signature: IdSignature): DeclarationDescriptor? = when (signature) {
|
||||
is IdSignature.AccessorSignature -> findDescriptorForAccessorSignature(signature)
|
||||
is IdSignature.PublicSignature -> findDescriptorForPublicSignature(signature)
|
||||
else -> error("only PublicSignature or AccessorSignature should reach this point, got $signature")
|
||||
}
|
||||
|
||||
private fun findDescriptorForAccessorSignature(signature: IdSignature.AccessorSignature): DeclarationDescriptor? {
|
||||
val propertyDescriptor = findDescriptorBySignature(signature.propertySignature) as? PropertyDescriptor ?: return null
|
||||
return propertyDescriptor.accessors.singleOrNull {
|
||||
it.name == signature.accessorSignature.classFqn.shortName()
|
||||
}
|
||||
}
|
||||
|
||||
private fun findDescriptorForPublicSignature(signature: IdSignature.PublicSignature): DeclarationDescriptor? {
|
||||
val packageDescriptor = moduleDescriptor.getPackage(signature.packageFqName())
|
||||
val pathSegments = signature.classFqn.pathSegments()
|
||||
val toplevelDescriptors = packageDescriptor.memberScope.getContributedDescriptors { name -> name == pathSegments.first() }
|
||||
.filter { it.name == pathSegments.first() }
|
||||
val candidates = pathSegments.drop(1).fold(toplevelDescriptors) { acc, current ->
|
||||
acc.flatMap { container ->
|
||||
val classDescriptor = container as? ClassDescriptor ?: return@flatMap emptyList()
|
||||
val nextStepCandidates = classDescriptor.constructors +
|
||||
classDescriptor.unsubstitutedMemberScope.getContributedDescriptors { name -> name == current }
|
||||
nextStepCandidates.filter { it.name == current }
|
||||
}
|
||||
}
|
||||
return candidates.firstOrNull { symbolTable.signaturer.composeSignature(it) == signature }
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.bind(declaration: IrDeclaration) {
|
||||
when (this) {
|
||||
is WrappedValueParameterDescriptor -> bind(declaration as IrValueParameter)
|
||||
is WrappedReceiverParameterDescriptor -> bind(declaration as IrValueParameter)
|
||||
is WrappedTypeParameterDescriptor -> bind(declaration as IrTypeParameter)
|
||||
is WrappedVariableDescriptor -> bind(declaration as IrVariable)
|
||||
is WrappedVariableDescriptorWithAccessor -> bind(declaration as IrLocalDelegatedProperty)
|
||||
is WrappedSimpleFunctionDescriptor -> bind(declaration as IrSimpleFunction)
|
||||
is WrappedClassConstructorDescriptor -> bind(declaration as IrConstructor)
|
||||
is WrappedClassDescriptor -> bind(declaration as IrClass)
|
||||
is WrappedEnumEntryDescriptor -> bind(declaration as IrEnumEntry)
|
||||
is WrappedPropertyDescriptor -> (declaration as? IrProperty)?.let { bind(it) }
|
||||
is WrappedTypeAliasDescriptor -> bind(declaration as IrTypeAlias)
|
||||
is WrappedFieldDescriptor -> bind(declaration as IrField)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ interface ReferenceSymbolTable {
|
||||
fun leaveScope(owner: DeclarationDescriptor)
|
||||
}
|
||||
|
||||
open class SymbolTable(private val signaturer: IdSignatureComposer) : ReferenceSymbolTable {
|
||||
open class SymbolTable(val signaturer: IdSignatureComposer) : ReferenceSymbolTable {
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
val lazyWrapper = IrLazySymbolTable(this)
|
||||
|
||||
+7
@@ -603,6 +603,13 @@ abstract class KotlinIrLinker(
|
||||
if (!signature.shouldBeDeserialized()) return null
|
||||
|
||||
val descriptor = symbol.descriptor
|
||||
|
||||
/*
|
||||
Wrapped descriptors come from inside IrLinker. If a symbol with such a descriptor ends up here, this means we
|
||||
have already looked for it in IrLinker and failed.
|
||||
*/
|
||||
if (descriptor is WrappedDeclarationDescriptor<*>) return null
|
||||
|
||||
if (descriptor is FunctionClassDescriptor || (descriptor.containingDeclaration is FunctionClassDescriptor)) {
|
||||
return null
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// FILE: klib.kt
|
||||
package fromKlib
|
||||
|
||||
class C {
|
||||
val inClass = "O"
|
||||
}
|
||||
|
||||
val toplevel get() = "K"
|
||||
|
||||
fun referByDescriptor(s: String) = s.length
|
||||
|
||||
// FILE: test.kt
|
||||
import fromKlib.C
|
||||
import fromKlib.referByDescriptor
|
||||
import fromKlib.toplevel
|
||||
|
||||
fun box(): String {
|
||||
referByDescriptor("heh")
|
||||
return C().inClass + toplevel
|
||||
}
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: klib.kt
|
||||
package fromKlib
|
||||
|
||||
|
||||
+5
@@ -29,6 +29,11 @@ public class CompileKotlinAgainstKlibTestGenerated extends AbstractCompileKotlin
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxKlib"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("properties.kt")
|
||||
public void testProperties() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxKlib/properties.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxKlib/simple.kt");
|
||||
|
||||
Reference in New Issue
Block a user