From d237afdea5da30237f3a8adc22dad81d6a10466f Mon Sep 17 00:00:00 2001 From: KonstantinAnisimov Date: Mon, 18 Dec 2017 15:03:55 +0300 Subject: [PATCH] Revert "Revert commits: (#1162) --- .../backend/konan/lower/FunctionInlining.kt | 74 +++++++------------ 1 file changed, 26 insertions(+), 48 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 3ccf8d71335..fae1c6978b1 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 @@ -26,7 +26,10 @@ import org.jetbrains.kotlin.backend.konan.descriptors.isFunctionInvoke import org.jetbrains.kotlin.backend.konan.descriptors.needsInlining import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride import org.jetbrains.kotlin.backend.konan.ir.DeserializerDriver -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.ValueDescriptor +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrFunction @@ -44,7 +47,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import org.jetbrains.kotlin.types.TypeProjectionImpl import org.jetbrains.kotlin.types.TypeSubstitutor - //-----------------------------------------------------------------------------// internal class FunctionInlining(val context: Context): IrElementTransformerVoidWithContext() { @@ -66,31 +68,21 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW override fun visitCall(expression: IrCall): IrExpression { - val functionDescriptor = expression.descriptor - if (!functionDescriptor.needsInlining) return super.visitCall(expression) // This call does not need inlining. - if (isInlineFunctionScope()) return super.visitCall(expression) // Ignore inlining in functions declared as "inline" + val irCall = super.visitCall(expression) as IrCall + val functionDescriptor = irCall.descriptor + if (!functionDescriptor.needsInlining) return irCall // This call does not need inlining. - val functionDeclaration = getFunctionDeclaration(expression) // Get declaration of the function to be inlined. + val functionDeclaration = getFunctionDeclaration(irCall) // Get declaration of the function to be inlined. if (functionDeclaration == null) { // We failed to get the declaration. val message = "Inliner failed to obtain function declaration: " + functionDescriptor.fqNameSafe.toString() - context.reportWarning(message, currentFile, expression) // Report warning. - return super.visitCall(expression) + context.reportWarning(message, currentFile, irCall) // Report warning. + return irCall } + functionDeclaration.transformChildrenVoid(this) // Process recursive inline. val inliner = Inliner(globalSubstituteMap, functionDeclaration, currentScope!!, context) // Create inliner for this scope. - val inlinedFunctionBody = inliner.inline(expression) // Return newly created IrInlineBody instead of IrCall. - inlinedFunctionBody.transformChildrenVoid(this) - return inlinedFunctionBody - } - - //-------------------------------------------------------------------------// - - private fun isInlineFunctionScope(): Boolean { - if (currentFunction == null) return false - val scopeOwner = currentFunction!!.scope.scopeOwner - if (scopeOwner !is FunctionDescriptor) return false - return scopeOwner.isInline + return inliner.inline(irCall ) // Return newly created IrInlineBody instead of IrCall. } //-------------------------------------------------------------------------// @@ -234,35 +226,21 @@ private class Inliner(val globalSubstituteMap: MutableMap") - } - - //-------------------------------------------------------------------------// - - fun IrExpression.isInlinableBody(): Boolean { - if (this !is IrBlock) return false // Lambda must be represented with IrBlock. - val lastStatement = statements.last() - if (lastStatement !is IrCallableReference) return false // Second statement of the lambda block must be CallableReference. - return isAnonymousFunction(lastStatement.descriptor) - } } //-------------------------------------------------------------------------// @@ -353,7 +331,7 @@ private class Inliner(val globalSubstituteMap: MutableMap