diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 8d9e9edb26d..21635203491 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -6683,6 +6683,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { @@ -6752,6 +6764,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt index a2688ccb741..61c21eec304 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt @@ -58,8 +58,8 @@ class IrLazyClass( ArrayList().also { typeTranslator.buildWithScope(this) { generateChildStubs(descriptor.constructors, it) - generateMemberStubs(descriptor.defaultType.memberScope, it) - generateMemberStubs(descriptor.staticScope, it) + generateChildStubs(descriptor.defaultType.memberScope.getContributedDescriptors(), it) + generateChildStubs(descriptor.staticScope.getContributedDescriptors(), it) } }.also { it.forEach { @@ -68,6 +68,22 @@ class IrLazyClass( } } + private fun generateChildStubs(descriptors: Collection, declarations: MutableList) { + descriptors.mapNotNullTo(declarations) { descriptor -> + if (shouldBuildStub(descriptor)) stubGenerator.generateMemberStub(descriptor) else null + } + } + + private fun shouldBuildStub(descriptor: DeclarationDescriptor): Boolean = + descriptor !is DeclarationDescriptorWithVisibility || + !DescriptorVisibilities.isPrivate(descriptor.visibility) || + // Always build lazy IR stubs for inline class primary constructors. + // This is needed because primary constructors of inline classes can be private, and prior to 1.5.0, there was no way + // to determine the inline class representation other than by loading the single value parameter of the primary constructor + // (corresponding metadata entry was added in 1.5.0). Backend still tries to load inline class representation in this way + // to support compilation against inline classes compiled with 1.4.30 or earlier. + (descriptor is ConstructorDescriptor && isInline) + override var typeParameters: List by lazyVar(stubGenerator.lock) { descriptor.declaredTypeParameters.mapTo(arrayListOf()) { stubGenerator.generateOrGetTypeParameterStub(it) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt index 6218521c3f8..9b81675acb5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator -import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.KotlinType import kotlin.properties.ReadWriteProperty @@ -36,17 +35,6 @@ interface IrLazyDeclarationBase : IrDeclaration { isHidden = false, isAssignable = false ) - fun generateMemberStubs(memberScope: MemberScope, container: MutableList) { - generateChildStubs(memberScope.getContributedDescriptors(), container) - } - - fun generateChildStubs(descriptors: Collection, declarations: MutableList) { - descriptors.mapNotNullTo(declarations) { descriptor -> - if (descriptor is DeclarationDescriptorWithVisibility && DescriptorVisibilities.isPrivate(descriptor.visibility)) null - else stubGenerator.generateMemberStub(descriptor) - } - } - fun createLazyAnnotations(): ReadWriteProperty> = lazyVar(stubGenerator.lock) { descriptor.annotations.mapNotNull(typeTranslator.constantValueGenerator::generateAnnotationConstructorCall).toMutableList() } diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt new file mode 100644 index 00000000000..545e361112c --- /dev/null +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt @@ -0,0 +1,14 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// MODULE: lib +// USE_OLD_INLINE_CLASSES_MANGLING_SCHEME +// FILE: A.kt + +inline class A private constructor(val value: String) { + constructor(c: Char) : this(c + "K") +} + +// MODULE: main(lib) +// FILE: B.kt + +fun box(): String = A('O').value diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt new file mode 100644 index 00000000000..6a7ef3b5d5d --- /dev/null +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt @@ -0,0 +1,16 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// MODULE: lib +// USE_OLD_INLINE_CLASSES_MANGLING_SCHEME +// FILE: A.kt + +inline class A private constructor(private val value: String) { + constructor(c: Char) : this(c + "K") + + val publicValue: String get() = value +} + +// MODULE: main(lib) +// FILE: B.kt + +fun box(): String = A('O').publicValue diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt new file mode 100644 index 00000000000..0d662768543 --- /dev/null +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +// MODULE: lib +// FILE: A.kt + +inline class A private constructor(val value: String) { + constructor(c: Char) : this(c + "K") +} + +// MODULE: main(lib) +// FILE: B.kt + +fun box(): String = A('O').value diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt new file mode 100644 index 00000000000..17a3023e3e4 --- /dev/null +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +// MODULE: lib +// FILE: A.kt + +inline class A private constructor(private val value: String) { + constructor(c: Char) : this(c + "K") + + val publicValue: String get() = value +} + +// MODULE: main(lib) +// FILE: B.kt + +fun box(): String = A('O').publicValue 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 6c44a1cd7df..b993ffad915 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 @@ -6683,6 +6683,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { @@ -6752,6 +6764,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() 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 a4a9730f1b7..88fe2c26ef6 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 @@ -6683,6 +6683,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { @@ -6752,6 +6764,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java index ec0049cde6c..1f306923ef5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxTestGenerated.java @@ -548,6 +548,18 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { @@ -617,6 +629,18 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java index e657087e67a..d66a3486685 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxTestGenerated.java @@ -548,6 +548,18 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { @@ -617,6 +629,18 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateCompanionObjectValInDifferentModule.kt"); } + @Test + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructor.kt"); + } + + @Test + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/oldMangling/privateConstructorWithPrivateField.kt"); + } + @Test @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index cf0424e954d..f752cc7b269 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -4460,6 +4460,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateCompanionObjectValInDifferentModule.kt"); } + @TestMetadata("privateConstructor.kt") + public void testPrivateConstructor() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructor.kt"); + } + + @TestMetadata("privateConstructorWithPrivateField.kt") + public void testPrivateConstructorWithPrivateField() throws Exception { + runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateConstructorWithPrivateField.kt"); + } + @TestMetadata("privateTopLevelValInDifferentModule.kt") public void testPrivateTopLevelValInDifferentModule() throws Exception { runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/inlineClasses/privateTopLevelValInDifferentModule.kt");