diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index 8ec6394a0c2..2a2e72ecbf8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -402,25 +402,23 @@ public abstract class StackValue { private static void boxInlineClass(@NotNull KotlinType kotlinType, @NotNull InstructionAdapter v) { Type boxedType = KotlinTypeMapper.mapInlineClassTypeAsDeclaration(kotlinType); - Type owner = KotlinTypeMapper.mapToErasedInlineClassType(kotlinType); Type underlyingType = KotlinTypeMapper.mapUnderlyingTypeOfInlineClassType(kotlinType); if (TypeUtils.isNullableType(kotlinType) && !isPrimitive(underlyingType)) { - boxOrUnboxWithNullCheck(v, vv -> invokeBoxMethod(vv, boxedType, owner, underlyingType)); + boxOrUnboxWithNullCheck(v, vv -> invokeBoxMethod(vv, boxedType, underlyingType)); } else { - invokeBoxMethod(v, boxedType, owner, underlyingType); + invokeBoxMethod(v, boxedType, underlyingType); } } private static void invokeBoxMethod( @NotNull InstructionAdapter v, Type boxedType, - Type owner, Type underlyingType ) { v.invokestatic( - owner.getInternalName(), + boxedType.getInternalName(), InlineClassDescriptorResolver.BOX_METHOD_NAME.asString(), Type.getMethodDescriptor(boxedType, underlyingType), false diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt index baeae977fb7..12e833f09e8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt @@ -237,9 +237,8 @@ private fun AbstractInsnNode.isInlineClassUnboxing(state: GenerationState) = private fun MethodInsnNode.isInlineClassBoxingMethodDescriptor(state: GenerationState): Boolean { if (name != InlineClassDescriptorResolver.BOX_METHOD_NAME.asString()) return false - if (!owner.endsWith(JvmAbi.ERASED_INLINE_CLASS_SUFFIX)) return false - val ownerType = Type.getObjectType(owner.removeSuffix(JvmAbi.ERASED_INLINE_CLASS_SUFFIX)) + val ownerType = Type.getObjectType(owner) val descriptor = state.jvmBackendClassResolver.resolveToClassDescriptors(ownerType).singleOrNull() ?: return false if (!descriptor.isInline) return false diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassesOnPassingToVarargs.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassesOnPassingToVarargs.kt index 99ca300e9bd..22f2e9e5ce2 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassesOnPassingToVarargs.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassesOnPassingToVarargs.kt @@ -15,7 +15,7 @@ fun test(u1: UInt, u2: UInt, u3: UInt?) { } // @TestKt.class: -// 3 INVOKESTATIC UInt\$Erased.box +// 3 INVOKESTATIC UInt\.box // 0 INVOKEVIRTUAL UInt.unbox // 0 valueOf // 0 intValue \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxMethodCalledByInlineClass.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxMethodCalledByInlineClass.kt new file mode 100644 index 00000000000..6dd30fff001 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxMethodCalledByInlineClass.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +InlineClasses + +// FILE: Z.kt +inline class Z(val x: Int) + +// FILE: Test.kt +fun test(): Any = Z(42) + +// @TestKt.class: +// 0 INVOKESTATIC Z\$Erased\.box +// 0 INVOKESTATIC Z\-Erased\.box +// 1 INVOKESTATIC Z\.box \(I\)LZ; \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxResultAfterConstructorCall.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxResultAfterConstructorCall.kt index 44cdee6cc24..a349498b1a1 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxResultAfterConstructorCall.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxResultAfterConstructorCall.kt @@ -15,10 +15,10 @@ fun test() { } // @TestKt.class: -// 1 INVOKESTATIC AsInt\$Erased.box +// 1 INVOKESTATIC AsInt\.box // 0 INVOKEVIRTUAL AsInt.unbox -// 1 INVOKESTATIC AsAny\$Erased.box +// 1 INVOKESTATIC AsAny\.box // 0 INVOKEVIRTUAL AsAny.unbox // 1 valueOf diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt index 56c788386b1..650dad0a430 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt @@ -13,7 +13,7 @@ inline class UInt(val a: Int) { fun takeNullable(a: UInt?) {} -// 2 INVOKESTATIC UInt\$Erased.box +// 2 INVOKESTATIC UInt\.box // 0 INVOKEVIRTUAL Foo.unbox // 1 valueOf diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInlineClassFromMethodReturnType.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInlineClassFromMethodReturnType.kt index 8a5f8c29ee4..8232d9d41d1 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInlineClassFromMethodReturnType.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInlineClassFromMethodReturnType.kt @@ -25,7 +25,7 @@ fun test(f: Foo) { } // @TestKt.class: -// 6 INVOKESTATIC Foo\$Erased.box +// 6 INVOKESTATIC Foo\.box // 4 INVOKEVIRTUAL Foo.unbox // 0 valueOf // 0 intValue \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInsideLambdaAsLastExpression.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInsideLambdaAsLastExpression.kt index bc2bcdedd5d..f11db249382 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInsideLambdaAsLastExpression.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInsideLambdaAsLastExpression.kt @@ -18,6 +18,7 @@ fun test(x: UInt?, y: UInt) { // @TestKt.class: // 0 INVOKESTATIC UInt\$Erased.box +// 0 INVOKESTATIC UInt\.box // 1 INVOKEVIRTUAL UInt.unbox // 0 valueOf diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOfInlineClassesWithFunctionalTypes.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOfInlineClassesWithFunctionalTypes.kt index 2c6d8e263c4..7fbaa78c2f9 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOfInlineClassesWithFunctionalTypes.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOfInlineClassesWithFunctionalTypes.kt @@ -17,10 +17,10 @@ fun test() { } // @TestKt.class: -// 1 INVOKESTATIC UInt\$Erased.box +// 1 INVOKESTATIC UInt\.box // 2 INVOKEVIRTUAL UInt.unbox -// 1 INVOKESTATIC ULong\$Erased.box +// 1 INVOKESTATIC ULong\.box // 2 INVOKEVIRTUAL ULong.unbox // 0 valueOf diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOnInlinedParameters.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOnInlinedParameters.kt index d21251915af..705bd9a3b47 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOnInlinedParameters.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxOnInlinedParameters.kt @@ -23,7 +23,7 @@ fun test(f: Foo) { } // @TestKt.class: -// 2 INVOKESTATIC Foo\$Erased.box +// 2 INVOKESTATIC Foo\.box // 1 INVOKEVIRTUAL Foo.unbox // 0 valueOf // 0 intValue \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxingForNonLocalAndLabeledReturnsOfInlineClasses.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxingForNonLocalAndLabeledReturnsOfInlineClasses.kt index 2fd46f03edf..1d9b0798b95 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxingForNonLocalAndLabeledReturnsOfInlineClasses.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxingForNonLocalAndLabeledReturnsOfInlineClasses.kt @@ -27,7 +27,7 @@ fun labeled(): ULong? { } // @TestKt.class: -// 2 INVOKESTATIC ULong\$Erased.box +// 2 INVOKESTATIC ULong\.box // 0 INVOKEVIRTUAL ULong.unbox // 0 valueOf diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingOnFunctionCall.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingOnFunctionCall.kt index 75f848305eb..90571f07d69 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingOnFunctionCall.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingOnFunctionCall.kt @@ -11,7 +11,7 @@ fun test(a: InlineNotNullPrimitive, b: InlineNotNullReference) { testNotNullReference(b, b, b, b) // 2 box } -// 3 INVOKESTATIC InlineNotNullPrimitive\$Erased.box -// 2 INVOKESTATIC InlineNotNullReference\$Erased.box +// 3 INVOKESTATIC InlineNotNullPrimitive\.box +// 2 INVOKESTATIC InlineNotNullReference\.box // 0 valueOf \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingUnboxingInsideInlinedLambda.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingUnboxingInsideInlinedLambda.kt index 9f2d0c2a7a9..337b4220d90 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingUnboxingInsideInlinedLambda.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingUnboxingInsideInlinedLambda.kt @@ -29,7 +29,7 @@ fun takeNullableUInt(y: UInt?) {} inline fun T.myLet(f: (T) -> Unit) = f(this) // @TestKt.class: -// 1 INVOKESTATIC UInt\$Erased.box +// 1 INVOKESTATIC UInt\.box // 5 INVOKEVIRTUAL UInt.unbox // 0 intValue diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt index 12759de7fd5..354182af104 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt @@ -22,9 +22,9 @@ fun transformToNullableTarget(a: AsInt): AsInt? = a as AsInt? // box fun transformNullableToNullableTarget(a: AsInt?): AsInt? = a as AsInt? // @ReferenceKt.class: -// 2 INVOKESTATIC AsAny\$Erased.box +// 2 INVOKESTATIC AsAny\.box // 1 INVOKEVIRTUAL AsAny.unbox // @PrimitiveKt.class: -// 2 INVOKESTATIC AsInt\$Erased.box +// 2 INVOKESTATIC AsInt\.box // 1 INVOKEVIRTUAL AsInt.unbox diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOperationsOnNonTrivialSpread.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOperationsOnNonTrivialSpread.kt index dcc13deda82..696f301c451 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOperationsOnNonTrivialSpread.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOperationsOnNonTrivialSpread.kt @@ -10,6 +10,7 @@ fun test1(us: UIntArray) { // @NoBoxingKt.class: // 0 INVOKESTATIC kotlin.UInt\$Erased.box +// 0 INVOKESTATIC kotlin.UInt\.box // 0 INVOKEVIRTUAL kotlin.UInt.unbox // FILE: Boxing.kt @@ -21,5 +22,5 @@ fun test2(nullable: UInt?, ns: Array) { } // @BoxingKt.class: -// 2 INVOKESTATIC kotlin.UInt\$Erased.box +// 2 INVOKESTATIC kotlin.UInt\.box // 0 INVOKEVIRTUAL kotlin.UInt.unbox \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/passInlineClassesWithSpreadOperatorToVarargs.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/passInlineClassesWithSpreadOperatorToVarargs.kt index 88e93276f24..c47d521a728 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/passInlineClassesWithSpreadOperatorToVarargs.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/passInlineClassesWithSpreadOperatorToVarargs.kt @@ -14,7 +14,7 @@ fun test(u1: UInt, u2: UInt, us: Array) { } // @TestKt.class: -// 2 INVOKESTATIC UInt\$Erased.box +// 2 INVOKESTATIC UInt\.box // 0 INVOKEVIRTUAL UInt.unbox // 2 CHECKCAST \[LUInt diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArrayIteratorWithoutBoxing.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArrayIteratorWithoutBoxing.kt index 1f4b339dbb6..e0956f0beab 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArrayIteratorWithoutBoxing.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArrayIteratorWithoutBoxing.kt @@ -27,7 +27,7 @@ fun test() { fun takeUInt(u: UInt) {} -// 1 INVOKESTATIC UInt\$Erased.box +// 1 INVOKESTATIC UInt\.box // 1 INVOKEVIRTUAL UInt.unbox // 0 INVOKEVIRTUAL UIntIterator.iterator diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArraySwapBoxing.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArraySwapBoxing.kt index 395b1f546e2..c77dd8d526d 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArraySwapBoxing.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/uIntArraySwapBoxing.kt @@ -23,5 +23,6 @@ fun UIntArray.swap(i: Int, j: Int) { // @TestKt.class: // 0 INVOKEVIRTUAL UInt.unbox // 0 INVOKESTATIC UInt\$Erased.box +// 0 INVOKESTATIC UInt\.box // 0 intValue // 0 valueOf \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/unboxMethodCalledByInlineClass.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/unboxMethodCalledByInlineClass.kt new file mode 100644 index 00000000000..ad913c1384e --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/unboxMethodCalledByInlineClass.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +InlineClasses + +// FILE: Z.kt +inline class Z(val x: Int) + +// FILE: Test.kt +fun test(xs: List) = xs[0] + +// @TestKt.class: +// 0 INVOKEVIRTUAL Z\$Erased\.unbox +// 0 INVOKEVIRTUAL Z\-Erased\.unbox +// 1 INVOKEVIRTUAL Z\.unbox \(\)I \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 94308423881..a612254d9d2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -2008,6 +2008,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/boxInlineClassesOnPassingToVarargs.kt"); } + @TestMetadata("boxMethodCalledByInlineClass.kt") + public void testBoxMethodCalledByInlineClass() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/boxMethodCalledByInlineClass.kt"); + } + @TestMetadata("boxResultAfterConstructorCall.kt") public void testBoxResultAfterConstructorCall() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/boxResultAfterConstructorCall.kt"); @@ -2197,6 +2202,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { public void testUnboxInlineClassesAfterSmartCasts() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/unboxInlineClassesAfterSmartCasts.kt"); } + + @TestMetadata("unboxMethodCalledByInlineClass.kt") + public void testUnboxMethodCalledByInlineClass() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/unboxMethodCalledByInlineClass.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/interfaces")