[Commonizer] Minor: Change signature of CirConversions functions

^KT-48288
This commit is contained in:
sebastian.sellmair
2021-09-16 09:35:16 +02:00
committed by Space
parent 75d7c830e7
commit d0cd7c81ea
3 changed files with 26 additions and 27 deletions
@@ -9,47 +9,47 @@ import org.jetbrains.kotlin.commonizer.mergedtree.CirProvided
import org.jetbrains.kotlin.commonizer.mergedtree.CirProvidedClassifiers import org.jetbrains.kotlin.commonizer.mergedtree.CirProvidedClassifiers
import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibilities
internal fun CirProvidedClassifiers.toCirClassOrTypeAliasTypeOrNull(type: CirProvided.ClassOrTypeAliasType): CirClassOrTypeAliasType? { internal fun CirProvided.ClassOrTypeAliasType.toCirClassOrTypeAliasTypeOrNull(classifiers: CirProvidedClassifiers): CirClassOrTypeAliasType? {
return when (type) { return when (this) {
is CirProvided.ClassType -> toCirClassTypeOrNull(type) is CirProvided.ClassType -> this.toCirClassTypeOrNull(classifiers)
is CirProvided.TypeAliasType -> toCirTypeAliasTypeOrNull(type) is CirProvided.TypeAliasType -> this.toCirTypeAliasTypeOrNull(classifiers)
} }
} }
internal fun CirProvidedClassifiers.toCirTypeAliasTypeOrNull(type: CirProvided.TypeAliasType): CirTypeAliasType? { internal fun CirProvided.TypeAliasType.toCirTypeAliasTypeOrNull(classifiers: CirProvidedClassifiers): CirTypeAliasType? {
val typeAlias = this.classifier(type.classifierId) as? CirProvided.TypeAlias ?: return null val typeAlias = classifiers.classifier(classifierId) as? CirProvided.TypeAlias ?: return null
return CirTypeAliasType.createInterned( return CirTypeAliasType.createInterned(
typeAliasId = type.classifierId, typeAliasId = classifierId,
isMarkedNullable = type.isMarkedNullable, isMarkedNullable = isMarkedNullable,
arguments = type.arguments.map { toCirTypeProjection(it) ?: return null }, arguments = arguments.map { it.toCirTypeProjection(classifiers) ?: return null },
underlyingType = toCirClassOrTypeAliasTypeOrNull(typeAlias.underlyingType) ?: return null underlyingType = typeAlias.underlyingType.toCirClassOrTypeAliasTypeOrNull(classifiers) ?: return null
) )
} }
internal fun CirProvidedClassifiers.toCirClassTypeOrNull(type: CirProvided.ClassType): CirClassType? { internal fun CirProvided.ClassType.toCirClassTypeOrNull(classifiers: CirProvidedClassifiers): CirClassType? {
return CirClassType.createInterned( return CirClassType.createInterned(
classId = type.classifierId, classId = classifierId,
outerType = type.outerType?.let { toCirClassTypeOrNull(it) ?: return null }, outerType = outerType?.let { it.toCirClassTypeOrNull(classifiers) ?: return null },
isMarkedNullable = type.isMarkedNullable, isMarkedNullable = isMarkedNullable,
arguments = type.arguments.map { toCirTypeProjection(it) ?: return null }, arguments = arguments.map { it.toCirTypeProjection(classifiers) ?: return null },
visibility = Visibilities.Public, visibility = Visibilities.Public,
) )
} }
internal fun CirProvidedClassifiers.toCirTypeProjection(type: CirProvided.TypeProjection): CirTypeProjection? { internal fun CirProvided.TypeProjection.toCirTypeProjection(classifiers: CirProvidedClassifiers): CirTypeProjection? {
return when (type) { return when (this) {
is CirProvided.StarTypeProjection -> CirStarTypeProjection is CirProvided.StarTypeProjection -> CirStarTypeProjection
is CirProvided.RegularTypeProjection -> toCirRegularTypeProjectionOrNull(type) is CirProvided.RegularTypeProjection -> this.toCirRegularTypeProjectionOrNull(classifiers)
} }
} }
internal fun CirProvidedClassifiers.toCirRegularTypeProjectionOrNull( internal fun CirProvided.RegularTypeProjection.toCirRegularTypeProjectionOrNull(
projection: CirProvided.RegularTypeProjection classifiers: CirProvidedClassifiers
): CirRegularTypeProjection? { ): CirRegularTypeProjection? {
return CirRegularTypeProjection( return CirRegularTypeProjection(
projectionKind = projection.variance, projectionKind = variance,
type = when (val type = projection.type) { type = when (val type = type) {
is CirProvided.ClassOrTypeAliasType -> toCirClassOrTypeAliasTypeOrNull(type) ?: return null is CirProvided.ClassOrTypeAliasType -> type.toCirClassOrTypeAliasTypeOrNull(classifiers) ?: return null
is CirProvided.TypeParameterType -> CirTypeParameterType.createInterned(type.index, type.isMarkedNullable) is CirProvided.TypeParameterType -> CirTypeParameterType.createInterned(type.index, type.isMarkedNullable)
} }
) )
@@ -49,7 +49,7 @@ internal class SimpleCirSupertypesResolver(
private fun CirProvidedClassifiers.supertypesFromProvidedClass(type: CirClassType, classifier: CirProvided.Class): Set<CirClassType> { private fun CirProvidedClassifiers.supertypesFromProvidedClass(type: CirClassType, classifier: CirProvided.Class): Set<CirClassType> {
return classifier.supertypes.filterIsInstance<CirProvided.ClassType>() return classifier.supertypes.filterIsInstance<CirProvided.ClassType>()
.mapNotNull { superType -> toCirClassTypeOrNull(superType) } .mapNotNull { superType -> superType.toCirClassTypeOrNull(this) }
.mapNotNull { superType -> buildSupertypeFromClassifierSupertype(type, superType) } .mapNotNull { superType -> buildSupertypeFromClassifierSupertype(type, superType) }
.toSet() .toSet()
} }
@@ -65,8 +65,7 @@ internal class ClassOrTypeAliasTypeCommonizer(
typeAliasId = classifierId, typeAliasId = classifierId,
arguments = arguments, arguments = arguments,
isMarkedNullable = isMarkedNullable, isMarkedNullable = isMarkedNullable,
underlyingType = classifiers.commonDependencies underlyingType = dependencyClassifier.underlyingType.toCirClassOrTypeAliasTypeOrNull(classifiers.commonDependencies)
.toCirClassOrTypeAliasTypeOrNull(dependencyClassifier.underlyingType)
?.withParentArguments(arguments, isMarkedNullable) ?: return null ?.withParentArguments(arguments, isMarkedNullable) ?: return null
) )
@@ -181,7 +180,7 @@ internal class ClassOrTypeAliasTypeCommonizer(
return CirTypeAliasType.createInterned( return CirTypeAliasType.createInterned(
destinationTypeAliasId, destinationTypeAliasId,
underlyingType = providedClassifiers.toCirClassOrTypeAliasTypeOrNull(destinationTypeAlias.underlyingType) ?: return null, underlyingType = destinationTypeAlias.underlyingType.toCirClassOrTypeAliasTypeOrNull(providedClassifiers) ?: return null,
arguments = emptyList(), arguments = emptyList(),
isMarkedNullable = sourceType.isMarkedNullable isMarkedNullable = sourceType.isMarkedNullable
) )