IR fixes to help symbolization of K/N
This commit is contained in:
+2
-3
@@ -490,9 +490,8 @@ open class WrappedClassDescriptor(
|
||||
|
||||
override fun getThisAsReceiverParameter() = owner.thisReceiver?.descriptor as ReceiverParameterDescriptor
|
||||
|
||||
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? {
|
||||
TODO("not implemented")
|
||||
}
|
||||
override fun getUnsubstitutedPrimaryConstructor() =
|
||||
owner.declarations.filterIsInstance<IrConstructor>().singleOrNull { it.isPrimary }?.descriptor
|
||||
|
||||
override fun getDeclaredTypeParameters() = owner.typeParameters.map { it.descriptor }
|
||||
|
||||
|
||||
@@ -18,11 +18,10 @@ package org.jetbrains.kotlin.backend.common.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
||||
import org.jetbrains.kotlin.backend.common.deepCopyWithVariables
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedTypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||
@@ -35,6 +34,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
@@ -92,61 +92,45 @@ fun FunctionDescriptor.createOverriddenDescriptor(owner: ClassDescriptor, final:
|
||||
}
|
||||
|
||||
fun IrClass.addSimpleDelegatingConstructor(
|
||||
superConstructor: IrConstructor,
|
||||
irBuiltIns: IrBuiltIns,
|
||||
origin: IrDeclarationOrigin,
|
||||
isPrimary: Boolean = false
|
||||
): IrConstructor {
|
||||
val superConstructorDescriptor = superConstructor.descriptor
|
||||
val constructorDescriptor = ClassConstructorDescriptorImpl.createSynthesized(
|
||||
/* containingDeclaration = */ this.descriptor,
|
||||
/* annotations = */ Annotations.EMPTY,
|
||||
/* isPrimary = */ isPrimary,
|
||||
/* source = */ SourceElement.NO_SOURCE
|
||||
)
|
||||
val valueParameters = superConstructor.valueParameters.map {
|
||||
val descriptor = it.descriptor as ValueParameterDescriptor
|
||||
val newDescriptor = descriptor.copy(constructorDescriptor, descriptor.name, descriptor.index)
|
||||
IrValueParameterImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
newDescriptor,
|
||||
it.type,
|
||||
it.varargElementType
|
||||
)
|
||||
}
|
||||
superConstructor: IrConstructor,
|
||||
irBuiltIns: IrBuiltIns,
|
||||
isPrimary: Boolean = false,
|
||||
origin: IrDeclarationOrigin? = null
|
||||
) = WrappedClassConstructorDescriptor().let { descriptor ->
|
||||
IrConstructorImpl(
|
||||
startOffset, endOffset,
|
||||
origin ?: this.origin,
|
||||
IrConstructorSymbolImpl(descriptor),
|
||||
superConstructor.name,
|
||||
superConstructor.visibility,
|
||||
defaultType,
|
||||
false,
|
||||
false,
|
||||
isPrimary
|
||||
).also { constructor ->
|
||||
descriptor.bind(constructor)
|
||||
constructor.parent = this
|
||||
declarations += constructor
|
||||
|
||||
|
||||
constructorDescriptor.initialize(
|
||||
valueParameters.map { it.descriptor as ValueParameterDescriptor },
|
||||
superConstructorDescriptor.visibility
|
||||
)
|
||||
constructorDescriptor.returnType = superConstructorDescriptor.returnType
|
||||
|
||||
return IrConstructorImpl(startOffset, endOffset, origin, constructorDescriptor, this.defaultType).also { constructor ->
|
||||
|
||||
assert(superConstructor.dispatchReceiverParameter == null) // Inner classes aren't supported.
|
||||
|
||||
constructor.valueParameters += valueParameters
|
||||
superConstructor.valueParameters.mapIndexedTo(constructor.valueParameters) { index, parameter ->
|
||||
parameter.copyTo(constructor, index = index)
|
||||
}
|
||||
|
||||
constructor.body = IrBlockBodyImpl(
|
||||
startOffset, endOffset,
|
||||
listOf(
|
||||
IrDelegatingConstructorCallImpl(
|
||||
startOffset, endOffset, irBuiltIns.unitType,
|
||||
superConstructor.symbol, superConstructor.descriptor
|
||||
).apply {
|
||||
constructor.valueParameters.forEachIndexed { idx, parameter ->
|
||||
putValueArgument(idx, IrGetValueImpl(startOffset, endOffset, parameter.type, parameter.symbol))
|
||||
}
|
||||
},
|
||||
IrInstanceInitializerCallImpl(startOffset, endOffset, this.symbol, irBuiltIns.unitType)
|
||||
)
|
||||
startOffset, endOffset,
|
||||
listOf(
|
||||
IrDelegatingConstructorCallImpl(
|
||||
startOffset, endOffset, irBuiltIns.unitType,
|
||||
superConstructor.symbol, superConstructor.descriptor,
|
||||
0, superConstructor.valueParameters.size
|
||||
).apply {
|
||||
constructor.valueParameters.forEachIndexed { idx, parameter ->
|
||||
putValueArgument(idx, IrGetValueImpl(startOffset, endOffset, parameter.type, parameter.symbol))
|
||||
}
|
||||
},
|
||||
IrInstanceInitializerCallImpl(startOffset, endOffset, this.symbol, irBuiltIns.unitType)
|
||||
)
|
||||
)
|
||||
|
||||
constructor.parent = this
|
||||
this.declarations.add(constructor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
||||
|
||||
@@ -218,7 +219,8 @@ fun IrBuilderWithScope.irCall(callee: IrFunction, origin: IrStatementOrigin): Ir
|
||||
IrCallImpl(startOffset, endOffset, callee.returnType, callee.symbol, callee.descriptor, origin)
|
||||
|
||||
fun IrBuilderWithScope.irDelegatingConstructorCall(callee: IrConstructor): IrDelegatingConstructorCall =
|
||||
IrDelegatingConstructorCallImpl(startOffset, endOffset, callee.returnType, callee.symbol, callee.descriptor, callee.typeParameters.size)
|
||||
IrDelegatingConstructorCallImpl(startOffset, endOffset, callee.returnType, callee.symbol, callee.descriptor,
|
||||
callee.parentAsClass.typeParameters.size, callee.valueParameters.size)
|
||||
|
||||
fun IrBuilderWithScope.irCallOp(
|
||||
callee: IrFunctionSymbol,
|
||||
|
||||
+7
@@ -50,6 +50,13 @@ class IrDelegatingConstructorCallImpl(
|
||||
descriptor: ClassConstructorDescriptor
|
||||
) : this(startOffset, endOffset, type, symbol, descriptor, descriptor.typeParametersCount, descriptor.valueParameters.size)
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: IrType,
|
||||
symbol: IrConstructorSymbol
|
||||
) : this(startOffset, endOffset, type, symbol, symbol.descriptor)
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
|
||||
@@ -442,21 +442,6 @@ fun createField(
|
||||
return IrFieldImpl(startOffset, endOffset, origin, descriptor, type)
|
||||
}
|
||||
|
||||
fun IrFunction.createDispatchReceiverParameter() {
|
||||
assert(this.dispatchReceiverParameter == null)
|
||||
|
||||
val descriptor = this.descriptor.dispatchReceiverParameter ?: return
|
||||
|
||||
this.dispatchReceiverParameter = IrValueParameterImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
descriptor,
|
||||
this.parentAsClass.defaultType,
|
||||
null
|
||||
).also { it.parent = this }
|
||||
}
|
||||
|
||||
// In presence of `IrBlock`s, return the expression that actually serves as the value (the last one).
|
||||
tailrec fun IrExpression.removeBlocks(): IrExpression? = when (this) {
|
||||
is IrBlock -> (statements.last() as? IrExpression)?.removeBlocks()
|
||||
|
||||
Reference in New Issue
Block a user