IR: add type parameter to IrMemberAccessExpression and some subclasses
This is needed to get rid of the diamond hierarchy:
IrMemberAccessExpression
/ \
/ \
IrFunctionAccessExpression IrCallableReference
\ /
\ /
IrFunctionReference
In the subsequent commit, IrFunctionReference no longer inherits from
IrFunctionAccessExpression; the more precise type of `val symbol:
IrFunctionSymbol` is now carried via the generic type argument.
This will help to refactor IR element hierarchy from interfaces to
classes, improving performance of visitors and transformers.
This commit is contained in:
+1
-1
@@ -131,7 +131,7 @@ class IfNullExpressionsFusionLowering(val context: CommonBackendContext) : FileL
|
||||
is IrConstructorCall,
|
||||
is IrGetSingletonValue,
|
||||
is IrFunctionExpression,
|
||||
is IrCallableReference,
|
||||
is IrCallableReference<*>,
|
||||
is IrClassReference,
|
||||
is IrGetClass ->
|
||||
return false
|
||||
|
||||
+2
-4
@@ -45,8 +45,7 @@ private class KCallableNamePropertyLowering(val context: BackendContext) : FileL
|
||||
}
|
||||
|
||||
private class KCallableNamePropertyTransformer(val lower: KCallableNamePropertyLowering) : IrElementTransformerVoid() {
|
||||
|
||||
private fun nameForCallableMember(reference: IrCallableReference): Name {
|
||||
private fun nameForCallableMember(reference: IrCallableReference<*>): Name {
|
||||
return when (reference) {
|
||||
is IrFunctionReference -> reference.symbol.owner.name
|
||||
is IrPropertyReference -> reference.symbol.owner.name
|
||||
@@ -56,8 +55,7 @@ private class KCallableNamePropertyTransformer(val lower: KCallableNamePropertyL
|
||||
}
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
|
||||
val callableReference = expression.dispatchReceiver as? IrCallableReference ?: return expression
|
||||
val callableReference = expression.dispatchReceiver as? IrCallableReference<*> ?: return expression
|
||||
|
||||
//TODO rewrite checking
|
||||
val directMember = expression.symbol.owner.let {
|
||||
|
||||
+6
-4
@@ -367,7 +367,7 @@ class LocalDeclarationsLowering(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T : IrMemberAccessExpression> T.mapValueParameters(
|
||||
inline fun <T : IrMemberAccessExpression<*>> T.mapValueParameters(
|
||||
newTarget: IrFunction,
|
||||
transform: (IrValueParameter) -> IrExpression?
|
||||
): T =
|
||||
@@ -377,8 +377,10 @@ class LocalDeclarationsLowering(
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : IrMemberAccessExpression> T.fillArguments2(oldExpression: IrMemberAccessExpression, newTarget: IrFunction): T {
|
||||
|
||||
private fun <T : IrMemberAccessExpression<*>> T.fillArguments2(
|
||||
oldExpression: IrMemberAccessExpression<*>,
|
||||
newTarget: IrFunction
|
||||
): T {
|
||||
mapValueParameters(newTarget) { newValueParameterDeclaration ->
|
||||
val oldParameter = newParameterToOld[newValueParameterDeclaration]
|
||||
|
||||
@@ -542,7 +544,7 @@ class LocalDeclarationsLowering(
|
||||
it.copyTypeArgumentsFrom(oldCall)
|
||||
}
|
||||
|
||||
private fun IrMemberAccessExpression.setLocalTypeArguments(callee: IrFunction) {
|
||||
private fun IrMemberAccessExpression<*>.setLocalTypeArguments(callee: IrFunction) {
|
||||
val context = localFunctions[callee] ?: return
|
||||
for ((outerTypeParameter, innerTypeParameter) in context.capturedTypeParameterToTypeParameter) {
|
||||
putTypeArgument(innerTypeParameter.index, outerTypeParameter.defaultType) // TODO: remap default type!
|
||||
|
||||
Reference in New Issue
Block a user