[Commonizer] Remove unnecessary nullability at CirKnownClassifiers.commonDependeeLibraries
This commit is contained in:
+1
-1
@@ -128,7 +128,7 @@ internal class CommonizationVisitor(
|
|||||||
val supertypesMap: MutableMap<CirType, CommonizedGroup<CirType>> = linkedMapOf() // preserve supertype order
|
val supertypesMap: MutableMap<CirType, CommonizedGroup<CirType>> = linkedMapOf() // preserve supertype order
|
||||||
for ((index, typeAlias) in targetDeclarations.withIndex()) {
|
for ((index, typeAlias) in targetDeclarations.withIndex()) {
|
||||||
val expandedClassId = typeAlias!!.expandedType.classifierId
|
val expandedClassId = typeAlias!!.expandedType.classifierId
|
||||||
if (classifiers.commonDependeeLibraries?.hasClassifier(expandedClassId) == true)
|
if (classifiers.commonDependeeLibraries.hasClassifier(expandedClassId))
|
||||||
return null // this case is not supported yet
|
return null // this case is not supported yet
|
||||||
|
|
||||||
val expandedClassNode = classifiers.commonized.classNode(expandedClassId) ?: return null
|
val expandedClassNode = classifiers.commonized.classNode(expandedClassId) ?: return null
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ private class TypeAliasShortCircuitingCommonizer(
|
|||||||
private tailrec fun computeCommonizedUnderlyingType(underlyingType: CirClassOrTypeAliasType): CirClassOrTypeAliasType {
|
private tailrec fun computeCommonizedUnderlyingType(underlyingType: CirClassOrTypeAliasType): CirClassOrTypeAliasType {
|
||||||
return when (underlyingType) {
|
return when (underlyingType) {
|
||||||
is CirClassType -> underlyingType
|
is CirClassType -> underlyingType
|
||||||
is CirTypeAliasType -> if (classifiers.commonDependeeLibraries?.hasClassifier(underlyingType.classifierId) == true)
|
is CirTypeAliasType -> if (classifiers.commonDependeeLibraries.hasClassifier(underlyingType.classifierId))
|
||||||
underlyingType
|
underlyingType
|
||||||
else
|
else
|
||||||
computeCommonizedUnderlyingType(underlyingType.underlyingType)
|
computeCommonizedUnderlyingType(underlyingType.underlyingType)
|
||||||
|
|||||||
+2
-2
@@ -220,7 +220,7 @@ private class TypeArgumentListCommonizer(classifiers: CirKnownClassifiers) : Abs
|
|||||||
)
|
)
|
||||||
|
|
||||||
private fun commonizeClass(classId: ClassId, classifiers: CirKnownClassifiers): Boolean {
|
private fun commonizeClass(classId: ClassId, classifiers: CirKnownClassifiers): Boolean {
|
||||||
if (classifiers.commonDependeeLibraries?.hasClassifier(classId) == true) {
|
if (classifiers.commonDependeeLibraries.hasClassifier(classId)) {
|
||||||
// The class is from common fragment of dependee library (ex: stdlib). Already commonized.
|
// The class is from common fragment of dependee library (ex: stdlib). Already commonized.
|
||||||
return true
|
return true
|
||||||
} else if (classId.packageFqName.isUnderKotlinNativeSyntheticPackages) {
|
} else if (classId.packageFqName.isUnderKotlinNativeSyntheticPackages) {
|
||||||
@@ -247,7 +247,7 @@ private fun commonizeClass(classId: ClassId, classifiers: CirKnownClassifiers):
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun commonizeTypeAlias(typeAliasId: ClassId, classifiers: CirKnownClassifiers): CommonizedTypeAliasAnswer {
|
private fun commonizeTypeAlias(typeAliasId: ClassId, classifiers: CirKnownClassifiers): CommonizedTypeAliasAnswer {
|
||||||
if (classifiers.commonDependeeLibraries?.hasClassifier(typeAliasId) == true) {
|
if (classifiers.commonDependeeLibraries.hasClassifier(typeAliasId)) {
|
||||||
// The type alias is from common fragment of dependee library (ex: stdlib). Already commonized.
|
// The type alias is from common fragment of dependee library (ex: stdlib). Already commonized.
|
||||||
return SUCCESS_FROM_DEPENDEE_LIBRARY
|
return SUCCESS_FROM_DEPENDEE_LIBRARY
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -25,7 +25,8 @@ class CirKnownClassifiers(
|
|||||||
val dependeeLibraries: Map<Target, CirProvidedClassifiers>
|
val dependeeLibraries: Map<Target, CirProvidedClassifiers>
|
||||||
) {
|
) {
|
||||||
// a shortcut for fast access
|
// a shortcut for fast access
|
||||||
val commonDependeeLibraries: CirProvidedClassifiers? = dependeeLibraries.filterKeys { it is SharedTarget }.values.singleOrNull()
|
val commonDependeeLibraries: CirProvidedClassifiers =
|
||||||
|
dependeeLibraries.filterKeys { it is SharedTarget }.values.singleOrNull() ?: CirProvidedClassifiers.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CirCommonizedClassifiers {
|
interface CirCommonizedClassifiers {
|
||||||
@@ -86,6 +87,10 @@ interface CirProvidedClassifiers {
|
|||||||
//fun classifier(classifierId: ClassId): Any?
|
//fun classifier(classifierId: ClassId): Any?
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
internal val EMPTY = object : CirProvidedClassifiers {
|
||||||
|
override fun hasClassifier(classifierId: ClassId) = false
|
||||||
|
}
|
||||||
|
|
||||||
// N.B. This is suboptimal implementation. It will be replaced by another implementation that will
|
// N.B. This is suboptimal implementation. It will be replaced by another implementation that will
|
||||||
// retrieve classifier information directly from the metadata.
|
// retrieve classifier information directly from the metadata.
|
||||||
fun fromModules(storageManager: StorageManager, modules: () -> Collection<ModuleDescriptor>) = object : CirProvidedClassifiers {
|
fun fromModules(storageManager: StorageManager, modules: () -> Collection<ModuleDescriptor>) = object : CirProvidedClassifiers {
|
||||||
|
|||||||
Reference in New Issue
Block a user