[FIR] KT-46968: Remove FirCompositeScope-s from the type resolution
This commit is contained in:
+25
-20
@@ -55,7 +55,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
|
||||
private fun resolveToSymbol(
|
||||
typeRef: FirTypeRef,
|
||||
scope: FirScope,
|
||||
scopes: List<FirScope>,
|
||||
): Pair<FirBasedSymbol<*>?, ConeSubstitutor?> {
|
||||
return when (typeRef) {
|
||||
is FirResolvedTypeRef -> {
|
||||
@@ -68,25 +68,30 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
var resolvedSymbol: FirBasedSymbol<*>? = null
|
||||
var substitutor: ConeSubstitutor? = null
|
||||
val qualifier = typeRef.qualifier
|
||||
scope.processClassifiersByNameWithSubstitution(qualifier.first().name) { symbol, substitutorFromScope ->
|
||||
if (resolvedSymbol != null) return@processClassifiersByNameWithSubstitution
|
||||
resolvedSymbol = when (symbol) {
|
||||
is FirClassLikeSymbol<*> -> {
|
||||
if (qualifier.size == 1) {
|
||||
symbol
|
||||
} else {
|
||||
resolveLocalClassChain(symbol, qualifier)
|
||||
?: qualifierResolver.resolveSymbolWithPrefix(qualifier, symbol.classId)
|
||||
?: qualifierResolver.resolveEnumEntrySymbol(qualifier, symbol.classId)
|
||||
}
|
||||
}
|
||||
is FirTypeParameterSymbol -> {
|
||||
assert(qualifier.size == 1)
|
||||
symbol
|
||||
}
|
||||
else -> error("!")
|
||||
for (scope in scopes) {
|
||||
if (resolvedSymbol != null) {
|
||||
break
|
||||
}
|
||||
scope.processClassifiersByNameWithSubstitution(qualifier.first().name) { symbol, substitutorFromScope ->
|
||||
if (resolvedSymbol != null) return@processClassifiersByNameWithSubstitution
|
||||
resolvedSymbol = when (symbol) {
|
||||
is FirClassLikeSymbol<*> -> {
|
||||
if (qualifier.size == 1) {
|
||||
symbol
|
||||
} else {
|
||||
resolveLocalClassChain(symbol, qualifier)
|
||||
?: qualifierResolver.resolveSymbolWithPrefix(qualifier, symbol.classId)
|
||||
?: qualifierResolver.resolveEnumEntrySymbol(qualifier, symbol.classId)
|
||||
}
|
||||
}
|
||||
is FirTypeParameterSymbol -> {
|
||||
assert(qualifier.size == 1)
|
||||
symbol
|
||||
}
|
||||
else -> error("!")
|
||||
}
|
||||
substitutor = substitutorFromScope
|
||||
}
|
||||
substitutor = substitutorFromScope
|
||||
}
|
||||
|
||||
// TODO: Imports
|
||||
@@ -376,7 +381,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
return when (typeRef) {
|
||||
is FirResolvedTypeRef -> typeRef.type
|
||||
is FirUserTypeRef -> {
|
||||
val (symbol, substitutor) = resolveToSymbol(typeRef, scopeClassDeclaration.scope)
|
||||
val (symbol, substitutor) = resolveToSymbol(typeRef, scopeClassDeclaration.scopes)
|
||||
resolveUserType(
|
||||
typeRef,
|
||||
symbol,
|
||||
|
||||
+4
-2
@@ -67,7 +67,8 @@ class FirSpecificTypeResolverTransformer(
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
override fun transformTypeRef(typeRef: FirTypeRef, data: ScopeClassDeclaration): FirResolvedTypeRef {
|
||||
session.lookupTracker?.recordTypeLookup(typeRef, data.scope.scopeOwnerLookupNames, currentFile?.source)
|
||||
val scopeOwnerLookupNames = data.scopes.flatMap { it.scopeOwnerLookupNames }
|
||||
session.lookupTracker?.recordTypeLookup(typeRef, scopeOwnerLookupNames, currentFile?.source)
|
||||
typeRef.transformChildren(this, data)
|
||||
return transformType(typeRef, typeResolver.resolveType(typeRef, data, areBareTypesAllowed, isOperandOfIsOperator))
|
||||
}
|
||||
@@ -78,7 +79,8 @@ class FirSpecificTypeResolverTransformer(
|
||||
data: ScopeClassDeclaration
|
||||
): FirResolvedTypeRef {
|
||||
functionTypeRef.transformChildren(this, data)
|
||||
session.lookupTracker?.recordTypeLookup(functionTypeRef, data.scope.scopeOwnerLookupNames, currentFile?.source)
|
||||
val scopeOwnerLookupNames = data.scopes.flatMap { it.scopeOwnerLookupNames }
|
||||
session.lookupTracker?.recordTypeLookup(functionTypeRef, scopeOwnerLookupNames, currentFile?.source)
|
||||
val resolvedType = typeResolver.resolveType(functionTypeRef, data, areBareTypesAllowed, isOperandOfIsOperator).takeIfAcceptable()
|
||||
return if (resolvedType != null && resolvedType !is ConeClassErrorType) {
|
||||
buildResolvedTypeRef {
|
||||
|
||||
+3
-2
@@ -303,7 +303,7 @@ open class FirSupertypeResolverVisitor(
|
||||
val transformer = FirSpecificTypeResolverTransformer(session)
|
||||
val resolvedTypesRefs = resolveSuperTypeRefs(
|
||||
transformer,
|
||||
ScopeClassDeclaration(FirCompositeScope(scopes), classDeclarationsStack.lastOrNull())
|
||||
ScopeClassDeclaration(scopes, classDeclarationsStack.lastOrNull())
|
||||
)
|
||||
|
||||
supertypeComputationSession.storeSupertypes(classLikeDeclaration, resolvedTypesRefs)
|
||||
@@ -335,7 +335,8 @@ open class FirSupertypeResolverVisitor(
|
||||
session.lookupTracker?.let {
|
||||
val fileSource = getFirClassifierContainerFileIfAny(classLikeDeclaration.symbol)?.source
|
||||
for (supertypeRef in supertypeRefs) {
|
||||
it.recordTypeLookup(supertypeRef, scopeDeclaration.scope.scopeOwnerLookupNames, fileSource)
|
||||
val scopeOwnerLookupNames = scopeDeclaration.scopes.flatMap { scope -> scope.scopeOwnerLookupNames }
|
||||
it.recordTypeLookup(supertypeRef, scopeOwnerLookupNames, fileSource)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeCyclicTypeBound
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
import org.jetbrains.kotlin.fir.scopes.FirCompositeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.createImportingScopes
|
||||
import org.jetbrains.kotlin.fir.scopes.getNestedClassifierScope
|
||||
@@ -47,7 +46,7 @@ open class FirTypeResolveTransformer(
|
||||
) : FirAbstractTreeTransformer<Any?>(FirResolvePhase.TYPES) {
|
||||
private val classDeclarationsStack = ArrayDeque<FirRegularClass>()
|
||||
private val scopes = mutableListOf<FirScope>()
|
||||
private val towerScope = FirCompositeScope(scopes.asReversed())
|
||||
private val towerScope = scopes.asReversed()
|
||||
|
||||
init {
|
||||
scopes.addAll(initialScopes.asReversed())
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
|
||||
data class ScopeClassDeclaration(
|
||||
val scope: FirScope,
|
||||
val scopes: List<FirScope>,
|
||||
val topDeclaration: FirRegularClass?
|
||||
)
|
||||
+1
-1
@@ -69,7 +69,7 @@ open class FirBodyResolveTransformer(
|
||||
transformTypeRef(
|
||||
typeRef,
|
||||
ScopeClassDeclaration(
|
||||
FirCompositeScope(components.createCurrentScopeList()),
|
||||
components.createCurrentScopeList(),
|
||||
context.topClassDeclaration
|
||||
)
|
||||
)
|
||||
|
||||
+2
-2
@@ -24,10 +24,10 @@ internal abstract class FirAbstractAnnotationResolveTransformer<D, S>(
|
||||
) : FirDefaultTransformer<D>() {
|
||||
abstract override fun transformAnnotation(annotation: FirAnnotation, data: D): FirStatement
|
||||
|
||||
protected lateinit var scope: FirScope
|
||||
protected lateinit var scopes: List<FirScope>
|
||||
|
||||
override fun transformFile(file: FirFile, data: D): FirFile {
|
||||
scope = FirCompositeScope(createImportingScopes(file, session, scopeSession, useCaching = false))
|
||||
scopes = createImportingScopes(file, session, scopeSession, useCaching = false)
|
||||
val state = beforeChildren(file)
|
||||
file.transformDeclarations(this, data)
|
||||
afterChildren(state)
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ private class FirAnnotationResolveTransformer(
|
||||
): FirStatement {
|
||||
return annotation.transformAnnotationTypeRef(
|
||||
typeResolverTransformer,
|
||||
ScopeClassDeclaration(scope, classDeclarationsStack.lastOrNull())
|
||||
ScopeClassDeclaration(scopes, classDeclarationsStack.lastOrNull())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user