Use erased upper bound instead of checking for inline type

This commit is contained in:
Ilmir Usmanov
2021-02-17 14:26:59 +01:00
parent 741c1a864f
commit cacd84390e
5 changed files with 10 additions and 5 deletions
@@ -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)
}
@@ -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 =
@@ -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<IrCallableReference<*>>
@@ -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
@@ -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()
@@ -1,5 +1,6 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND: WASM
object Foo {
fun foo(result: Result<String>) {