Change lookup tags from interfaces to abstract classes

This commit is contained in:
Simon Ogorodnik
2019-06-04 14:36:23 +03:00
committed by Mikhail Glukhikh
parent a10deb5f69
commit 146a53f18c
16 changed files with 37 additions and 34 deletions
@@ -8,30 +8,33 @@ package org.jetbrains.kotlin.fir.symbols
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
interface ConeClassifierLookupTag {
val name: Name
abstract class ConeClassifierLookupTag {
abstract val name: Name
}
interface ConeClassifierLookupTagWithFixedSymbol {
val symbol: ConeClassifierSymbol
abstract class ConeClassifierLookupTagWithFixedSymbol : ConeClassifierLookupTag() {
abstract val symbol: ConeClassifierSymbol
}
interface ConeTypeParameterLookupTag : ConeClassifierLookupTag {
override val name: Name
data class ConeTypeParameterLookupTag(val typeParameterSymbol: ConeTypeParameterSymbol) : ConeClassifierLookupTagWithFixedSymbol() {
override val name: Name get() = typeParameterSymbol.name
override val symbol: ConeClassifierSymbol
get() = typeParameterSymbol
}
interface ConeClassLikeLookupTag : ConeClassifierLookupTag {
val classId: ClassId
abstract class ConeClassLikeLookupTag : ConeClassifierLookupTag() {
abstract val classId: ClassId
override val name: Name
get() = classId.shortClassName
}
interface ConeTypeAliasLookupTag : ConeClassLikeLookupTag
abstract class ConeTypeAliasLookupTag : ConeClassLikeLookupTag()
interface ConeClassLookupTag : ConeClassLikeLookupTag
abstract class ConeClassLookupTag : ConeClassLikeLookupTag()
class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeLookupTag {
class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeLookupTag() {
var boundSymbol: Pair<*, *>? = null
override fun equals(other: Any?): Boolean {
@@ -16,8 +16,9 @@ interface ConeClassifierSymbol : ConeSymbol, TypeParameterMarker {
fun toLookupTag(): ConeClassifierLookupTag
}
interface ConeTypeParameterSymbol : ConeClassifierSymbol, ConeTypeParameterLookupTag {
override fun toLookupTag(): ConeTypeParameterLookupTag = this
interface ConeTypeParameterSymbol : ConeClassifierSymbol {
override fun toLookupTag(): ConeTypeParameterLookupTag = ConeTypeParameterLookupTag(this)
val name: Name
}
interface ConeClassLikeSymbol : ConeClassifierSymbol, TypeConstructorMarker {
@@ -220,7 +220,8 @@ class JavaSymbolProvider(
FirResolvedTypeRefImpl(
this@JavaSymbolProvider.session, null,
firSymbol.constructType(
classTypeParameters.map { ConeTypeParameterTypeImpl(it.symbol, false) }.toTypedArray(), false
classTypeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }.toTypedArray(),
false
)
)
).apply {
@@ -160,7 +160,7 @@ internal fun JavaClassifierType.toConeKotlinTypeWithNullability(
}
is JavaTypeParameter -> {
val symbol = javaTypeParameterStack[classifier]
ConeTypeParameterTypeImpl(symbol, isNullable)
ConeTypeParameterTypeImpl(symbol.toLookupTag(), isNullable)
}
else -> ConeClassErrorType(reason = "Unexpected classifier: $classifier")
}
@@ -149,7 +149,7 @@ private fun JavaClassifierType.enhanceInflexibleType(
val kotlinClassId = mappedId ?: classId
ConeClassLikeLookupTagImpl(kotlinClassId)
}
is JavaTypeParameter -> javaTypeParameterStack[classifier]
is JavaTypeParameter -> javaTypeParameterStack[classifier].toLookupTag()
else -> return toNotNullConeKotlinType(session, javaTypeParameterStack)
}
@@ -73,7 +73,7 @@ class JavaClassUseSiteScope(
if (overriddenInJava.typeParameters.size != base.typeParameters.size) return false
val types = base.typeParameters.map {
ConeTypeParameterTypeImpl(it.symbol, false)
ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false)
}
val substitution = ConeSubstitutorByMap(overriddenInJava.typeParameters.map { it.symbol }.zip(types).toMap())
if (!overriddenInJava.typeParameters.zip(base.typeParameters).all { (a, b) ->
@@ -450,7 +450,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
this,
ConeClassTypeImpl(
firClass.symbol.toLookupTag(),
typeParameters.map { ConeTypeParameterTypeImpl(it.symbol, false) }.toTypedArray(),
typeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }.toTypedArray(),
false
)
)
@@ -732,7 +732,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) {
private fun typeParametersFromSelfType(delegatedSelfTypeRef: FirTypeRef): List<FirTypeParameter> {
return delegatedSelfTypeRef.coneTypeSafe<ConeKotlinType>()
?.typeArguments
?.map { ((it as ConeTypeParameterType).lookupTag as FirTypeParameterSymbol).fir }
?.map { ((it as ConeTypeParameterType).lookupTag.symbol as FirTypeParameterSymbol).fir }
?: emptyList()
}
@@ -247,7 +247,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
null,
ConeClassTypeImpl(
klass.symbol.toLookupTag(),
typeParameters.map { ConeTypeParameterTypeImpl(it.symbol, false) }.toTypedArray(),
typeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }.toTypedArray(),
false
)
)
@@ -57,7 +57,7 @@ class FirTypeDeserializer(
private fun typeParameterSymbol(typeParameterId: Int): ConeTypeParameterLookupTag? =
typeParameterDescriptors[typeParameterId] ?: parent?.typeParameterSymbol(typeParameterId)
typeParameterDescriptors[typeParameterId]?.toLookupTag() ?: parent?.typeParameterSymbol(typeParameterId)
private fun ProtoBuf.TypeParameter.Variance.convertVariance(): Variance {
@@ -150,7 +150,7 @@ class FirTypeDeserializer(
val name = nameResolver.getString(proto.typeParameterName)
// TODO: Optimize
ownTypeParameters.find { it.name.asString() == name }
ownTypeParameters.find { it.name.asString() == name }?.toLookupTag()
}
else -> null
}
@@ -48,7 +48,7 @@ fun ConeAbbreviatedType.directExpansionType(useSiteSession: FirSession): ConeCla
fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): ConeClassifierSymbol? =
when (this) {
is ConeClassLikeLookupTag -> toSymbol(useSiteSession)
is ConeTypeParameterSymbol -> this
is ConeTypeParameterLookupTag -> this.symbol
else -> error("sealed ${this::class}")
}
@@ -67,7 +67,7 @@ fun ConeClassifierLookupTag.constructType(typeArguments: Array<ConeKotlinTypePro
fun ConeClassifierSymbol.constructType(typeArguments: Array<ConeKotlinTypeProjection>, isNullable: Boolean): ConeLookupTagBasedType {
return when (this) {
is ConeTypeParameterSymbol -> {
ConeTypeParameterTypeImpl(this, isNullable)
ConeTypeParameterTypeImpl(this.toLookupTag(), isNullable)
}
is ConeClassSymbol -> {
ConeClassTypeImpl(this.toLookupTag(), typeArguments, isNullable)
@@ -34,7 +34,7 @@ fun ConeInferenceContext.hasNullableSuperType(type: ConeKotlinType): Boolean {
return false
}
class ConeTypeVariableTypeConstructor(val debugName: String) : ConeSymbol, ConeClassifierLookupTag, TypeVariableTypeConstructorMarker {
class ConeTypeVariableTypeConstructor(val debugName: String) : ConeSymbol, ConeClassifierLookupTag(), TypeVariableTypeConstructorMarker {
override val name: Name get() = Name.identifier(debugName)
}
@@ -134,6 +134,6 @@ class ConeSubstitutorByMap(val substitution: Map<ConeTypeParameterSymbol, ConeKo
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeTypeParameterType) return null
return makeNullableIfNeed(type.isMarkedNullable, substitution[type.lookupTag])
return makeNullableIfNeed(type.isMarkedNullable, substitution[type.lookupTag.symbol])
}
}
@@ -39,7 +39,7 @@ class FirCallCompleterTransformer(
val subCandidate = calleeReference.candidate
val declaration = subCandidate.symbol.firUnsafe<FirCallableMemberDeclaration>()
val newTypeParameters = declaration.typeParameters.map { ConeTypeParameterTypeImpl(it.symbol, false) }
val newTypeParameters = declaration.typeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }
.map { subCandidate.substitutor.substituteOrSelf(it) }
.map { finalSubstitutor.substituteOrSelf(it) }
.mapIndexed { index, type ->
@@ -36,7 +36,7 @@ abstract class AbstractFirOverrideScope(val session: FirSession) : FirScope {
if (member.typeParameters.size != self.typeParameters.size) return false
val types = self.typeParameters.map {
ConeTypeParameterTypeImpl(it.symbol, false)
ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false)
}
val substitution = ConeSubstitutorByMap(member.typeParameters.map { it.symbol }.zip(types).toMap())
if (!member.typeParameters.zip(self.typeParameters).all { (a, b) ->
@@ -30,4 +30,4 @@ class FirTypeAliasSymbol(
class TypeAliasLookupTagImpl(
override val classId: ClassId
) : ConeTypeAliasLookupTag
) : ConeTypeAliasLookupTag()
@@ -9,16 +9,14 @@ import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.name.Name
class FirTypeParameterSymbol : AbstractFirBasedSymbol<FirTypeParameter>(), ConeTypeParameterSymbol, ConeTypeParameterLookupTag,
ConeClassifierLookupTagWithFixedSymbol {
class FirTypeParameterSymbol : AbstractFirBasedSymbol<FirTypeParameter>(), ConeTypeParameterSymbol {
override val name: Name
get() = fir.name
override val symbol: ConeClassifierSymbol
get() = this
private val lookupTag = ConeTypeParameterLookupTag(this)
override fun toLookupTag(): ConeTypeParameterLookupTag = this
override fun toLookupTag(): ConeTypeParameterLookupTag = lookupTag
override fun equals(other: Any?): Boolean {
return other is FirTypeParameterSymbol && fir == other.fir