[Commonizer] Don't keep kotlin/Any as the single supertype in CirClass
This commit is contained in:
+2
-1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
|
|||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassImpl
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassImpl
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||||
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.filteredSupertypes
|
||||||
import org.jetbrains.kotlin.resolve.isInlineClass
|
import org.jetbrains.kotlin.resolve.isInlineClass
|
||||||
|
|
||||||
object CirClassFactory {
|
object CirClassFactory {
|
||||||
@@ -32,7 +33,7 @@ object CirClassFactory {
|
|||||||
isInner = source.isInner,
|
isInner = source.isInner,
|
||||||
isExternal = source.isExternal
|
isExternal = source.isExternal
|
||||||
).apply {
|
).apply {
|
||||||
setSupertypes(source.typeConstructor.supertypes.compactMap { CirTypeFactory.create(it) })
|
setSupertypes(source.filteredSupertypes.compactMap { CirTypeFactory.create(it) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
|||||||
+3
-11
@@ -6,9 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.commonizer.core
|
package org.jetbrains.kotlin.descriptors.commonizer.core
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
|
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.CirType
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
|
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.*
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapNotNull
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapNotNull
|
||||||
@@ -98,7 +96,7 @@ internal class CommonizationVisitor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find out common (and commonized) supertypes
|
// find out common (and commonized) supertypes
|
||||||
commonClass.commonizeSupertypes(node.classifierId, node.collectCommonSupertypes())
|
commonClass.commonizeSupertypes(node.collectCommonSupertypes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ internal class CommonizationVisitor(
|
|||||||
|
|
||||||
if (commonClassifier is CirClass) {
|
if (commonClassifier is CirClass) {
|
||||||
// find out common (and commonized) supertypes
|
// find out common (and commonized) supertypes
|
||||||
commonClassifier.commonizeSupertypes(node.classifierId, node.collectCommonSupertypes())
|
commonClassifier.commonizeSupertypes(node.collectCommonSupertypes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,18 +142,12 @@ internal class CommonizationVisitor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun CirClass.commonizeSupertypes(
|
private fun CirClass.commonizeSupertypes(
|
||||||
classId: CirEntityId,
|
|
||||||
supertypesMap: Map<CirType, CommonizedGroup<CirType>>?
|
supertypesMap: Map<CirType, CommonizedGroup<CirType>>?
|
||||||
) {
|
) {
|
||||||
val commonSupertypes = supertypesMap?.values?.compactMapNotNull { supertypesGroup ->
|
val commonSupertypes = supertypesMap?.values?.compactMapNotNull { supertypesGroup ->
|
||||||
commonize(supertypesGroup, TypeCommonizer(classifiers))
|
commonize(supertypesGroup, TypeCommonizer(classifiers))
|
||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
|
|
||||||
setSupertypes(
|
setSupertypes(commonSupertypes)
|
||||||
if (commonSupertypes.isEmpty() && classId !in SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS)
|
|
||||||
listOf(CirTypeFactory.StandardTypes.ANY)
|
|
||||||
else
|
|
||||||
commonSupertypes
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -10,11 +10,13 @@ import kotlinx.metadata.klib.*
|
|||||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDeserializer
|
import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDeserializer
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirValueParameterImpl
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirValueParameterImpl
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.core.computeExpandedType
|
import org.jetbrains.kotlin.descriptors.commonizer.core.computeExpandedType
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.metadata.TypeAliasExpansion.*
|
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.DEFAULT_SETTER_VALUE_NAME
|
||||||
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
@@ -99,7 +101,12 @@ internal fun CirClass.buildClass(
|
|||||||
}
|
}
|
||||||
|
|
||||||
clazz.companionObject = companion?.name
|
clazz.companionObject = companion?.name
|
||||||
supertypes.mapTo(clazz.supertypes) { it.buildType(context) }
|
|
||||||
|
val supertypes = supertypes
|
||||||
|
if (supertypes.isEmpty() && className !in SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES)
|
||||||
|
clazz.supertypes += CirTypeFactory.StandardTypes.ANY.buildType(context)
|
||||||
|
else
|
||||||
|
supertypes.mapTo(clazz.supertypes) { it.buildType(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun linkSealedClassesWithSubclasses(packageName: CirPackageName, classConsumer: ClassConsumer) {
|
internal fun linkSealedClassesWithSubclasses(packageName: CirPackageName, classConsumer: ClassConsumer) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
||||||
|
|
||||||
|
import kotlinx.metadata.ClassName
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
@@ -26,6 +27,9 @@ internal val SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS: List<CirEntityId> = lis
|
|||||||
NOTHING_CLASS_ID
|
NOTHING_CLASS_ID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal val SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES: List<ClassName> =
|
||||||
|
SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_IDS.map(CirEntityId::toString)
|
||||||
|
|
||||||
private val STANDARD_KOTLIN_PACKAGES: List<CirPackageName> = listOf(
|
private val STANDARD_KOTLIN_PACKAGES: List<CirPackageName> = listOf(
|
||||||
CirPackageName.create(StandardNames.BUILT_INS_PACKAGE_FQ_NAME),
|
CirPackageName.create(StandardNames.BUILT_INS_PACKAGE_FQ_NAME),
|
||||||
CirPackageName.create("kotlinx")
|
CirPackageName.create("kotlinx")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
|
||||||
@@ -43,6 +44,9 @@ internal val ClassifierDescriptorWithTypeParameters.classifierId: CirEntityId
|
|||||||
internal inline val TypeParameterDescriptor.filteredUpperBounds: List<KotlinType>
|
internal inline val TypeParameterDescriptor.filteredUpperBounds: List<KotlinType>
|
||||||
get() = upperBounds.takeUnless { it.singleOrNull()?.isNullableAny() == true } ?: emptyList()
|
get() = upperBounds.takeUnless { it.singleOrNull()?.isNullableAny() == true } ?: emptyList()
|
||||||
|
|
||||||
|
internal inline val ClassDescriptor.filteredSupertypes: Collection<KotlinType>
|
||||||
|
get() = typeConstructor.supertypes.takeUnless { it.size == 1 && KotlinBuiltIns.isAny(it.first()) } ?: emptyList()
|
||||||
|
|
||||||
internal val KotlinType.signature: CirTypeSignature
|
internal val KotlinType.signature: CirTypeSignature
|
||||||
get() {
|
get() {
|
||||||
// use of interner saves up to 95% of duplicates
|
// use of interner saves up to 95% of duplicates
|
||||||
|
|||||||
Reference in New Issue
Block a user