diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt index 8e8e2b1ea69..554262b5d54 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt @@ -310,10 +310,28 @@ internal fun DeclarationDescriptor.getMemberScope(): MemberScope { } // It is possible to declare "external inline fun", -// but it doesn't have much sence for native, +// but it doesn't have much sense for native, // since externals don't have IR bodies. -internal val FunctionDescriptor.needsInlining: Boolean - get() = (this.isInline && !this.isExternal) + +// Enforce inlining of some constructors (ByteArray, IntArray, ...) +val mustInlineFunctions = setOf( + "kotlin.DoubleArray.", + "kotlin.FloatArray.", + "kotlin.ByteArray.", + "kotlin.ShortArray.", + "kotlin.IntArray.", + "kotlin.LongArray.", + "kotlin.CharArray.", + "kotlin.BooleanArray." +) + +internal val FunctionDescriptor.needsInlining: Boolean + get(): Boolean { + val needs = this.isInline && !this.isExternal + if (valueParameters.size != 2) return needs // Constructor must have two parameters. + if (mustInlineFunctions.contains(fqNameSafe.toString())) return true + return needs + } internal val FunctionDescriptor.needsSerializedIr: Boolean get() = (this.needsInlining && this.isExported()) 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 3470ed8ffbe..6139c84fd95 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 @@ -56,7 +56,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW val irCall = super.visitCall(expression) as IrCall val functionDescriptor = irCall.descriptor as FunctionDescriptor - if (!needsInlining(functionDescriptor)) return irCall // This call does not need inlining. + if (!functionDescriptor.needsInlining) return irCall // This call does not need inlining. val functionDeclaration = getFunctionDeclaration(irCall) // Get declaration of the function to be inlined. if (functionDeclaration == null) { // We failed to get the declaration. @@ -83,28 +83,6 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW return functionDeclaration as IrFunction? } - //-------------------------------------------------------------------------// - // Enforce inlining of some constructors (ByteArray, IntArray, ...) - - private fun needsInlining(functionDescriptor: FunctionDescriptor): Boolean { - - val needsInlining = functionDescriptor.needsInlining - val functionName = functionDescriptor.name.toString() - if (functionName != "") return needsInlining // This is not constructor. - if (functionDescriptor.valueParameters.size != 2) return needsInlining // Constructor must have two parameters. - - val returnType = functionDescriptor.returnType.toString() - if (returnType == "DoubleArray") return true - if (returnType == "FloatArray" ) return true - if (returnType == "ByteArray" ) return true - if (returnType == "ShortArray" ) return true - if (returnType == "IntArray" ) return true - if (returnType == "LongArray" ) return true - if (returnType == "CharArray" ) return true - - return needsInlining - } - //-------------------------------------------------------------------------// override fun visitElement(element: IrElement) = element.accept(this, null)