Supported IrFunctionExpression in inliner
This commit is contained in:
+1
-1
@@ -239,9 +239,9 @@ internal val allLoweringsPhase = namedIrModulePhase(
|
|||||||
description = "IR Lowering",
|
description = "IR Lowering",
|
||||||
lower = removeExpectDeclarationsPhase then
|
lower = removeExpectDeclarationsPhase then
|
||||||
lowerBeforeInlinePhase then
|
lowerBeforeInlinePhase then
|
||||||
provisionalFunctionExpressionPhase then
|
|
||||||
arrayConstructorPhase then
|
arrayConstructorPhase then
|
||||||
inlinePhase then
|
inlinePhase then
|
||||||
|
provisionalFunctionExpressionPhase then
|
||||||
lowerAfterInlinePhase then
|
lowerAfterInlinePhase then
|
||||||
interopPart1Phase then
|
interopPart1Phase then
|
||||||
performByIrFile(
|
performByIrFile(
|
||||||
|
|||||||
+6
-23
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.backend.konan.Context
|
|||||||
import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride
|
import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.backend.common.lower.ProvisionalFunctionExpressionLowering
|
|
||||||
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
@@ -51,10 +50,7 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
|
|||||||
if (callee.isTypeOfIntrinsic())
|
if (callee.isTypeOfIntrinsic())
|
||||||
return expression
|
return expression
|
||||||
|
|
||||||
/**
|
val actualCallee = getFunctionDeclaration(callee.symbol)
|
||||||
* HACK: it's temporary workaround over inliner's disability to work with IrFunctionExpression, should be removed.
|
|
||||||
*/
|
|
||||||
val actualCallee = getFunctionDeclaration(callee.symbol).transform(ProvisionalFunctionExpressionLowering(), null) as IrFunction
|
|
||||||
|
|
||||||
val parent = allScopes.map { it.irElement }.filterIsInstance<IrDeclarationParent>().lastOrNull()
|
val parent = allScopes.map { it.irElement }.filterIsInstance<IrDeclarationParent>().lastOrNull()
|
||||||
|
|
||||||
@@ -231,11 +227,10 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
|
|||||||
}.implicitCastIfNeededTo(expression.type)
|
}.implicitCastIfNeededTo(expression.type)
|
||||||
return this@FunctionInlining.visitExpression(super.visitExpression(immediateCall))
|
return this@FunctionInlining.visitExpression(super.visitExpression(immediateCall))
|
||||||
}
|
}
|
||||||
if (functionArgument !is IrBlock)
|
if (functionArgument !is IrFunctionExpression)
|
||||||
return super.visitCall(expression)
|
return super.visitCall(expression)
|
||||||
|
|
||||||
val functionDeclaration = functionArgument.statements[0] as IrFunction
|
val newExpression = inlineFunction(expression, functionArgument.function, false) // Inline the lambda. Lambda parameters will be substituted with lambda arguments.
|
||||||
val newExpression = inlineFunction(expression, functionDeclaration, false) // Inline the lambda. Lambda parameters will be substituted with lambda arguments.
|
|
||||||
return newExpression.transform(this, null) // Substitute lambda arguments with target function arguments.
|
return newExpression.transform(this, null) // Substitute lambda arguments with target function arguments.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,21 +261,9 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
|
|||||||
val argumentExpression: IrExpression) {
|
val argumentExpression: IrExpression) {
|
||||||
|
|
||||||
val isInlinableLambdaArgument: Boolean
|
val isInlinableLambdaArgument: Boolean
|
||||||
get() {
|
get() = parameter.isInlineParameter() &&
|
||||||
if (!parameter.isInlineParameter()) return false
|
(argumentExpression is IrFunctionReference
|
||||||
if (argumentExpression is IrFunctionReference) return true
|
|| argumentExpression is IrFunctionExpression)
|
||||||
|
|
||||||
// Do pattern-matching on IR.
|
|
||||||
if (argumentExpression !is IrBlock) return false
|
|
||||||
if (argumentExpression.origin != IrStatementOrigin.LAMBDA &&
|
|
||||||
argumentExpression.origin != IrStatementOrigin.ANONYMOUS_FUNCTION) return false
|
|
||||||
val statements = argumentExpression.statements
|
|
||||||
val irFunction = statements[0]
|
|
||||||
val irCallableReference = statements[1]
|
|
||||||
if (irFunction !is IrFunction) return false
|
|
||||||
if (irCallableReference !is IrCallableReference) return false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
val isImmutableVariableLoad: Boolean
|
val isImmutableVariableLoad: Boolean
|
||||||
get() = argumentExpression.let {
|
get() = argumentExpression.let {
|
||||||
|
|||||||
Reference in New Issue
Block a user