Drop all usages of inlineFunctionSymbol in IrReturnableBlock
This commit is contained in:
+1
-1
@@ -104,7 +104,7 @@ private fun IrBody.move(
|
|||||||
// TODO use a generic inliner (e.g. JS/Native's FunctionInlining.Inliner)
|
// TODO use a generic inliner (e.g. JS/Native's FunctionInlining.Inliner)
|
||||||
// Inline simple function calls without type parameters, default parameters, or varargs.
|
// Inline simple function calls without type parameters, default parameters, or varargs.
|
||||||
fun IrFunction.inline(target: IrDeclarationParent, arguments: List<IrValueDeclaration> = listOf()): IrReturnableBlock =
|
fun IrFunction.inline(target: IrDeclarationParent, arguments: List<IrValueDeclaration> = listOf()): IrReturnableBlock =
|
||||||
IrReturnableBlockImpl(startOffset, endOffset, returnType, IrReturnableBlockSymbolImpl(), null, symbol).apply {
|
IrReturnableBlockImpl(startOffset, endOffset, returnType, IrReturnableBlockSymbolImpl(), null).apply {
|
||||||
statements += body!!.move(this@inline, target, symbol, explicitParameters.zip(arguments).toMap()).statements
|
statements += body!!.move(this@inline, target, symbol, explicitParameters.zip(arguments).toMap()).statements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
|
|||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.isUnit
|
import org.jetbrains.kotlin.ir.types.isUnit
|
||||||
import org.jetbrains.kotlin.ir.types.typeWith
|
import org.jetbrains.kotlin.ir.types.typeWith
|
||||||
|
import org.jetbrains.kotlin.ir.util.dump
|
||||||
|
import org.jetbrains.kotlin.ir.util.statements
|
||||||
|
|
||||||
fun IrReturnTarget.returnType(context: CommonBackendContext) =
|
fun IrReturnTarget.returnType(context: CommonBackendContext) =
|
||||||
when (this) {
|
when (this) {
|
||||||
@@ -121,3 +123,24 @@ fun CommonBackendContext.createArrayOfExpression(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified }
|
fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified }
|
||||||
|
|
||||||
|
// This code is partially duplicated in jvm FunctionReferenceLowering::adapteeCall
|
||||||
|
// The difference is jvm version doesn't support ReturnableBlock, but returns call node instead of called function.
|
||||||
|
fun IrFunction.getAdapteeFromAdaptedForReferenceFunction() : IrFunction? {
|
||||||
|
if (origin != IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE) return null
|
||||||
|
// The body of a callable reference adapter contains either only a call, or an IMPLICIT_COERCION_TO_UNIT type operator
|
||||||
|
// applied to a either a call or ReturnableBlock produced from that call inlining.
|
||||||
|
// That call's target is the original function which we need to get.
|
||||||
|
fun unknownStructure(): Nothing = throw UnsupportedOperationException("Unknown structure of ADAPTER_FOR_CALLABLE_REFERENCE: ${dump()}")
|
||||||
|
val call = when (val statement = body?.statements?.singleOrNull() ?: unknownStructure()) {
|
||||||
|
is IrTypeOperatorCall -> {
|
||||||
|
if (statement.operator != IrTypeOperator.IMPLICIT_COERCION_TO_UNIT) unknownStructure()
|
||||||
|
statement.argument
|
||||||
|
}
|
||||||
|
is IrReturn -> statement.value
|
||||||
|
else -> statement
|
||||||
|
}
|
||||||
|
if (call is IrReturnableBlock) return call.inlineFunction ?: unknownStructure()
|
||||||
|
if (call !is IrFunctionAccessExpression) unknownStructure()
|
||||||
|
return call.symbol.owner
|
||||||
|
}
|
||||||
|
|||||||
-1
@@ -235,7 +235,6 @@ class FunctionInlining(
|
|||||||
symbol = irReturnableBlockSymbol,
|
symbol = irReturnableBlockSymbol,
|
||||||
origin = null,
|
origin = null,
|
||||||
statements = listOf(inlinedBlock),
|
statements = listOf(inlinedBlock),
|
||||||
inlineFunctionSymbol = inlineFunctionResolver.getFunctionSymbol(callee)
|
|
||||||
).apply {
|
).apply {
|
||||||
transformChildrenVoid(object : IrElementTransformerVoid() {
|
transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||||
override fun visitReturn(expression: IrReturn): IrExpression {
|
override fun visitReturn(expression: IrReturn): IrExpression {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ package org.jetbrains.kotlin.ir.expressions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrReturnTarget
|
import org.jetbrains.kotlin.ir.declarations.IrReturnTarget
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +18,4 @@ import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
|||||||
*/
|
*/
|
||||||
abstract class IrReturnableBlock : IrBlock(), IrSymbolOwner, IrReturnTarget {
|
abstract class IrReturnableBlock : IrBlock(), IrSymbolOwner, IrReturnTarget {
|
||||||
abstract override val symbol: IrReturnableBlockSymbol
|
abstract override val symbol: IrReturnableBlockSymbol
|
||||||
|
|
||||||
abstract var inlineFunctionSymbol: IrFunctionSymbol?
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ class IrReturnableBlockImpl(
|
|||||||
override var type: IrType,
|
override var type: IrType,
|
||||||
override val symbol: IrReturnableBlockSymbol,
|
override val symbol: IrReturnableBlockSymbol,
|
||||||
override var origin: IrStatementOrigin? = null,
|
override var origin: IrStatementOrigin? = null,
|
||||||
override var inlineFunctionSymbol: IrFunctionSymbol? = null
|
|
||||||
) : IrReturnableBlock() {
|
) : IrReturnableBlock() {
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val descriptor: FunctionDescriptor
|
override val descriptor: FunctionDescriptor
|
||||||
@@ -73,8 +72,7 @@ class IrReturnableBlockImpl(
|
|||||||
symbol: IrReturnableBlockSymbol,
|
symbol: IrReturnableBlockSymbol,
|
||||||
origin: IrStatementOrigin?,
|
origin: IrStatementOrigin?,
|
||||||
statements: List<IrStatement>,
|
statements: List<IrStatement>,
|
||||||
inlineFunctionSymbol: IrFunctionSymbol? = null
|
) : this(startOffset, endOffset, type, symbol, origin) {
|
||||||
) : this(startOffset, endOffset, type, symbol, origin, inlineFunctionSymbol) {
|
|
||||||
this.statements.addAll(statements)
|
this.statements.addAll(statements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -457,8 +457,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.type.remapType(),
|
expression.type.remapType(),
|
||||||
symbolRemapper.getReferencedReturnableBlock(expression.symbol),
|
symbolRemapper.getReferencedReturnableBlock(expression.symbol),
|
||||||
mapStatementOrigin(expression.origin),
|
mapStatementOrigin(expression.origin),
|
||||||
expression.statements.map { it.transform() },
|
expression.statements.map { it.transform() }
|
||||||
expression.inlineFunctionSymbol
|
|
||||||
).copyAttributes(expression)
|
).copyAttributes(expression)
|
||||||
else if (expression is IrInlinedFunctionBlock)
|
else if (expression is IrInlinedFunctionBlock)
|
||||||
IrInlinedFunctionBlockImpl(
|
IrInlinedFunctionBlockImpl(
|
||||||
|
|||||||
@@ -1391,27 +1391,6 @@ val IrFunction.isValueClassTypedEquals: Boolean
|
|||||||
&& (parentClass.isValue)
|
&& (parentClass.isValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This code is partially duplicated in jvm FunctionReferenceLowering::adapteeCall
|
|
||||||
// The difference is jvm version doesn't support ReturnableBlock, but returns call node instead of called function.
|
|
||||||
fun IrFunction.getAdapteeFromAdaptedForReferenceFunction() : IrFunction? {
|
|
||||||
if (origin != IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE) return null
|
|
||||||
// The body of a callable reference adapter contains either only a call, or an IMPLICIT_COERCION_TO_UNIT type operator
|
|
||||||
// applied to a either a call or ReturnableBlock produced from that call inlining.
|
|
||||||
// That call's target is the original function which we need to get.
|
|
||||||
fun unknownStructure(): Nothing = throw UnsupportedOperationException("Unknown structure of ADAPTER_FOR_CALLABLE_REFERENCE: ${dump()}")
|
|
||||||
val call = when (val statement = body?.statements?.singleOrNull() ?: unknownStructure()) {
|
|
||||||
is IrTypeOperatorCall -> {
|
|
||||||
if (statement.operator != IrTypeOperator.IMPLICIT_COERCION_TO_UNIT) unknownStructure()
|
|
||||||
statement.argument
|
|
||||||
}
|
|
||||||
is IrReturn -> statement.value
|
|
||||||
else -> statement
|
|
||||||
}
|
|
||||||
if (call is IrReturnableBlock) return (call.inlineFunctionSymbol ?: unknownStructure()).owner
|
|
||||||
if (call !is IrFunctionAccessExpression) { unknownStructure() }
|
|
||||||
return call.symbol.owner
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method is used to calculate the previous offset from the current one to prevent situations when it can calculate
|
* The method is used to calculate the previous offset from the current one to prevent situations when it can calculate
|
||||||
* [UNDEFINED_OFFSET] from 0 offset and -2 offset from the [UNDEFINED OFFSET]
|
* [UNDEFINED_OFFSET] from 0 offset and -2 offset from the [UNDEFINED OFFSET]
|
||||||
@@ -1422,4 +1401,4 @@ val Int.previousOffset
|
|||||||
0 -> 0
|
0 -> 0
|
||||||
-1 -> UNDEFINED_OFFSET
|
-1 -> UNDEFINED_OFFSET
|
||||||
else -> minus(1)
|
else -> minus(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -645,7 +645,6 @@ object IrTree : AbstractTreeBuilder() {
|
|||||||
parent(returnTarget)
|
parent(returnTarget)
|
||||||
|
|
||||||
+symbol(returnableBlockSymbolType)
|
+symbol(returnableBlockSymbolType)
|
||||||
+field("inlineFunctionSymbol", functionSymbolType, nullable = true)
|
|
||||||
}
|
}
|
||||||
val inlinedFunctionBlock: ElementConfig by element(Expression) {
|
val inlinedFunctionBlock: ElementConfig by element(Expression) {
|
||||||
parent(block)
|
parent(block)
|
||||||
|
|||||||
+1
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan.lower
|
package org.jetbrains.kotlin.backend.konan.lower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.*
|
import org.jetbrains.kotlin.backend.common.*
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.getAdapteeFromAdaptedForReferenceFunction
|
||||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
||||||
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
|
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
|
||||||
|
|||||||
Reference in New Issue
Block a user