IR: make IrCall take IrSimpleFunctionSymbol
This commit is contained in:
+6
-4
@@ -288,10 +288,10 @@ class CallAndReferenceGenerator(
|
||||
val startOffset = adapteeFunction.startOffset
|
||||
val endOffset = adapteeFunction.endOffset
|
||||
val type = adapteeFunction.returnType
|
||||
val irCall =
|
||||
if (adapteeSymbol is IrConstructorSymbol) {
|
||||
val irCall = when (adapteeSymbol) {
|
||||
is IrConstructorSymbol ->
|
||||
IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, adapteeSymbol)
|
||||
} else {
|
||||
is IrSimpleFunctionSymbol ->
|
||||
IrCallImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
@@ -302,7 +302,9 @@ class CallAndReferenceGenerator(
|
||||
origin = null,
|
||||
superQualifierSymbol = null
|
||||
)
|
||||
}
|
||||
else ->
|
||||
error("unknown callee kind: ${adapteeFunction.render()}")
|
||||
}
|
||||
|
||||
if (boundDispatchReceiver != null || boundExtensionReceiver != null) {
|
||||
val receiverValue = IrGetValueImpl(
|
||||
|
||||
+1
-1
@@ -341,7 +341,7 @@ open class DefaultParameterInjector(
|
||||
return visitFunctionAccessExpression(expression) {
|
||||
with(expression) {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type, it,
|
||||
startOffset, endOffset, type, it as IrSimpleFunctionSymbol,
|
||||
typeArgumentsCount = typeArgumentsCount,
|
||||
valueArgumentsCount = it.owner.valueParameters.size,
|
||||
origin = DEFAULT_DISPATCH_CALL,
|
||||
|
||||
+1
-1
@@ -509,7 +509,7 @@ class LocalDeclarationsLowering(
|
||||
rewriteFunctionBody(irElement, null)
|
||||
}
|
||||
|
||||
private fun createNewCall(oldCall: IrCall, newCallee: IrFunction) =
|
||||
private fun createNewCall(oldCall: IrCall, newCallee: IrSimpleFunction) =
|
||||
IrCallImpl(
|
||||
oldCall.startOffset, oldCall.endOffset,
|
||||
newCallee.returnType,
|
||||
|
||||
+16
-11
@@ -234,17 +234,22 @@ class FunctionInlining(
|
||||
}
|
||||
|
||||
val immediateCall = with(expression) {
|
||||
if (function is IrConstructor) {
|
||||
val classTypeParametersCount = function.parentAsClass.typeParameters.size
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset,
|
||||
endOffset,
|
||||
function.returnType,
|
||||
function.symbol,
|
||||
classTypeParametersCount
|
||||
)
|
||||
} else
|
||||
IrCallImpl(startOffset, endOffset, function.returnType, functionArgument.symbol)
|
||||
when (function) {
|
||||
is IrConstructor -> {
|
||||
val classTypeParametersCount = function.parentAsClass.typeParameters.size
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset,
|
||||
endOffset,
|
||||
function.returnType,
|
||||
function.symbol,
|
||||
classTypeParametersCount
|
||||
)
|
||||
}
|
||||
is IrSimpleFunction ->
|
||||
IrCallImpl(startOffset, endOffset, function.returnType, function.symbol)
|
||||
else ->
|
||||
error("Unknown function kind : ${function.render()}")
|
||||
}
|
||||
}.apply {
|
||||
for (parameter in functionParameters) {
|
||||
val argument =
|
||||
|
||||
@@ -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,
|
||||
|
||||
+25
-8
@@ -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()}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+6
-6
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -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)
|
||||
|
||||
@@ -101,7 +101,7 @@ class JvmBackendContext(
|
||||
internal val multifileFacadesToAdd = mutableMapOf<JvmClassName, MutableList<IrClass>>()
|
||||
val multifileFacadeForPart = mutableMapOf<IrClass, JvmClassName>()
|
||||
internal val multifileFacadeClassForPart = mutableMapOf<IrClass, IrClass>()
|
||||
internal val multifileFacadeMemberToPartMember = mutableMapOf<IrFunction, IrFunction>()
|
||||
internal val multifileFacadeMemberToPartMember = mutableMapOf<IrSimpleFunction, IrSimpleFunction>()
|
||||
|
||||
internal val hiddenConstructors = mutableMapOf<IrConstructor, IrConstructor>()
|
||||
|
||||
@@ -117,7 +117,7 @@ class JvmBackendContext(
|
||||
val suspendFunctionOriginalToView = mutableMapOf<IrFunction, IrFunction>()
|
||||
val fakeContinuation: IrExpression = createFakeContinuation(this)
|
||||
|
||||
val staticDefaultStubs = mutableMapOf<IrFunctionSymbol, IrFunction>()
|
||||
val staticDefaultStubs = mutableMapOf<IrSimpleFunctionSymbol, IrSimpleFunction>()
|
||||
|
||||
val inlineClassReplacements = MemoizedInlineClassReplacements(state.functionsWithInlineClassReturnTypesMangled, irFactory)
|
||||
|
||||
|
||||
@@ -268,7 +268,11 @@ fun IrBody.replaceThisByStaticReference(
|
||||
fun createPlaceholderAnyNType(irBuiltIns: IrBuiltIns): IrType =
|
||||
irBuiltIns.anyNType
|
||||
|
||||
fun createDelegatingCallWithPlaceholderTypeArguments(existingCall: IrCall, redirectTarget: IrFunction, irBuiltIns: IrBuiltIns): IrCall =
|
||||
fun createDelegatingCallWithPlaceholderTypeArguments(
|
||||
existingCall: IrCall,
|
||||
redirectTarget: IrSimpleFunction,
|
||||
irBuiltIns: IrBuiltIns
|
||||
): IrCall =
|
||||
IrCallImpl(
|
||||
existingCall.startOffset,
|
||||
existingCall.endOffset,
|
||||
|
||||
+3
-3
@@ -47,7 +47,7 @@ internal val generateMultifileFacadesPhase = makeCustomPhase<JvmBackendContext,
|
||||
description = "Generate JvmMultifileClass facades, based on the information provided by FileClassLowering",
|
||||
prerequisite = setOf(fileClassPhase),
|
||||
op = { context, input ->
|
||||
val functionDelegates = mutableMapOf<IrFunction, IrFunction>()
|
||||
val functionDelegates = mutableMapOf<IrSimpleFunction, IrSimpleFunction>()
|
||||
|
||||
// In -Xmultifile-parts-inherit mode, instead of generating "bridge" methods in the facade which call into parts,
|
||||
// we construct an inheritance chain such that all part members are present as fake overrides in the facade.
|
||||
@@ -89,7 +89,7 @@ private fun generateMultifileFacades(
|
||||
module: ModuleDescriptor,
|
||||
context: JvmBackendContext,
|
||||
shouldGeneratePartHierarchy: Boolean,
|
||||
functionDelegates: MutableMap<IrFunction, IrFunction>
|
||||
functionDelegates: MutableMap<IrSimpleFunction, IrSimpleFunction>
|
||||
): List<IrFile> =
|
||||
context.multifileFacadesToAdd.map { (jvmClassName, partClasses) ->
|
||||
val kotlinPackageFqName = partClasses.first().fqNameWhenAvailable!!.parent()
|
||||
@@ -250,7 +250,7 @@ private fun IrSimpleFunction.createMultifileDelegateIfNeeded(
|
||||
}
|
||||
|
||||
private class UpdateFunctionCallSites(
|
||||
private val functionDelegates: MutableMap<IrFunction, IrFunction>
|
||||
private val functionDelegates: MutableMap<IrSimpleFunction, IrSimpleFunction>
|
||||
) : FileLoweringPass, IrElementTransformer<IrFunction?> {
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.transformChildren(this, null)
|
||||
|
||||
+4
-4
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturn
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrLocalDelegatedPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
*/
|
||||
internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTransformerVoid(), ClassLoweringPass {
|
||||
|
||||
private val removedFunctions = hashMapOf<IrFunctionSymbol, IrFunctionSymbol>()
|
||||
private val removedFunctions = hashMapOf<IrSimpleFunctionSymbol, IrSimpleFunctionSymbol>()
|
||||
|
||||
override fun lower(irClass: IrClass) {
|
||||
if (!irClass.isJvmInterface) return
|
||||
@@ -199,7 +199,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
|
||||
// Bridge from static to static method - simply fill the function arguments to the parameters.
|
||||
// By nature of the generation of both source and target of bridge, they line up.
|
||||
private fun IrFunction.bridgeToStatic(callTarget: IrFunction) {
|
||||
private fun IrFunction.bridgeToStatic(callTarget: IrSimpleFunction) {
|
||||
body = IrExpressionBodyImpl(IrCallImpl(startOffset, endOffset, returnType, callTarget.symbol).also { call ->
|
||||
|
||||
callTarget.typeParameters.forEachIndexed { i, _ ->
|
||||
@@ -214,7 +214,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
|
||||
// Bridge from static DefaultImpl method to the interface method. Arguments need to
|
||||
// be shifted in presence of dispatch and extension receiver.
|
||||
private fun IrFunction.bridgeViaAccessorTo(callTarget: IrFunction) {
|
||||
private fun IrFunction.bridgeViaAccessorTo(callTarget: IrSimpleFunction) {
|
||||
body = IrExpressionBodyImpl(
|
||||
IrCallImpl(
|
||||
startOffset,
|
||||
|
||||
+9
-4
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.allTypeParameters
|
||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_OVERLOADS_FQ_NAME
|
||||
|
||||
internal val jvmOverloadsAnnotationPhase = makeIrFilePhase(
|
||||
@@ -55,10 +56,14 @@ private class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : C
|
||||
private fun generateWrapper(target: IrFunction, numDefaultParametersToExpect: Int): IrFunction {
|
||||
val wrapperIrFunction = context.irFactory.generateWrapperHeader(target, numDefaultParametersToExpect)
|
||||
|
||||
val call = if (target is IrConstructor)
|
||||
IrDelegatingConstructorCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.irBuiltIns.unitType, target.symbol)
|
||||
else
|
||||
IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, target.returnType, target.symbol)
|
||||
val call = when (target) {
|
||||
is IrConstructor ->
|
||||
IrDelegatingConstructorCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.irBuiltIns.unitType, target.symbol)
|
||||
is IrSimpleFunction ->
|
||||
IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, target.returnType, target.symbol)
|
||||
else ->
|
||||
error("unknown function kind: ${target.render()}")
|
||||
}
|
||||
for (arg in wrapperIrFunction.allTypeParameters) {
|
||||
call.putTypeArgument(arg.index, arg.defaultType)
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
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.IrType
|
||||
import org.jetbrains.kotlin.ir.util.fqNameForIrSerialization
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
@@ -59,7 +59,7 @@ class JvmStandardLibraryBuiltInsLowering(val context: JvmBackendContext) : FileL
|
||||
|
||||
// Originals are so far only instance methods, and the replacements are
|
||||
// statics, so we copy dispatch receivers to a value argument if needed.
|
||||
private fun IrCall.replaceWithCallTo(replacement: IrFunctionSymbol) =
|
||||
private fun IrCall.replaceWithCallTo(replacement: IrSimpleFunctionSymbol) =
|
||||
IrCallImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class ResolveInlineCalls(val context: JvmBackendContext) : IrElementTransformerV
|
||||
})
|
||||
}
|
||||
|
||||
private fun IrFunction.resolveMultiFileFacades(): IrFunction? =
|
||||
private fun IrFunction.resolveMultiFileFacades(): IrSimpleFunction? =
|
||||
if (origin == JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE) {
|
||||
context.multifileFacadeMemberToPartMember[this]
|
||||
} else null
|
||||
|
||||
+3
-6
@@ -25,10 +25,7 @@ import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.then
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturn
|
||||
@@ -63,7 +60,7 @@ private class StaticDefaultFunctionLowering(val context: JvmBackendContext) : Ir
|
||||
irClass.accept(this, null)
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction): IrStatement = super.visitFunction(
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction): IrStatement = super.visitFunction(
|
||||
if (declaration.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER && declaration.dispatchReceiverParameter != null)
|
||||
context.getStaticFunctionWithReceivers(declaration).also {
|
||||
it.body = declaration.moveBodyTo(it)
|
||||
@@ -106,7 +103,7 @@ private class StaticDefaultCallLowering(
|
||||
}
|
||||
}
|
||||
|
||||
private fun JvmBackendContext.getStaticFunctionWithReceivers(function: IrFunction) =
|
||||
private fun JvmBackendContext.getStaticFunctionWithReceivers(function: IrSimpleFunction) =
|
||||
staticDefaultStubs.getOrPut(function.symbol) {
|
||||
irFactory.createStaticFunctionWithReceivers(function.parent, function.name, function)
|
||||
}
|
||||
|
||||
+4
-4
@@ -313,7 +313,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
}
|
||||
}
|
||||
|
||||
private fun createSimpleFunctionCall(accessor: IrFunction, targetSymbol: IrFunctionSymbol, superQualifierSymbol: IrClassSymbol?) =
|
||||
private fun createSimpleFunctionCall(accessor: IrFunction, targetSymbol: IrSimpleFunctionSymbol, superQualifierSymbol: IrClassSymbol?) =
|
||||
IrCallImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
accessor.returnType,
|
||||
@@ -410,7 +410,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
is IrCall -> IrCallImpl(
|
||||
oldExpression.startOffset, oldExpression.endOffset,
|
||||
oldExpression.type,
|
||||
accessorSymbol, oldExpression.typeArgumentsCount,
|
||||
accessorSymbol as IrSimpleFunctionSymbol, oldExpression.typeArgumentsCount,
|
||||
oldExpression.origin
|
||||
)
|
||||
is IrDelegatingConstructorCall -> IrDelegatingConstructorCallImpl(
|
||||
@@ -447,7 +447,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
|
||||
private fun modifyGetterExpression(
|
||||
oldExpression: IrGetField,
|
||||
accessorSymbol: IrFunctionSymbol
|
||||
accessorSymbol: IrSimpleFunctionSymbol
|
||||
): IrCall {
|
||||
val call = IrCallImpl(
|
||||
oldExpression.startOffset, oldExpression.endOffset,
|
||||
@@ -463,7 +463,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
|
||||
private fun modifySetterExpression(
|
||||
oldExpression: IrSetField,
|
||||
accessorSymbol: IrFunctionSymbol
|
||||
accessorSymbol: IrSimpleFunctionSymbol
|
||||
): IrCall {
|
||||
val call = IrCallImpl(
|
||||
oldExpression.startOffset, oldExpression.endOffset,
|
||||
|
||||
+2
-3
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.builders.irGet
|
||||
import org.jetbrains.kotlin.ir.builders.irTemporary
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDynamicOperatorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
@@ -317,8 +316,8 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen
|
||||
val getterDescriptor = unwrappedPropertyDescriptor.unwrappedGetMethod
|
||||
val setterDescriptor = unwrappedPropertyDescriptor.unwrappedSetMethod
|
||||
|
||||
val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceFunction(it.original) }
|
||||
val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceFunction(it.original) }
|
||||
val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) }
|
||||
val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceSimpleFunction(it.original) }
|
||||
|
||||
val propertyIrType = descriptor.type.toIrType()
|
||||
return if (getterSymbol != null || setterSymbol != null) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrDynamicType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
@@ -122,7 +121,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
|
||||
) =
|
||||
if (descriptor is LocalVariableDescriptor && descriptor.isDelegated) {
|
||||
val getterDescriptor = descriptor.getter!!
|
||||
val getterSymbol = context.symbolTable.referenceFunction(getterDescriptor.original)
|
||||
val getterSymbol = context.symbolTable.referenceSimpleFunction(getterDescriptor.original)
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, descriptor.type.toIrType(), getterSymbol, origin ?: IrStatementOrigin.GET_LOCAL_PROPERTY
|
||||
).apply {
|
||||
@@ -207,7 +206,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
|
||||
dispatchReceiver
|
||||
)
|
||||
} else {
|
||||
val getterSymbol = context.symbolTable.referenceFunction(getMethodDescriptor.original)
|
||||
val getterSymbol = context.symbolTable.referenceSimpleFunction(getMethodDescriptor.original)
|
||||
IrCallImpl(
|
||||
startOffset, endOffset,
|
||||
irType,
|
||||
@@ -333,7 +332,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val originalSymbol = context.symbolTable.referenceFunction(functionDescriptor.original)
|
||||
val originalSymbol = context.symbolTable.referenceSimpleFunction(functionDescriptor.original)
|
||||
IrCallImpl(
|
||||
startOffset, endOffset,
|
||||
irType,
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.ir.expressions.typeParametersCount
|
||||
import org.jetbrains.kotlin.ir.util.createIrClassFromDescriptor
|
||||
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
|
||||
import org.jetbrains.kotlin.ir.util.properties
|
||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDelegatedSuperTypeEntry
|
||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||
@@ -332,7 +331,7 @@ class ClassGenerator(
|
||||
val substitutedDelegateTo = substituteDelegateToDescriptor(delegatedDescriptor, delegateToDescriptor)
|
||||
val returnType = substitutedDelegateTo.returnType!!
|
||||
|
||||
val delegateToSymbol = context.symbolTable.referenceFunction(delegateToDescriptor.original)
|
||||
val delegateToSymbol = context.symbolTable.referenceSimpleFunction(delegateToDescriptor.original)
|
||||
|
||||
val irCall = IrCallImpl(
|
||||
startOffset, endOffset,
|
||||
|
||||
+1
-2
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
||||
import org.jetbrains.kotlin.ir.types.makeNotNull
|
||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -413,7 +412,7 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
functionDescriptor: FunctionDescriptor,
|
||||
receiver: IrExpression
|
||||
): IrExpression {
|
||||
val originalSymbol = context.symbolTable.referenceFunction(functionDescriptor.original)
|
||||
val originalSymbol = context.symbolTable.referenceSimpleFunction(functionDescriptor.original)
|
||||
return IrCallImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
|
||||
+8
-12
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -197,18 +198,13 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
||||
|
||||
val irType = resolvedDescriptor.returnType!!.toIrType()
|
||||
|
||||
val irCall =
|
||||
if (resolvedDescriptor is ConstructorDescriptor)
|
||||
IrConstructorCallImpl.fromSymbolDescriptor(
|
||||
startOffset, endOffset, irType,
|
||||
adapteeSymbol as IrConstructorSymbol
|
||||
)
|
||||
else
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, irType,
|
||||
adapteeSymbol,
|
||||
origin = null, superQualifierSymbol = null
|
||||
)
|
||||
val irCall = when (adapteeSymbol) {
|
||||
is IrConstructorSymbol ->
|
||||
IrConstructorCallImpl.fromSymbolDescriptor(startOffset, endOffset, irType, adapteeSymbol)
|
||||
is IrSimpleFunctionSymbol ->
|
||||
IrCallImpl(startOffset, endOffset, irType, adapteeSymbol, origin = null, superQualifierSymbol = null)
|
||||
else -> error("Unknown symbol kind $adapteeSymbol")
|
||||
}
|
||||
|
||||
val hasBoundDispatchReceiver = resolvedCall.dispatchReceiver != null && resolvedCall.dispatchReceiver !is TransientReceiver
|
||||
val hasBoundExtensionReceiver = resolvedCall.extensionReceiver != null && resolvedCall.extensionReceiver !is TransientReceiver
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||
|
||||
@@ -126,9 +126,9 @@ class AccessorPropertyLValue(
|
||||
endOffset: Int,
|
||||
origin: IrStatementOrigin?,
|
||||
type: IrType,
|
||||
val getter: IrFunctionSymbol?,
|
||||
val getter: IrSimpleFunctionSymbol?,
|
||||
val getterDescriptor: FunctionDescriptor?,
|
||||
val setter: IrFunctionSymbol?,
|
||||
val setter: IrSimpleFunctionSymbol?,
|
||||
val setterDescriptor: FunctionDescriptor?,
|
||||
val typeArguments: List<IrType>?,
|
||||
callReceiver: CallReceiver,
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
|
||||
abstract class IrCall(
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
) : IrFunctionAccessExpression(typeArgumentsCount, valueArgumentsCount) {
|
||||
override abstract val symbol: IrSimpleFunctionSymbol
|
||||
abstract val superQualifierSymbol: IrClassSymbol?
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.typeParametersCount
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
@@ -31,7 +31,7 @@ class IrCallImpl(
|
||||
override val startOffset: Int,
|
||||
override val endOffset: Int,
|
||||
override val type: IrType,
|
||||
override val symbol: IrFunctionSymbol,
|
||||
override val symbol: IrSimpleFunctionSymbol,
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
override val origin: IrStatementOrigin? = null,
|
||||
@@ -48,7 +48,7 @@ class IrCallImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: IrType,
|
||||
symbol: IrFunctionSymbol,
|
||||
symbol: IrSimpleFunctionSymbol,
|
||||
origin: IrStatementOrigin? = null,
|
||||
superQualifierSymbol: IrClassSymbol? = null
|
||||
) : this(
|
||||
@@ -61,7 +61,7 @@ class IrCallImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: IrType,
|
||||
symbol: IrFunctionSymbol,
|
||||
symbol: IrSimpleFunctionSymbol,
|
||||
typeArgumentsCount: Int,
|
||||
origin: IrStatementOrigin? = null,
|
||||
superQualifierSymbol: IrClassSymbol? = null
|
||||
|
||||
@@ -519,7 +519,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
}
|
||||
|
||||
private fun shallowCopyCall(expression: IrCall): IrCall {
|
||||
val newCallee = symbolRemapper.getReferencedFunction(expression.symbol)
|
||||
val newCallee = symbolRemapper.getReferencedSimpleFunction(expression.symbol)
|
||||
return IrCallImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type.remapType(),
|
||||
|
||||
@@ -411,7 +411,7 @@ fun irConstructorCall(
|
||||
|
||||
fun irCall(
|
||||
call: IrFunctionAccessExpression,
|
||||
newFunction: IrFunction,
|
||||
newFunction: IrSimpleFunction,
|
||||
receiversAsArguments: Boolean = false,
|
||||
argumentsAsReceivers: Boolean = false,
|
||||
newSuperQualifierSymbol: IrClassSymbol? = null
|
||||
@@ -426,7 +426,7 @@ fun irCall(
|
||||
|
||||
fun irCall(
|
||||
call: IrFunctionAccessExpression,
|
||||
newSymbol: IrFunctionSymbol,
|
||||
newSymbol: IrSimpleFunctionSymbol,
|
||||
receiversAsArguments: Boolean = false,
|
||||
argumentsAsReceivers: Boolean = false,
|
||||
newSuperQualifierSymbol: IrClassSymbol? = null
|
||||
|
||||
+1
-1
@@ -379,7 +379,7 @@ abstract class IrFileDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeCall(proto: ProtoCall, start: Int, end: Int, type: IrType): IrCall {
|
||||
val symbol = deserializeIrSymbolAndRemap(proto.symbol) as IrFunctionSymbol
|
||||
val symbol = deserializeIrSymbolAndRemap(proto.symbol) as IrSimpleFunctionSymbol
|
||||
|
||||
val superSymbol = if (proto.hasSuper()) {
|
||||
deserializeIrSymbolAndRemap(proto.`super`) as IrClassSymbol
|
||||
|
||||
+2
-3
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
@@ -51,7 +50,7 @@ class ParcelableIrTransformer(private val context: IrPluginContext, private val
|
||||
private fun IrPluginContext.createIrBuilder(symbol: IrSymbol) =
|
||||
DeclarationIrBuilder(this, symbol, symbol.owner.startOffset, symbol.owner.endOffset)
|
||||
|
||||
private val symbolMap = mutableMapOf<IrFunctionSymbol, IrFunctionSymbol>()
|
||||
private val symbolMap = mutableMapOf<IrSimpleFunctionSymbol, IrSimpleFunctionSymbol>()
|
||||
|
||||
private val irFactory: IrFactory = IrFactoryImpl
|
||||
|
||||
@@ -91,7 +90,7 @@ class ParcelableIrTransformer(private val context: IrPluginContext, private val
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction): IrStatement {
|
||||
// Remap overridden symbols, otherwise the code might break in BridgeLowering
|
||||
declaration.overriddenSymbols = declaration.overriddenSymbols.map { symbol ->
|
||||
(symbolMap[symbol] ?: symbol) as IrSimpleFunctionSymbol
|
||||
symbolMap[symbol] ?: symbol
|
||||
}
|
||||
return super.visitSimpleFunction(declaration)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user