From 356400158f7a20fec25dd5e426936dabe8c47af1 Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Thu, 23 Nov 2017 13:30:13 +0300 Subject: [PATCH] All arguments of inline function are evaluated. --- .../backend/konan/lower/FunctionInlining.kt | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 1f8605b2abc..0e79a92804b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -225,29 +225,22 @@ private class Inliner(val globalSubstituteMap: MutableMap) return false // Parameter is constant - nothing to evaluate. - if (argumentExpression is IrCallableReference) return false // Parameter is callable reference - nothing to evaluate. - if (isLambdaExpression(argumentExpression) - && !(parameterDescriptor is ValueParameterDescriptor - && parameterDescriptor.isNoinline)) return false // Parameter is lambda and it is not noInline - will be inlined. - return true + if (argumentExpression !is IrBlock) return false // Lambda must be represented with IrBlock. + if (argumentExpression.origin != IrStatementOrigin.LAMBDA && // Origin must be LAMBDA or ANONYMOUS. + argumentExpression.origin != IrStatementOrigin.ANONYMOUS_FUNCTION) return false + + val statements = argumentExpression.statements + val irFunction = statements[0] // Lambda function declaration. + val irCallableReference = statements[1] // Lambda callable reference. + if (irFunction !is IrFunction) return false // First statement of the block must be lambda declaration. + if (irCallableReference !is IrCallableReference) return false // Second statement of the block must be CallableReference. + if (parameterDescriptor is ValueParameterDescriptor && + parameterDescriptor.isNoinline) return false // If parameter marked as "noinline" - do not inline. + return true // The expression represents lambda. } - - private fun isLambdaExpression(expression: IrExpression) : Boolean { - if (expression !is IrBlock) return false // Lambda must be represented with IrBlock. - if (expression.origin != IrStatementOrigin.LAMBDA // Origin must be LAMBDA or ANONYMOUS. - && expression.origin != IrStatementOrigin.ANONYMOUS_FUNCTION) return false - - val statements = expression.statements - val irFunction = statements[0] - val irCallableReference = statements[1] - if (irFunction !is IrFunction) return false // First statement of the block must be lambda declaration. - if (irCallableReference !is IrCallableReference) return false // Second statement of the block must be CallableReference. - return true // The expression represents lambda. - } } //-------------------------------------------------------------------------// @@ -338,8 +331,8 @@ private class Inliner(val globalSubstituteMap: MutableMap argumentExpression to new map. + if (it.isInlinableLambda) { // If argument is inlinable lambda. + substituteMap[parameterDescriptor] = it.argumentExpression // Associate parameter with lambda argument. return@forEach }