Use erased upper bound instead of checking for inline type
This commit is contained in:
+2
-1
@@ -635,10 +635,11 @@ class ExpressionCodegen(
|
|||||||
// it generates them as normal functions and not objects.
|
// it generates them as normal functions and not objects.
|
||||||
// Thus, we need to unbox inline class argument with reference underlying type.
|
// Thus, we need to unbox inline class argument with reference underlying type.
|
||||||
private fun unboxInlineClassArgumentOfInlineCallableReference(arg: IrGetValue) {
|
private fun unboxInlineClassArgumentOfInlineCallableReference(arg: IrGetValue) {
|
||||||
if (!arg.type.isInlined()) return
|
if (!arg.type.erasedUpperBound.isInline) return
|
||||||
if (arg.type.isMappedToPrimitive) return
|
if (arg.type.isMappedToPrimitive) return
|
||||||
if (!irFunction.isInlineCallableReference) return
|
if (!irFunction.isInlineCallableReference) return
|
||||||
if (irFunction.extensionReceiverParameter?.symbol == arg.symbol) 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)
|
StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType.toIrBasedKotlinType(), mv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -225,7 +225,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
|||||||
if (isBoundReceiver) return false
|
if (isBoundReceiver) return false
|
||||||
if (function !is IrSimpleFunction) return false
|
if (function !is IrSimpleFunction) return false
|
||||||
if (!function.isInlineCallableReference) return false
|
if (!function.isInlineCallableReference) return false
|
||||||
return type.isInlined() && !type.isMappedToPrimitive
|
return type.erasedUpperBound.isInline && !type.isMappedToPrimitive
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapSignatureSkipGeneric(function: IrFunction): JvmMethodSignature =
|
fun mapSignatureSkipGeneric(function: IrFunction): JvmMethodSignature =
|
||||||
|
|||||||
+3
-1
@@ -59,6 +59,8 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const val STUB_FOR_INLINING = "stub_for_inlining"
|
||||||
|
|
||||||
private class InlineCallableReferenceToLambdaTransformer(
|
private class InlineCallableReferenceToLambdaTransformer(
|
||||||
val context: JvmBackendContext,
|
val context: JvmBackendContext,
|
||||||
val inlinableReferences: Set<IrCallableReference<*>>
|
val inlinableReferences: Set<IrCallableReference<*>>
|
||||||
@@ -140,7 +142,7 @@ private class InlineCallableReferenceToLambdaTransformer(
|
|||||||
val function = context.irFactory.buildFun {
|
val function = context.irFactory.buildFun {
|
||||||
setSourceRange(expression)
|
setSourceRange(expression)
|
||||||
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
||||||
name = Name.identifier("stub_for_inlining")
|
name = Name.identifier(STUB_FOR_INLINING)
|
||||||
visibility = DescriptorVisibilities.LOCAL
|
visibility = DescriptorVisibilities.LOCAL
|
||||||
returnType = referencedFunction.returnType
|
returnType = referencedFunction.returnType
|
||||||
isSuspend = referencedFunction.isSuspend
|
isSuspend = referencedFunction.isSuspend
|
||||||
|
|||||||
+3
-2
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.backend.jvm.lower.inlineclasses
|
package org.jetbrains.kotlin.backend.jvm.lower.inlineclasses
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
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.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.codegen.state.InfoForMangling
|
import org.jetbrains.kotlin.codegen.state.InfoForMangling
|
||||||
import org.jetbrains.kotlin.codegen.state.collectFunctionSignatureForManglingSuffix
|
import org.jetbrains.kotlin.codegen.state.collectFunctionSignatureForManglingSuffix
|
||||||
@@ -168,9 +169,9 @@ val IrFunction.isPrimaryInlineClassConstructor: Boolean
|
|||||||
get() = this is IrConstructor && isPrimary && constructedClass.isInline
|
get() = this is IrConstructor && isPrimary && constructedClass.isInline
|
||||||
|
|
||||||
val IrFunction.isInlineCallableReference: Boolean
|
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
|
val IrType.isMappedToPrimitive: Boolean
|
||||||
get() = isInlined() &&
|
get() = erasedUpperBound.isInline &&
|
||||||
!(isNullable() && makeNotNull().unboxInlineClass().isNullable()) &&
|
!(isNullable() && makeNotNull().unboxInlineClass().isNullable()) &&
|
||||||
makeNotNull().unboxInlineClass().isPrimitiveType()
|
makeNotNull().unboxInlineClass().isPrimitiveType()
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// KJS_WITH_FULL_RUNTIME
|
// KJS_WITH_FULL_RUNTIME
|
||||||
|
// IGNORE_BACKEND: WASM
|
||||||
|
|
||||||
object Foo {
|
object Foo {
|
||||||
fun foo(result: Result<String>) {
|
fun foo(result: Result<String>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user