diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java index 8f635e698f8..8a37f814e74 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java @@ -7342,6 +7342,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java index 7d1f20ca600..5a541f2ed3d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java @@ -7342,6 +7342,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index fffd55c242a..3c4f74432b0 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -7343,6 +7343,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index 678802f2382..702a6907e18 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java @@ -7343,6 +7343,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index f95c3fd56c0..54526ad5c53 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -7343,6 +7343,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt index bee8cce355b..c5893825fae 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt @@ -26,6 +26,7 @@ class JsMapping : DefaultMapping() { val secondaryConstructorToFactory = DefaultDelegateFactory.newDeclarationToDeclarationMapping() val objectToGetInstanceFunction = DefaultDelegateFactory.newDeclarationToDeclarationMapping() val objectToInstanceField = DefaultDelegateFactory.newDeclarationToDeclarationMapping() + val functionToInstanceField = DefaultDelegateFactory.newDeclarationToDeclarationMapping() val classToSyntheticPrimaryConstructor = DefaultDelegateFactory.newDeclarationToDeclarationMapping() val privateMemberToCorrespondingStatic = DefaultDelegateFactory.newDeclarationToDeclarationMapping() diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrJsUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrJsUtils.kt index 2884e8697e8..36388e90511 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrJsUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/IrJsUtils.kt @@ -120,10 +120,6 @@ fun IrSimpleFunction.isObjectInstanceGetter(): Boolean { return origin == JsLoweredDeclarationOrigin.OBJECT_GET_INSTANCE_FUNCTION } -fun IrDeclaration.isObjectInstanceField(): Boolean { - return this is IrField && isObjectInstanceField() -} - fun IrField.isObjectInstanceField(): Boolean { return origin == IrDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt index aab068047f1..4c40e8fbb66 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt @@ -286,7 +286,6 @@ private val singleAbstractMethodPhase = makeIrModulePhase( description = "Replace SAM conversions with instances of interface-implementing classes" ) - private val localDelegatedPropertiesLoweringPhase = makeIrModulePhase( { LocalDelegatedPropertiesLowering() }, name = "LocalDelegatedPropertiesLowering", @@ -307,6 +306,13 @@ private val localClassExtractionPhase = makeIrModulePhase( prerequisite = setOf(localDeclarationsLoweringPhase) ) +private val staticCallableReferenceLoweringPhase = makeIrModulePhase( + ::WasmStaticCallableReferenceLowering, + name = "WasmStaticCallableReferenceLowering", + description = "Turn static callable references into singletons", + prerequisite = setOf(callableReferencePhase, localClassExtractionPhase) +) + private val innerClassesLoweringPhase = makeIrModulePhase( { context -> InnerClassesLowering(context, context.innerClassesSupport) }, name = "InnerClassesLowering", @@ -653,6 +659,7 @@ val loweringList = listOf( localDelegatedPropertiesLoweringPhase, localDeclarationsLoweringPhase, localClassExtractionPhase, + staticCallableReferenceLoweringPhase, innerClassesLoweringPhase, innerClassesMemberBodyLoweringPhase, innerClassConstructorCallsLoweringPhase, diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUsefulDeclarationProcessor.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUsefulDeclarationProcessor.kt index 43dadecf809..f1296ea4354 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUsefulDeclarationProcessor.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUsefulDeclarationProcessor.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.backend.wasm.dce import org.jetbrains.kotlin.backend.wasm.WasmBackendContext import org.jetbrains.kotlin.backend.wasm.ir2wasm.* +import org.jetbrains.kotlin.backend.wasm.lower.isFunctionReferenceInstanceField import org.jetbrains.kotlin.backend.wasm.utils.* import org.jetbrains.kotlin.ir.backend.js.dce.UsefulDeclarationProcessor import org.jetbrains.kotlin.ir.backend.js.utils.* @@ -48,7 +49,7 @@ internal class WasmUsefulDeclarationProcessor( } override fun visitSetField(expression: IrSetField, data: IrDeclaration) { - if (!expression.symbol.owner.isObjectInstanceField()) { + if (!expression.symbol.owner.run { isObjectInstanceField() || isFunctionReferenceInstanceField() }) { super.visitSetField(expression, data) } } @@ -56,7 +57,7 @@ internal class WasmUsefulDeclarationProcessor( override fun visitGetField(expression: IrGetField, data: IrDeclaration) { val field = expression.symbol.owner - if (field.isObjectInstanceField()) { + if (field.isObjectInstanceField() || field.isFunctionReferenceInstanceField()) { field.type.classOrFail.owner.primaryConstructor?.enqueue(field, "object lazy initialization") } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUselessDeclarationsRemover.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUselessDeclarationsRemover.kt index 955f9865711..1e4e0026bef 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUselessDeclarationsRemover.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUselessDeclarationsRemover.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.backend.wasm.dce import org.jetbrains.kotlin.backend.wasm.WasmBackendContext +import org.jetbrains.kotlin.backend.wasm.lower.isFunctionReferenceInstanceField import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.backend.js.utils.isObjectInstanceField import org.jetbrains.kotlin.ir.declarations.* @@ -56,7 +57,7 @@ class WasmUselessDeclarationsRemover( private fun IrSimpleFunction.removeUnusedObjectsInitializers() { (body as? IrBlockBody)?.statements?.removeIf { - it is IrSetField && it.symbol.owner.isObjectInstanceField() && it.symbol.owner !in usefulDeclarations + it is IrSetField && it.symbol.owner.run { isObjectInstanceField() || isFunctionReferenceInstanceField() } && it.symbol.owner !in usefulDeclarations } } } \ No newline at end of file diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmPropertyReferenceLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmPropertyReferenceLowering.kt index 67c311561c9..8d055d60132 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmPropertyReferenceLowering.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmPropertyReferenceLowering.kt @@ -310,7 +310,7 @@ internal class WasmPropertyReferenceLowering(val context: WasmBackendContext) : return type.classifier == expectedClass } - private companion object { - private val DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION = IrDeclarationOriginImpl("KPROPERTIES_FOR_DELEGATION") + companion object { + val DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION = IrDeclarationOriginImpl("KPROPERTIES_FOR_DELEGATION") } } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmStaticCallableReferenceLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmStaticCallableReferenceLowering.kt new file mode 100644 index 00000000000..0140811f931 --- /dev/null +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmStaticCallableReferenceLowering.kt @@ -0,0 +1,93 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.backend.wasm.lower + +import org.jetbrains.kotlin.backend.common.FileLoweringPass +import org.jetbrains.kotlin.backend.common.getOrPut +import org.jetbrains.kotlin.backend.common.lower.createIrBuilder +import org.jetbrains.kotlin.backend.wasm.WasmBackendContext +import org.jetbrains.kotlin.backend.wasm.lower.WasmPropertyReferenceLowering.Companion.DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION +import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.ir.IrStatement +import org.jetbrains.kotlin.ir.backend.js.lower.CallableReferenceLowering.Companion.FUNCTION_REFERENCE_IMPL +import org.jetbrains.kotlin.ir.backend.js.lower.CallableReferenceLowering.Companion.LAMBDA_IMPL +import org.jetbrains.kotlin.ir.builders.declarations.buildField +import org.jetbrains.kotlin.ir.builders.irCall +import org.jetbrains.kotlin.ir.builders.irExprBody +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrConstructorCall +import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl +import org.jetbrains.kotlin.ir.types.makeNullable +import org.jetbrains.kotlin.ir.util.constructedClass +import org.jetbrains.kotlin.ir.util.defaultType +import org.jetbrains.kotlin.ir.util.primaryConstructor +import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid +import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid +import org.jetbrains.kotlin.name.Name + +class WasmStaticCallableReferenceLowering(val context: WasmBackendContext) : FileLoweringPass { + override fun lower(irFile: IrFile) { + val irFields = mutableSetOf() + val firstKProperty = irFile.declarations.indexOfFirst { it.origin == DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION } + + irFile.transformChildrenVoid(object : IrElementTransformerVoid() { + override fun visitClass(declaration: IrClass): IrStatement { + declaration.transformChildrenVoid() + if (declaration.isSyntheticSingleton) { + val functionReferenceField = declaration.getOrCreateInstanceField().apply { + parent = irFile + initializer = context.createIrBuilder(symbol).run { + irExprBody(irCall(declaration.primaryConstructor!!)) + } + } + irFields.add(functionReferenceField) + } + return declaration + } + + override fun visitConstructorCall(expression: IrConstructorCall): IrExpression { + val constructedClass = expression.symbol.owner.constructedClass + if (!constructedClass.isSyntheticSingleton) + return super.visitConstructorCall(expression) + + val instanceField = constructedClass.getOrCreateInstanceField() + return IrGetFieldImpl(expression.startOffset, expression.endOffset, instanceField.symbol, expression.type) + } + }) + + // Should be placed before KProperty initializations + if (firstKProperty != -1) { + irFile.declarations.addAll(firstKProperty, irFields) + } else { + irFile.declarations.addAll(irFields) + } + } + + + private fun IrClass.getOrCreateInstanceField(): IrField = context.mapping.functionToInstanceField.getOrPut(this) { + val klass = this + context.irFactory.buildField { + name = Name.identifier(klass.name.asString() + "_instance") + type = klass.defaultType.makeNullable() + isStatic = true + isFinal = true + origin = FUNCTION_REFERENCE_SINGLETON_FIELD + visibility = DescriptorVisibilities.PRIVATE + }.apply { + initializer = null + } + } +} + +val FUNCTION_REFERENCE_SINGLETON_FIELD by IrDeclarationOriginImpl + +fun IrField.isFunctionReferenceInstanceField(): Boolean { + return origin == FUNCTION_REFERENCE_SINGLETON_FIELD +} + +val IrClass.isSyntheticSingleton: Boolean + get() = (origin == LAMBDA_IMPL || origin == FUNCTION_REFERENCE_IMPL) && primaryConstructor!!.valueParameters.isEmpty() diff --git a/compiler/testData/codegen/box/closures/closuresAsSingleton.kt b/compiler/testData/codegen/box/closures/closuresAsSingleton.kt new file mode 100644 index 00000000000..9611044377e --- /dev/null +++ b/compiler/testData/codegen/box/closures/closuresAsSingleton.kt @@ -0,0 +1,7 @@ +// KT-64803 + +fun generateClosure(): () -> Unit = {} + +fun box(): String { + return if (generateClosure().hashCode() != generateClosure().hashCode()) "Fail: hashCode are not equals" else "OK" +} diff --git a/compiler/testData/debug/stepping/anonymousFunction.kt b/compiler/testData/debug/stepping/anonymousFunction.kt index af446775fc3..4f0c7274bb9 100644 --- a/compiler/testData/debug/stepping/anonymousFunction.kt +++ b/compiler/testData/debug/stepping/anonymousFunction.kt @@ -25,7 +25,7 @@ fun box() { // EXPECTATIONS WASM // test.kt:1 $box -// test.kt:7 $box (9, 9, 4) +// test.kt:7 $box (9, 4) // test.kt:4 $eval (27, 30) // test.kt:8 $box$lambda.invoke (9, 9, 9, 9) // String.kt:141 $kotlin.stringLiteral (17, 28, 17) diff --git a/compiler/testData/debug/stepping/anonymousFunctionDirect.kt b/compiler/testData/debug/stepping/anonymousFunctionDirect.kt index a2907406bb1..ea7d239d54e 100644 --- a/compiler/testData/debug/stepping/anonymousFunctionDirect.kt +++ b/compiler/testData/debug/stepping/anonymousFunctionDirect.kt @@ -18,7 +18,7 @@ fun box() { // EXPECTATIONS WASM // test.kt:1 $box -// test.kt:5 $box (4, 4, 4) +// test.kt:5 $box // test.kt:6 $box$lambda.invoke (9, 9, 9, 9) // String.kt:141 $kotlin.stringLiteral (17, 28, 17) // Array.kt:59 $kotlin.Array.get (19, 26, 34, 8) diff --git a/compiler/testData/debug/stepping/dataClass.kt b/compiler/testData/debug/stepping/dataClass.kt index e0466031caa..562777498f3 100644 --- a/compiler/testData/debug/stepping/dataClass.kt +++ b/compiler/testData/debug/stepping/dataClass.kt @@ -234,7 +234,7 @@ fun box() { // Number2String.kt:55 $kotlin.wasm.internal.itoa32 (8, 26, 8) // Number2String.kt:57 $kotlin.wasm.internal.itoa32 (15, 31, 15) // Number2String.kt:58 $kotlin.wasm.internal.itoa32 (11, 19, 11, 24, 32, 24, 4) -// Assertions.kt:14 $kotlin.assert (11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4) +// Assertions.kt:14 $kotlin.assert (11, 18, 4, 11, 18, 4, 11, 18, 4, 11, 18, 4, 11, 18, 4) // Assertions.kt:21 $kotlin.assert (9, 8, 9, 8, 9, 8, 9, 8, 9, 8) // Assertions.kt:25 $kotlin.assert (1, 1, 1, 1, 1) // Assertions.kt:15 $kotlin.assert (1, 1, 1, 1, 1) diff --git a/compiler/testData/debug/stepping/functionCallWithLambdaParam.kt b/compiler/testData/debug/stepping/functionCallWithLambdaParam.kt index 9802e2c0287..7606e040b15 100644 --- a/compiler/testData/debug/stepping/functionCallWithLambdaParam.kt +++ b/compiler/testData/debug/stepping/functionCallWithLambdaParam.kt @@ -45,10 +45,10 @@ fun foo(f: () -> Unit) { // EXPECTATIONS WASM // test.kt:1 $box -// test.kt:5 $box (8, 8, 4) +// test.kt:5 $box (8, 4) // test.kt:15 $foo (4, 4) // test.kt:6 $box$lambda.invoke (20, 12, 21) // test.kt:16 $foo (1, 1) -// test.kt:9 $box (10, 10, 4) +// test.kt:9 $box (10, 4) // test.kt:10 $box$lambda.invoke (16, 8, 17) // test.kt:12 $box diff --git a/compiler/testData/debug/stepping/kt42208.kt b/compiler/testData/debug/stepping/kt42208.kt index 55023fb4904..c20598f99bb 100644 --- a/compiler/testData/debug/stepping/kt42208.kt +++ b/compiler/testData/debug/stepping/kt42208.kt @@ -27,7 +27,7 @@ inline fun foo() = { // EXPECTATIONS WASM // test.kt:1 $box // test.kt:6 $box (4, 4) -// test1.kt:10 $box (19, 19) +// test1.kt:10 $box // test1.kt:11 $box // test.kt:8 $box$lambda.invoke // test.kt:7 $box diff --git a/compiler/testData/debug/stepping/kt42208b.kt b/compiler/testData/debug/stepping/kt42208b.kt index 62214cc79f1..01fcb1f1589 100644 --- a/compiler/testData/debug/stepping/kt42208b.kt +++ b/compiler/testData/debug/stepping/kt42208b.kt @@ -30,7 +30,7 @@ inline fun foo() = { // EXPECTATIONS WASM // test.kt:1 $box // test.kt:6 $box -// test1.kt:11 $box (19, 19) +// test1.kt:11 $box // test1.kt:12 $box // test.kt:7 $box // test.kt:9 $box$lambda.invoke diff --git a/compiler/testData/debug/stepping/kt42208c.kt b/compiler/testData/debug/stepping/kt42208c.kt index 4d649d6b2b0..93d683e78ff 100644 --- a/compiler/testData/debug/stepping/kt42208c.kt +++ b/compiler/testData/debug/stepping/kt42208c.kt @@ -52,7 +52,7 @@ fun baz(v:(() -> Unit)) { // EXPECTATIONS WASM // test.kt:1 $box // test.kt:6 $box (8, 4) -// test1.kt:12 $box (19, 19, 19, 19) +// test1.kt:12 $box (19, 19) // test1.kt:13 $box (1, 1) // test3.kt:16 $baz (4, 4) // test.kt:10 $box$lambda.invoke diff --git a/compiler/testData/debug/stepping/namedCallableReference.kt b/compiler/testData/debug/stepping/namedCallableReference.kt index 3c8349a0552..33105c8d5eb 100644 --- a/compiler/testData/debug/stepping/namedCallableReference.kt +++ b/compiler/testData/debug/stepping/namedCallableReference.kt @@ -35,7 +35,7 @@ fun g() {} // EXPECTATIONS WASM // test.kt:1 $box // test.kt:4 $box (12, 4) -// test.kt:5 $box (6, 6, 4) +// test.kt:5 $box (6, 4) // test.kt:9 $f // test.kt:12 $g // test.kt:10 $f diff --git a/compiler/testData/debug/stepping/variablesWithoutInitializer.kt b/compiler/testData/debug/stepping/variablesWithoutInitializer.kt index 29d1b42d3a1..267ecb6e28f 100644 --- a/compiler/testData/debug/stepping/variablesWithoutInitializer.kt +++ b/compiler/testData/debug/stepping/variablesWithoutInitializer.kt @@ -54,7 +54,7 @@ fun box() { // Number2String.kt:55 $kotlin.wasm.internal.itoa32 (8, 26, 8) // Number2String.kt:57 $kotlin.wasm.internal.itoa32 (15, 31, 15) // Number2String.kt:58 $kotlin.wasm.internal.itoa32 (11, 19, 11, 24, 32, 24, 4) -// Assertions.kt:14 $kotlin.assert (11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4, 11, 18, 18, 4) +// Assertions.kt:14 $kotlin.assert (11, 18, 4, 11, 18, 4, 11, 18, 4, 11, 18, 4, 11, 18, 4, 11, 18, 4) // Assertions.kt:21 $kotlin.assert (9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8) // Assertions.kt:25 $kotlin.assert (1, 1, 1, 1, 1, 1) // Assertions.kt:15 $kotlin.assert (1, 1, 1, 1, 1, 1) diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java index cb74ac846d0..2edbed0ebd8 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java @@ -7343,6 +7343,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index d54fad42c22..9593bdcc9eb 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -7103,6 +7103,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index a5fbd7cc635..56e67ad05ad 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -7343,6 +7343,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 117babb43c4..5a3573bc1fd 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -7343,6 +7343,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1b1c600b7c7..9eea5c86572 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6427,6 +6427,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { runTest("compiler/testData/codegen/box/closures/crossinlineLocalDeclaration.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index bcddf4b6fcc..d307570ebaa 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -5555,6 +5555,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java index 816a679ead9..b6fcba28773 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java @@ -5555,6 +5555,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 0c0c831f5d2..e9e8f455c22 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -5555,6 +5555,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 6cf0f8aaed3..51347f5c22e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -5555,6 +5555,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java index a468e9d8a86..47a4d77539e 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java @@ -6163,6 +6163,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java index c1b8d500159..d6b4d809e9e 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java @@ -6295,6 +6295,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java index 114e3c21edb..e25f35cf2fc 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java @@ -6031,6 +6031,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java index 42c6685a865..d6399ae8af5 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java @@ -6164,6 +6164,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmJsCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmJsCodegenBoxTestGenerated.java index 5985b0c407e..9214d49b600 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmJsCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmJsCodegenBoxTestGenerated.java @@ -5537,6 +5537,12 @@ public class FirWasmJsCodegenBoxTestGenerated extends AbstractFirWasmJsCodegenBo runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception { diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java index b904fb5c65a..6d258293de9 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java @@ -5537,6 +5537,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt"); } + @Test + @TestMetadata("closuresAsSingleton.kt") + public void testClosuresAsSingleton() throws Exception { + runTest("compiler/testData/codegen/box/closures/closuresAsSingleton.kt"); + } + @Test @TestMetadata("crossinlineLocalDeclaration.kt") public void testCrossinlineLocalDeclaration() throws Exception {