IR: make IrCall take IrSimpleFunctionSymbol

This commit is contained in:
Georgy Bronnikov
2020-08-10 13:02:44 +03:00
parent 4901cdb11f
commit 18ae665d41
30 changed files with 124 additions and 100 deletions
@@ -21,7 +21,7 @@ object JsIrBuilder {
object SYNTHESIZED_STATEMENT : IrStatementOriginImpl("SYNTHESIZED_STATEMENT")
object SYNTHESIZED_DECLARATION : IrDeclarationOriginImpl("SYNTHESIZED_DECLARATION")
fun buildCall(target: IrFunctionSymbol, type: IrType? = null, typeArguments: List<IrType>? = null): IrCall {
fun buildCall(target: IrSimpleFunctionSymbol, type: IrType? = null, typeArguments: List<IrType>? = null): IrCall {
val owner = target.owner
return IrCallImpl(
UNDEFINED_OFFSET,
@@ -22,10 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrTypeProjection
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.util.defaultType
import org.jetbrains.kotlin.ir.util.explicitParameters
import org.jetbrains.kotlin.ir.util.isSuspend
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.name.Name
@@ -220,10 +217,30 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
private fun IrSimpleFunction.buildInvoke(): IrFunctionAccessExpression {
val callee = function
val irCall = reference.run {
if (callee is IrConstructor) {
IrConstructorCallImpl(startOffset, endOffset, callee.parentAsClass.defaultType, callee.symbol, callee.typeParameters.size, 0 /* TODO */, callee.valueParameters.size, CALLABLE_REFERENCE_INVOKE)
} else {
IrCallImpl(startOffset, endOffset, callee.returnType, callee.symbol, callee.typeParameters.size, callee.valueParameters.size, CALLABLE_REFERENCE_INVOKE)
when (callee) {
is IrConstructor ->
IrConstructorCallImpl(
startOffset,
endOffset,
callee.parentAsClass.defaultType,
callee.symbol,
callee.typeParameters.size,
0 /* TODO */,
callee.valueParameters.size,
CALLABLE_REFERENCE_INVOKE
)
is IrSimpleFunction ->
IrCallImpl(
startOffset,
endOffset,
callee.returnType,
callee.symbol,
callee.typeParameters.size,
callee.valueParameters.size,
CALLABLE_REFERENCE_INVOKE
)
else ->
error("unknown function kind: ${callee.render()}")
}
}
@@ -121,7 +121,7 @@ class CreateScriptFunctionsPhase(val context: CommonBackendContext) : FileLoweri
)
}
private fun createCall(function: IrFunction): IrCall {
private fun createCall(function: IrSimpleFunction): IrCall {
return IrCallImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, function.returnType,
function.symbol,
@@ -5,19 +5,19 @@
package org.jetbrains.kotlin.ir.backend.js.lower.calls
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.irCall
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.SimpleType
typealias SymbolToTransformer = MutableMap<IrFunctionSymbol, (IrFunctionAccessExpression) -> IrExpression>
internal fun SymbolToTransformer.add(from: Map<IrClassifierSymbol, IrFunctionSymbol>, to: IrFunctionSymbol) {
internal fun SymbolToTransformer.add(from: Map<IrClassifierSymbol, IrFunctionSymbol>, to: IrSimpleFunctionSymbol) {
from.forEach { _, func ->
add(func, to)
}
@@ -33,7 +33,7 @@ internal fun SymbolToTransformer.add(from: IrFunctionSymbol, to: (IrFunctionAcce
put(from, to)
}
internal fun SymbolToTransformer.add(from: IrFunctionSymbol, to: IrFunctionSymbol, dispatchReceiverAsFirstArgument: Boolean = false) {
internal fun SymbolToTransformer.add(from: IrFunctionSymbol, to: IrSimpleFunctionSymbol, dispatchReceiverAsFirstArgument: Boolean = false) {
put(from) { call -> irCall(call, to, dispatchReceiverAsFirstArgument) }
}
@@ -47,11 +47,11 @@ internal fun <K> MutableMap<K, (IrFunctionAccessExpression) -> IrExpression>.add
internal typealias MemberToTransformer = HashMap<SimpleMemberKey, (IrFunctionAccessExpression) -> IrExpression>
internal fun MemberToTransformer.add(type: IrType, name: Name, v: IrFunctionSymbol) {
internal fun MemberToTransformer.add(type: IrType, name: Name, v: IrSimpleFunctionSymbol) {
add(type, name) { irCall(it, v, receiversAsArguments = true) }
}
internal fun MemberToTransformer.add(type: IrType, name: Name, v: IrFunction) {
internal fun MemberToTransformer.add(type: IrType, name: Name, v: IrSimpleFunction) {
add(type, name, v.symbol)
}
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.irCall
import org.jetbrains.kotlin.name.Name
@@ -117,7 +118,7 @@ class NumberOperatorCallsTransformer(context: JsIrBackendContext) : CallsTransfo
private fun irBinaryOp(
call: IrFunctionAccessExpression,
intrinsic: IrFunctionSymbol,
intrinsic: IrSimpleFunctionSymbol,
toInt32: Boolean = false
): IrExpression {
val newCall = irCall(call, intrinsic, receiversAsArguments = true)
@@ -170,7 +171,7 @@ class NumberOperatorCallsTransformer(context: JsIrBackendContext) : CallsTransfo
private fun transformDecrement(call: IrFunctionAccessExpression) =
transformCrement(call, intrinsics.jsMinus)
private fun transformCrement(call: IrFunctionAccessExpression, correspondingBinaryOp: IrFunctionSymbol): IrExpression {
private fun transformCrement(call: IrFunctionAccessExpression, correspondingBinaryOp: IrSimpleFunctionSymbol): IrExpression {
val operation = irCall(call, correspondingBinaryOp, receiversAsArguments = true).apply {
putValueArgument(1, buildInt(1))
}
@@ -262,7 +263,7 @@ class NumberOperatorCallsTransformer(context: JsIrBackendContext) : CallsTransfo
}
}
fun IrFunctionSymbol.call(vararg arguments: IrExpression) =
fun IrSimpleFunctionSymbol.call(vararg arguments: IrExpression) =
JsIrBuilder.buildCall(this, owner.returnType).apply {
for ((idx, arg) in arguments.withIndex()) {
putValueArgument(idx, arg)