[FIR] Add containingDeclarationSymbol to FirTypeParameter

This commit is contained in:
Ivan Kochurkin
2021-07-08 22:31:59 +03:00
committed by TeamCityServer
parent 0c25d280ee
commit 345152d198
11 changed files with 148 additions and 81 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub
import org.jetbrains.kotlin.fir.resolve.defaultType
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
@@ -62,7 +63,8 @@ class FirDeserializationContext(
containerSource: DeserializedContainerSource? = this.containerSource,
outerClassSymbol: FirRegularClassSymbol? = this.outerClassSymbol,
annotationDeserializer: AbstractAnnotationDeserializer = this.annotationDeserializer,
capturesTypeParameters: Boolean = true
capturesTypeParameters: Boolean = true,
containingDeclarationSymbol: FirBasedSymbol<*>? = this.outerClassSymbol
): FirDeserializationContext = FirDeserializationContext(
nameResolver,
typeTable,
@@ -70,7 +72,15 @@ class FirDeserializationContext(
moduleData,
packageFqName,
relativeClassName,
FirTypeDeserializer(moduleData, nameResolver, typeTable, annotationDeserializer, typeParameterProtos, typeDeserializer),
FirTypeDeserializer(
moduleData,
nameResolver,
typeTable,
annotationDeserializer,
typeParameterProtos,
typeDeserializer,
containingDeclarationSymbol
),
annotationDeserializer,
constDeserializer,
containerSource,
@@ -101,7 +111,8 @@ class FirDeserializationContext(
relativeClassName = null,
typeParameterProtos = emptyList(),
containerSource,
outerClassSymbol = null
outerClassSymbol = null,
containingDeclarationSymbol = null
)
fun createForClass(
@@ -124,6 +135,7 @@ class FirDeserializationContext(
classId.relativeClassName,
classProto.typeParameterList,
containerSource,
outerClassSymbol,
outerClassSymbol
)
@@ -139,6 +151,7 @@ class FirDeserializationContext(
typeParameterProtos: List<ProtoBuf.TypeParameter>,
containerSource: DeserializedContainerSource?,
outerClassSymbol: FirRegularClassSymbol?,
containingDeclarationSymbol: FirBasedSymbol<*>?
): FirDeserializationContext {
return FirDeserializationContext(
nameResolver, typeTable,
@@ -152,7 +165,8 @@ class FirDeserializationContext(
typeTable,
annotationDeserializer,
typeParameterProtos,
null
null,
containingDeclarationSymbol
),
annotationDeserializer,
constDeserializer,
@@ -176,8 +190,9 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
fun loadTypeAlias(proto: ProtoBuf.TypeAlias): FirTypeAlias {
val flags = proto.flags
val name = c.nameResolver.getName(proto.name)
val local = c.childContext(proto.typeParameterList)
val classId = ClassId(c.packageFqName, name)
val symbol = FirTypeAliasSymbol(classId)
val local = c.childContext(proto.typeParameterList, containingDeclarationSymbol = symbol)
return buildTypeAlias {
moduleData = c.moduleData
origin = FirDeclarationOrigin.Library
@@ -193,7 +208,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
}
annotations += c.annotationDeserializer.loadTypeAliasAnnotations(proto, local.nameResolver)
symbol = FirTypeAliasSymbol(classId)
this.symbol = symbol
expandedTypeRef = proto.underlyingType(c.typeTable).toTypeRef(local)
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
@@ -212,7 +227,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
val callableName = c.nameResolver.getName(proto.name)
val callableId = CallableId(c.packageFqName, c.relativeClassName, callableName)
val symbol = FirPropertySymbol(callableId)
val local = c.childContext(proto.typeParameterList)
val local = c.childContext(proto.typeParameterList, containingDeclarationSymbol = symbol)
// Per documentation on Property.getter_flags in metadata.proto, if an accessor flags field is absent, its value should be computed
// by taking hasAnnotations/visibility/modality from property flags, and using false for the rest
@@ -381,7 +396,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
val callableName = c.nameResolver.getName(proto.name)
val callableId = CallableId(c.packageFqName, c.relativeClassName, callableName)
val symbol = FirNamedFunctionSymbol(callableId)
val local = c.childContext(proto.typeParameterList)
val local = c.childContext(proto.typeParameterList, containingDeclarationSymbol = symbol)
val simpleFunction = buildSimpleFunction {
moduleData = c.moduleData
@@ -443,7 +458,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
val relativeClassName = c.relativeClassName!!
val callableId = CallableId(c.packageFqName, relativeClassName, relativeClassName.shortName())
val symbol = FirConstructorSymbol(callableId)
val local = c.childContext(emptyList())
val local = c.childContext(emptyList(), containingDeclarationSymbol = symbol)
val isPrimary = !Flags.IS_SECONDARY.get(flags)
val typeParameters = classBuilder.typeParameters
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
@@ -43,7 +44,8 @@ class FirTypeDeserializer(
val typeTable: TypeTable,
val annotationDeserializer: AbstractAnnotationDeserializer,
typeParameterProtos: List<ProtoBuf.TypeParameter>,
val parent: FirTypeDeserializer?
val parent: FirTypeDeserializer?,
val containingSymbol: FirBasedSymbol<*>?
) {
private val typeParameterDescriptors: Map<Int, FirTypeParameterSymbol> = if (typeParameterProtos.isNotEmpty()) {
LinkedHashMap<Int, FirTypeParameterSymbol>()
@@ -73,6 +75,7 @@ class FirTypeDeserializer(
origin = FirDeclarationOrigin.Library
this.name = name
this.symbol = symbol
this.containingDeclarationSymbol = containingSymbol
variance = proto.variance.convertVariance()
isReified = proto.reified
}
@@ -229,6 +229,7 @@ private class SyntheticFunctionalInterfaceCache(private val moduleData: FirModul
origin = FirDeclarationOrigin.BuiltIns
name = Name.identifier("P$it")
symbol = FirTypeParameterSymbol()
containingDeclarationSymbol = this@symbol
variance = Variance.IN_VARIANCE
isReified = false
bounds += moduleData.session.builtinTypes.nullableAnyType
@@ -242,6 +243,7 @@ private class SyntheticFunctionalInterfaceCache(private val moduleData: FirModul
origin = FirDeclarationOrigin.BuiltIns
name = Name.identifier("R")
symbol = FirTypeParameterSymbol()
containingDeclarationSymbol = this@symbol
variance = Variance.OUT_VARIANCE
isReified = false
bounds += moduleData.session.builtinTypes.nullableAnyType