From 344c11af7f9046fbcb5bf4267cf18d54e933ba11 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 18 Nov 2019 09:41:22 +0100 Subject: [PATCH] JVM_IR. Support multifile facades in default function inlining --- .../backend/jvm/codegen/ExpressionCodegen.kt | 10 +++++++++- .../jvm/codegen/IrSourceCompilerForInline.kt | 14 ++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index b0108567eed..c2d04443784 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -937,6 +937,14 @@ class ExpressionCodegen( } } + private fun IrFunction.resolveMultiFileFacades(): IrFunction { + //TODO: move to ResolveInlineCalls lower (now it's goes before generateMultifileFacadesPhase) + return if (origin == JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE) { + context.multifileFacadeMemberToPartMember[this]?.let { return it } + error("Function from a multi-file facade without the link to the function in the part: ${this.render()}") + } else this + } + private fun getOrCreateCallGenerator( element: IrFunctionAccessExpression, data: BlockInfo, signature: JvmMethodSignature ): IrCallGenerator { @@ -946,7 +954,7 @@ class ExpressionCodegen( return IrCallGenerator.DefaultCallGenerator } - val callee = element.symbol.owner + val callee = element.symbol.owner.resolveMultiFileFacades() val typeArgumentContainer = if (callee is IrConstructor) callee.parentAsClass else callee val typeArguments = if (element.typeArgumentsCount == 0) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt index b425d630533..425d1bb5155 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.util.isSuspend import org.jetbrains.kotlin.ir.util.parentAsClass import org.jetbrains.kotlin.ir.util.render -import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature @@ -96,21 +95,12 @@ class IrSourceCompilerForInline( asmMethod: Method ): SMAPAndMethodNode { assert(callableDescriptor == callee.symbol.descriptor.original) { "Expected $callableDescriptor got ${callee.descriptor.original}" } - val irFunction = getFunctionToInline(jvmSignature, callDefault) + val irFunction = getFunctionToInline() return makeInlineNode(irFunction, FakeClassCodegen(irFunction, codegen.classCodegen), false) } - private fun getFunctionToInline(jvmSignature: JvmMethodSignature, callDefault: Boolean): IrFunction { + private fun getFunctionToInline(): IrFunction { val parent = callee.parentAsClass - if (callDefault) { - /*TODO: get rid of hack*/ - return parent.declarations.filterIsInstance().single { - it.descriptor.name.asString() == jvmSignature.asmMethod.name + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX && - codegen.context.methodSignatureMapper.mapSignatureSkipGeneric(callee).asmMethod.descriptor.startsWith( - jvmSignature.asmMethod.descriptor.substringBeforeLast(')') - ) - } - } if (parent.fileParent.fileEntry is MultifileFacadeFileEntry) { codegen.context.multifileFacadeMemberToPartMember[callee]?.let { return it }