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 class ConeAbbreviatedType : ConeClassLikeType() {
|
||||||
abstract val abbreviationLookupTag: ConeClassLikeLookupTag
|
abstract val abbreviationLookupTag: ConeClassLikeLookupTag
|
||||||
|
|
||||||
abstract val directExpansion: ConeClassLikeType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ConeTypeParameterType : ConeLookupTagBasedType() {
|
abstract class ConeTypeParameterType : ConeLookupTagBasedType() {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ open class ConeClassTypeImpl(
|
|||||||
class ConeAbbreviatedTypeImpl(
|
class ConeAbbreviatedTypeImpl(
|
||||||
override val abbreviationLookupTag: ConeClassLikeLookupTag,
|
override val abbreviationLookupTag: ConeClassLikeLookupTag,
|
||||||
override val typeArguments: Array<out ConeKotlinTypeProjection>,
|
override val typeArguments: Array<out ConeKotlinTypeProjection>,
|
||||||
override val directExpansion: ConeClassLikeType,
|
|
||||||
isNullable: Boolean
|
isNullable: Boolean
|
||||||
) : ConeAbbreviatedType() {
|
) : ConeAbbreviatedType() {
|
||||||
override val lookupTag: ConeClassLikeLookupTag
|
override val lookupTag: ConeClassLikeLookupTag
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ class FirTypeDeserializer(
|
|||||||
|
|
||||||
val abbreviatedTypeProto = proto.abbreviatedType(typeTable) ?: return simpleType
|
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.ConeClassTypeImpl
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||||
import org.jetbrains.kotlin.types.Variance
|
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 {
|
inline fun <K, V, VA : V> MutableMap<K, V>.getOrPut(key: K, defaultValue: (K) -> VA, postCompute: (VA) -> Unit): V {
|
||||||
val value = get(key)
|
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? =
|
fun ConeClassLikeLookupTag.toSymbol(useSiteSession: FirSession): ConeClassifierSymbol? =
|
||||||
useSiteSession.getService(FirSymbolProvider::class).getSymbolByLookupTag(this)
|
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? =
|
fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): ConeClassifierSymbol? =
|
||||||
when (this) {
|
when (this) {
|
||||||
is ConeClassLikeLookupTag -> toSymbol(useSiteSession)
|
is ConeClassLikeLookupTag -> toSymbol(useSiteSession)
|
||||||
@@ -51,7 +57,6 @@ fun ConeClassifierSymbol.constructType(typeArguments: Array<ConeKotlinTypeProjec
|
|||||||
ConeAbbreviatedTypeImpl(
|
ConeAbbreviatedTypeImpl(
|
||||||
abbreviationLookupTag = this.toLookupTag(),
|
abbreviationLookupTag = this.toLookupTag(),
|
||||||
typeArguments = typeArguments,
|
typeArguments = typeArguments,
|
||||||
directExpansion = fir.expandedConeType ?: ConeClassErrorType("Unresolved expansion"),
|
|
||||||
isNullable = isNullable
|
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.FirRegularClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||||
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
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.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
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.ConeAbbreviatedType
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: Boolean) : FirAbstractTreeTransformer() {
|
abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: Boolean) : FirAbstractTreeTransformer() {
|
||||||
protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
|
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) {
|
return when (this) {
|
||||||
is ConeAbbreviatedType -> directExpansion.takeIf { it !is ConeClassErrorType }?.computePartialExpansion()
|
is ConeAbbreviatedType -> directExpansionType(useSiteSession)?.computePartialExpansion(useSiteSession)
|
||||||
else -> return this
|
else -> this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
|||||||
is FirClassSymbol -> {
|
is FirClassSymbol -> {
|
||||||
val superClassType =
|
val superClassType =
|
||||||
fir.superConeTypes
|
fir.superConeTypes
|
||||||
.map { it.computePartialExpansion() }
|
.map { it.computePartialExpansion(useSiteSession) }
|
||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
it !is ConeClassErrorType &&
|
it !is ConeClassErrorType &&
|
||||||
(it?.lookupTag?.toSymbol(useSiteSession) as? FirClassSymbol)?.fir?.classKind == ClassKind.CLASS
|
(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)
|
superClassType.lookupTag.toSymbol(useSiteSession)?.collectSuperClasses(list, useSiteSession)
|
||||||
}
|
}
|
||||||
is FirTypeAliasSymbol -> {
|
is FirTypeAliasSymbol -> {
|
||||||
val expansion = fir.expandedConeType?.computePartialExpansion() ?: return
|
val expansion = fir.expandedConeType?.computePartialExpansion(useSiteSession) ?: return
|
||||||
expansion.lookupTag.toSymbol(useSiteSession)?.collectSuperClasses(list, useSiteSession)
|
expansion.lookupTag.toSymbol(useSiteSession)?.collectSuperClasses(list, useSiteSession)
|
||||||
}
|
}
|
||||||
else -> error("?!id:1")
|
else -> error("?!id:1")
|
||||||
@@ -86,7 +88,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
|||||||
when (this) {
|
when (this) {
|
||||||
is FirClassSymbol -> {
|
is FirClassSymbol -> {
|
||||||
val superClassTypes =
|
val superClassTypes =
|
||||||
fir.superConeTypes.mapNotNull { it.computePartialExpansion() }
|
fir.superConeTypes.mapNotNull { it.computePartialExpansion(useSiteSession) }
|
||||||
list += superClassTypes
|
list += superClassTypes
|
||||||
if (deep)
|
if (deep)
|
||||||
superClassTypes.forEach {
|
superClassTypes.forEach {
|
||||||
@@ -96,7 +98,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is FirTypeAliasSymbol -> {
|
is FirTypeAliasSymbol -> {
|
||||||
val expansion = fir.expandedConeType?.computePartialExpansion() ?: return
|
val expansion = fir.expandedConeType?.computePartialExpansion(useSiteSession) ?: return
|
||||||
expansion.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes(list, deep, useSiteSession)
|
expansion.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes(list, deep, useSiteSession)
|
||||||
}
|
}
|
||||||
else -> error("?!id:1")
|
else -> error("?!id:1")
|
||||||
|
|||||||
-1
@@ -71,7 +71,6 @@ class FirClassSubstitutionScope(
|
|||||||
is ConeAbbreviatedTypeImpl -> ConeAbbreviatedTypeImpl(
|
is ConeAbbreviatedTypeImpl -> ConeAbbreviatedTypeImpl(
|
||||||
abbreviationLookupTag,
|
abbreviationLookupTag,
|
||||||
newArguments as Array<ConeKotlinTypeProjection>,
|
newArguments as Array<ConeKotlinTypeProjection>,
|
||||||
directExpansion.substitute() as? ConeClassLikeType ?: directExpansion,
|
|
||||||
nullability.isNullable
|
nullability.isNullable
|
||||||
)
|
)
|
||||||
is ConeFunctionType -> TODO("Substitute function type properly")
|
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.expandedConeType
|
||||||
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
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.ConeClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||||
@@ -93,7 +92,6 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
|
|||||||
is ConeAbbreviatedType -> ConeAbbreviatedTypeImpl(
|
is ConeAbbreviatedType -> ConeAbbreviatedTypeImpl(
|
||||||
lookupTag,
|
lookupTag,
|
||||||
typeArguments,
|
typeArguments,
|
||||||
directExpansion,
|
|
||||||
nullable
|
nullable
|
||||||
)
|
)
|
||||||
is ConeFunctionType -> ConeFunctionTypeImpl(
|
is ConeFunctionType -> ConeFunctionTypeImpl(
|
||||||
@@ -267,4 +265,4 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
|
|||||||
override fun SimpleTypeMarker.isSingleClassifierType(): Boolean {
|
override fun SimpleTypeMarker.isSingleClassifierType(): Boolean {
|
||||||
TODO("not implemented")
|
TODO("not implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ FILE: NestedOfAliasedType.kt
|
|||||||
|
|
||||||
}
|
}
|
||||||
public final typealias TA = R|A|
|
public final typealias TA = R|A|
|
||||||
public final class B : R|TA = A| {
|
public final class B : R|TA| {
|
||||||
public constructor(): super<R|TA = A|>()
|
public constructor(): super<R|TA|>()
|
||||||
|
|
||||||
public final class NestedInB : R|A.Nested| {
|
public final class NestedInB : R|A.Nested| {
|
||||||
public constructor(): super<R|A.Nested|>()
|
public constructor(): super<R|A.Nested|>()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FILE: TypeAliasExpansion.kt
|
FILE: TypeAliasExpansion.kt
|
||||||
public final class MyClass : R|b/TA = b/A| {
|
public final class MyClass : R|b/TA| {
|
||||||
public constructor(): super<R|b/TA = b/A|>()
|
public constructor(): super<R|b/TA|>()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ FILE: simpleTypeAlias.kt
|
|||||||
public abstract interface B {
|
public abstract interface B {
|
||||||
}
|
}
|
||||||
public final typealias C = R|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|>()
|
public constructor(): super<R|kotlin/Any|>()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ FILE: typeAliasWithGeneric.kt
|
|||||||
}
|
}
|
||||||
<S, T : R|A|> public abstract interface B {
|
<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|>()
|
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()
|
sb.toString()
|
||||||
}
|
}
|
||||||
is ConeTypeParameterType -> {
|
is ConeTypeParameterType -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user