Get rid of ConeAbbreviatedType::directExpansion
It becomes necessary after extracting supertypes resolution into a separate phase. But also it looks reasonable because direct expansion actually depends on the module we are looking from.
This commit is contained in:
@@ -104,8 +104,6 @@ abstract class ConeClassType : ConeClassLikeType()
|
||||
|
||||
abstract class ConeAbbreviatedType : ConeClassLikeType() {
|
||||
abstract val abbreviationLookupTag: ConeClassLikeLookupTag
|
||||
|
||||
abstract val directExpansion: ConeClassLikeType
|
||||
}
|
||||
|
||||
abstract class ConeTypeParameterType : ConeLookupTagBasedType() {
|
||||
|
||||
@@ -20,7 +20,6 @@ open class ConeClassTypeImpl(
|
||||
class ConeAbbreviatedTypeImpl(
|
||||
override val abbreviationLookupTag: ConeClassLikeLookupTag,
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>,
|
||||
override val directExpansion: ConeClassLikeType,
|
||||
isNullable: Boolean
|
||||
) : ConeAbbreviatedType() {
|
||||
override val lookupTag: ConeClassLikeLookupTag
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ class FirTypeDeserializer(
|
||||
|
||||
val abbreviatedTypeProto = proto.abbreviatedType(typeTable) ?: return simpleType
|
||||
|
||||
return ConeAbbreviatedTypeImpl(typeSymbol(abbreviatedTypeProto) as ConeClassLikeLookupTag, arguments, simpleType, isNullable = false)
|
||||
return ConeAbbreviatedTypeImpl(typeSymbol(abbreviatedTypeProto) as ConeClassLikeLookupTag, arguments, isNullable = false)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.types.impl.ConeAbbreviatedTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
inline fun <K, V, VA : V> MutableMap<K, V>.getOrPut(key: K, defaultValue: (K) -> VA, postCompute: (VA) -> Unit): V {
|
||||
val value = get(key)
|
||||
@@ -31,6 +32,11 @@ inline fun <K, V, VA : V> MutableMap<K, V>.getOrPut(key: K, defaultValue: (K) ->
|
||||
fun ConeClassLikeLookupTag.toSymbol(useSiteSession: FirSession): ConeClassifierSymbol? =
|
||||
useSiteSession.getService(FirSymbolProvider::class).getSymbolByLookupTag(this)
|
||||
|
||||
fun ConeAbbreviatedType.directExpansionType(useSiteSession: FirSession): ConeClassLikeType? =
|
||||
abbreviationLookupTag
|
||||
.toSymbol(useSiteSession)
|
||||
?.safeAs<FirTypeAliasSymbol>()?.fir?.expandedConeType
|
||||
|
||||
fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): ConeClassifierSymbol? =
|
||||
when (this) {
|
||||
is ConeClassLikeLookupTag -> toSymbol(useSiteSession)
|
||||
@@ -51,7 +57,6 @@ fun ConeClassifierSymbol.constructType(typeArguments: Array<ConeKotlinTypeProjec
|
||||
ConeAbbreviatedTypeImpl(
|
||||
abbreviationLookupTag = this.toLookupTag(),
|
||||
typeArguments = typeArguments,
|
||||
directExpansion = fir.expandedConeType ?: ConeClassErrorType("Unresolved expansion"),
|
||||
isNullable = isNullable
|
||||
)
|
||||
}
|
||||
|
||||
+9
-7
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
||||
import org.jetbrains.kotlin.fir.resolve.directExpansionType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
||||
@@ -20,6 +21,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeAbbreviatedType
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: Boolean) : FirAbstractTreeTransformer() {
|
||||
protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
|
||||
@@ -47,10 +49,10 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
||||
}
|
||||
}
|
||||
|
||||
private tailrec fun ConeClassLikeType.computePartialExpansion(): ConeClassLikeType? {
|
||||
private tailrec fun ConeClassLikeType.computePartialExpansion(useSiteSession: FirSession): ConeClassLikeType? {
|
||||
return when (this) {
|
||||
is ConeAbbreviatedType -> directExpansion.takeIf { it !is ConeClassErrorType }?.computePartialExpansion()
|
||||
else -> return this
|
||||
is ConeAbbreviatedType -> directExpansionType(useSiteSession)?.computePartialExpansion(useSiteSession)
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +64,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
||||
is FirClassSymbol -> {
|
||||
val superClassType =
|
||||
fir.superConeTypes
|
||||
.map { it.computePartialExpansion() }
|
||||
.map { it.computePartialExpansion(useSiteSession) }
|
||||
.firstOrNull {
|
||||
it !is ConeClassErrorType &&
|
||||
(it?.lookupTag?.toSymbol(useSiteSession) as? FirClassSymbol)?.fir?.classKind == ClassKind.CLASS
|
||||
@@ -71,7 +73,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
||||
superClassType.lookupTag.toSymbol(useSiteSession)?.collectSuperClasses(list, useSiteSession)
|
||||
}
|
||||
is FirTypeAliasSymbol -> {
|
||||
val expansion = fir.expandedConeType?.computePartialExpansion() ?: return
|
||||
val expansion = fir.expandedConeType?.computePartialExpansion(useSiteSession) ?: return
|
||||
expansion.lookupTag.toSymbol(useSiteSession)?.collectSuperClasses(list, useSiteSession)
|
||||
}
|
||||
else -> error("?!id:1")
|
||||
@@ -86,7 +88,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
||||
when (this) {
|
||||
is FirClassSymbol -> {
|
||||
val superClassTypes =
|
||||
fir.superConeTypes.mapNotNull { it.computePartialExpansion() }
|
||||
fir.superConeTypes.mapNotNull { it.computePartialExpansion(useSiteSession) }
|
||||
list += superClassTypes
|
||||
if (deep)
|
||||
superClassTypes.forEach {
|
||||
@@ -96,7 +98,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
||||
}
|
||||
}
|
||||
is FirTypeAliasSymbol -> {
|
||||
val expansion = fir.expandedConeType?.computePartialExpansion() ?: return
|
||||
val expansion = fir.expandedConeType?.computePartialExpansion(useSiteSession) ?: return
|
||||
expansion.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes(list, deep, useSiteSession)
|
||||
}
|
||||
else -> error("?!id:1")
|
||||
|
||||
-1
@@ -71,7 +71,6 @@ class FirClassSubstitutionScope(
|
||||
is ConeAbbreviatedTypeImpl -> ConeAbbreviatedTypeImpl(
|
||||
abbreviationLookupTag,
|
||||
newArguments as Array<ConeKotlinTypeProjection>,
|
||||
directExpansion.substitute() as? ConeClassLikeType ?: directExpansion,
|
||||
nullability.isNullable
|
||||
)
|
||||
is ConeFunctionType -> TODO("Substitute function type properly")
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||
@@ -93,7 +92,6 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
|
||||
is ConeAbbreviatedType -> ConeAbbreviatedTypeImpl(
|
||||
lookupTag,
|
||||
typeArguments,
|
||||
directExpansion,
|
||||
nullable
|
||||
)
|
||||
is ConeFunctionType -> ConeFunctionTypeImpl(
|
||||
@@ -267,4 +265,4 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
|
||||
override fun SimpleTypeMarker.isSingleClassifierType(): Boolean {
|
||||
TODO("not implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ FILE: NestedOfAliasedType.kt
|
||||
|
||||
}
|
||||
public final typealias TA = R|A|
|
||||
public final class B : R|TA = A| {
|
||||
public constructor(): super<R|TA = A|>()
|
||||
public final class B : R|TA| {
|
||||
public constructor(): super<R|TA|>()
|
||||
|
||||
public final class NestedInB : R|A.Nested| {
|
||||
public constructor(): super<R|A.Nested|>()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
FILE: TypeAliasExpansion.kt
|
||||
public final class MyClass : R|b/TA = b/A| {
|
||||
public constructor(): super<R|b/TA = b/A|>()
|
||||
public final class MyClass : R|b/TA| {
|
||||
public constructor(): super<R|b/TA|>()
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ FILE: simpleTypeAlias.kt
|
||||
public abstract interface B {
|
||||
}
|
||||
public final typealias C = R|B|
|
||||
public final class D : R|C = B| {
|
||||
public final class D : R|C| {
|
||||
public constructor(): super<R|kotlin/Any|>()
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ FILE: typeAliasWithGeneric.kt
|
||||
}
|
||||
<S, T : R|A|> public abstract interface B {
|
||||
}
|
||||
public final class D : R|C<A> = B<T, A>| {
|
||||
public final class D : R|C<A>| {
|
||||
public constructor(): super<R|kotlin/Any|>()
|
||||
|
||||
}
|
||||
|
||||
@@ -636,9 +636,6 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
||||
}
|
||||
})
|
||||
}
|
||||
if (this is ConeAbbreviatedType) {
|
||||
sb.append(" = ${this.directExpansion.asString()}")
|
||||
}
|
||||
sb.toString()
|
||||
}
|
||||
is ConeTypeParameterType -> {
|
||||
|
||||
Reference in New Issue
Block a user