From cacd84390e522a96fbc3fca9236db6a3b6454a78 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Wed, 17 Feb 2021 14:26:59 +0100 Subject: [PATCH] Use erased upper bound instead of checking for inline type --- .../kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 3 ++- .../kotlin/backend/jvm/codegen/MethodSignatureMapper.kt | 2 +- .../backend/jvm/lower/InlineCallableReferenceToLambda.kt | 4 +++- .../kotlin/backend/jvm/lower/inlineclasses/InlineClassAbi.kt | 5 +++-- .../box/inlineClasses/callableReferences/let/result.kt | 1 + 5 files changed, 10 insertions(+), 5 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 0aa7333d22b..7897b0aa9c0 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 @@ -635,10 +635,11 @@ class ExpressionCodegen( // it generates them as normal functions and not objects. // Thus, we need to unbox inline class argument with reference underlying type. private fun unboxInlineClassArgumentOfInlineCallableReference(arg: IrGetValue) { - if (!arg.type.isInlined()) return + if (!arg.type.erasedUpperBound.isInline) return if (arg.type.isMappedToPrimitive) return if (!irFunction.isInlineCallableReference) return if (irFunction.extensionReceiverParameter?.symbol == arg.symbol) return + if (arg.type.isNullable() && arg.type.makeNotNull().unboxInlineClass().isNullable()) return StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType.toIrBasedKotlinType(), mv) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index c885a659577..5bec4388da2 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -225,7 +225,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { if (isBoundReceiver) return false if (function !is IrSimpleFunction) return false if (!function.isInlineCallableReference) return false - return type.isInlined() && !type.isMappedToPrimitive + return type.erasedUpperBound.isInline && !type.isMappedToPrimitive } fun mapSignatureSkipGeneric(function: IrFunction): JvmMethodSignature = diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt index 117a35e05ef..3299eee777a 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt @@ -59,6 +59,8 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte } } +const val STUB_FOR_INLINING = "stub_for_inlining" + private class InlineCallableReferenceToLambdaTransformer( val context: JvmBackendContext, val inlinableReferences: Set> @@ -140,7 +142,7 @@ private class InlineCallableReferenceToLambdaTransformer( val function = context.irFactory.buildFun { setSourceRange(expression) origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA - name = Name.identifier("stub_for_inlining") + name = Name.identifier(STUB_FOR_INLINING) visibility = DescriptorVisibilities.LOCAL returnType = referencedFunction.returnType isSuspend = referencedFunction.isSuspend diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/InlineClassAbi.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/InlineClassAbi.kt index 37e39052d9e..985779d8149 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/InlineClassAbi.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/InlineClassAbi.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.backend.jvm.lower.inlineclasses import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound +import org.jetbrains.kotlin.backend.jvm.lower.STUB_FOR_INLINING import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.codegen.state.InfoForMangling import org.jetbrains.kotlin.codegen.state.collectFunctionSignatureForManglingSuffix @@ -168,9 +169,9 @@ val IrFunction.isPrimaryInlineClassConstructor: Boolean get() = this is IrConstructor && isPrimary && constructedClass.isInline val IrFunction.isInlineCallableReference: Boolean - get() = origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA && name.asString().contains("\$stub_for_inlining") + get() = origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA && name.asString().contains("\$$STUB_FOR_INLINING") val IrType.isMappedToPrimitive: Boolean - get() = isInlined() && + get() = erasedUpperBound.isInline && !(isNullable() && makeNotNull().unboxInlineClass().isNullable()) && makeNotNull().unboxInlineClass().isPrimitiveType() \ No newline at end of file diff --git a/compiler/testData/codegen/box/inlineClasses/callableReferences/let/result.kt b/compiler/testData/codegen/box/inlineClasses/callableReferences/let/result.kt index 70021248e67..9fc9f2473f9 100644 --- a/compiler/testData/codegen/box/inlineClasses/callableReferences/let/result.kt +++ b/compiler/testData/codegen/box/inlineClasses/callableReferences/let/result.kt @@ -1,5 +1,6 @@ // WITH_RUNTIME // KJS_WITH_FULL_RUNTIME +// IGNORE_BACKEND: WASM object Foo { fun foo(result: Result) {