diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java index 20dc3db9a96..eae587e2d32 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java @@ -3167,6 +3167,11 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noAssertionsForInlineClassesBasedOnNullableTypes.kt"); } + @TestMetadata("noBoxingInMethod.kt") + public void testNoBoxingInMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingInMethod.kt"); + } + @TestMetadata("noBoxingOnCastOperations.kt") public void testNoBoxingOnCastOperations() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt index 0143226cfd3..86bb3071e74 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt @@ -13,6 +13,8 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.lower.irBlockBody import org.jetbrains.kotlin.backend.common.lower.loops.forLoopsPhase import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase +import org.jetbrains.kotlin.backend.common.pop +import org.jetbrains.kotlin.backend.common.push import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.* @@ -121,7 +123,9 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F private fun transformSimpleFunctionFlat(function: IrSimpleFunction, replacement: IrSimpleFunction): List { replacement.valueParameters.forEach { it.transformChildrenVoid() } + allScopes.push(createScope(function)) replacement.body = function.body?.transform(this, null)?.patchDeclarationParents(replacement) + allScopes.pop() replacement.copyAttributes(function) // Don't create a wrapper for functions which are only used in an unboxed context @@ -409,7 +413,6 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F val irElement = scope.irElement when { irElement is IrAnonymousInitializer -> return InitBlockOrConstructorImpl.InitBlock - irElement is IrClass && irElement.isInline -> return InitBlockOrConstructorImpl.InitBlock irElement is IrFunction && irElement.origin == JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR -> return InitBlockOrConstructorImpl.ConstructorImpl(irElement) } diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt index 6ef6901785b..93298f7e82c 100644 --- a/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt @@ -16,15 +16,14 @@ fun takeNullable(a: UInt?) {} // 1 valueOf // 0 intValue -// JVM_TEMPLATES: +// -- 1 before takeNullable +// -- 1 before takeAnyInside // 2 INVOKESTATIC UInt\.box + +// JVM_TEMPLATES: // -- equals-impl // 1 INVOKEVIRTUAL UInt\.unbox // JVM_IR_TEMPLATES: -// -- 1 before takeNullable -// -- 1 before takeAnyInside -// -- 1 before takeAnyInside's GETFIELD -// 3 INVOKESTATIC UInt\.box // -- getA, toString, hashCode, equals-impl, equals // 5 INVOKEVIRTUAL UInt\.unbox \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingInMethod.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingInMethod.kt new file mode 100644 index 00000000000..f212b8df7b9 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingInMethod.kt @@ -0,0 +1,5 @@ +inline class IC(val value: Int) { + inline fun toLong(): Long = this.value.toLong() +} + +// 0 INVOKESTATIC IC\.box-impl \ 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 fd5d59cf89b..26afbae6c86 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -3112,6 +3112,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noAssertionsForInlineClassesBasedOnNullableTypes.kt"); } + @TestMetadata("noBoxingInMethod.kt") + public void testNoBoxingInMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingInMethod.kt"); + } + @TestMetadata("noBoxingOnCastOperations.kt") public void testNoBoxingOnCastOperations() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ae490456eb7..b145be72620 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14799,16 +14799,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/anySuperCall.kt"); } - @TestMetadata("boxImplDoesNotExecuteInitBlock.kt") - public void ignoreBoxImplDoesNotExecuteInitBlock() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxImplDoesNotExecuteInitBlock.kt"); - } - - @TestMetadata("initBlock.kt") - public void ignoreInitBlock() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/initBlock.kt"); - } - @TestMetadata("inlineClassWithCustomEquals.kt") public void ignoreInlineClassWithCustomEquals() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineClassWithCustomEquals.kt"); @@ -14842,6 +14832,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/boundCallableReferencePassedToInlineFunction.kt"); } + @TestMetadata("boxImplDoesNotExecuteInitBlock.kt") + public void testBoxImplDoesNotExecuteInitBlock() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/boxImplDoesNotExecuteInitBlock.kt"); + } + @TestMetadata("boxNullableValueOfInlineClassWithNonNullUnderlyingType.kt") public void testBoxNullableValueOfInlineClassWithNonNullUnderlyingType() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/boxNullableValueOfInlineClassWithNonNullUnderlyingType.kt"); @@ -15127,6 +15122,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/genericVararg2ndConstructor.kt"); } + @TestMetadata("initBlock.kt") + public void testInitBlock() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/initBlock.kt"); + } + @TestMetadata("inlineClassAsLastExpressionInInLambda.kt") public void testInlineClassAsLastExpressionInInLambda() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 4bb2ca1297b..e1b2a17d070 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -3167,6 +3167,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noAssertionsForInlineClassesBasedOnNullableTypes.kt"); } + @TestMetadata("noBoxingInMethod.kt") + public void testNoBoxingInMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingInMethod.kt"); + } + @TestMetadata("noBoxingOnCastOperations.kt") public void testNoBoxingOnCastOperations() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/noBoxingOnCastOperations.kt");