From 4bab505c3a12fffe9369f445bddd14b857e21e48 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Sat, 6 Feb 2021 15:31:02 +0300 Subject: [PATCH] [Commonizer] Introduce CIR entities for representing various flavors of names - CirName - simple name - CirPackageName - fully-qualified name of the package - CirEntityName - fully-qualified name of some entity, ex: Class, TypeAlias --- .../commonizer/cir/CirAnnotation.kt | 6 +- .../descriptors/commonizer/cir/CirClass.kt | 4 +- .../commonizer/cir/CirConstantValue.kt | 7 +- .../commonizer/cir/CirDeclaration.kt | 10 +- .../descriptors/commonizer/cir/CirName.kt | 150 ++++++++++++ .../descriptors/commonizer/cir/CirPackage.kt | 4 +- .../descriptors/commonizer/cir/CirType.kt | 5 +- .../cir/factory/CirAnnotationFactory.kt | 17 +- .../commonizer/cir/factory/CirClassFactory.kt | 11 +- .../cir/factory/CirConstantValueFactory.kt | 13 +- .../cir/factory/CirFunctionFactory.kt | 6 +- .../cir/factory/CirModuleFactory.kt | 9 +- .../cir/factory/CirPackageFactory.kt | 4 +- .../cir/factory/CirPropertyFactory.kt | 6 +- .../cir/factory/CirTypeAliasFactory.kt | 6 +- .../commonizer/cir/factory/CirTypeFactory.kt | 11 +- .../cir/factory/CirTypeParameterFactory.kt | 7 +- .../cir/factory/CirValueParameterFactory.kt | 7 +- .../commonizer/cir/impl/CirAnnotationImpl.kt | 6 +- .../commonizer/cir/impl/CirClassImpl.kt | 10 +- .../commonizer/cir/impl/CirClassTypeImpl.kt | 4 +- .../commonizer/cir/impl/CirFunctionImpl.kt | 3 +- .../commonizer/cir/impl/CirModuleImpl.kt | 4 +- .../commonizer/cir/impl/CirPackageImpl.kt | 4 +- .../commonizer/cir/impl/CirPropertyImpl.kt | 3 +- .../commonizer/cir/impl/CirTypeAliasImpl.kt | 3 +- .../cir/impl/CirTypeAliasTypeImpl.kt | 4 +- .../cir/impl/CirTypeParameterImpl.kt | 4 +- .../cir/impl/CirValueParameterImpl.kt | 4 +- .../commonizer/cir/impl/RecursionMarkers.kt | 8 +- .../AbstractFunctionOrPropertyCommonizer.kt | 4 +- .../commonizer/core/AnnotationsCommonizer.kt | 61 ++--- .../core/CallableValueParametersCommonizer.kt | 19 +- .../commonizer/core/ClassCommonizer.kt | 4 +- .../commonizer/core/CommonizationVisitor.kt | 13 +- .../commonizer/core/ModuleCommonizer.kt | 4 +- .../commonizer/core/PackageCommonizer.kt | 8 +- .../commonizer/core/TypeAliasCommonizer.kt | 7 +- .../commonizer/core/TypeCommonizer.kt | 17 +- .../core/TypeParameterCommonizer.kt | 4 +- .../core/ValueParameterCommonizer.kt | 6 +- .../core/ValueParameterListCommonizer.kt | 4 +- .../commonizer/mergedtree/CirClassNode.kt | 10 +- .../commonizer/mergedtree/CirModuleNode.kt | 4 +- .../commonizer/mergedtree/CirNode.kt | 18 +- .../commonizer/mergedtree/CirPackageNode.kt | 12 +- .../commonizer/mergedtree/CirRootNode.kt | 4 +- .../commonizer/mergedtree/CirTreeMerger.kt | 38 ++- .../commonizer/mergedtree/CirTypeAliasNode.kt | 6 +- .../mergedtree/approximationKeys.kt | 11 +- .../mergedtree/classifierContainers.kt | 63 +++-- .../commonizer/mergedtree/collectors.kt | 5 +- .../commonizer/mergedtree/nodeBuilders.kt | 6 +- .../commonizer/metadata/entityBuilders.kt | 43 ++-- .../commonizer/metadata/metadataBuilder.kt | 53 ++-- .../descriptors/commonizer/utils/fqName.kt | 71 +++--- .../descriptors/commonizer/utils/interners.kt | 35 --- .../commonizer/utils/moduleDescriptor.kt | 29 ++- .../descriptors/commonizer/utils/type.kt | 13 +- .../core/AnnotationsCommonizerTest.kt | 26 +- .../commonizer/core/CirEntityIdTest.kt | 229 ++++++++++++++++++ .../commonizer/core/CirNameTest.kt | 54 +++++ .../commonizer/core/CirPackageNameTest.kt | 109 +++++++++ .../commonizer/core/TypeCommonizerTest.kt | 14 +- .../core/TypeParameterCommonizerTest.kt | 4 +- .../core/ValueParameterCommonizerTest.kt | 6 +- .../descriptors/commonizer/utils/mocks.kt | 20 +- 67 files changed, 908 insertions(+), 466 deletions(-) create mode 100644 native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirName.kt delete mode 100644 native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/interners.kt create mode 100644 native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirEntityIdTest.kt create mode 100644 native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirNameTest.kt create mode 100644 native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirPackageNameTest.kt diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt index ac3b40d5a7d..f7711863c73 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt @@ -5,10 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir -import org.jetbrains.kotlin.name.Name - interface CirAnnotation { val type: CirClassType - val constantValueArguments: Map> - val annotationValueArguments: Map + val constantValueArguments: Map> + val annotationValueArguments: Map } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt index da49b3d888e..b7078dfcb64 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt @@ -5,10 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir -import org.jetbrains.kotlin.name.Name - interface CirClass : CirClassifier, CirContainingClass { - var companion: Name? // null means no companion object + var companion: CirName? // null means no companion object val isCompanion: Boolean val isInline: Boolean val isInner: Boolean diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirConstantValue.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirConstantValue.kt index 1644e8c3598..959687906e0 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirConstantValue.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirConstantValue.kt @@ -5,9 +5,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.Name - sealed class CirConstantValue { abstract val value: T @@ -28,8 +25,8 @@ sealed class CirConstantValue { data class DoubleValue(override val value: Double) : CirConstantValue() data class BooleanValue(override val value: Boolean) : CirConstantValue() - data class EnumValue(val enumClassId: ClassId, val enumEntryName: Name) : CirConstantValue() { - override val value: String = "${enumClassId.asString()}.${enumEntryName.asString()}" + data class EnumValue(val enumClassId: CirEntityId, val enumEntryName: CirName) : CirConstantValue() { + override val value: String = "${enumClassId}.${enumEntryName}" } data class ArrayValue(override val value: List>) : CirConstantValue>>() diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt index 4200302c849..18ab45d73bd 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt @@ -6,8 +6,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name /** * An intermediate representation of [DeclarationDescriptor]s for commonization purposes. @@ -17,7 +15,7 @@ import org.jetbrains.kotlin.name.Name * - [CirTypeAlias] - [TypeAliasDescriptor] * - [CirFunction] - [SimpleFunctionDescriptor] * - [CirProperty] - [PropertyDescriptor] - * - [CirPackage] - union of multiple [PackageFragmentDescriptor]s with the same [FqName] contributed by commonized [ModuleDescriptor]s + * - [CirPackage] - union of multiple [PackageFragmentDescriptor]s with the same FQ name contributed by commonized [ModuleDescriptor]s * - [CirModule] - [ModuleDescriptor] * - [CirRoot] - the root of the whole Commonizer IR tree */ @@ -28,11 +26,7 @@ interface CirHasAnnotations { } interface CirHasName { - val name: Name -} - -interface CirHasFqName { - val fqName: FqName + val name: CirName } interface CirHasVisibility { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirName.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirName.kt new file mode 100644 index 00000000000..e5c697fec07 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirName.kt @@ -0,0 +1,150 @@ +/* + * Copyright 2010-2021 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.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName.Companion.create +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName.Companion.create +import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode +import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner +import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name + +/** + * A representation of a simple name. Examples: + * 1) name of class without package and outer class name (if this is nested class). + * 2) name of class member such as property or function. + * 3) name of type parameter, name of value parameter. + * + * New instances are created via [create] method which encapsulates interning to avoid duplicated instances. + */ +class CirName private constructor(val name: String) { + override fun equals(other: Any?): Boolean = other is CirName && (other === this || other.name == name) + override fun hashCode(): Int = hashCode(name) + override fun toString(): String = name + + fun toStrippedString(): String = name.removeSurrounding("<", ">") + + companion object { + fun create(name: String): CirName = interner.intern(CirName(name)) + fun create(name: Name): CirName = create(name.asString()) + + private val interner = Interner() + } +} + +/** + * A representation of a fully-qualified package name. + * + * New instances are created via [create] method which encapsulates interning to avoid duplicated instances. + */ +class CirPackageName private constructor(val segments: Array) { + override fun equals(other: Any?): Boolean = other is CirPackageName && (other === this || other.segments.contentEquals(segments)) + override fun hashCode(): Int = hashCode(segments) + override fun toString(): String = segments.joinToString(".") + + fun toMetadataString(): String = segments.joinToString("/") + + fun isRoot(): Boolean = segments.isEmpty() + + fun startsWith(other: CirPackageName): Boolean { + return when { + other.isRoot() -> true + other.segments.size > segments.size -> false + else -> { + for (i in other.segments.indices) { + if (segments[i] != other.segments[i]) return false + } + true + } + } + } + + companion object { + val ROOT: CirPackageName = CirPackageName(emptyArray()) + + fun create(packageFqName: String): CirPackageName = create(splitComplexNameToArray(packageFqName, ".") { it }) + fun create(packageFqName: FqName): CirPackageName = if (packageFqName.isRoot) ROOT else create(packageFqName.asString()) + fun create(segments: Array): CirPackageName = if (segments.isEmpty()) ROOT else interner.intern(CirPackageName(segments)) + + private val interner = Interner() + + init { + interner.intern(ROOT) + } + } +} + +/** + * A representation of a fully-qualified classifier ID which includes [CirPackageName] and few [CirName] elements + * to uniquely address any class or type alias. Outer classes and type aliases always have single element + * in [relativeNameSegments]. While nested classes have more than one element in [relativeNameSegments] (the amount + * of elements depends on the nesting depth). + * + * New instances are created via [create] method which encapsulates interning to avoid duplicated instances. + */ +class CirEntityId private constructor(val packageName: CirPackageName, val relativeNameSegments: Array) { + override fun equals(other: Any?): Boolean = when { + other === this -> true + other is CirEntityId -> other.packageName == packageName && other.relativeNameSegments.contentEquals(relativeNameSegments) + else -> false + } + + override fun hashCode(): Int = hashCode(packageName).appendHashCode(relativeNameSegments) + + override fun toString(): String = buildString { + packageName.segments.joinTo(this, "/") + append('/') + relativeNameSegments.joinTo(this, ".") + } + + fun createNestedEntityId(entityName: CirName): CirEntityId = create(packageName, relativeNameSegments + entityName) + + val isNestedEntity: Boolean get() = relativeNameSegments.size > 1 + + companion object { + fun create(entityId: String): CirEntityId { + val rawPackageName: String + val rawRelativeName: String + when (val index = entityId.lastIndexOf('/')) { + -1 -> { + rawPackageName = "" + rawRelativeName = entityId + } + else -> { + rawPackageName = entityId.substring(0, index) + rawRelativeName = entityId.substring(index + 1) + } + } + + val packageName = CirPackageName.create(splitComplexNameToArray(rawPackageName, "/") { it }) + val relativeNameSegments = splitComplexNameToArray(rawRelativeName, ".", CirName::create) + + return create(packageName, relativeNameSegments) + } + + fun create(classifierId: ClassId): CirEntityId { + val packageName = CirPackageName.create(classifierId.packageFqName) + val relativeNameSegments = splitComplexNameToArray(classifierId.relativeClassName.asString(), ".", CirName::create) + + return create(packageName, relativeNameSegments) + } + + fun create(packageName: CirPackageName, relativeName: CirName): CirEntityId = create(packageName, arrayOf(relativeName)) + + fun create(packageName: CirPackageName, relativeNameSegments: Array): CirEntityId = + interner.intern(CirEntityId(packageName, relativeNameSegments)) + + private val interner = Interner() + } +} + +private inline fun splitComplexNameToArray(complexName: String, delimiter: String, transform: (String) -> T): Array { + if (complexName.isEmpty()) return emptyArray() + val segments = complexName.split(delimiter) + return Array(segments.size) { index -> transform(segments[index]) } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt index 54586c10a27..7ab72b86677 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt @@ -5,4 +5,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir -interface CirPackage : CirDeclaration, CirHasFqName +interface CirPackage : CirDeclaration { + val packageName: CirPackageName +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt index 043ee6dd38b..e3644dee6a8 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.types.AbbreviatedType import org.jetbrains.kotlin.types.Variance @@ -58,13 +57,13 @@ data class CirTypeParameterType( } sealed class CirClassOrTypeAliasType : CirSimpleType() { - abstract val classifierId: ClassId + abstract val classifierId: CirEntityId abstract val arguments: List override fun appendDescriptionTo(builder: StringBuilder) = appendDescriptionTo(builder, shortNameOnly = false) protected open fun appendDescriptionTo(builder: StringBuilder, shortNameOnly: Boolean) { - builder.append(if (shortNameOnly) classifierId.relativeClassName.shortName().asString() else classifierId.asString()) + builder.append(if (shortNameOnly) classifierId.relativeNameSegments.last() else classifierId) if (arguments.isNotEmpty()) arguments.joinTo(builder, prefix = "<", postfix = ">") super.appendDescriptionTo(builder) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt index e7e65eba15f..250fe79d212 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt @@ -10,10 +10,10 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirAnnotationImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.* import org.jetbrains.kotlin.descriptors.commonizer.utils.compact -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.constants.AnnotationValue import org.jetbrains.kotlin.resolve.constants.ConstantValue @@ -28,16 +28,17 @@ object CirAnnotationFactory { if (allValueArguments.isEmpty()) return create(type = type, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap()) - val constantValueArguments: MutableMap> = THashMap(allValueArguments.size) - val annotationValueArguments: MutableMap = THashMap(allValueArguments.size) + val constantValueArguments: MutableMap> = THashMap(allValueArguments.size) + val annotationValueArguments: MutableMap = THashMap(allValueArguments.size) allValueArguments.forEach { (name, constantValue) -> + val cirName = CirName.create(name) if (constantValue is AnnotationValue) - annotationValueArguments[name.intern()] = create(source = constantValue.value) + annotationValueArguments[cirName] = create(source = constantValue.value) else - constantValueArguments[name.intern()] = CirConstantValueFactory.createSafely( + constantValueArguments[cirName] = CirConstantValueFactory.createSafely( constantValue = constantValue, - constantName = name, + constantName = cirName, owner = source, ) } @@ -51,8 +52,8 @@ object CirAnnotationFactory { fun create( type: CirClassType, - constantValueArguments: Map>, - annotationValueArguments: Map + constantValueArguments: Map>, + annotationValueArguments: Map ): CirAnnotation { return interner.intern( CirAnnotationImpl( diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt index 29fb91d6889..642311b7fac 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt @@ -11,22 +11,21 @@ import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.isInlineClass object CirClassFactory { fun create(source: ClassDescriptor): CirClass = create( annotations = source.annotations.compactMap(CirAnnotationFactory::create), - name = source.name.intern(), + name = CirName.create(source.name), typeParameters = source.declaredTypeParameters.compactMap(CirTypeParameterFactory::create), visibility = source.visibility, modality = source.modality, kind = source.kind, - companion = source.companionObjectDescriptor?.name?.intern(), + companion = source.companionObjectDescriptor?.name?.let(CirName::create), isCompanion = source.isCompanionObject, isData = source.isData, isInline = source.isInlineClass(), @@ -39,12 +38,12 @@ object CirClassFactory { @Suppress("NOTHING_TO_INLINE") inline fun create( annotations: List, - name: Name, + name: CirName, typeParameters: List, visibility: DescriptorVisibility, modality: Modality, kind: ClassKind, - companion: Name?, + companion: CirName?, isCompanion: Boolean, isData: Boolean, isInline: Boolean, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirConstantValueFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirConstantValueFactory.kt index 2c5075e4424..250ffa871af 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirConstantValueFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirConstantValueFactory.kt @@ -6,19 +6,19 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapIndexed -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.constants.* object CirConstantValueFactory { fun createSafely( constantValue: ConstantValue<*>, - constantName: Name? = null, + constantName: CirName? = null, owner: Any, ): CirConstantValue<*> = createSafely( constantValue = constantValue, - location = { "${owner::class.java}, $owner" + constantName?.asString()?.let { "[$it]" } } + location = { "${owner::class.java}, $owner" + constantName?.toString()?.let { "[$it]" } } ) private fun createSafely( @@ -42,7 +42,10 @@ object CirConstantValueFactory { is DoubleValue -> CirConstantValue.DoubleValue(constantValue.value) is BooleanValue -> CirConstantValue.BooleanValue(constantValue.value) - is EnumValue -> CirConstantValue.EnumValue(constantValue.enumClassId.intern(), constantValue.enumEntryName.intern()) + is EnumValue -> CirConstantValue.EnumValue( + CirEntityId.create(constantValue.enumClassId), + CirName.create(constantValue.enumEntryName) + ) is NullValue -> CirConstantValue.NullValue is ArrayValue -> CirConstantValue.ArrayValue( diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt index ff00d8bcc16..1b22cc3e3b9 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt @@ -9,13 +9,11 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirFunctionImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name object CirFunctionFactory { fun create(source: SimpleFunctionDescriptor, containingClass: CirContainingClass?): CirFunction = create( annotations = source.annotations.compactMap(CirAnnotationFactory::create), - name = source.name.intern(), + name = CirName.create(source.name), typeParameters = source.typeParameters.compactMap(CirTypeParameterFactory::create), visibility = source.visibility, modality = source.modality, @@ -31,7 +29,7 @@ object CirFunctionFactory { @Suppress("NOTHING_TO_INLINE") inline fun create( annotations: List, - name: Name, + name: CirName, typeParameters: List, visibility: DescriptorVisibility, modality: Modality, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt index da0e8d6ca31..9f1071b08d3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt @@ -5,14 +5,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirModuleImpl -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name object CirModuleFactory { - fun create(source: ModuleDescriptor): CirModule = create(source.name.intern()) - - fun create(name: Name) = CirModuleImpl(name) + fun create(name: CirName) = CirModuleImpl(name) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt index b7b2d1898ef..cdfcf857baa 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt @@ -6,9 +6,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPackageImpl -import org.jetbrains.kotlin.name.FqName object CirPackageFactory { - fun create(fqName: FqName): CirPackage = CirPackageImpl(fqName) + fun create(packageName: CirPackageName): CirPackage = CirPackageImpl(packageName) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt index 263ff5e9a1a..86808b55fd7 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt @@ -12,8 +12,6 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertyImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name object CirPropertyFactory { fun create(source: PropertyDescriptor, containingClass: CirContainingClass?): CirProperty { @@ -26,7 +24,7 @@ object CirPropertyFactory { return create( annotations = source.annotations.compactMap(CirAnnotationFactory::create), - name = source.name.intern(), + name = CirName.create(source.name), typeParameters = source.typeParameters.compactMap(CirTypeParameterFactory::create), visibility = source.visibility, modality = source.modality, @@ -50,7 +48,7 @@ object CirPropertyFactory { @Suppress("NOTHING_TO_INLINE") inline fun create( annotations: List, - name: Name, + name: CirName, typeParameters: List, visibility: DescriptorVisibility, modality: Modality, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt index bb4c3716fdb..7923348e8ec 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt @@ -10,13 +10,11 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeAliasImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name object CirTypeAliasFactory { fun create(source: TypeAliasDescriptor): CirTypeAlias = create( annotations = source.annotations.compactMap(CirAnnotationFactory::create), - name = source.name.intern(), + name = CirName.create(source.name), typeParameters = source.declaredTypeParameters.compactMap(CirTypeParameterFactory::create), visibility = source.visibility, underlyingType = CirTypeFactory.create(source.underlyingType, useAbbreviation = true) as CirClassOrTypeAliasType, @@ -26,7 +24,7 @@ object CirTypeAliasFactory { @Suppress("NOTHING_TO_INLINE") inline fun create( annotations: List, - name: Name, + name: CirName, typeParameters: List, visibility: DescriptorVisibility, underlyingType: CirClassOrTypeAliasType, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt index 688baeef93a..cda5e6b83db 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassTypeImpl import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeAliasTypeImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.* -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.types.* object CirTypeFactory { @@ -42,7 +41,7 @@ object CirTypeFactory { when (val classifierDescriptor = abbreviation.declarationDescriptor) { is TypeAliasDescriptor -> { return createTypeAliasType( - typeAliasId = classifierDescriptor.internedClassId, + typeAliasId = classifierDescriptor.classifierId, underlyingType = create(extractExpandedType(source), useAbbreviation = true) as CirClassOrTypeAliasType, arguments = createArguments(abbreviation.arguments, useAbbreviation = true), isMarkedNullable = abbreviation.isMarkedNullable @@ -70,7 +69,7 @@ object CirTypeFactory { val cirExpandedTypeWithProperNullability = if (source.isMarkedNullable) makeNullable(cirExpandedType) else cirExpandedType createTypeAliasType( - typeAliasId = classifierDescriptor.internedClassId, + typeAliasId = classifierDescriptor.classifierId, underlyingType = cirExpandedTypeWithProperNullability, arguments = createArguments(source.arguments, useAbbreviation = true), isMarkedNullable = source.isMarkedNullable @@ -82,7 +81,7 @@ object CirTypeFactory { } fun createClassType( - classId: ClassId, + classId: CirEntityId, outerType: CirClassType?, visibility: DescriptorVisibility, arguments: List, @@ -100,7 +99,7 @@ object CirTypeFactory { } fun createTypeAliasType( - typeAliasId: ClassId, + typeAliasId: CirEntityId, underlyingType: CirClassOrTypeAliasType, arguments: List, isMarkedNullable: Boolean @@ -170,7 +169,7 @@ object CirTypeFactory { } return createClassType( - classId = classDescriptor.internedClassId, + classId = classDescriptor.classifierId, outerType = outerType, visibility = classDescriptor.visibility, arguments = remainingArguments, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt index ad6c008945e..aede18423eb 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt @@ -7,12 +7,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeParameterImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.typeUtil.isNullableAny @@ -23,7 +22,7 @@ object CirTypeParameterFactory { return create( annotations = source.annotations.compactMap(CirAnnotationFactory::create), - name = source.name.intern(), + name = CirName.create(source.name), isReified = source.isReified, variance = source.variance, upperBounds = filteredUpperBounds.compactMap(CirTypeFactory::create) @@ -33,7 +32,7 @@ object CirTypeParameterFactory { @Suppress("NOTHING_TO_INLINE") inline fun create( annotations: List, - name: Name, + name: CirName, isReified: Boolean, variance: Variance, upperBounds: List diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt index 165e7df9e20..1525a481e81 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt @@ -7,20 +7,19 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirValueParameterImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name object CirValueParameterFactory { private val interner = Interner() fun create(source: ValueParameterDescriptor): CirValueParameter = create( annotations = source.annotations.compactMap(CirAnnotationFactory::create), - name = source.name.intern(), + name = CirName.create(source.name), returnType = CirTypeFactory.create(source.returnType!!), varargElementType = source.varargElementType?.let(CirTypeFactory::create), declaresDefaultValue = source.declaresDefaultValue(), @@ -30,7 +29,7 @@ object CirValueParameterFactory { fun create( annotations: List, - name: Name, + name: CirName, returnType: CirType, varargElementType: CirType?, declaresDefaultValue: Boolean, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt index 02f39825a87..39f028635d8 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt @@ -8,14 +8,14 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode -import org.jetbrains.kotlin.name.Name data class CirAnnotationImpl( override val type: CirClassType, - override val constantValueArguments: Map>, - override val annotationValueArguments: Map + override val constantValueArguments: Map>, + override val annotationValueArguments: Map ) : CirAnnotation { // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode private var cachedHashCode = 0 diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt index 49dd69552ad..84827c18075 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt @@ -8,20 +8,16 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.DescriptorVisibility -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter -import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.descriptors.commonizer.cir.* data class CirClassImpl( override val annotations: List, - override val name: Name, + override val name: CirName, override val typeParameters: List, override val visibility: DescriptorVisibility, override val modality: Modality, override val kind: ClassKind, - override var companion: Name?, + override var companion: CirName?, override val isCompanion: Boolean, override val isData: Boolean, override val isInline: Boolean, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassTypeImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassTypeImpl.kt index 7d91040dd2a..fd3c8d97671 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassTypeImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassTypeImpl.kt @@ -7,13 +7,13 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeProjection import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode -import org.jetbrains.kotlin.name.ClassId data class CirClassTypeImpl( - override val classifierId: ClassId, + override val classifierId: CirEntityId, override val outerType: CirClassType?, override val visibility: DescriptorVisibility, // visibility of the class descriptor override val arguments: List, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt index cfea44e0acc..8dd9113ebfc 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt @@ -9,11 +9,10 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.* -import org.jetbrains.kotlin.name.Name data class CirFunctionImpl( override val annotations: List, - override val name: Name, + override val name: CirName, override val typeParameters: List, override val visibility: DescriptorVisibility, override val modality: Modality, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt index b9a2655f571..7ee8706f4b3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt @@ -6,8 +6,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule -import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName data class CirModuleImpl( - override val name: Name + override val name: CirName ) : CirModule diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt index d3c285ca65b..9f4e0f8b000 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt @@ -6,8 +6,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage -import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName data class CirPackageImpl( - override val fqName: FqName + override val packageName: CirPackageName ) : CirPackage diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt index d70b6865cbf..b5549c18c04 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt @@ -9,11 +9,10 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.* -import org.jetbrains.kotlin.name.Name data class CirPropertyImpl( override val annotations: List, - override val name: Name, + override val name: CirName, override val typeParameters: List, override val visibility: DescriptorVisibility, override val modality: Modality, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt index 6cb409db0a3..6da6b47e091 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt @@ -7,11 +7,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.commonizer.cir.* -import org.jetbrains.kotlin.name.Name data class CirTypeAliasImpl( override val annotations: List, - override val name: Name, + override val name: CirName, override val typeParameters: List, override val visibility: DescriptorVisibility, override val underlyingType: CirClassOrTypeAliasType, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasTypeImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasTypeImpl.kt index 9631f7a0ae0..65726178a9a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasTypeImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasTypeImpl.kt @@ -6,14 +6,14 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassOrTypeAliasType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAliasType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeProjection import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode -import org.jetbrains.kotlin.name.ClassId data class CirTypeAliasTypeImpl( - override val classifierId: ClassId, + override val classifierId: CirEntityId, override val underlyingType: CirClassOrTypeAliasType, override val arguments: List, override val isMarkedNullable: Boolean diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt index 28f6d9669f9..4d2ba1dd79f 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt @@ -6,14 +6,14 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance data class CirTypeParameterImpl( override val annotations: List, - override val name: Name, + override val name: CirName, override val isReified: Boolean, override val variance: Variance, override val upperBounds: List diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt index 16ce4761aa1..9acc38366f9 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt @@ -6,15 +6,15 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode -import org.jetbrains.kotlin.name.Name data class CirValueParameterImpl( override val annotations: List, - override val name: Name, + override val name: CirName, override val returnType: CirType, override val varargElementType: CirType?, override val declaresDefaultValue: Boolean, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt index 20648badf71..7e90e3ffd1f 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt @@ -5,11 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassifier -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRecursionMarker -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType -import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.descriptors.commonizer.cir.* object CirClassRecursionMarker : CirClass, CirRecursionMarker { override val annotations get() = unsupported() @@ -18,7 +14,7 @@ object CirClassRecursionMarker : CirClass, CirRecursionMarker { override val visibility get() = unsupported() override val modality get() = unsupported() override val kind get() = unsupported() - override var companion: Name? + override var companion: CirName? get() = unsupported() set(_) = unsupported() override val isCompanion get() = unsupported() diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt index 9005a109dcb..44498dc546c 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt @@ -9,13 +9,13 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFunctionOrProperty +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers -import org.jetbrains.kotlin.name.Name abstract class AbstractFunctionOrPropertyCommonizer( classifiers: CirKnownClassifiers ) : AbstractStandardCommonizer() { - protected lateinit var name: Name + protected lateinit var name: CirName protected val modality = ModalityCommonizer() protected val visibility = VisibilityCommonizer.lowering() protected val extensionReceiver = ExtensionReceiverCommonizer(classifiers) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt index eef8bbd1738..4ef561e1601 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt @@ -9,13 +9,12 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory import org.jetbrains.kotlin.descriptors.commonizer.core.AnnotationsCommonizer.Companion.FALLBACK_MESSAGE import org.jetbrains.kotlin.descriptors.commonizer.utils.* -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import kotlin.DeprecationLevel.WARNING /** @@ -56,20 +55,22 @@ private class DeprecatedAnnotationCommonizer : Commonizer> = if (level == WARNING) { - // don't populate with the default level value - compactMapOf(PROPERTY_NAME_MESSAGE, messageValue) - } else - compactMapOf( - PROPERTY_NAME_MESSAGE, messageValue, - PROPERTY_NAME_LEVEL, level.toDeprecationLevelValue() - ) + val constantValueArguments: Map> = + if (level == WARNING) { + // don't populate with the default level value + compactMapOf(PROPERTY_NAME_MESSAGE, messageValue) + } else + compactMapOf( + PROPERTY_NAME_MESSAGE, messageValue, + PROPERTY_NAME_LEVEL, level.toDeprecationLevelValue() + ) - val annotationValueArguments: Map = if (replaceWithExpression.isEmpty() && replaceWithImports.isEmpty()) { - // don't populate with empty (default) ReplaceWith - emptyMap() - } else - compactMapOf(PROPERTY_NAME_REPLACE_WITH, replaceWithExpression.toReplaceWithValue(replaceWithImports)) + val annotationValueArguments: Map = + if (replaceWithExpression.isEmpty() && replaceWithImports.isEmpty()) { + // don't populate with empty (default) ReplaceWith + emptyMap() + } else + compactMapOf(PROPERTY_NAME_REPLACE_WITH, replaceWithExpression.toReplaceWithValue(replaceWithImports)) return CirAnnotationFactory.create( type = DEPRECATED_ANNOTATION_TYPE, @@ -128,12 +129,12 @@ private class DeprecatedAnnotationCommonizer : Commonizer = listOf( @@ -143,16 +144,16 @@ private class DeprecatedAnnotationCommonizer : Commonizer = DeprecationLevel.values().associate { - it.name to EnumValue(DEPRECATION_LEVEL_CLASS_ID, Name.identifier(it.name).intern()) + it.name to EnumValue(DEPRECATION_LEVEL_CLASS_ID, CirName.create(it.name)) } - private fun buildAnnotationType(classId: ClassId) = CirTypeFactory.createClassType( + private fun buildAnnotationType(classId: CirEntityId) = CirTypeFactory.createClassType( classId = classId, outerType = null, visibility = DescriptorVisibilities.PUBLIC, @@ -188,16 +189,16 @@ private class DeprecatedAnnotationCommonizer : Commonizer): CirAnnotation = createReplaceWithAnnotation(this, imports) - private inline fun Map>.getString(name: Name): String? = + private inline fun Map>.getString(name: CirName): String? = (this[name] as? StringValue)?.value - private inline fun Map>.getEnumEntryName(name: Name): String? = - (this[name] as? EnumValue)?.enumEntryName?.asString() + private inline fun Map>.getEnumEntryName(name: CirName): String? = + (this[name] as? EnumValue)?.enumEntryName?.name - private inline fun Map.getAnnotation(name: Name): CirAnnotation? = + private inline fun Map.getAnnotation(name: CirName): CirAnnotation? = this[name] - private inline fun Map>.getStringArray(name: Name): List? { + private inline fun Map>.getStringArray(name: CirName): List? { val elements: List> = (this[name] as? ArrayValue)?.value ?: return null if (elements.isEmpty()) return emptyList() diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CallableValueParametersCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CallableValueParametersCommonizer.kt index a33598b081d..a5d1f482d30 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CallableValueParametersCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CallableValueParametersCommonizer.kt @@ -8,15 +8,14 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import com.intellij.util.containers.FactoryMap import org.jetbrains.kotlin.descriptors.commonizer.cir.CirCallableMemberWithParameters import org.jetbrains.kotlin.descriptors.commonizer.cir.CirHasAnnotations +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirValueParameterFactory import org.jetbrains.kotlin.descriptors.commonizer.core.CallableValueParametersCommonizer.CallableToPatch.Companion.doNothing import org.jetbrains.kotlin.descriptors.commonizer.core.CallableValueParametersCommonizer.CallableToPatch.Companion.patchCallables import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapIndexed -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.descriptors.commonizer.utils.isObjCInteropCallableAnnotation -import org.jetbrains.kotlin.name.Name class CallableValueParametersCommonizer( classifiers: CirKnownClassifiers @@ -40,7 +39,7 @@ class CallableValueParametersCommonizer( companion object { fun doNothing(): () -> Unit = {} - fun List.patchCallables(generated: Boolean, newNames: List): () -> Unit { + fun List.patchCallables(generated: Boolean, newNames: List): () -> Unit { val callablesToPatch = filter { it.originalNames is ValueParameterNames.Generated == generated } .takeIf { it.isNotEmpty() } ?: return doNothing() @@ -72,10 +71,10 @@ class CallableValueParametersCommonizer( private sealed class ValueParameterNames { object Generated : ValueParameterNames() - data class Real(val names: List) : ValueParameterNames() + data class Real(val names: List) : ValueParameterNames() class MultipleReal(valueParameters: List) : ValueParameterNames() { - val generatedNames: List = generatedNames(valueParameters) + val generatedNames: List = generatedNames(valueParameters) } companion object { @@ -87,7 +86,7 @@ class CallableValueParametersCommonizer( var real = false val names = callable.valueParameters.mapIndexed { index, valueParameter -> val name = valueParameter.name - val plainName = name.asString() + val plainName = name.name if (valueParameter.varargElementType != null) { if (plainName != VARIADIC_ARGUMENTS) { @@ -107,7 +106,7 @@ class CallableValueParametersCommonizer( return if (real) Real(names) else Generated } - fun generatedNames(valueParameters: List): List = + fun generatedNames(valueParameters: List): List = valueParameters.mapIndexed { index, valueParameter -> if (valueParameter.varargElementType != null) { VARIADIC_ARGUMENTS_NAME @@ -223,9 +222,9 @@ class CallableValueParametersCommonizer( private const val VARIADIC_ARGUMENTS = "variadicArguments" private const val REGULAR_ARGUMENT_PREFIX = "arg" - private val VARIADIC_ARGUMENTS_NAME = Name.identifier(VARIADIC_ARGUMENTS).intern() - private val REGULAR_ARGUMENT_NAMES = FactoryMap.create { index -> - Name.identifier(REGULAR_ARGUMENT_PREFIX + index).intern() + private val VARIADIC_ARGUMENTS_NAME = CirName.create(VARIADIC_ARGUMENTS) + private val REGULAR_ARGUMENT_NAMES = FactoryMap.create { index -> + CirName.create(REGULAR_ARGUMENT_PREFIX + index) } private fun CirCallableMemberWithParameters.canNamesBeOverwritten(): Boolean { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt index 577e4a8e8b8..8fa13fbd82d 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt @@ -7,12 +7,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers -import org.jetbrains.kotlin.name.Name class ClassCommonizer(classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName private lateinit var kind: ClassKind private val typeParameters = TypeParameterListCommonizer(classifiers) private val modality = ModalityCommonizer() diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt index d69afd980bf..17e2832692c 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt @@ -6,13 +6,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.descriptors.commonizer.utils.* import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapNotNull -import org.jetbrains.kotlin.descriptors.commonizer.utils.internedClassId -import org.jetbrains.kotlin.name.ClassId internal class CommonizationVisitor( private val classifiers: CirKnownClassifiers, @@ -88,7 +87,7 @@ internal class CommonizationVisitor( // companion object should have the same name for each target class, then it could be set to common class val companionObjectName = node.targetDeclarations.mapTo(HashSet()) { it!!.companion }.singleOrNull() if (companionObjectName != null) { - val companionObjectClassId = internedClassId(node.classId, companionObjectName) + val companionObjectClassId = node.classifierId.createNestedEntityId(companionObjectName) val companionObjectNode = classifiers.commonized.classNode(companionObjectClassId) ?: error("Can't find companion object with class ID $companionObjectClassId") @@ -99,7 +98,7 @@ internal class CommonizationVisitor( } // find out common (and commonized) supertypes - commonClass.commonizeSupertypes(node.classId, node.collectCommonSupertypes()) + commonClass.commonizeSupertypes(node.classifierId, node.collectCommonSupertypes()) } } @@ -112,7 +111,7 @@ internal class CommonizationVisitor( if (commonClassifier is CirClass) { // find out common (and commonized) supertypes - commonClassifier.commonizeSupertypes(node.classId, node.collectCommonSupertypes()) + commonClassifier.commonizeSupertypes(node.classifierId, node.collectCommonSupertypes()) } } @@ -135,7 +134,7 @@ internal class CommonizationVisitor( val expandedClassNode = classifiers.commonized.classNode(expandedClassId) ?: return null val expandedClass = expandedClassNode.targetDeclarations[index] - ?: error("Can't find expanded class with class ID $expandedClassId and index $index for type alias $classId") + ?: error("Can't find expanded class with class ID $expandedClassId and index $index for type alias $classifierId") for (supertype in expandedClass.supertypes) { supertypesMap.getOrPut(supertype) { CommonizedGroup(targetDeclarations.size) }[index] = supertype @@ -145,7 +144,7 @@ internal class CommonizationVisitor( } private fun CirClass.commonizeSupertypes( - classId: ClassId, + classId: CirEntityId, supertypesMap: Map>? ) { val commonSupertypes = supertypesMap?.values?.compactMapNotNull { supertypesGroup -> diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ModuleCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ModuleCommonizer.kt index 44a0ed87fcc..636c557c36e 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ModuleCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ModuleCommonizer.kt @@ -6,11 +6,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirModuleFactory -import org.jetbrains.kotlin.name.Name class ModuleCommonizer : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName override fun commonizationResult() = CirModuleFactory.create(name = name) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PackageCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PackageCommonizer.kt index a6d763d8ded..5fa9dc2b15e 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PackageCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PackageCommonizer.kt @@ -6,16 +6,16 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirPackageFactory -import org.jetbrains.kotlin.name.FqName class PackageCommonizer : AbstractStandardCommonizer() { - private lateinit var fqName: FqName + private lateinit var packageName: CirPackageName - override fun commonizationResult() = CirPackageFactory.create(fqName = fqName) + override fun commonizationResult() = CirPackageFactory.create(packageName = packageName) override fun initialize(first: CirPackage) { - fqName = first.fqName + packageName = first.packageName } override fun doCommonizeWith(next: CirPackage) = true diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt index 1c3d6629fd5..200502317c3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeAliasFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers -import org.jetbrains.kotlin.name.Name /** * Primary (optimistic) branch: @@ -45,7 +44,7 @@ class TypeAliasCommonizer(classifiers: CirKnownClassifiers) : AbstractStandardCo private class TypeAliasShortCircuitingCommonizer( private val classifiers: CirKnownClassifiers ) : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName private val typeParameters = TypeParameterListCommonizer(classifiers) private var underlyingType: CirClassOrTypeAliasType? = null // null means not computed yet private val expandedType = TypeCommonizer(classifiers) @@ -79,7 +78,7 @@ private class TypeAliasShortCircuitingCommonizer( } private class TypeAliasLiftingUpCommonizer(classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName private val typeParameters = TypeParameterListCommonizer(classifiers) private val underlyingType = TypeCommonizer(classifiers) private val visibility = VisibilityCommonizer.lowering() @@ -111,7 +110,7 @@ private class TypeAliasLiftingUpCommonizer(classifiers: CirKnownClassifiers) : A } private class TypeAliasExpectClassCommonizer : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName private val classVisibility = VisibilityCommonizer.equalizing() override fun commonizationResult(): CirClass = CirClassFactory.create( diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt index 114d9d3c0e0..9225ec14d1a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.core.CommonizedTypeAliasAnswe import org.jetbrains.kotlin.descriptors.commonizer.core.CommonizedTypeAliasAnswer.Companion.SUCCESS_FROM_DEPENDEE_LIBRARY import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderKotlinNativeSyntheticPackages -import org.jetbrains.kotlin.name.ClassId class TypeCommonizer(private val classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { private lateinit var wrapped: Commonizer<*, CirType> @@ -38,7 +37,7 @@ class TypeCommonizer(private val classifiers: CirKnownClassifiers) : AbstractSta } private class ClassTypeCommonizer(private val classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { - private lateinit var classId: ClassId + private lateinit var classId: CirEntityId private val outerType = OuterClassTypeCommonizer(classifiers) private lateinit var anyVisibility: DescriptorVisibility private val arguments = TypeArgumentListCommonizer(classifiers) @@ -80,7 +79,7 @@ private class OuterClassTypeCommonizer(classifiers: CirKnownClassifiers) : private class TypeAliasTypeCommonizer(private val classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { - private lateinit var typeAliasId: ClassId + private lateinit var typeAliasId: CirEntityId private val arguments = TypeArgumentListCommonizer(classifiers) private var isMarkedNullable = false private var commonizedTypeBuilder: CommonizedTypeAliasTypeBuilder? = null // null means not selected yet @@ -122,12 +121,12 @@ private class TypeAliasTypeCommonizer(private val classifiers: CirKnownClassifie // builds a new type for "common" library fragment for the given combination of type alias types in "platform" fragments private interface CommonizedTypeAliasTypeBuilder { - fun build(typeAliasId: ClassId, arguments: List, isMarkedNullable: Boolean): CirClassOrTypeAliasType + fun build(typeAliasId: CirEntityId, arguments: List, isMarkedNullable: Boolean): CirClassOrTypeAliasType companion object { // type alias has been commonized to expect class, need to build type for expect class fun forClass(commonClass: CirClass) = object : CommonizedTypeAliasTypeBuilder { - override fun build(typeAliasId: ClassId, arguments: List, isMarkedNullable: Boolean) = + override fun build(typeAliasId: CirEntityId, arguments: List, isMarkedNullable: Boolean) = CirTypeFactory.createClassType( classId = typeAliasId, outerType = null, // there can't be outer type @@ -143,7 +142,7 @@ private class TypeAliasTypeCommonizer(private val classifiers: CirKnownClassifie // type alias don't needs to be commonized because it is from the standard library fun forKnownUnderlyingType(underlyingType: CirClassOrTypeAliasType) = object : CommonizedTypeAliasTypeBuilder { - override fun build(typeAliasId: ClassId, arguments: List, isMarkedNullable: Boolean): CirTypeAliasType { + override fun build(typeAliasId: CirEntityId, arguments: List, isMarkedNullable: Boolean): CirTypeAliasType { val underlyingTypeWithProperNullability = if (isMarkedNullable && !underlyingType.isMarkedNullable) CirTypeFactory.makeNullable(underlyingType) else @@ -192,11 +191,11 @@ private class FlexibleTypeCommonizer(classifiers: CirKnownClassifiers) : Abstrac lowerBound.commonizeWith(next.lowerBound) && upperBound.commonizeWith(next.upperBound) } -private fun commonizeClass(classId: ClassId, classifiers: CirKnownClassifiers): Boolean { +private fun commonizeClass(classId: CirEntityId, classifiers: CirKnownClassifiers): Boolean { if (classifiers.commonDependeeLibraries.hasClassifier(classId)) { // The class is from common fragment of dependee library (ex: stdlib). Already commonized. return true - } else if (classId.packageFqName.isUnderKotlinNativeSyntheticPackages) { + } else if (classId.packageName.isUnderKotlinNativeSyntheticPackages) { // C/Obj-C forward declarations are: // - Either resolved to real classes/interfaces from other interop libraries (which are generated by C-interop tool and // are known to have modality/visibility/other attributes to successfully pass commonization). @@ -219,7 +218,7 @@ private fun commonizeClass(classId: ClassId, classifiers: CirKnownClassifiers): } } -private fun commonizeTypeAlias(typeAliasId: ClassId, classifiers: CirKnownClassifiers): CommonizedTypeAliasAnswer { +private fun commonizeTypeAlias(typeAliasId: CirEntityId, classifiers: CirKnownClassifiers): CommonizedTypeAliasAnswer { if (classifiers.commonDependeeLibraries.hasClassifier(typeAliasId)) { // The type alias is from common fragment of dependee library (ex: stdlib). Already commonized. return SUCCESS_FROM_DEPENDEE_LIBRARY diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt index 70aa038131e..dd205c4efef 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt @@ -5,15 +5,15 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeParameterFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance class TypeParameterCommonizer(classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName private var isReified = false private lateinit var variance: Variance private val upperBounds = TypeParameterUpperBoundsCommonizer(classifiers) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt index 1df5409fee9..3503b61479d 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt @@ -5,15 +5,15 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirValueParameterFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers import org.jetbrains.kotlin.descriptors.commonizer.utils.isNull -import org.jetbrains.kotlin.name.Name class ValueParameterCommonizer(classifiers: CirKnownClassifiers) : AbstractStandardCommonizer() { - private lateinit var name: Name + private lateinit var name: CirName private val returnType = TypeCommonizer(classifiers) private var varargElementType: CirType? = null private var isCrossinline = true @@ -49,7 +49,7 @@ class ValueParameterCommonizer(classifiers: CirKnownClassifiers) : AbstractStand return result } - fun overwriteName(name: Name) { + fun overwriteName(name: CirName) { this.name = name } } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt index 7293af81380..4d628f36d45 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt @@ -5,14 +5,14 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers -import org.jetbrains.kotlin.name.Name class ValueParameterListCommonizer(classifiers: CirKnownClassifiers) : AbstractListCommonizer( singleElementCommonizerFactory = { ValueParameterCommonizer(classifiers) } ) { - fun overwriteNames(names: List) { + fun overwriteNames(names: List) { forEachSingleElementCommonizer { index, singleElementCommonizer -> (singleElementCommonizer as ValueParameterCommonizer).overwriteName(names[index]) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirClassNode.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirClassNode.kt index 8351d8349a7..71fca5e3f9a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirClassNode.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirClassNode.kt @@ -7,21 +7,21 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import gnu.trove.THashMap import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.NullableLazyValue class CirClassNode( override val targetDeclarations: CommonizedGroup, override val commonDeclaration: NullableLazyValue, - override val classId: ClassId -) : CirNodeWithClassId, CirNodeWithMembers { + override val classifierId: CirEntityId +) : CirNodeWithClassifierId, CirNodeWithMembers { val constructors: MutableMap = THashMap() override val properties: MutableMap = THashMap() override val functions: MutableMap = THashMap() - override val classes: MutableMap = THashMap() + override val classes: MutableMap = THashMap() override fun accept(visitor: CirNodeVisitor, data: T): R = visitor.visitClassNode(this, data) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirModuleNode.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirModuleNode.kt index 53c889c18e2..f55a8d1632f 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirModuleNode.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirModuleNode.kt @@ -7,15 +7,15 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import gnu.trove.THashMap import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.storage.NullableLazyValue class CirModuleNode( override val targetDeclarations: CommonizedGroup, override val commonDeclaration: NullableLazyValue ) : CirNode { - val packages: MutableMap = THashMap() + val packages: MutableMap = THashMap() override fun accept(visitor: CirNodeVisitor, data: T) = visitor.visitModuleNode(this, data) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNode.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNode.kt index 09f1049e4bf..b6069ae877c 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNode.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNode.kt @@ -5,12 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassifier -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirLiftedUpDeclaration +import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.NullableLazyValue interface CirNode { @@ -28,10 +24,10 @@ interface CirNode { fun toString(node: CirNode<*, *>) = buildString { if (node is CirPackageNode) { - append("packageFqName=").append(node.packageFqName.asString()).append(", ") + append("packageName=").append(node.packageName).append(", ") } - if (node is CirNodeWithClassId) { - append("classId=").append(node.classId.asString()).append(", ") + if (node is CirNodeWithClassifierId) { + append("classifierId=").append(node.classifierId).append(", ") } append("target=") node.targetDeclarations.joinTo(this) @@ -41,8 +37,8 @@ interface CirNode { } } -interface CirNodeWithClassId : CirNode { - val classId: ClassId +interface CirNodeWithClassifierId : CirNode { + val classifierId: CirEntityId } interface CirNodeWithLiftingUp : CirNode { @@ -53,5 +49,5 @@ interface CirNodeWithLiftingUp : CirNode interface CirNodeWithMembers : CirNode { val properties: MutableMap val functions: MutableMap - val classes: MutableMap + val classes: MutableMap } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirPackageNode.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirPackageNode.kt index e571a60ea90..5762cce7327 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirPackageNode.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirPackageNode.kt @@ -6,11 +6,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import gnu.trove.THashMap +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.firstNonNull -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.NullableLazyValue class CirPackageNode( @@ -20,11 +20,11 @@ class CirPackageNode( override val properties: MutableMap = THashMap() override val functions: MutableMap = THashMap() - override val classes: MutableMap = THashMap() - val typeAliases: MutableMap = THashMap() + override val classes: MutableMap = THashMap() + val typeAliases: MutableMap = THashMap() - val packageFqName: FqName - get() = targetDeclarations.firstNonNull().fqName + val packageName: CirPackageName + get() = targetDeclarations.firstNonNull().packageName override fun accept(visitor: CirNodeVisitor, data: T) = visitor.visitPackageNode(this, data) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirRootNode.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirRootNode.kt index df6d0c66263..ae6f9024762 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirRootNode.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirRootNode.kt @@ -7,17 +7,17 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import gnu.trove.THashMap import org.jetbrains.kotlin.descriptors.commonizer.CommonizerTarget +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirNode.Companion.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.NullableLazyValue class CirRootNode( override val targetDeclarations: CommonizedGroup, override val commonDeclaration: NullableLazyValue ) : CirNode { - val modules: MutableMap = THashMap() + val modules: MutableMap = THashMap() fun getTarget(targetIndex: Int): CommonizerTarget = (if (targetIndex == indexOfCommon) commonDeclaration() else targetDeclarations[targetIndex])!!.target diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt index a70643075ab..200d2bf29bb 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt @@ -10,12 +10,10 @@ import org.jetbrains.kotlin.descriptors.commonizer.LeafTarget import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider.ModuleInfo import org.jetbrains.kotlin.descriptors.commonizer.CommonizerParameters import org.jetbrains.kotlin.descriptors.commonizer.TargetProvider +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.* -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.descriptors.commonizer.utils.internedClassId -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.StorageManager @@ -123,27 +121,27 @@ class CirTreeMerger( ) { processCInteropModuleAttributes(moduleInfo) - val moduleName: Name = moduleDescriptor.name.intern() + val moduleName: CirName = CirName.create(moduleDescriptor.name) val moduleNode: CirModuleNode = rootNode.modules.getOrPut(moduleName) { buildModuleNode(storageManager, size) } moduleNode.targetDeclarations[targetIndex] = CirModuleFactory.create(moduleName) - moduleDescriptor.collectNonEmptyPackageMemberScopes { packageFqName, packageMemberScope -> - processPackage(moduleNode, targetIndex, packageFqName.intern(), packageMemberScope) + moduleDescriptor.collectNonEmptyPackageMemberScopes { packageName, packageMemberScope -> + processPackage(moduleNode, targetIndex, packageName, packageMemberScope) } } private fun processPackage( moduleNode: CirModuleNode, targetIndex: Int, - packageFqName: FqName, + packageName: CirPackageName, packageMemberScope: MemberScope ) { - val packageNode: CirPackageNode = moduleNode.packages.getOrPut(packageFqName) { + val packageNode: CirPackageNode = moduleNode.packages.getOrPut(packageName) { buildPackageNode(storageManager, size) } - packageNode.targetDeclarations[targetIndex] = CirPackageFactory.create(packageFqName) + packageNode.targetDeclarations[targetIndex] = CirPackageFactory.create(packageName) packageMemberScope.collectMembers( PropertyCollector { propertyDescriptor -> @@ -154,7 +152,7 @@ class CirTreeMerger( }, ClassCollector { classDescriptor -> processClass(packageNode, targetIndex, classDescriptor) { className -> - internedClassId(packageFqName, className) + CirEntityId.create(packageName, className) } }, TypeAliasCollector { typeAliasDescriptor -> @@ -195,9 +193,9 @@ class CirTreeMerger( ownerNode: CirNodeWithMembers<*, *>, targetIndex: Int, classDescriptor: ClassDescriptor, - classIdFunction: (Name) -> ClassId + classIdFunction: (CirName) -> CirEntityId ) { - val className = classDescriptor.name.intern() + val className = CirName.create(classDescriptor.name) val classId = classIdFunction(className) val classNode: CirClassNode = ownerNode.classes.getOrPut(className) { @@ -220,7 +218,7 @@ class CirTreeMerger( }, ClassCollector { nestedClassDescriptor -> processClass(classNode, targetIndex, nestedClassDescriptor) { nestedClassName -> - internedClassId(classId, nestedClassName) + classId.createNestedEntityId(nestedClassName) } } ) @@ -245,8 +243,8 @@ class CirTreeMerger( targetIndex: Int, typeAliasDescriptor: TypeAliasDescriptor ) { - val typeAliasName = typeAliasDescriptor.name.intern() - val typeAliasClassId = internedClassId(packageNode.packageFqName, typeAliasName) + val typeAliasName = CirName.create(typeAliasDescriptor.name) + val typeAliasClassId = CirEntityId.create(packageNode.packageName, typeAliasName) val typeAliasNode: CirTypeAliasNode = packageNode.typeAliases.getOrPut(typeAliasName) { buildTypeAliasNode(storageManager, size, classifiers, typeAliasClassId) @@ -257,12 +255,12 @@ class CirTreeMerger( private fun processCInteropModuleAttributes(moduleInfo: ModuleInfo) { val cInteropAttributes = moduleInfo.cInteropAttributes ?: return val exportForwardDeclarations = cInteropAttributes.exportForwardDeclarations.takeIf { it.isNotEmpty() } ?: return - val mainPackageFqName = FqName(cInteropAttributes.mainPackageFqName).intern() + val mainPackageFqName = CirPackageName.create(cInteropAttributes.mainPackageFqName) exportForwardDeclarations.forEach { classFqName -> // Class has synthetic package FQ name (cnames/objcnames). Need to transfer it to the main package. - val className = Name.identifier(classFqName.substringAfterLast('.')).intern() - classifiers.forwardDeclarations.addExportedForwardDeclaration(internedClassId(mainPackageFqName, className)) + val className = CirName.create(classFqName.substringAfterLast('.')) + classifiers.forwardDeclarations.addExportedForwardDeclaration(CirEntityId.create(mainPackageFqName, className)) } } } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTypeAliasNode.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTypeAliasNode.kt index 06f0a464fbd..cddfbfb982e 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTypeAliasNode.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTypeAliasNode.kt @@ -6,16 +6,16 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassifier +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAlias import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.storage.NullableLazyValue class CirTypeAliasNode( override val targetDeclarations: CommonizedGroup, override val commonDeclaration: NullableLazyValue, - override val classId: ClassId -) : CirNodeWithClassId, CirNodeWithLiftingUp { + override val classifierId: CirEntityId +) : CirNodeWithClassifierId, CirNodeWithLiftingUp { override fun accept(visitor: CirNodeVisitor, data: T): R = visitor.visitTypeAliasNode(this, data) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt index 8679475a246..2dff588cb1d 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt @@ -6,33 +6,32 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature import org.jetbrains.kotlin.descriptors.commonizer.core.Commonizer import org.jetbrains.kotlin.descriptors.commonizer.utils.* -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.descriptors.commonizer.utils.signature -import org.jetbrains.kotlin.name.Name /** Used for approximation of [PropertyDescriptor]s before running concrete [Commonizer]s */ data class PropertyApproximationKey( - val name: Name, + val name: CirName, val extensionReceiverParameterType: CirTypeSignature? ) { constructor(property: PropertyDescriptor) : this( - property.name.intern(), + CirName.create(property.name), property.extensionReceiverParameter?.type?.signature ) } /** Used for approximation of [SimpleFunctionDescriptor]s before running concrete [Commonizer]s */ data class FunctionApproximationKey( - val name: Name, + val name: CirName, val valueParametersTypes: Array, private val additionalValueParametersNamesHash: Int, val extensionReceiverParameterType: CirTypeSignature? ) { constructor(function: SimpleFunctionDescriptor) : this( - function.name.intern(), + CirName.create(function.name), function.valueParameters.toTypeSignatures(), additionalValueParameterNamesHash(function), function.extensionReceiverParameter?.type?.signature diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifierContainers.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifierContainers.kt index f047224bcff..2138318d4aa 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifierContainers.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifierContainers.kt @@ -10,11 +10,10 @@ import gnu.trove.THashSet import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.commonizer.SharedTarget import org.jetbrains.kotlin.descriptors.commonizer.CommonizerTarget -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderKotlinNativeSyntheticPackages import org.jetbrains.kotlin.descriptors.commonizer.utils.resolveClassOrTypeAlias -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.getValue @@ -31,27 +30,27 @@ class CirKnownClassifiers( interface CirCommonizedClassifiers { /* Accessors */ - fun classNode(classId: ClassId): CirClassNode? - fun typeAliasNode(typeAliasId: ClassId): CirTypeAliasNode? + fun classNode(classId: CirEntityId): CirClassNode? + fun typeAliasNode(typeAliasId: CirEntityId): CirTypeAliasNode? /* Mutators */ - fun addClassNode(classId: ClassId, node: CirClassNode) - fun addTypeAliasNode(typeAliasId: ClassId, node: CirTypeAliasNode) + fun addClassNode(classId: CirEntityId, node: CirClassNode) + fun addTypeAliasNode(typeAliasId: CirEntityId, node: CirTypeAliasNode) companion object { fun default() = object : CirCommonizedClassifiers { - private val classNodes = THashMap() - private val typeAliases = THashMap() + private val classNodes = THashMap() + private val typeAliases = THashMap() - override fun classNode(classId: ClassId) = classNodes[classId] - override fun typeAliasNode(typeAliasId: ClassId) = typeAliases[typeAliasId] + override fun classNode(classId: CirEntityId) = classNodes[classId] + override fun typeAliasNode(typeAliasId: CirEntityId) = typeAliases[typeAliasId] - override fun addClassNode(classId: ClassId, node: CirClassNode) { + override fun addClassNode(classId: CirEntityId, node: CirClassNode) { val oldNode = classNodes.put(classId, node) check(oldNode == null) { "Rewriting class node $classId" } } - override fun addTypeAliasNode(typeAliasId: ClassId, node: CirTypeAliasNode) { + override fun addTypeAliasNode(typeAliasId: CirEntityId, node: CirTypeAliasNode) { val oldNode = typeAliases.put(typeAliasId, node) check(oldNode == null) { "Rewriting type alias node $typeAliasId" } } @@ -61,19 +60,19 @@ interface CirCommonizedClassifiers { interface CirForwardDeclarations { /* Accessors */ - fun isExportedForwardDeclaration(classId: ClassId): Boolean + fun isExportedForwardDeclaration(classId: CirEntityId): Boolean /* Mutators */ - fun addExportedForwardDeclaration(classId: ClassId) + fun addExportedForwardDeclaration(classId: CirEntityId) companion object { fun default() = object : CirForwardDeclarations { - private val exportedForwardDeclarations = THashSet() + private val exportedForwardDeclarations = THashSet() - override fun isExportedForwardDeclaration(classId: ClassId) = classId in exportedForwardDeclarations + override fun isExportedForwardDeclaration(classId: CirEntityId) = classId in exportedForwardDeclarations - override fun addExportedForwardDeclaration(classId: ClassId) { - check(!classId.packageFqName.isUnderKotlinNativeSyntheticPackages) + override fun addExportedForwardDeclaration(classId: CirEntityId) { + check(!classId.packageName.isUnderKotlinNativeSyntheticPackages) exportedForwardDeclarations += classId } } @@ -81,45 +80,43 @@ interface CirForwardDeclarations { } interface CirProvidedClassifiers { - fun hasClassifier(classifierId: ClassId): Boolean + fun hasClassifier(classifierId: CirEntityId): Boolean // TODO: implement later //fun classifier(classifierId: ClassId): Any? companion object { internal val EMPTY = object : CirProvidedClassifiers { - override fun hasClassifier(classifierId: ClassId) = false + override fun hasClassifier(classifierId: CirEntityId) = false } // N.B. This is suboptimal implementation. It will be replaced by another implementation that will // retrieve classifier information directly from the metadata. fun fromModules(storageManager: StorageManager, modules: () -> Collection) = object : CirProvidedClassifiers { - private val nonEmptyMemberScopes: Map by storageManager.createLazyValue { - THashMap().apply { + private val nonEmptyMemberScopes: Map by storageManager.createLazyValue { + THashMap().apply { for (module in modules()) { - module.collectNonEmptyPackageMemberScopes(probeRootPackageForEmptiness = true) { packageFqName, memberScope -> - this[packageFqName.intern()] = memberScope + module.collectNonEmptyPackageMemberScopes(probeRootPackageForEmptiness = true) { packageName, memberScope -> + this[packageName] = memberScope } } } } - private val presentClassifiers = THashSet() - private val missingClassifiers = THashSet() + private val presentClassifiers = THashSet() + private val missingClassifiers = THashSet() - override fun hasClassifier(classifierId: ClassId): Boolean { - val relativeClassName: FqName = classifierId.relativeClassName - if (relativeClassName.isRoot) + override fun hasClassifier(classifierId: CirEntityId): Boolean { + if (classifierId.relativeNameSegments.isEmpty()) return false - val packageFqName = classifierId.packageFqName - val memberScope = nonEmptyMemberScopes[packageFqName] ?: return false + val memberScope = nonEmptyMemberScopes[classifierId.packageName] ?: return false return when (classifierId) { in presentClassifiers -> true in missingClassifiers -> false else -> { - val found = memberScope.resolveClassOrTypeAlias(relativeClassName) != null + val found = memberScope.resolveClassOrTypeAlias(classifierId.relativeNameSegments) != null when (found) { true -> presentClassifiers += classifierId false -> missingClassifiers += classifierId diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/collectors.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/collectors.kt index 2f7a34f7033..ba08a232890 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/collectors.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/collectors.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.backend.common.serialization.metadata.impl.ClassifierAliasingPackageFragmentDescriptor import org.jetbrains.kotlin.backend.common.serialization.metadata.impl.ExportedForwardDeclarationsPackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.utils.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope @@ -65,7 +66,7 @@ internal inline fun FunctionCollector( // collects member scopes for every non-empty package provided by this module internal fun ModuleDescriptor.collectNonEmptyPackageMemberScopes( probeRootPackageForEmptiness: Boolean = false, // false is the default as probing might be expensive and is not always necessary - collector: (FqName, MemberScope) -> Unit + collector: (CirPackageName, MemberScope) -> Unit ) { // we don's need to process fragments from other modules which are the dependencies of this module, so // let's use the appropriate package fragment provider @@ -88,7 +89,7 @@ internal fun ModuleDescriptor.collectNonEmptyPackageMemberScopes( "package member scope for $packageFqName in $name", ownPackageMemberScopes ) - collector(packageFqName, memberScope) + collector(CirPackageName.create(packageFqName), memberScope) } packageFragmentProvider.getSubPackagesOf(packageFqName, alwaysTrue()).toSet().map { recurse(it) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt index be14f98527c..dada2dfd93f 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt @@ -6,11 +6,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassRecursionMarker import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassifierRecursionMarker import org.jetbrains.kotlin.descriptors.commonizer.core.* import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.storage.NullableLazyValue import org.jetbrains.kotlin.storage.StorageManager @@ -75,7 +75,7 @@ internal fun buildClassNode( size: Int, classifiers: CirKnownClassifiers, parentCommonDeclaration: NullableLazyValue<*>?, - classId: ClassId + classId: CirEntityId ): CirClassNode = buildNode( storageManager = storageManager, size = size, @@ -106,7 +106,7 @@ internal fun buildTypeAliasNode( storageManager: StorageManager, size: Int, classifiers: CirKnownClassifiers, - typeAliasId: ClassId + typeAliasId: CirEntityId ): CirTypeAliasNode = buildNode( storageManager = storageManager, size = size, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/entityBuilders.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/entityBuilders.kt index 8d5a8f4ccb5..85405edf513 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/entityBuilders.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/entityBuilders.kt @@ -16,15 +16,12 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.descriptors.commonizer.metadata.TypeAliasExpansion.* import org.jetbrains.kotlin.descriptors.commonizer.utils.DEFAULT_SETTER_VALUE_NAME import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap -import org.jetbrains.kotlin.descriptors.commonizer.utils.strip -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance internal fun CirModule.buildModule( fragments: Collection ): KlibModuleMetadata = KlibModuleMetadata( - name = name.strip(), + name = name.toStrippedString(), fragments = fragments.toList(), annotations = emptyList() ) @@ -35,7 +32,7 @@ internal fun CirPackage.buildModuleFragment( topLevelFunctions: Collection, topLevelProperties: Collection ): KmModuleFragment = KmModuleFragment().also { fragment -> - fragment.fqName = fqName.asString() + fragment.fqName = packageName.toString() allClasses.forEach { fragment.classes += it fragment.className += it.name @@ -43,7 +40,7 @@ internal fun CirPackage.buildModuleFragment( if (topLevelTypeAliases.isNotEmpty() || topLevelFunctions.isNotEmpty() || topLevelProperties.isNotEmpty()) { fragment.pkg = KmPackage().also { pkg -> - pkg.fqName = fqName.asString() + pkg.fqName = packageName.toString() pkg.typeAliases += topLevelTypeAliases pkg.functions += topLevelFunctions pkg.properties += topLevelProperties @@ -101,15 +98,15 @@ internal fun CirClass.buildClass( } } - clazz.companionObject = companion?.asString() + clazz.companionObject = companion?.name supertypes.mapTo(clazz.supertypes) { it.buildType(context) } } -internal fun linkSealedClassesWithSubclasses(packageFqName: FqName, classConsumer: ClassConsumer) { +internal fun linkSealedClassesWithSubclasses(packageName: CirPackageName, classConsumer: ClassConsumer) { if (classConsumer.allClasses.isEmpty() || classConsumer.sealedClasses.isEmpty()) return - val packageName = packageFqName.asString().replace('.', '/') - fun ClassName.isInSamePackage(): Boolean = substringBeforeLast('/', "") == packageName + val metadataPackageName = packageName.toMetadataString() + fun ClassName.isInSamePackage(): Boolean = substringBeforeLast('/', "") == metadataPackageName val sealedClassesMap: Map = classConsumer.sealedClasses.associateBy { it.name } @@ -136,7 +133,7 @@ internal fun CirTypeAlias.buildTypeAlias( context: MetadataBuildingVisitorContext ): KmTypeAlias = KmTypeAlias( flags = typeAliasFlags(), - name = name.asString() + name = name.name ).also { typeAlias -> annotations.mapTo(typeAlias.annotations) { it.buildAnnotation() } typeParameters.buildTypeParameters(context, output = typeAlias.typeParameters) @@ -148,7 +145,7 @@ internal fun CirProperty.buildProperty( context: MetadataBuildingVisitorContext, ): KmProperty = KmProperty( flags = propertyFlags(isExpect = context.isCommon && !isLiftedUp), - name = name.asString(), + name = name.name, getterFlags = getter?.propertyAccessorFlags(this, this) ?: NO_FLAGS, setterFlags = setter?.let { setter -> setter.propertyAccessorFlags(setter, this) } ?: NO_FLAGS ).also { property -> @@ -180,7 +177,7 @@ internal fun CirFunction.buildFunction( context: MetadataBuildingVisitorContext, ): KmFunction = KmFunction( flags = functionFlags(isExpect = context.isCommon && kind != CallableMemberDescriptor.Kind.SYNTHESIZED), - name = name.asString() + name = name.name ).also { function -> annotations.mapTo(function.annotations) { it.buildAnnotation() } typeParameters.buildTypeParameters(context, output = function.typeParameters) @@ -195,17 +192,17 @@ internal fun CirFunction.buildFunction( private fun CirAnnotation.buildAnnotation(): KmAnnotation { val arguments = LinkedHashMap>(constantValueArguments.size + annotationValueArguments.size, 1F) - constantValueArguments.forEach { (name: Name, value: CirConstantValue<*>) -> - arguments[name.asString()] = value.buildAnnotationArgument() + constantValueArguments.forEach { (name: CirName, value: CirConstantValue<*>) -> + arguments[name.name] = value.buildAnnotationArgument() ?: error("Unexpected constant value inside of $this") } - annotationValueArguments.forEach { (name: Name, nested: CirAnnotation) -> - arguments[name.asString()] = KmAnnotationArgument.AnnotationValue(nested.buildAnnotation()) + annotationValueArguments.forEach { (name: CirName, nested: CirAnnotation) -> + arguments[name.name] = KmAnnotationArgument.AnnotationValue(nested.buildAnnotation()) } return KmAnnotation( - className = type.classifierId.asString(), + className = type.classifierId.toString(), arguments = arguments ) } @@ -228,7 +225,7 @@ private fun CirConstantValue<*>.buildAnnotationArgument(): KmAnnotationArgument< is CirConstantValue.DoubleValue -> KmAnnotationArgument.DoubleValue(value) is CirConstantValue.BooleanValue -> KmAnnotationArgument.BooleanValue(value) - is CirConstantValue.EnumValue -> KmAnnotationArgument.EnumValue(enumClassId.asString(), enumEntryName.asString()) + is CirConstantValue.EnumValue -> KmAnnotationArgument.EnumValue(enumClassId.toString(), enumEntryName.name) is CirConstantValue.NullValue -> null is CirConstantValue.ArrayValue -> KmAnnotationArgument.ArrayValue(value.compactMap { element -> @@ -240,7 +237,7 @@ private fun CirValueParameter.buildValueParameter( context: MetadataBuildingVisitorContext ): KmValueParameter = KmValueParameter( flags = valueParameterFlags(), - name = name.asString() + name = name.name ).also { parameter -> annotations.mapTo(parameter.annotations) { it.buildAnnotation() } parameter.type = returnType.buildType(context) @@ -256,7 +253,7 @@ private fun List.buildTypeParameters( mapIndexedTo(output) { index, cirTypeParameter -> KmTypeParameter( flags = cirTypeParameter.typeParameterFlags(), - name = cirTypeParameter.name.asString(), + name = cirTypeParameter.name.name, id = context.typeParameterIndexOffset + index, variance = cirTypeParameter.variance.buildVariance() ).also { parameter -> @@ -292,7 +289,7 @@ private fun CirClassType.buildType( context: MetadataBuildingVisitorContext, expansion: TypeAliasExpansion ): KmType = KmType(typeFlags()).also { type -> - type.classifier = KmClassifier.Class(classifierId.asString()) + type.classifier = KmClassifier.Class(classifierId.toString()) arguments.mapTo(type.arguments) { it.buildArgument(context, expansion) } outerType?.let { type.outerType = it.buildType(context, expansion) } } @@ -316,7 +313,7 @@ private fun CirTypeAliasType.buildAbbreviationType( expansion: TypeAliasExpansion ): KmType { val abbreviationType = KmType(typeFlags()) - abbreviationType.classifier = KmClassifier.TypeAlias(classifierId.asString()) + abbreviationType.classifier = KmClassifier.TypeAlias(classifierId.toString()) arguments.mapTo(abbreviationType.arguments) { it.buildArgument(context, expansion) } return abbreviationType } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/metadataBuilder.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/metadataBuilder.kt index 443ca93498b..9b707ff9a72 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/metadataBuilder.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/metadata/metadataBuilder.kt @@ -15,10 +15,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.stats.DeclarationType import org.jetbrains.kotlin.descriptors.commonizer.stats.StatsCollector import org.jetbrains.kotlin.descriptors.commonizer.stats.StatsCollector.StatsKey import org.jetbrains.kotlin.descriptors.commonizer.utils.DEFAULT_CONSTRUCTOR_NAME -import org.jetbrains.kotlin.descriptors.commonizer.utils.strip -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.descriptors.commonizer.utils.firstNonNull import org.jetbrains.kotlin.descriptors.commonizer.metadata.MetadataBuildingVisitorContext.Path @@ -65,8 +61,8 @@ private class MetadataBuildingVisitor( val cirModule = moduleContext.get(node) ?: return null val fragments: MutableCollection = mutableListOf() - node.packages.mapNotNullTo(fragments) { (packageFqName, packageNode) -> - val packageContext = moduleContext.packageContext(packageFqName) + node.packages.mapNotNullTo(fragments) { (packageName, packageNode) -> + val packageContext = moduleContext.packageContext(packageName) packageNode.accept(this, packageContext)?.cast() } @@ -106,7 +102,7 @@ private class MetadataBuildingVisitor( } } - linkSealedClassesWithSubclasses(cirPackage.fqName, classConsumer) + linkSealedClassesWithSubclasses(cirPackage.packageName, classConsumer) val topLevelFunctions: Collection = node.functions.mapNotNull { (functionKey, functionNode) -> val functionContext = packageContext.callableMemberContext(functionKey.name) @@ -221,12 +217,12 @@ private class MetadataBuildingVisitor( Flag.Class.IS_ENUM_CLASS(clazz.flags) -> DeclarationType.ENUM_CLASS Flag.Class.IS_ENUM_ENTRY(clazz.flags) -> DeclarationType.ENUM_ENTRY Flag.Class.IS_INTERFACE(clazz.flags) -> when { - (classContext.currentPath as Path.Classifier).classifierId.isNestedClass -> DeclarationType.NESTED_INTERFACE + (classContext.currentPath as Path.Classifier).classifierId.isNestedEntity -> DeclarationType.NESTED_INTERFACE else -> DeclarationType.TOP_LEVEL_INTERFACE } else -> when { Flag.Class.IS_COMPANION_OBJECT(clazz.flags) -> DeclarationType.COMPANION_OBJECT - (classContext.currentPath as Path.Classifier).classifierId.isNestedClass -> DeclarationType.NESTED_CLASS + (classContext.currentPath as Path.Classifier).classifierId.isNestedEntity -> DeclarationType.NESTED_CLASS else -> DeclarationType.TOP_LEVEL_CLASS } } @@ -246,7 +242,7 @@ private class MetadataBuildingVisitor( propertyNode: CirPropertyNode ) = logDeclaration(propertyContext.targetIndex) { val declarationType = when { - (propertyContext.currentPath as Path.CallableMember).memberId.isNestedClass -> DeclarationType.NESTED_VAL + (propertyContext.currentPath as Path.CallableMember).memberId.isNestedEntity -> DeclarationType.NESTED_VAL propertyNode.targetDeclarations.firstNonNull().isConst -> DeclarationType.TOP_LEVEL_CONST_VAL else -> DeclarationType.TOP_LEVEL_VAL } @@ -266,7 +262,7 @@ private class MetadataBuildingVisitor( functionKey: FunctionApproximationKey ) = logDeclaration(functionContext.targetIndex) { val declarationType = when { - (functionContext.currentPath as Path.CallableMember).memberId.isNestedClass -> DeclarationType.NESTED_FUN + (functionContext.currentPath as Path.CallableMember).memberId.isNestedEntity -> DeclarationType.NESTED_FUN else -> DeclarationType.TOP_LEVEL_FUN } @@ -308,31 +304,30 @@ internal data class MetadataBuildingVisitorContext( } @Suppress("MemberVisibilityCanBePrivate") - class Module(val moduleName: Name) : Path() { - override fun toString() = moduleName.strip() + class Module(val moduleName: CirName) : Path() { + override fun toString() = moduleName.toStrippedString() } - class Package(val packageFqName: FqName) : Path() { - fun nestedClassifier(classifierName: Name) = Classifier(ClassId(packageFqName, classifierName)) - fun nestedCallableMember(memberName: Name) = CallableMember(ClassId(packageFqName, memberName)) + class Package(val packageName: CirPackageName) : Path() { + fun nestedClassifier(classifierName: CirName) = Classifier(CirEntityId.create(packageName, classifierName)) + fun nestedCallableMember(memberName: CirName) = CallableMember(CirEntityId.create(packageName, memberName)) - override fun toString() = packageFqName.asString() + override fun toString() = packageName.toString() } - class Classifier(val classifierId: ClassId) : Path() { - fun nestedClassifier(classifierName: Name) = Classifier(classifierId.createNestedClassId(classifierName)) - fun nestedCallableMember(memberName: Name) = CallableMember(classifierId.createNestedClassId(memberName)) + class Classifier(val classifierId: CirEntityId) : Path() { + fun nestedClassifier(classifierName: CirName) = Classifier(classifierId.createNestedEntityId(classifierName)) + fun nestedCallableMember(memberName: CirName) = CallableMember(classifierId.createNestedEntityId(memberName)) - override fun toString() = classifierId.asString() + override fun toString() = classifierId.toString() } - class CallableMember(val memberId: ClassId) : Path() { - override fun toString() = memberId.asString() + class CallableMember(val memberId: CirEntityId) : Path() { + override fun toString() = memberId.toString() } } - fun moduleContext(moduleName: Name): MetadataBuildingVisitorContext { - check(moduleName.isSpecial) + fun moduleContext(moduleName: CirName): MetadataBuildingVisitorContext { check(currentPath is Path.Empty) return MetadataBuildingVisitorContext( @@ -344,7 +339,7 @@ internal data class MetadataBuildingVisitorContext( ) } - fun packageContext(packageFqName: FqName): MetadataBuildingVisitorContext { + fun packageContext(packageName: CirPackageName): MetadataBuildingVisitorContext { check(currentPath is Path.Module) return MetadataBuildingVisitorContext( @@ -352,12 +347,12 @@ internal data class MetadataBuildingVisitorContext( target = target, isCommon = isCommon, typeParameterIndexOffset = 0, - currentPath = Path.Package(packageFqName) + currentPath = Path.Package(packageName) ) } fun classifierContext( - classifierName: Name, + classifierName: CirName, outerClassTypeParametersCount: Int = 0 ): MetadataBuildingVisitorContext { val newPath = when (currentPath) { @@ -382,7 +377,7 @@ internal data class MetadataBuildingVisitorContext( } fun callableMemberContext( - memberName: Name, + memberName: CirName, ownerClassTypeParametersCount: Int = 0 ): MetadataBuildingVisitorContext { val newPath = when (currentPath) { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/fqName.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/fqName.kt index ef3085ea234..cb356d0d220 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/fqName.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/fqName.kt @@ -8,72 +8,61 @@ package org.jetbrains.kotlin.descriptors.commonizer.utils import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.konan.impl.ForwardDeclarationsFqNames -internal val DEPRECATED_ANNOTATION_FQN: FqName = FqName(Deprecated::class.java.name).intern() -internal val DEPRECATED_ANNOTATION_CLASS_ID: ClassId = internedClassId(DEPRECATED_ANNOTATION_FQN) +internal val DEPRECATED_ANNOTATION_FQN: FqName = FqName(Deprecated::class.java.name) +internal val DEPRECATED_ANNOTATION_CLASS_ID: CirEntityId = CirEntityId.create("kotlin/Deprecated") -internal val ANY_CLASS_ID: ClassId = internedClassId(StandardNames.FqNames.any.toSafe().intern()) -private val NOTHING_CLASS_ID: ClassId = internedClassId(StandardNames.FqNames.nothing.toSafe().intern()) +internal val ANY_CLASS_ID: CirEntityId = CirEntityId.create("kotlin/Any") +private val NOTHING_CLASS_ID: CirEntityId = CirEntityId.create("kotlin/Nothing") -internal val SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS = listOf( +internal val SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS: List = listOf( ANY_CLASS_ID, NOTHING_CLASS_ID ) -private val STANDARD_KOTLIN_PACKAGES = listOf( - StandardNames.BUILT_INS_PACKAGE_FQ_NAME.asString(), - "kotlinx" +private val STANDARD_KOTLIN_PACKAGES: List = listOf( + CirPackageName.create(StandardNames.BUILT_INS_PACKAGE_FQ_NAME), + CirPackageName.create("kotlinx") ) -private val KOTLIN_NATIVE_SYNTHETIC_PACKAGES = ForwardDeclarationsFqNames.syntheticPackages - .map { fqName -> - check(!fqName.isRoot) - fqName.asString() +private val KOTLIN_NATIVE_SYNTHETIC_PACKAGES: List = ForwardDeclarationsFqNames.syntheticPackages + .map { packageFqName -> + check(!packageFqName.isRoot) + CirPackageName.create(packageFqName) } -private const val CINTEROP_PACKAGE = "kotlinx.cinterop" +private val CINTEROP_PACKAGE: CirPackageName = CirPackageName.create("kotlinx.cinterop") -private val OBJC_INTEROP_CALLABLE_ANNOTATIONS = listOf( - "ObjCMethod", - "ObjCConstructor", - "ObjCFactory" +private val OBJC_INTEROP_CALLABLE_ANNOTATIONS: List = listOf( + CirName.create("ObjCMethod"), + CirName.create("ObjCConstructor"), + CirName.create("ObjCFactory") ) -internal val DEFAULT_CONSTRUCTOR_NAME = Name.identifier("").intern() -internal val DEFAULT_SETTER_VALUE_NAME = Name.identifier("value").intern() +internal val DEFAULT_CONSTRUCTOR_NAME: CirName = CirName.create("") +internal val DEFAULT_SETTER_VALUE_NAME: CirName = CirName.create("value") internal fun Name.strip(): String = asString().removeSurrounding("<", ">") -internal val FqName.isUnderStandardKotlinPackages: Boolean - get() = hasAnyPrefix(STANDARD_KOTLIN_PACKAGES) +internal val CirPackageName.isUnderStandardKotlinPackages: Boolean + get() = STANDARD_KOTLIN_PACKAGES.any(::startsWith) -internal val FqName.isUnderKotlinNativeSyntheticPackages: Boolean - get() = hasAnyPrefix(KOTLIN_NATIVE_SYNTHETIC_PACKAGES) +internal val CirPackageName.isUnderKotlinNativeSyntheticPackages: Boolean + get() = KOTLIN_NATIVE_SYNTHETIC_PACKAGES.any(::startsWith) -@Suppress("NOTHING_TO_INLINE") -private inline fun FqName.hasAnyPrefix(prefixes: List): Boolean = - asString().let { fqName -> prefixes.any(fqName::hasPrefix) } - -private fun String.hasPrefix(prefix: String): Boolean { - val lengthDifference = length - prefix.length - return when { - lengthDifference == 0 -> this == prefix - lengthDifference > 0 -> this[prefix.length] == '.' && this.startsWith(prefix) - else -> false - } -} - -internal val ClassId.isObjCInteropCallableAnnotation: Boolean - get() = packageFqName.asString() == CINTEROP_PACKAGE && relativeClassName.asString() in OBJC_INTEROP_CALLABLE_ANNOTATIONS +internal val CirEntityId.isObjCInteropCallableAnnotation: Boolean + get() = packageName == CINTEROP_PACKAGE && relativeNameSegments.singleOrNull() in OBJC_INTEROP_CALLABLE_ANNOTATIONS internal val AnnotationDescriptor.isObjCInteropCallableAnnotation: Boolean get() { val classifier = type.declarationDescriptor - return classifier.name.asString() in OBJC_INTEROP_CALLABLE_ANNOTATIONS - && (classifier.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.asString() == CINTEROP_PACKAGE + return CirName.create(classifier.name) in OBJC_INTEROP_CALLABLE_ANNOTATIONS + && (classifier.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.let(CirPackageName::create) == CINTEROP_PACKAGE } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/interners.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/interners.kt deleted file mode 100644 index 444e9230860..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/interners.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2020 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.descriptors.commonizer.utils - -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name - -internal fun FqName.intern(): FqName = fqNameInterner.intern(this) -internal fun Name.intern(): Name = nameInterner.intern(this) -internal fun ClassId.intern(): ClassId = classIdInterner.intern(this) - -@Suppress("NOTHING_TO_INLINE") -internal inline fun internedClassId(topLevelFqName: FqName): ClassId { - val packageFqName = topLevelFqName.parent().intern() - val className = topLevelFqName.shortName().intern() - return internedClassId(packageFqName, className) -} - -internal fun internedClassId(packageFqName: FqName, classifierName: Name): ClassId { - val relativeClassName = FqName.topLevel(classifierName).intern() - return ClassId(packageFqName, relativeClassName, false).intern() -} - -internal fun internedClassId(ownerClassId: ClassId, nestedClassName: Name): ClassId { - val relativeClassName = ownerClassId.relativeClassName.child(nestedClassName).intern() - return ClassId(ownerClassId.packageFqName, relativeClassName, ownerClassId.isLocal).intern() -} - -private val fqNameInterner = Interner() -private val nameInterner = Interner() -private val classIdInterner = Interner() diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/moduleDescriptor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/moduleDescriptor.kt index 6a621fe419e..c1d5f843939 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/moduleDescriptor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/moduleDescriptor.kt @@ -8,12 +8,13 @@ package org.jetbrains.kotlin.descriptors.commonizer.utils import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.konan.util.KlibMetadataFactories import org.jetbrains.kotlin.library.metadata.NativeTypeTransformer import org.jetbrains.kotlin.library.metadata.NullFlexibleTypeDeserializer -import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.serialization.konan.impl.KlibResolvedModuleDescriptorsFactoryImpl import org.jetbrains.kotlin.storage.StorageManager @@ -31,27 +32,29 @@ internal fun createKotlinNativeForwardDeclarationsModule( storageManager = storageManager ) -internal fun MemberScope.resolveClassOrTypeAlias(relativeClassName: FqName): ClassifierDescriptorWithTypeParameters? { +internal fun MemberScope.resolveClassOrTypeAlias(relativeNameSegments: Array): ClassifierDescriptorWithTypeParameters? { var memberScope: MemberScope = this if (memberScope is MemberScope.Empty) return null - val classifierName = if ('.' in relativeClassName.asString()) { - // resolve member scope of the nested class - relativeClassName.pathSegments().reduce { first, second -> - memberScope = (memberScope.getContributedClassifier( - first, - NoLookupLocation.FOR_ALREADY_TRACKED - ) as? ClassDescriptor)?.unsubstitutedMemberScope ?: return null + val classifierName = when (relativeNameSegments.size) { + 0 -> return null + 1 -> relativeNameSegments[0] + else -> { + // resolve member scope of the nested class + relativeNameSegments.reduce { first, second -> + memberScope = (memberScope.getContributedClassifier( + Name.identifier(first.name), + NoLookupLocation.FOR_ALREADY_TRACKED + ) as? ClassDescriptor)?.unsubstitutedMemberScope ?: return null - second + second + } } - } else { - relativeClassName.shortName() } return memberScope.getContributedClassifier( - classifierName, + Name.identifier(classifierName.name), NoLookupLocation.FOR_ALREADY_TRACKED ) as? ClassifierDescriptorWithTypeParameters } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt index afea96fd00a..d56c1f07fb0 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt @@ -9,8 +9,10 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.resolve.descriptorUtil.classId import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.makeNotNullable @@ -30,10 +32,13 @@ internal fun extractExpandedType(abbreviated: AbbreviatedType): SimpleType { return expanded } -internal val ClassifierDescriptorWithTypeParameters.internedClassId: ClassId +internal val ClassifierDescriptorWithTypeParameters.classifierId: CirEntityId get() = when (val owner = containingDeclaration) { - is PackageFragmentDescriptor -> internedClassId(owner.fqName.intern(), name.intern()) - is ClassDescriptor -> internedClassId(owner.internedClassId, name.intern()) + is PackageFragmentDescriptor -> CirEntityId.create( + packageName = CirPackageName.create(owner.fqName), + relativeName = CirName.create(name) + ) + is ClassDescriptor -> owner.classifierId.createNestedEntityId(CirName.create(name)) else -> error("Unexpected containing declaration type for $this: ${owner::class}, $owner") } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt index 10349f592d6..c6a9a3e36de 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt @@ -5,16 +5,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassType -import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue +import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue.* import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.junit.Test import kotlin.DeprecationLevel.* @@ -285,8 +280,8 @@ class AnnotationsCommonizerTest : AbstractCommonizerTest, Li private fun mockAnnotation( fqName: String, - constantValueArguments: Map> = emptyMap(), - annotationValueArguments: Map = emptyMap() + constantValueArguments: Map> = emptyMap(), + annotationValueArguments: Map = emptyMap() ): CirAnnotation = CirAnnotationFactory.create( type = CirTypeFactory.create(mockClassType(fqName)) as CirClassType, constantValueArguments = constantValueArguments, @@ -303,8 +298,8 @@ private fun mockDeprecated( mockAnnotation( fqName = "kotlin.ReplaceWith", constantValueArguments = mapOf( - Name.identifier("expression") to StringValue(replaceWithExpression), - Name.identifier("imports") to ArrayValue(replaceWithImports.map(::StringValue)) + CirName.create("expression") to StringValue(replaceWithExpression), + CirName.create("imports") to ArrayValue(replaceWithImports.map(::StringValue)) ), annotationValueArguments = emptyMap() ) @@ -312,15 +307,12 @@ private fun mockDeprecated( return mockAnnotation( fqName = "kotlin.Deprecated", - constantValueArguments = HashMap>().apply { - this[Name.identifier("message")] = StringValue(message) + constantValueArguments = HashMap>().apply { + this[CirName.create("message")] = StringValue(message) if (level != WARNING) - this[Name.identifier("level")] = EnumValue( - ClassId.topLevel(FqName("kotlin.DeprecationLevel")), - Name.identifier(level.name) - ) + this[CirName.create("level")] = EnumValue(CirEntityId.create("kotlin/DeprecationLevel"), CirName.create(level.name)) }, - annotationValueArguments = if (replaceWith != null) mapOf(Name.identifier("replaceWith") to replaceWith) else emptyMap() + annotationValueArguments = if (replaceWith != null) mapOf(CirName.create("replaceWith") to replaceWith) else emptyMap() ) } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirEntityIdTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirEntityIdTest.kt new file mode 100644 index 00000000000..49de0701ad9 --- /dev/null +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirEntityIdTest.kt @@ -0,0 +1,229 @@ +/* + * Copyright 2010-2021 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.descriptors.commonizer.core + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName +import org.jetbrains.kotlin.name.ClassId +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertSame +import kotlin.test.assertTrue + +class CirEntityIdTest { + @Test + fun createAndIntern() { + class TestRow( + val rawEntityId: String, + val packageSegments: Array, + val rawRelativeNameSegments: List + ) + + listOf( + TestRow( + rawEntityId = "", + packageSegments = emptyArray(), + rawRelativeNameSegments = emptyList() + ), + TestRow( + rawEntityId = "/", + packageSegments = emptyArray(), + rawRelativeNameSegments = emptyList() + ), + TestRow( + rawEntityId = "foo/", + packageSegments = arrayOf("foo"), + rawRelativeNameSegments = emptyList() + ), + TestRow( + rawEntityId = "foo/bar/", + packageSegments = arrayOf("foo", "bar"), + rawRelativeNameSegments = emptyList() + ), + TestRow( + rawEntityId = "foo/bar/baz/", + packageSegments = arrayOf("foo", "bar", "baz"), + rawRelativeNameSegments = emptyList() + ), + TestRow( + rawEntityId = "My", + packageSegments = emptyArray(), + rawRelativeNameSegments = listOf("My") + ), + TestRow( + rawEntityId = "My.Test", + packageSegments = emptyArray(), + rawRelativeNameSegments = listOf("My", "Test") + ), + TestRow( + rawEntityId = "My.Test.Class", + packageSegments = emptyArray(), + rawRelativeNameSegments = listOf("My", "Test", "Class") + ), + TestRow( + rawEntityId = "/My", + packageSegments = emptyArray(), + rawRelativeNameSegments = listOf("My") + ), + TestRow( + rawEntityId = "/My.Test", + packageSegments = emptyArray(), + rawRelativeNameSegments = listOf("My", "Test") + ), + TestRow( + rawEntityId = "/My.Test.Class", + packageSegments = emptyArray(), + rawRelativeNameSegments = listOf("My", "Test", "Class") + ), + TestRow( + rawEntityId = "foo/My", + packageSegments = arrayOf("foo"), + rawRelativeNameSegments = listOf("My") + ), + TestRow( + rawEntityId = "foo/My.Test", + packageSegments = arrayOf("foo"), + rawRelativeNameSegments = listOf("My", "Test") + ), + TestRow( + rawEntityId = "foo/My.Test.Class", + packageSegments = arrayOf("foo"), + rawRelativeNameSegments = listOf("My", "Test", "Class") + ), + TestRow( + rawEntityId = "foo/bar/My", + packageSegments = arrayOf("foo", "bar"), + rawRelativeNameSegments = listOf("My") + ), + TestRow( + rawEntityId = "foo/bar/My.Test", + packageSegments = arrayOf("foo", "bar"), + rawRelativeNameSegments = listOf("My", "Test") + ), + TestRow( + rawEntityId = "foo/bar/My.Test.Class", + packageSegments = arrayOf("foo", "bar"), + rawRelativeNameSegments = listOf("My", "Test", "Class") + ), + TestRow( + rawEntityId = "foo/bar/baz/My", + packageSegments = arrayOf("foo", "bar", "baz"), + rawRelativeNameSegments = listOf("My") + ), + TestRow( + rawEntityId = "foo/bar/baz/My.Test", + packageSegments = arrayOf("foo", "bar", "baz"), + rawRelativeNameSegments = listOf("My", "Test") + ), + TestRow( + rawEntityId = "foo/bar/baz/My.Test.Class", + packageSegments = arrayOf("foo", "bar", "baz"), + rawRelativeNameSegments = listOf("My", "Test", "Class") + ) + ).forEach { testRow -> + with(testRow) { + // nullable, because ClassId may not have empty class name + val classifierId: ClassId? = if (rawRelativeNameSegments.isNotEmpty()) ClassId.fromString(rawEntityId) else null + + val packageName = CirPackageName.create(packageSegments) + val relativeNameSegments = rawRelativeNameSegments.map(CirName::create).toTypedArray() + + val entityIds = listOfNotNull( + CirEntityId.create(rawEntityId), + CirEntityId.create(rawEntityId), + classifierId?.let(CirEntityId::create), + classifierId?.let(CirEntityId::create), + CirEntityId.create(packageName, relativeNameSegments), + CirEntityId.create(packageName, relativeNameSegments) + ) + + val first = entityIds.first() + entityIds.forEach { entityId -> + assertSame(first, entityId) + assertSame(packageName, entityId.packageName) + assertTrue(relativeNameSegments.contentEquals(entityId.relativeNameSegments)) + } + } + } + } + + @Test + fun toStringConversion() { + listOf( + "" to "/", + "/" to "/", + "foo/" to "foo/", + "foo/bar/" to "foo/bar/", + "foo/bar/baz/" to "foo/bar/baz/", + "My" to "/My", + "My.Test" to "/My.Test", + "My.Test.Class" to "/My.Test.Class", + "foo/My" to "foo/My", + "foo/bar/My.Test" to "foo/bar/My.Test", + "foo/bar/baz/My.Test.Class" to "foo/bar/baz/My.Test.Class" + ).forEach { (rawEntityId, asStringRepresentation) -> + assertEquals(asStringRepresentation, CirEntityId.create(rawEntityId).toString()) + } + } + + @Test + fun createNested() { + val nested1 = CirName.create("Nested1") + val nested2 = CirName.create("Nested2") + + listOf( + "", + "/", + "foo/", + "foo/bar/", + "Outer", + "/Outer", + "foo/Outer", + "foo/bar/Outer", + "Outer.Nested", + "/Outer.Nested", + "foo/Outer.Nested", + "foo/bar/Outer.Nested" + ).forEach { rawEntityId -> + val entityId = CirEntityId.create(rawEntityId) + val n1 = entityId.createNestedEntityId(nested1) + assertSame(entityId.packageName, n1.packageName) + assertEquals(entityId.relativeNameSegments.isNotEmpty(), n1.isNestedEntity) + assertEquals(entityId.relativeNameSegments.toList(), n1.relativeNameSegments.dropLast(1)) + + val n2 = n1.createNestedEntityId(nested2) + assertSame(entityId.packageName, n2.packageName) + assertTrue(n2.isNestedEntity) + assertEquals(entityId.relativeNameSegments.toList(), n2.relativeNameSegments.dropLast(2)) + } + } + + @Test + fun isNested() { + listOf( + "" to false, + "/" to false, + "foo/" to false, + "foo/bar/" to false, + "My" to false, + "My.Test" to true, + "My.Test.Class" to true, + "/My" to false, + "/My.Test" to true, + "/My.Test.Class" to true, + "foo/My" to false, + "foo/My.Test" to true, + "foo/My.Test.Class" to true, + "foo/bar/My" to false, + "foo/bar/My.Test" to true, + "foo/bar/My.Test.Class" to true, + ).forEach { (rawEntityId, isNested) -> + assertEquals(isNested, CirEntityId.create(rawEntityId).isNestedEntity) + } + } +} + diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirNameTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirNameTest.kt new file mode 100644 index 00000000000..f551dda6eea --- /dev/null +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirNameTest.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2021 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.descriptors.commonizer.core + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName +import org.jetbrains.kotlin.name.Name +import org.junit.Test +import kotlin.test.assertSame +import kotlin.test.assertEquals + +class CirNameTest { + @Test + fun createAndIntern() { + listOf("", "foo", "bar", "").forEach { rawName -> + val kotlinName = Name.guessByFirstCharacter(rawName) + + val names = listOf( + CirName.create(rawName), + CirName.create(rawName), + CirName.create(kotlinName), + CirName.create(kotlinName) + ) + + val first = names.first() + names.forEach { name -> + assertSame(first, name) + } + } + } + + @Test + fun toStringConversion() { + listOf("", "foo", "bar", "").forEach { rawName -> + val name = CirName.create(rawName) + assertEquals(rawName, name.name) + assertEquals(rawName, name.toString()) + } + } + + @Test + fun toStrippedStringConversion() { + listOf( + "" to "", + "foo" to "foo", + "bar" to "bar", + "" to "stdlib" + ).forEach { (rawName, strippedName) -> + assertEquals(strippedName, CirName.create(rawName).toStrippedString()) + } + } +} diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirPackageNameTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirPackageNameTest.kt new file mode 100644 index 00000000000..bc2807d3886 --- /dev/null +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/CirPackageNameTest.kt @@ -0,0 +1,109 @@ +/* + * Copyright 2010-2021 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.descriptors.commonizer.core + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackageName +import org.jetbrains.kotlin.name.FqName +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertSame +import kotlin.test.assertTrue + +class CirPackageNameTest { + @Test + fun createAndIntern() { + listOf( + "" to emptyArray(), + "foo" to arrayOf("foo"), + "foo.bar" to arrayOf("foo", "bar"), + "foo.bar.baz" to arrayOf("foo", "bar", "baz") + ).forEach { (rawPackageFqName, segments) -> + val packageFqName = FqName(rawPackageFqName) + + val packageNames = listOf( + CirPackageName.create(rawPackageFqName), + CirPackageName.create(rawPackageFqName), + CirPackageName.create(packageFqName), + CirPackageName.create(packageFqName), + CirPackageName.create(segments), + CirPackageName.create(segments) + ) + + val first = packageNames.first() + packageNames.forEach { packageName -> + assertTrue(segments.contentEquals(packageName.segments)) + assertSame(first, packageName) + } + } + } + + @Test + fun createRoot() { + val rootPackageNames = listOf( + CirPackageName.create(""), + CirPackageName.create(FqName("")), + CirPackageName.create(FqName.ROOT), + CirPackageName.create(emptyArray()) + ) + + val first = rootPackageNames.first() + rootPackageNames.forEach { rootPackageName -> + assertSame(first, rootPackageName) + assertTrue(rootPackageName.segments.isEmpty()) + assertTrue(rootPackageName.isRoot()) + assertSame(CirPackageName.ROOT, rootPackageName) + } + } + + @Test + fun toStringConversion() { + listOf( + "" to emptyArray(), + "foo" to arrayOf("foo"), + "foo.bar" to arrayOf("foo", "bar"), + "foo.bar.baz" to arrayOf("foo", "bar", "baz") + ).forEach { (rawPackageFqName, segments) -> + assertEquals(rawPackageFqName, CirPackageName.create(segments).toString()) + } + } + + @Test + fun toMetadataStringConversion() { + listOf( + "" to "", + "foo" to "foo", + "foo.bar" to "foo/bar", + "foo.bar.baz" to "foo/bar/baz" + ).forEach { (rawPackageFqName, metadataPackageFqName) -> + assertEquals(metadataPackageFqName, CirPackageName.create(rawPackageFqName).toMetadataString()) + } + } + + @Test + fun startsWith() { + val packageNames = listOf("", "foo", "foo.bar", "foo.bar.baz").map(CirPackageName::create) + + for (i in packageNames.indices) { + val a = packageNames[i] + for (j in packageNames.indices) { + val b = packageNames[j] + assertEquals(i >= j, a.startsWith(b)) + } + } + } + + @Test + fun notStartsWith() { + listOf( + "aa" to "ab", + "aa.bb" to "aa.bc", + "aa.bb" to "aa.bb.cc" + ).forEach { (a, b) -> + assertFalse(CirPackageName.create(a).startsWith(CirPackageName.create(b))) + } + } +} diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt index 1d482ce5c20..d1dd0ab3eed 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt @@ -9,16 +9,16 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.commonizer.LeafTarget import org.jetbrains.kotlin.descriptors.commonizer.SharedTarget +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeAliasFactory import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* +import org.jetbrains.kotlin.descriptors.commonizer.utils.classifierId import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.descriptors.commonizer.utils.mockTAType -import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.resolve.descriptorUtil.classId import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.getAbbreviation @@ -37,7 +37,7 @@ class TypeCommonizerTest : AbstractCommonizerTest() { forwardDeclarations = CirForwardDeclarations.default(), dependeeLibraries = mapOf( FAKE_SHARED_TARGET to object : CirProvidedClassifiers { - override fun hasClassifier(classifierId: ClassId): Boolean = classifierId.packageFqName.isUnderStandardKotlinPackages + override fun hasClassifier(classifierId: CirEntityId): Boolean = classifierId.packageName.isUnderStandardKotlinPackages } ) ) @@ -476,7 +476,7 @@ class TypeCommonizerTest : AbstractCommonizerTest() { val descriptor = (type.getAbbreviation() ?: type).constructor.declarationDescriptor when (descriptor) { is ClassDescriptor -> { - val classId = descriptor.classId ?: error("No class ID for ${descriptor::class.java}, $descriptor") + val classId = descriptor.classifierId val node = classifiers.classNode(classId) { buildClassNode( storageManager = LockBasedStorageManager.NO_LOCKS, @@ -489,7 +489,7 @@ class TypeCommonizerTest : AbstractCommonizerTest() { node.targetDeclarations[index] = CirClassFactory.create(descriptor) } is TypeAliasDescriptor -> { - val typeAliasId = descriptor.classId ?: error("No class ID for ${descriptor::class.java}, $descriptor") + val typeAliasId = descriptor.classifierId val node = classifiers.typeAliasNode(typeAliasId) { buildTypeAliasNode( storageManager = LockBasedStorageManager.NO_LOCKS, @@ -539,10 +539,10 @@ class TypeCommonizerTest : AbstractCommonizerTest() { private val FAKE_SHARED_TARGET = SharedTarget(setOf(LeafTarget("a"), LeafTarget("b"))) - private fun CirKnownClassifiers.classNode(classId: ClassId, computation: () -> CirClassNode) = + private fun CirKnownClassifiers.classNode(classId: CirEntityId, computation: () -> CirClassNode) = commonized.classNode(classId) ?: computation() - private fun CirKnownClassifiers.typeAliasNode(typeAliasId: ClassId, computation: () -> CirTypeAliasNode) = + private fun CirKnownClassifiers.typeAliasNode(typeAliasId: CirEntityId, computation: () -> CirTypeAliasNode) = commonized.typeAliasNode(typeAliasId) ?: computation() } } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt index 3057e51eb13..425d53aa1b7 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt @@ -5,12 +5,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeParameterFactory import org.jetbrains.kotlin.descriptors.commonizer.utils.MOCK_CLASSIFIERS import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance import org.junit.Test @@ -90,7 +90,7 @@ class TypeParameterCommonizerTest : AbstractCommonizerTest = listOf("kotlin.Any") ) = CirTypeParameterFactory.create( annotations = emptyList(), - name = Name.identifier(name), + name = CirName.create(name), isReified = isReified, variance = variance, upperBounds = upperBounds.map { CirTypeFactory.create(mockClassType(it)) } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt index 59d129249de..65e80ef656b 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory @@ -14,7 +15,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.core.TypeCommonizerTest.Compa import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers import org.jetbrains.kotlin.descriptors.commonizer.utils.MOCK_CLASSIFIERS import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType -import org.jetbrains.kotlin.name.Name import org.junit.Test class ValueParameterCommonizerTest : AbstractCommonizerTest() { @@ -158,7 +158,7 @@ class ValueParameterCommonizerTest : AbstractCommonizerTest, override val returnType: CirType, override val varargElementType: CirType?, diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt index 62f37b967d5..24cb7675972 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt @@ -13,14 +13,14 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.commonizer.* import org.jetbrains.kotlin.descriptors.commonizer.ResultsConsumer.ModuleResult import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider.ModuleInfo +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.descriptors.impl.AbstractTypeAliasDescriptor import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl import org.jetbrains.kotlin.library.SerializedMetadata -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.parentOrNull import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.LockBasedStorageManager @@ -126,7 +126,7 @@ internal val MOCK_CLASSIFIERS = CirKnownClassifiers( LockBasedStorageManager.NO_LOCKS.createNullableLazyValue { CirClassFactory.create( annotations = emptyList(), - name = Name.identifier("kotlin.Any"), + name = CirName.create("Any"), typeParameters = emptyList(), visibility = DescriptorVisibilities.PUBLIC, modality = Modality.OPEN, @@ -139,17 +139,17 @@ internal val MOCK_CLASSIFIERS = CirKnownClassifiers( isExternal = false ) }, - ClassId.fromString("kotlin/Any") + CirEntityId.create("kotlin/Any") ) - override fun classNode(classId: ClassId) = MOCK_CLASS_NODE - override fun typeAliasNode(typeAliasId: ClassId) = error("This method should not be called") - override fun addClassNode(classId: ClassId, node: CirClassNode) = error("This method should not be called") - override fun addTypeAliasNode(typeAliasId: ClassId, node: CirTypeAliasNode) = error("This method should not be called") + override fun classNode(classId: CirEntityId) = MOCK_CLASS_NODE + override fun typeAliasNode(typeAliasId: CirEntityId) = error("This method should not be called") + override fun addClassNode(classId: CirEntityId, node: CirClassNode) = error("This method should not be called") + override fun addTypeAliasNode(typeAliasId: CirEntityId, node: CirTypeAliasNode) = error("This method should not be called") }, forwardDeclarations = object : CirForwardDeclarations { - override fun isExportedForwardDeclaration(classId: ClassId) = false - override fun addExportedForwardDeclaration(classId: ClassId) = error("This method should not be called") + override fun isExportedForwardDeclaration(classId: CirEntityId) = false + override fun addExportedForwardDeclaration(classId: CirEntityId) = error("This method should not be called") }, dependeeLibraries = emptyMap() )