FIR: refactor cone types (arguments, projections)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
02bedeca05
commit
6c3fe5dc98
@@ -9,27 +9,46 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterSymbol
|
||||
|
||||
sealed class ConeKotlinTypeProjection(val kind: ProjectionKind)
|
||||
sealed class ConeKotlinTypeProjection {
|
||||
abstract val kind: ProjectionKind
|
||||
|
||||
companion object {
|
||||
val EMPTY_ARRAY = arrayOf<ConeKotlinTypeProjection>()
|
||||
}
|
||||
}
|
||||
|
||||
enum class ProjectionKind {
|
||||
STAR, IN, OUT, INVARIANT
|
||||
}
|
||||
|
||||
object StarProjection : ConeKotlinTypeProjection(ProjectionKind.STAR)
|
||||
|
||||
abstract class ConeKotlinTypeProjectionIn : ConeKotlinTypeProjection(ProjectionKind.IN) {
|
||||
abstract val type: ConeKotlinType
|
||||
object StarProjection : ConeKotlinTypeProjection() {
|
||||
override val kind: ProjectionKind
|
||||
get() = ProjectionKind.STAR
|
||||
}
|
||||
|
||||
abstract class ConeKotlinTypeProjectionOut : ConeKotlinTypeProjection(ProjectionKind.OUT) {
|
||||
abstract val type: ConeKotlinType
|
||||
class ConeKotlinTypeProjectionIn(val type: ConeKotlinType) : ConeKotlinTypeProjection() {
|
||||
override val kind: ProjectionKind
|
||||
get() = ProjectionKind.IN
|
||||
}
|
||||
|
||||
class ConeKotlinTypeProjectionOut(val type: ConeKotlinType) : ConeKotlinTypeProjection() {
|
||||
override val kind: ProjectionKind
|
||||
get() = ProjectionKind.OUT
|
||||
}
|
||||
|
||||
// We assume type IS an invariant type projection to prevent additional wrapper here
|
||||
// (more exactly, invariant type projection contains type)
|
||||
sealed class ConeKotlinType : ConeKotlinTypeProjection(ProjectionKind.INVARIANT)
|
||||
sealed class ConeKotlinType : ConeKotlinTypeProjection() {
|
||||
override val kind: ProjectionKind
|
||||
get() = ProjectionKind.INVARIANT
|
||||
|
||||
abstract val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
}
|
||||
|
||||
class ConeKotlinErrorType(val reason: String) : ConeKotlinType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
|
||||
override fun toString(): String {
|
||||
return "<ERROR TYPE: $reason>"
|
||||
}
|
||||
@@ -38,8 +57,9 @@ class ConeKotlinErrorType(val reason: String) : ConeKotlinType() {
|
||||
class ConeClassErrorType(val reason: String) : ConeClassLikeType() {
|
||||
override val symbol: ConeClassLikeSymbol
|
||||
get() = error("!")
|
||||
override val typeArguments: List<ConeKotlinTypeProjection>
|
||||
get() = emptyList()
|
||||
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
|
||||
override fun toString(): String {
|
||||
return "<ERROR CLASS: $reason>"
|
||||
@@ -52,8 +72,6 @@ sealed class ConeSymbolBasedType : ConeKotlinType() {
|
||||
|
||||
abstract class ConeClassLikeType : ConeSymbolBasedType() {
|
||||
abstract override val symbol: ConeClassLikeSymbol
|
||||
|
||||
abstract val typeArguments: List<ConeKotlinTypeProjection>
|
||||
}
|
||||
|
||||
abstract class ConeAbbreviatedType : ConeClassLikeType() {
|
||||
|
||||
@@ -7,9 +7,13 @@ package org.jetbrains.kotlin.fir.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.types.ConeFunctionType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
|
||||
|
||||
class ConeFunctionTypeImpl(
|
||||
override val receiverType: ConeKotlinType?,
|
||||
override val parameterTypes: List<ConeKotlinType>,
|
||||
override val returnType: ConeKotlinType
|
||||
) : ConeFunctionType()
|
||||
) : ConeFunctionType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
}
|
||||
@@ -11,20 +11,19 @@ import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
open class ConeClassTypeImpl(
|
||||
override val symbol: ConeClassLikeSymbol,
|
||||
override val typeArguments: List<ConeKotlinTypeProjection>
|
||||
override val typeArguments: Array<ConeKotlinTypeProjection>
|
||||
) : ConeClassLikeType()
|
||||
|
||||
class ConeKotlinTypeProjectionInImpl(override val type: ConeKotlinType) : ConeKotlinTypeProjectionIn()
|
||||
|
||||
class ConeKotlinTypeProjectionOutImpl(override val type: ConeKotlinType) : ConeKotlinTypeProjectionOut()
|
||||
|
||||
class ConeAbbreviatedTypeImpl(
|
||||
override val abbreviationSymbol: ConeClassLikeSymbol,
|
||||
override val typeArguments: List<ConeKotlinTypeProjection>,
|
||||
override val typeArguments: Array<ConeKotlinTypeProjection>,
|
||||
override val directExpansion: ConeClassLikeType
|
||||
) : ConeAbbreviatedType() {
|
||||
override val symbol: ConeClassLikeSymbol
|
||||
get() = abbreviationSymbol
|
||||
}
|
||||
|
||||
class ConeTypeParameterTypeImpl(override val symbol: ConeTypeParameterSymbol) : ConeTypeParameterType()
|
||||
class ConeTypeParameterTypeImpl(override val symbol: ConeTypeParameterSymbol) : ConeTypeParameterType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
}
|
||||
+3
-5
@@ -13,8 +13,6 @@ import org.jetbrains.kotlin.fir.symbols.LibraryTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeAbbreviatedTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeKotlinTypeProjectionInImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeKotlinTypeProjectionOutImpl
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
|
||||
@@ -78,7 +76,7 @@ class FirTypeDeserializer(
|
||||
|
||||
val arguments = proto.collectAllArguments().mapIndexed { index, proto ->
|
||||
typeArgument(constructor.typeParameters.getOrNull(index), proto)
|
||||
}.toList()
|
||||
}.toTypedArray()
|
||||
|
||||
val simpleType = if (Flags.SUSPEND_TYPE.get(proto.flags)) {
|
||||
//createSuspendFunctionType(annotations, constructor, arguments, proto.nullable)
|
||||
@@ -121,8 +119,8 @@ class FirTypeDeserializer(
|
||||
val coneType = type(type)
|
||||
return when (projection) {
|
||||
Variance.INVARIANT -> coneType
|
||||
Variance.IN_VARIANCE -> ConeKotlinTypeProjectionInImpl(coneType)
|
||||
Variance.OUT_VARIANCE -> ConeKotlinTypeProjectionOutImpl(coneType)
|
||||
Variance.IN_VARIANCE -> ConeKotlinTypeProjectionIn(coneType)
|
||||
Variance.OUT_VARIANCE -> ConeKotlinTypeProjectionOut(coneType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -25,14 +25,14 @@ class FirTypeResolverImpl : FirTypeResolver {
|
||||
val type = (it.type as FirResolvedType).type
|
||||
when (it.variance) {
|
||||
Variance.INVARIANT -> type
|
||||
Variance.IN_VARIANCE -> ConeKotlinTypeProjectionInImpl(type)
|
||||
Variance.OUT_VARIANCE -> ConeKotlinTypeProjectionOutImpl(type)
|
||||
Variance.IN_VARIANCE -> ConeKotlinTypeProjectionIn(type)
|
||||
Variance.OUT_VARIANCE -> ConeKotlinTypeProjectionOut(type)
|
||||
}
|
||||
}
|
||||
else -> error("!")
|
||||
}
|
||||
}
|
||||
}
|
||||
}.toTypedArray()
|
||||
|
||||
private fun ConeSymbol.toConeKotlinType(parts: List<FirQualifierPart>): ConeKotlinType? {
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedType
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -27,7 +28,7 @@ sealed class FirBuiltinType(
|
||||
Name.identifier(name)
|
||||
)
|
||||
),
|
||||
emptyList()
|
||||
ConeKotlinTypeProjection.EMPTY_ARRAY
|
||||
)
|
||||
|
||||
final override val isNullable = false
|
||||
|
||||
Reference in New Issue
Block a user