IR: remove obsolete descriptor-based utils for IrMemberAccessExpression

Except `putTypeArguments`, which is moved to psi2ir where it's used.
This commit is contained in:
Alexander Udalov
2023-03-28 18:56:05 +02:00
committed by Alexander Udalov
parent 36183c411a
commit 35776ed4fa
7 changed files with 18 additions and 62 deletions
@@ -1601,7 +1601,7 @@ class ExpressionCodegen(
//avoid ambiguity with type constructor type parameters
emptyMap()
} else typeArgumentContainer.typeParameters.associate {
it.symbol to element.getTypeArgumentOrDefault(it)
it.symbol to (element.getTypeArgument(it.index) ?: it.defaultType)
}
val mappings = TypeParameterMappings(typeMapper.typeSystem, typeArguments, allReified = false, typeMapper::mapTypeParameter)
@@ -862,3 +862,13 @@ internal fun unwrapCallableDescriptorAndTypeArguments(resolvedCall: ResolvedCall
return CallBuilder(resolvedCall, substitutedUnwrappedDescriptor, unwrappedTypeArguments)
}
internal inline fun IrMemberAccessExpression<*>.putTypeArguments(
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
toIrType: (KotlinType) -> IrType
) {
if (typeArguments == null) return
for ((typeParameter, typeArgument) in typeArguments) {
putTypeArgument(typeParameter.index, toIrType(typeArgument))
}
}
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
import org.jetbrains.kotlin.ir.expressions.putTypeArguments
import org.jetbrains.kotlin.ir.expressions.typeParametersCount
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
import org.jetbrains.kotlin.ir.types.IrSimpleType
@@ -8,14 +8,10 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
@@ -92,9 +88,6 @@ internal fun IrMemberAccessExpression<*>.throwNoSuchArgumentSlotException(kind:
)
}
fun IrMemberAccessExpression<*>.getTypeArgument(typeParameterDescriptor: TypeParameterDescriptor): IrType? =
getTypeArgument(typeParameterDescriptor.index)
fun IrMemberAccessExpression<*>.copyTypeArgumentsFrom(other: IrMemberAccessExpression<*>, shift: Int = 0) {
assert(typeArgumentsCount == other.typeArgumentsCount + shift) {
"Mismatching type arguments: $typeArgumentsCount vs ${other.typeArgumentsCount} + $shift"
@@ -104,16 +97,6 @@ fun IrMemberAccessExpression<*>.copyTypeArgumentsFrom(other: IrMemberAccessExpre
}
}
inline fun IrMemberAccessExpression<*>.putTypeArguments(
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
toIrType: (KotlinType) -> IrType
) {
if (typeArguments == null) return
for ((typeParameter, typeArgument) in typeArguments) {
putTypeArgument(typeParameter.index, toIrType(typeArgument))
}
}
val CallableDescriptor.typeParametersCount: Int
get() =
when (this) {
@@ -121,43 +104,6 @@ val CallableDescriptor.typeParametersCount: Int
else -> typeParameters.size
}
fun IrMemberAccessExpression<*>.getTypeArgumentOrDefault(irTypeParameter: IrTypeParameter) =
getTypeArgument(irTypeParameter.index) ?: irTypeParameter.defaultType
fun IrMemberAccessExpression<*>.getValueArgument(valueParameterDescriptor: ValueParameterDescriptor) =
getValueArgument(valueParameterDescriptor.index)
fun IrMemberAccessExpression<*>.putValueArgument(valueParameterDescriptor: ValueParameterDescriptor, valueArgument: IrExpression?) {
putValueArgument(valueParameterDescriptor.index, valueArgument)
}
@ObsoleteDescriptorBasedAPI
inline fun <T : IrMemberAccessExpression<*>> T.mapTypeParameters(transform: (TypeParameterDescriptor) -> IrType) : T =
apply {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.typeParameters.forEach {
putTypeArgument(it.index, transform(it))
}
}
@ObsoleteDescriptorBasedAPI
inline fun <T : IrMemberAccessExpression<*>> T.mapValueParameters(transform: (ValueParameterDescriptor) -> IrExpression?): T =
apply {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.valueParameters.forEach {
putValueArgument(it.index, transform(it))
}
}
@ObsoleteDescriptorBasedAPI
inline fun <T : IrMemberAccessExpression<*>> T.mapValueParametersIndexed(transform: (Int, ValueParameterDescriptor) -> IrExpression?): T =
apply {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.valueParameters.forEach {
putValueArgument(it.index, transform(it.index, it))
}
}
fun IrMemberAccessExpression<*>.putArgument(callee: IrFunction, parameter: IrValueParameter, argument: IrExpression) =
when (parameter) {
callee.dispatchReceiverParameter -> dispatchReceiver = argument
@@ -117,10 +117,11 @@ abstract class DataClassMembersGenerator(
irClass.defaultType,
constructedClass = irClass
).apply {
mapTypeParameters(::transform)
mapValueParameters {
val irValueParameter = irFunction.valueParameters[it.index]
irGet(irValueParameter.type, irValueParameter.symbol)
for ((i, typeParameter) in constructorSymbol.descriptor.typeParameters.withIndex()) {
putTypeArgument(i, transform(typeParameter))
}
for ((i, valueParameter) in irFunction.valueParameters.withIndex()) {
putValueArgument(i, irGet(valueParameter.type, valueParameter.symbol))
}
}
)
@@ -82,7 +82,7 @@ fun IrFunctionAccessExpression.getArgumentsWithSymbols(): List<Pair<IrValueParam
}
irFunction.valueParameters.forEach {
val arg = getValueArgument(it.descriptor as ValueParameterDescriptor)
val arg = getValueArgument((it.descriptor as ValueParameterDescriptor).index)
if (arg != null) {
res += (it.symbol to arg)
}
@@ -414,7 +414,7 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv
private fun FunctionGenerationContext.emitCreateUninitializedInstance(callSite: IrCall, resultSlot: LLVMValueRef?): LLVMValueRef {
val typeParameterT = context.ir.symbols.createUninitializedInstance.descriptor.typeParameters[0]
val enumClass = callSite.getTypeArgument(typeParameterT)!!
val enumClass = callSite.getTypeArgument(typeParameterT.index)!!
val enumIrClass = enumClass.getClass()!!
return allocInstance(enumIrClass, environment.calculateLifetime(callSite), resultSlot)
}