IR: remove unneeded casts after making IrCall's symbol a simple function
This commit is contained in:
+3
-4
@@ -220,12 +220,11 @@ class InlineClassLowering(val context: CommonBackendContext) {
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
expression.transformChildrenVoid(this)
|
||||
val function = expression.symbol.owner
|
||||
val function: IrSimpleFunction = expression.symbol.owner
|
||||
if (function.parent !is IrClass ||
|
||||
function.isStaticMethodOfClass ||
|
||||
!function.parentAsClass.isInline ||
|
||||
(function is IrSimpleFunction && !function.isReal) ||
|
||||
(function is IrConstructor && function.isPrimary)
|
||||
!function.isReal
|
||||
) {
|
||||
return expression
|
||||
}
|
||||
@@ -233,7 +232,7 @@ class InlineClassLowering(val context: CommonBackendContext) {
|
||||
return irCall(
|
||||
expression,
|
||||
getOrCreateStaticMethod(function),
|
||||
receiversAsArguments = (function is IrSimpleFunction)
|
||||
receiversAsArguments = true
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class PropertyAccessorInlineLowering(private val context: CommonBackendContext)
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
expression.transformChildrenVoid(this)
|
||||
|
||||
val callee = expression.symbol.owner as IrSimpleFunction
|
||||
val callee = expression.symbol.owner
|
||||
val property = callee.correspondingPropertySymbol?.owner ?: return expression
|
||||
|
||||
// Some devirtualization required here
|
||||
|
||||
+1
-4
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
@@ -73,9 +72,7 @@ class PrimitiveCompanionLowering(val context: JsIrBackendContext) : BodyLowering
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
val newCall = super.visitCall(expression) as IrCall
|
||||
|
||||
val function = expression.symbol.owner as IrSimpleFunction
|
||||
|
||||
val actualFunction = getActualPrimitiveCompanionPropertyAccessor(function)
|
||||
val actualFunction = getActualPrimitiveCompanionPropertyAccessor(expression.symbol.owner)
|
||||
?: return newCall
|
||||
|
||||
return irCall(newCall, actualFunction)
|
||||
|
||||
+4
-5
@@ -59,13 +59,12 @@ class PrimitiveContainerMemberCallTransformer(private val context: JsIrBackendCo
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformFunctionAccess(expression: IrFunctionAccessExpression): IrExpression {
|
||||
val symbol = expression.symbol
|
||||
symbolToTransformer[symbol]?.let {
|
||||
return it(expression)
|
||||
override fun transformFunctionAccess(call: IrFunctionAccessExpression): IrExpression {
|
||||
symbolToTransformer[call.symbol]?.let {
|
||||
return it(call)
|
||||
}
|
||||
|
||||
return expression
|
||||
return call
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -78,11 +78,8 @@ fun translateCall(
|
||||
transformer: IrElementToJsExpressionTransformer
|
||||
): JsExpression {
|
||||
val function = expression.symbol.owner.realOverrideTarget
|
||||
require(function is IrSimpleFunction) { "Only IrSimpleFunction could be called via IrCall" } // TODO: fix it in IrCall
|
||||
|
||||
val symbol = function.symbol
|
||||
|
||||
context.staticContext.intrinsics[symbol]?.let {
|
||||
context.staticContext.intrinsics[function.symbol]?.let {
|
||||
return it(expression, context)
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.irBlockBody
|
||||
import org.jetbrains.kotlin.ir.builders.irCall
|
||||
import org.jetbrains.kotlin.ir.builders.irGet
|
||||
@@ -128,7 +127,7 @@ private class InterfaceSuperCallsLowering(val context: JvmBackendContext) : IrEl
|
||||
return super.visitCall(expression)
|
||||
}
|
||||
|
||||
val superCallee = expression.symbol.owner as IrSimpleFunction
|
||||
val superCallee = expression.symbol.owner
|
||||
if (superCallee.isDefinitelyNotDefaultImplsMethod(context.state.jvmDefaultMode)) return super.visitCall(expression)
|
||||
|
||||
val redirectTarget = context.cachedDeclarations.getDefaultImplsFunction(superCallee)
|
||||
@@ -159,7 +158,7 @@ private class InterfaceDefaultCallsLowering(val context: JvmBackendContext) : Ir
|
||||
return super.visitCall(expression)
|
||||
}
|
||||
|
||||
val redirectTarget = context.cachedDeclarations.getDefaultImplsFunction(callee as IrSimpleFunction)
|
||||
val redirectTarget = context.cachedDeclarations.getDefaultImplsFunction(callee)
|
||||
|
||||
// InterfaceLowering bridges from DefaultImpls in compatibility mode -- if that's the case,
|
||||
// this phase will inadvertently cause a recursive loop as the bridge on the DefaultImpls
|
||||
@@ -201,7 +200,7 @@ private class InterfaceObjectCallsLowering(val context: JvmBackendContext) : IrE
|
||||
if (expression.superQualifierSymbol != null && !expression.isSuperToAny())
|
||||
return super.visitCall(expression)
|
||||
val callee = expression.symbol.owner
|
||||
if (callee !is IrSimpleFunction || !callee.hasInterfaceParent())
|
||||
if (!callee.hasInterfaceParent())
|
||||
return super.visitCall(expression)
|
||||
val resolved = callee.resolveFakeOverride()
|
||||
if (resolved?.isMethodOfAny() != true)
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ private class MakeCallsStatic(
|
||||
// Imported functions do not have their receiver parameter nulled by SingletonObjectJvmStaticLowering,
|
||||
// so we have to do it here.
|
||||
// TODO: would be better handled by lowering imported declarations.
|
||||
val callee = expression.symbol.owner as IrSimpleFunction
|
||||
val callee = expression.symbol.owner
|
||||
val newCallee = if (!callee.isInCurrentModule()) {
|
||||
callee.copyRemovingDispatchReceiver() // TODO: cache these
|
||||
} else callee
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
|
||||
@@ -43,7 +42,7 @@ private class ReplaceKFunctionInvokeWithFunctionInvoke : FileLoweringPass, IrEle
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
val callee = expression.symbol.owner
|
||||
if (callee !is IrSimpleFunction || callee.name != OperatorNameConventions.INVOKE) return super.visitCall(expression)
|
||||
if (callee.name != OperatorNameConventions.INVOKE) return super.visitCall(expression)
|
||||
|
||||
val parentClass = callee.parent as? IrClass ?: return super.visitCall(expression)
|
||||
if (!parentClass.defaultType.isKFunction() && !parentClass.defaultType.isKSuspendFunction()) return super.visitCall(expression)
|
||||
|
||||
-2
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.backend.common.ir.isElseBranch
|
||||
import org.jetbrains.kotlin.backend.wasm.ast.*
|
||||
import org.jetbrains.kotlin.backend.wasm.utils.getWasmInstructionAnnotation
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.isUnit
|
||||
@@ -89,7 +88,6 @@ class ExpressionTransformer : BaseTransformer<WasmInstruction, WasmCodegenContex
|
||||
|
||||
override fun visitCall(expression: IrCall, data: WasmCodegenContext): WasmInstruction {
|
||||
val function = expression.symbol.owner.realOverrideTarget
|
||||
require(function is IrSimpleFunction) { "Only IrSimpleFunction could be called via IrCall" }
|
||||
val valueArgs = (0 until expression.valueArgumentsCount).mapNotNull { expression.getValueArgument(it) }
|
||||
val irArguments = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) + valueArgs
|
||||
val wasmArguments = irArguments.map { expressionToWasmInstruction(it, data) }
|
||||
|
||||
+3
-3
@@ -5,13 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.interpreter.state
|
||||
|
||||
import org.jetbrains.kotlin.ir.interpreter.getLastOverridden
|
||||
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.interpreter.getLastOverridden
|
||||
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
@@ -33,7 +33,7 @@ internal class Primitive<T>(var value: T, val type: IrType) : State {
|
||||
// must add property's getter to declaration's list because they are not present in ir class for primitives
|
||||
val declarations = irClass.declarations.map { if (it is IrProperty) it.getter else it }
|
||||
return declarations.filterIsInstance<IrFunction>()
|
||||
.firstOrNull { it.symbol == owner.symbol || (it is IrSimpleFunction && owner is IrSimpleFunction && it.overrides(owner)) }
|
||||
.firstOrNull { it.symbol == owner.symbol || (it is IrSimpleFunction && it.overrides(owner)) }
|
||||
?.let { if (it.isFakeOverride) it.getLastOverridden() else it }
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.builders
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
@@ -278,14 +277,6 @@ fun IrBuilderWithScope.irCall(callee: IrConstructorSymbol): IrConstructorCall =
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol): IrFunctionAccessExpression =
|
||||
irCall(callee, callee.owner.returnType)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, descriptor: FunctionDescriptor, type: IrType): IrCall =
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type,
|
||||
callee as IrSimpleFunctionSymbol,
|
||||
valueArgumentsCount = callee.owner.valueParameters.size,
|
||||
typeArgumentsCount = callee.owner.typeParameters.size
|
||||
)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunction): IrFunctionAccessExpression =
|
||||
irCall(callee.symbol)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user