IR: removing WrappedDescriptors from symbols
This commit is contained in:
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
||||
import java.io.StringWriter
|
||||
|
||||
fun ir2string(ir: IrElement?): String = ir?.render() ?: ""
|
||||
@@ -129,12 +128,7 @@ fun IrValueParameter.copyTo(
|
||||
isNoinline: Boolean = this.isNoinline,
|
||||
isAssignable: Boolean = this.isAssignable
|
||||
): IrValueParameter {
|
||||
val descriptor = if (index < 0) {
|
||||
WrappedReceiverParameterDescriptor()
|
||||
} else {
|
||||
WrappedValueParameterDescriptor()
|
||||
}
|
||||
val symbol = IrValueParameterSymbolImpl(descriptor)
|
||||
val symbol = IrValueParameterSymbolImpl()
|
||||
val defaultValueCopy = defaultValue?.let { originalDefault ->
|
||||
factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) {
|
||||
expression = originalDefault.expression.deepCopyWithVariables().also {
|
||||
@@ -147,7 +141,6 @@ fun IrValueParameter.copyTo(
|
||||
name, index, type, varargElementType, isCrossinline = isCrossinline,
|
||||
isNoinline = isNoinline, isHidden = false, isAssignable = isAssignable
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = irFunction
|
||||
it.defaultValue = defaultValueCopy
|
||||
it.copyAnnotationsFrom(this)
|
||||
@@ -167,10 +160,9 @@ fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||
|
||||
fun IrFunction.copyReceiverParametersFrom(from: IrFunction, substitutionMap: Map<IrTypeParameterSymbol, IrType>) {
|
||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.run {
|
||||
val newDescriptor = WrappedReceiverParameterDescriptor()
|
||||
factory.createValueParameter(
|
||||
startOffset, endOffset, origin,
|
||||
IrValueParameterSymbolImpl(newDescriptor),
|
||||
IrValueParameterSymbolImpl(),
|
||||
name, index,
|
||||
type.substitute(substitutionMap),
|
||||
varargElementType?.substitute(substitutionMap),
|
||||
@@ -178,7 +170,6 @@ fun IrFunction.copyReceiverParametersFrom(from: IrFunction, substitutionMap: Map
|
||||
isHidden, isAssignable
|
||||
).also { parameter ->
|
||||
parameter.parent = this@copyReceiverParametersFrom
|
||||
newDescriptor.bind(this)
|
||||
}
|
||||
}
|
||||
extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this)
|
||||
@@ -428,11 +419,10 @@ fun IrClass.createParameterDeclarations() {
|
||||
fun IrFunction.createDispatchReceiverParameter(origin: IrDeclarationOrigin? = null) {
|
||||
assert(dispatchReceiverParameter == null)
|
||||
|
||||
val newDescriptor = WrappedReceiverParameterDescriptor()
|
||||
dispatchReceiverParameter = factory.createValueParameter(
|
||||
startOffset, endOffset,
|
||||
origin ?: parentAsClass.origin,
|
||||
IrValueParameterSymbolImpl(newDescriptor),
|
||||
IrValueParameterSymbolImpl(),
|
||||
Name.special("<this>"),
|
||||
-1,
|
||||
parentAsClass.defaultType,
|
||||
@@ -443,7 +433,6 @@ fun IrFunction.createDispatchReceiverParameter(origin: IrDeclarationOrigin? = nu
|
||||
isAssignable = false
|
||||
).apply {
|
||||
parent = this@createDispatchReceiverParameter
|
||||
newDescriptor.bind(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,11 +458,11 @@ val IrFunction.allParametersCount: Int
|
||||
private class FakeOverrideBuilderForLowerings : FakeOverrideBuilderStrategy() {
|
||||
|
||||
override fun linkFunctionFakeOverride(declaration: IrFakeOverrideFunction) {
|
||||
declaration.acquireSymbol(IrSimpleFunctionSymbolImpl(WrappedSimpleFunctionDescriptor()))
|
||||
declaration.acquireSymbol(IrSimpleFunctionSymbolImpl())
|
||||
}
|
||||
|
||||
override fun linkPropertyFakeOverride(declaration: IrFakeOverrideProperty) {
|
||||
val propertySymbol = IrPropertySymbolImpl(WrappedPropertyDescriptor())
|
||||
val propertySymbol = IrPropertySymbolImpl()
|
||||
declaration.getter?.let { it.correspondingPropertySymbol = propertySymbol }
|
||||
declaration.setter?.let { it.correspondingPropertySymbol = propertySymbol }
|
||||
|
||||
@@ -509,11 +498,10 @@ fun IrFactory.createStaticFunctionWithReceivers(
|
||||
copyMetadata: Boolean = true,
|
||||
typeParametersFromContext: List<IrTypeParameter> = listOf()
|
||||
): IrSimpleFunction {
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
return createFunction(
|
||||
oldFunction.startOffset, oldFunction.endOffset,
|
||||
origin,
|
||||
IrSimpleFunctionSymbolImpl(descriptor),
|
||||
IrSimpleFunctionSymbolImpl(),
|
||||
name,
|
||||
visibility,
|
||||
modality,
|
||||
@@ -528,7 +516,6 @@ fun IrFactory.createStaticFunctionWithReceivers(
|
||||
isInfix = oldFunction is IrSimpleFunction && oldFunction.isInfix,
|
||||
containerSource = oldFunction.containerSource,
|
||||
).apply {
|
||||
descriptor.bind(this)
|
||||
parent = irParent
|
||||
|
||||
val newTypeParametersFromContext = copyAndRenameConflictingTypeParametersFrom(
|
||||
|
||||
+14
-37
@@ -21,15 +21,12 @@ import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildClass(builder: IrClassBuilder): IrClass = with(builder) {
|
||||
val wrappedDescriptor = WrappedClassDescriptor()
|
||||
createClass(
|
||||
startOffset, endOffset, origin,
|
||||
IrClassSymbolImpl(wrappedDescriptor),
|
||||
IrClassSymbolImpl(),
|
||||
name, kind, visibility, modality,
|
||||
isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
inline fun IrFactory.buildClass(builder: IrClassBuilder.() -> Unit) =
|
||||
@@ -40,14 +37,12 @@ inline fun IrFactory.buildClass(builder: IrClassBuilder.() -> Unit) =
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildField(builder: IrFieldBuilder): IrField = with(builder) {
|
||||
val wrappedDescriptor = WrappedFieldDescriptor()
|
||||
createField(
|
||||
startOffset, endOffset, origin,
|
||||
IrFieldSymbolImpl(wrappedDescriptor),
|
||||
IrFieldSymbolImpl(),
|
||||
name, type, visibility, isFinal, isExternal, isStatic,
|
||||
).also {
|
||||
it.metadata = metadata
|
||||
wrappedDescriptor.bind(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,17 +70,13 @@ fun IrClass.addField(fieldName: String, fieldType: IrType, fieldVisibility: Desc
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildProperty(builder: IrPropertyBuilder): IrProperty = with(builder) {
|
||||
val wrappedDescriptor = WrappedPropertyDescriptor()
|
||||
|
||||
createProperty(
|
||||
startOffset, endOffset, origin,
|
||||
IrPropertySymbolImpl(wrappedDescriptor),
|
||||
IrPropertySymbolImpl(),
|
||||
name, visibility, modality,
|
||||
isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride,
|
||||
containerSource,
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
inline fun IrFactory.buildProperty(builder: IrPropertyBuilder.() -> Unit) =
|
||||
@@ -113,31 +104,25 @@ inline fun IrProperty.addGetter(builder: IrFunctionBuilder.() -> Unit = {}): IrS
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildFunction(builder: IrFunctionBuilder): IrSimpleFunction = with(builder) {
|
||||
val wrappedDescriptor = WrappedSimpleFunctionDescriptor()
|
||||
createFunction(
|
||||
startOffset, endOffset, origin,
|
||||
IrSimpleFunctionSymbolImpl(wrappedDescriptor),
|
||||
IrSimpleFunctionSymbolImpl(),
|
||||
name, visibility, modality, returnType,
|
||||
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride,
|
||||
containerSource,
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildConstructor(builder: IrFunctionBuilder): IrConstructor = with(builder) {
|
||||
val wrappedDescriptor = WrappedClassConstructorDescriptor()
|
||||
return createConstructor(
|
||||
startOffset, endOffset, origin,
|
||||
IrConstructorSymbolImpl(wrappedDescriptor),
|
||||
IrConstructorSymbolImpl(),
|
||||
Name.special("<init>"),
|
||||
visibility, returnType,
|
||||
isInline = isInline, isExternal = isExternal, isPrimary = isPrimary, isExpect = isExpect,
|
||||
containerSource = containerSource
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
inline fun IrFactory.buildFun(builder: IrFunctionBuilder.() -> Unit): IrSimpleFunction =
|
||||
@@ -207,28 +192,24 @@ fun <D> buildReceiverParameter(
|
||||
startOffset: Int = parent.startOffset,
|
||||
endOffset: Int = parent.endOffset
|
||||
): IrValueParameter
|
||||
where D : IrDeclaration, D : IrDeclarationParent = WrappedReceiverParameterDescriptor().let { wrappedDescriptor ->
|
||||
where D : IrDeclaration, D : IrDeclarationParent =
|
||||
parent.factory.createValueParameter(
|
||||
startOffset, endOffset, origin,
|
||||
IrValueParameterSymbolImpl(wrappedDescriptor),
|
||||
IrValueParameterSymbolImpl(),
|
||||
RECEIVER_PARAMETER_NAME, -1, type, null, isCrossinline = false, isNoinline = false,
|
||||
isHidden = false, isAssignable = false
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
it.parent = parent
|
||||
}
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildValueParameter(builder: IrValueParameterBuilder, parent: IrDeclarationParent): IrValueParameter =
|
||||
with(builder) {
|
||||
val wrappedDescriptor = WrappedValueParameterDescriptor()
|
||||
return createValueParameter(
|
||||
startOffset, endOffset, origin,
|
||||
IrValueParameterSymbolImpl(wrappedDescriptor),
|
||||
IrValueParameterSymbolImpl(),
|
||||
name, index, type, varargElementType, isCrossInline, isNoinline, isHidden, isAssignable
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
it.parent = parent
|
||||
}
|
||||
}
|
||||
@@ -283,13 +264,11 @@ fun IrSimpleFunction.addExtensionReceiver(type: IrType, origin: IrDeclarationOri
|
||||
@PublishedApi
|
||||
internal fun IrFactory.buildTypeParameter(builder: IrTypeParameterBuilder, parent: IrDeclarationParent): IrTypeParameter =
|
||||
with(builder) {
|
||||
val wrappedDescriptor = WrappedTypeParameterDescriptor()
|
||||
createTypeParameter(
|
||||
startOffset, endOffset, origin,
|
||||
IrTypeParameterSymbolImpl(wrappedDescriptor),
|
||||
IrTypeParameterSymbolImpl(),
|
||||
name, index, isReified, variance
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
it.superTypes = superTypes
|
||||
it.parent = parent
|
||||
}
|
||||
@@ -330,13 +309,11 @@ fun buildVariable(
|
||||
isConst: Boolean = false,
|
||||
isLateinit: Boolean = false,
|
||||
): IrVariable {
|
||||
val wrappedDescriptor = WrappedVariableDescriptor()
|
||||
return IrVariableImpl(
|
||||
startOffset, endOffset, origin,
|
||||
IrVariableSymbolImpl(wrappedDescriptor),
|
||||
IrVariableSymbolImpl(),
|
||||
name, type, isVar, isConst, isLateinit
|
||||
).also {
|
||||
wrappedDescriptor.bind(it)
|
||||
if (parent != null) {
|
||||
it.parent = parent
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user