[Commonizer] Minor. Post-review changes
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.types.*
|
|||||||
object CirTypeFactory {
|
object CirTypeFactory {
|
||||||
object StandardTypes {
|
object StandardTypes {
|
||||||
val ANY: CirClassType = createClassType(
|
val ANY: CirClassType = createClassType(
|
||||||
classId = ANY_CID,
|
classId = ANY_CLASS_ID,
|
||||||
outerType = null,
|
outerType = null,
|
||||||
visibility = DescriptorVisibilities.PUBLIC,
|
visibility = DescriptorVisibilities.PUBLIC,
|
||||||
arguments = emptyList(),
|
arguments = emptyList(),
|
||||||
|
|||||||
+5
-5
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
|||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
|
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.core.AnnotationsCommonizer.Companion.FALLBACK_MESSAGE
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.DEPRECATED_ANNOTATION_CID
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.DEPRECATED_ANNOTATION_CLASS_ID
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapOf
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapOf
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||||
@@ -38,7 +38,7 @@ class AnnotationsCommonizer : AbstractStandardCommonizer<List<CirAnnotation>, Li
|
|||||||
override fun initialize(first: List<CirAnnotation>) = Unit
|
override fun initialize(first: List<CirAnnotation>) = Unit
|
||||||
|
|
||||||
override fun doCommonizeWith(next: List<CirAnnotation>): Boolean {
|
override fun doCommonizeWith(next: List<CirAnnotation>): Boolean {
|
||||||
val nextDeprecatedAnnotation = next.firstOrNull { it.type.classifierId == DEPRECATED_ANNOTATION_CID } ?: return true
|
val nextDeprecatedAnnotation = next.firstOrNull { it.type.classifierId == DEPRECATED_ANNOTATION_CLASS_ID } ?: return true
|
||||||
|
|
||||||
val deprecatedAnnotationCommonizer = deprecatedAnnotationCommonizer
|
val deprecatedAnnotationCommonizer = deprecatedAnnotationCommonizer
|
||||||
?: DeprecatedAnnotationCommonizer().also { this.deprecatedAnnotationCommonizer = it }
|
?: DeprecatedAnnotationCommonizer().also { this.deprecatedAnnotationCommonizer = it }
|
||||||
@@ -148,14 +148,14 @@ private class DeprecatedAnnotationCommonizer : Commonizer<CirAnnotation, CirAnno
|
|||||||
).associateWith { StringValue(it) }
|
).associateWith { StringValue(it) }
|
||||||
private val FALLBACK_MESSAGE_VALUE = StringValue(FALLBACK_MESSAGE)
|
private val FALLBACK_MESSAGE_VALUE = StringValue(FALLBACK_MESSAGE)
|
||||||
|
|
||||||
private val DEPRECATED_ANNOTATION_TYPE = buildAnnotationType(DEPRECATED_ANNOTATION_CID)
|
private val DEPRECATED_ANNOTATION_TYPE = buildAnnotationType(DEPRECATED_ANNOTATION_CLASS_ID)
|
||||||
private val REPLACE_WITH_ANNOTATION_TYPE = buildAnnotationType(internedClassId(FqName(ReplaceWith::class.java.name)))
|
private val REPLACE_WITH_ANNOTATION_TYPE = buildAnnotationType(internedClassId(FqName(ReplaceWith::class.java.name)))
|
||||||
|
|
||||||
private val DEPRECATION_LEVEL_CID = internedClassId(FqName(DeprecationLevel::class.java.name))
|
private val DEPRECATION_LEVEL_CLASS_ID = internedClassId(FqName(DeprecationLevel::class.java.name))
|
||||||
|
|
||||||
// Optimization: Keep DeprecationLevel enum constants.
|
// Optimization: Keep DeprecationLevel enum constants.
|
||||||
private val DEPRECATION_LEVEL_ENUM_ENTRY_VALUES: Map<String, EnumValue> = DeprecationLevel.values().associate {
|
private val DEPRECATION_LEVEL_ENUM_ENTRY_VALUES: Map<String, EnumValue> = DeprecationLevel.values().associate {
|
||||||
it.name to EnumValue(DEPRECATION_LEVEL_CID, Name.identifier(it.name).intern())
|
it.name to EnumValue(DEPRECATION_LEVEL_CLASS_ID, Name.identifier(it.name).intern())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildAnnotationType(classId: ClassId) = CirTypeFactory.createClassType(
|
private fun buildAnnotationType(classId: ClassId) = CirTypeFactory.createClassType(
|
||||||
|
|||||||
+1
-1
@@ -153,7 +153,7 @@ internal class CommonizationVisitor(
|
|||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
|
|
||||||
setSupertypes(
|
setSupertypes(
|
||||||
if (commonSupertypes.isEmpty() && classId !in SPECIAL_CLASS_WITHOUT_SUPERTYPES_CIDS)
|
if (commonSupertypes.isEmpty() && classId !in SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS)
|
||||||
listOf(CirTypeFactory.StandardTypes.ANY)
|
listOf(CirTypeFactory.StandardTypes.ANY)
|
||||||
else
|
else
|
||||||
commonSupertypes
|
commonSupertypes
|
||||||
|
|||||||
+9
-5
@@ -7,12 +7,16 @@ package org.jetbrains.kotlin.descriptors.commonizer.metadata.utils
|
|||||||
|
|
||||||
import kotlinx.metadata.klib.KlibModuleMetadata
|
import kotlinx.metadata.klib.KlibModuleMetadata
|
||||||
|
|
||||||
|
private typealias FragmentPartContents = ByteArray
|
||||||
|
private typealias ListOfFragmentParts = List<FragmentPartContents>
|
||||||
|
private typealias MapOfFragmentParts = Map<String, FragmentPartContents>
|
||||||
|
|
||||||
class SerializedMetadataLibraryProvider(
|
class SerializedMetadataLibraryProvider(
|
||||||
override val moduleHeaderData: ByteArray,
|
override val moduleHeaderData: ByteArray,
|
||||||
fragments: List<List<ByteArray>>,
|
fragments: List<ListOfFragmentParts>,
|
||||||
fragmentNames: List<String>
|
fragmentNames: List<String>
|
||||||
) : KlibModuleMetadata.MetadataLibraryProvider {
|
) : KlibModuleMetadata.MetadataLibraryProvider {
|
||||||
private val fragmentMap: Map<String, Map<String, ByteArray>>
|
private val fragmentMap: Map<String, MapOfFragmentParts>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
check(fragments.size == fragmentNames.size)
|
check(fragments.size == fragmentNames.size)
|
||||||
@@ -21,11 +25,11 @@ class SerializedMetadataLibraryProvider(
|
|||||||
// fragmentName is package FQ name, fragmentShortName is right-most part of package FQ name
|
// fragmentName is package FQ name, fragmentShortName is right-most part of package FQ name
|
||||||
val fragmentShortName = fragmentName.substringAfterLast('.')
|
val fragmentShortName = fragmentName.substringAfterLast('.')
|
||||||
|
|
||||||
val fragmentParts = fragments[fragmentIndex]
|
val fragmentParts: ListOfFragmentParts = fragments[fragmentIndex]
|
||||||
val digitCount = fragmentParts.size.toString().length
|
val digitCount = fragmentParts.size.toString().length
|
||||||
|
|
||||||
// N.B. the same fragment part numbering scheme as in org.jetbrains.kotlin.library.impl.MetadataWriterImpl
|
// N.B. the same fragment part numbering scheme as in org.jetbrains.kotlin.library.impl.MetadataWriterImpl
|
||||||
val fragmentPartMap = fragmentParts.mapIndexed { partIndex, part ->
|
val fragmentPartMap: MapOfFragmentParts = fragmentParts.mapIndexed { partIndex, part ->
|
||||||
val partName = partIndex.toString().padStart(digitCount, '0') + "_" + fragmentShortName
|
val partName = partIndex.toString().padStart(digitCount, '0') + "_" + fragmentShortName
|
||||||
partName to part
|
partName to part
|
||||||
}.toMap()
|
}.toMap()
|
||||||
@@ -38,7 +42,7 @@ class SerializedMetadataLibraryProvider(
|
|||||||
return fragmentMap.getValue(fqName).keys
|
return fragmentMap.getValue(fqName).keys
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun packageMetadata(fqName: String, partName: String): ByteArray {
|
override fun packageMetadata(fqName: String, partName: String): FragmentPartContents {
|
||||||
return fragmentMap.getValue(fqName).getValue(partName)
|
return fragmentMap.getValue(fqName).getValue(partName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.serialization.konan.impl.ForwardDeclarationsFqNames
|
import org.jetbrains.kotlin.serialization.konan.impl.ForwardDeclarationsFqNames
|
||||||
|
|
||||||
internal val DEPRECATED_ANNOTATION_FQN: FqName = FqName(Deprecated::class.java.name).intern()
|
internal val DEPRECATED_ANNOTATION_FQN: FqName = FqName(Deprecated::class.java.name).intern()
|
||||||
internal val DEPRECATED_ANNOTATION_CID: ClassId = internedClassId(DEPRECATED_ANNOTATION_FQN)
|
internal val DEPRECATED_ANNOTATION_CLASS_ID: ClassId = internedClassId(DEPRECATED_ANNOTATION_FQN)
|
||||||
|
|
||||||
internal val ANY_CID: ClassId = internedClassId(StandardNames.FqNames.any.toSafe().intern())
|
internal val ANY_CLASS_ID: ClassId = internedClassId(StandardNames.FqNames.any.toSafe().intern())
|
||||||
private val NOTHING_CID: ClassId = internedClassId(StandardNames.FqNames.nothing.toSafe().intern())
|
private val NOTHING_CLASS_ID: ClassId = internedClassId(StandardNames.FqNames.nothing.toSafe().intern())
|
||||||
|
|
||||||
internal val SPECIAL_CLASS_WITHOUT_SUPERTYPES_CIDS = listOf(
|
internal val SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS = listOf(
|
||||||
ANY_CID,
|
ANY_CLASS_ID,
|
||||||
NOTHING_CID
|
NOTHING_CLASS_ID
|
||||||
)
|
)
|
||||||
|
|
||||||
private val STANDARD_KOTLIN_PACKAGES = listOf(
|
private val STANDARD_KOTLIN_PACKAGES = listOf(
|
||||||
|
|||||||
Reference in New Issue
Block a user