[FIR] Cleanup FIR modules. Part 7 (scopes package)
This commit is contained in:
@@ -26,14 +26,6 @@ class KotlinScopeProvider(
|
||||
scopeSession: ScopeSession
|
||||
) -> FirScope = { _, declaredMemberScope, _, _ -> declaredMemberScope }
|
||||
) : FirScopeProvider() {
|
||||
|
||||
|
||||
private fun substitutor(symbol: FirRegularClassSymbol, type: ConeClassLikeType, useSiteSession: FirSession): ConeSubstitutor {
|
||||
if (type.typeArguments.isEmpty()) return ConeSubstitutor.Empty
|
||||
val originalSubstitution = createSubstitution(symbol.fir.typeParameters, type.typeArguments, useSiteSession)
|
||||
return substitutorByMap(originalSubstitution)
|
||||
}
|
||||
|
||||
override fun getUseSiteMemberScope(
|
||||
klass: FirClass<*>,
|
||||
useSiteSession: FirSession,
|
||||
@@ -69,6 +61,12 @@ class KotlinScopeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
private fun substitutor(symbol: FirRegularClassSymbol, type: ConeClassLikeType, useSiteSession: FirSession): ConeSubstitutor {
|
||||
if (type.typeArguments.isEmpty()) return ConeSubstitutor.Empty
|
||||
val originalSubstitution = createSubstitution(symbol.fir.typeParameters, type.typeArguments, useSiteSession)
|
||||
return substitutorByMap(originalSubstitution)
|
||||
}
|
||||
|
||||
override fun getStaticMemberScopeForCallables(
|
||||
klass: FirClass<*>,
|
||||
useSiteSession: FirSession,
|
||||
|
||||
@@ -61,4 +61,3 @@ private fun doCreateImportingScopes(
|
||||
}
|
||||
|
||||
private val PACKAGE_MEMBER = scopeSessionKey<FqName, FirPackageMemberScope>()
|
||||
|
||||
|
||||
+9
-5
@@ -56,12 +56,10 @@ class FirClassSubstitutionScope(
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) {
|
||||
useSiteMemberScope.processFunctionsByName(name) process@{ original ->
|
||||
|
||||
val function = fakeOverrideFunctions.getOrPut(original) { createFakeOverrideFunction(original) }
|
||||
processor(function)
|
||||
}
|
||||
|
||||
|
||||
return super.processFunctionsByName(name, processor)
|
||||
}
|
||||
|
||||
@@ -138,6 +136,11 @@ class FirClassSubstitutionScope(
|
||||
return original
|
||||
}
|
||||
|
||||
/*
|
||||
* Member functions can't capture type parameters, so
|
||||
* it's safe to cast newTypeParameters to List<FirTypeParameter>
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return createFakeOverrideFunction(
|
||||
session,
|
||||
member,
|
||||
@@ -243,6 +246,10 @@ class FirClassSubstitutionScope(
|
||||
return original
|
||||
}
|
||||
|
||||
/*
|
||||
* Member properties can't capture type parameters, so
|
||||
* it's safe to cast newTypeParameters to List<FirTypeParameter>
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return createFakeOverrideProperty(
|
||||
session,
|
||||
@@ -350,7 +357,6 @@ class FirClassSubstitutionScope(
|
||||
typeParameters += newTypeParameters
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun createFakeOverrideFunction(
|
||||
@@ -479,13 +485,11 @@ class FirClassSubstitutionScope(
|
||||
typeParameters += newTypeParameters
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
|
||||
useSiteMemberScope.processDeclaredConstructors process@{ original ->
|
||||
|
||||
val constructor = fakeOverrideConstructors.getOrPut(original) { createFakeOverrideConstructor(original) }
|
||||
processor(constructor)
|
||||
}
|
||||
|
||||
-3
@@ -26,7 +26,6 @@ class FirClassUseSiteMemberScope(
|
||||
processor(it)
|
||||
}
|
||||
|
||||
|
||||
superTypesScope.processPropertiesByName(name) {
|
||||
val overriddenBy = it.getOverridden(seen)
|
||||
if (overriddenBy == null) {
|
||||
@@ -35,5 +34,3 @@ class FirClassUseSiteMemberScope(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-1
@@ -89,4 +89,3 @@ fun lazyNestedClassifierScope(
|
||||
if (existingNames.isEmpty()) return null
|
||||
return FirLazyNestedClassifierScope(classId, existingNames, symbolProvider)
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -15,7 +15,6 @@ class FirExplicitSimpleImportingScope(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
) : FirAbstractSimpleImportingScope(session, scopeSession) {
|
||||
|
||||
override val simpleImports =
|
||||
imports.filterIsInstance<FirResolvedImport>()
|
||||
.filter { !it.isAllUnder && it.importedName != null }
|
||||
|
||||
+2
-3
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
|
||||
class FirIntegerLiteralTypeScope(private val session: FirSession, val isUnsigned: Boolean) : FirTypeScope() {
|
||||
sealed class ILTKey {
|
||||
object Signed : ILTKey()
|
||||
@@ -48,6 +47,7 @@ class FirIntegerLiteralTypeScope(private val session: FirSession, val isUnsigned
|
||||
val SCOPE_SESSION_KEY = scopeSessionKey<ILTKey, FirTypeScope>()
|
||||
}
|
||||
|
||||
@Suppress("PrivatePropertyName")
|
||||
private val BINARY_OPERATOR_SYMBOLS = BINARY_OPERATOR_NAMES.map { name ->
|
||||
name to FirNamedFunctionSymbol(CallableId(name)).apply {
|
||||
createFirFunction(name, this).apply {
|
||||
@@ -68,6 +68,7 @@ class FirIntegerLiteralTypeScope(private val session: FirSession, val isUnsigned
|
||||
}
|
||||
}.toMap()
|
||||
|
||||
@Suppress("PrivatePropertyName")
|
||||
private val UNARY_OPERATOR_SYMBOLS = UNARY_OPERATOR_NAMES.map { name ->
|
||||
name to FirNamedFunctionSymbol(CallableId(name)).apply { createFirFunction(name, this) }
|
||||
}.toMap()
|
||||
@@ -85,7 +86,6 @@ class FirIntegerLiteralTypeScope(private val session: FirSession, val isUnsigned
|
||||
resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||
}
|
||||
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) {
|
||||
val symbol = BINARY_OPERATOR_SYMBOLS[name]
|
||||
?: UNARY_OPERATOR_SYMBOLS[name]
|
||||
@@ -165,4 +165,3 @@ class FirILTTypeRefPlaceHolder(
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -74,6 +74,6 @@ class FirIntegerOperatorCallBuilder : FirQualifiedAccessBuilder, FirCallBuilder,
|
||||
|
||||
}
|
||||
|
||||
inline fun buildFunctionCall(init: FirIntegerOperatorCallBuilder.() -> Unit): FirIntegerOperatorCall {
|
||||
inline fun buildIntegerOperatorFunctionCall(init: FirIntegerOperatorCallBuilder.() -> Unit): FirIntegerOperatorCall {
|
||||
return FirIntegerOperatorCallBuilder().apply(init).build()
|
||||
}
|
||||
-1
@@ -20,7 +20,6 @@ class FirLazyNestedClassifierScope(
|
||||
private val existingNames: List<Name>,
|
||||
private val symbolProvider: FirSymbolProvider
|
||||
) : FirScope() {
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(
|
||||
name: Name,
|
||||
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
|
||||
|
||||
@@ -19,14 +19,10 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirLocalScope private constructor(
|
||||
properties: PersistentMap<Name, FirVariableSymbol<*>>,
|
||||
functions: PersistentMultimap<Name, FirFunctionSymbol<*>>,
|
||||
classes: PersistentMap<Name, FirRegularClassSymbol>
|
||||
val properties: PersistentMap<Name, FirVariableSymbol<*>>,
|
||||
val functions: PersistentMultimap<Name, FirFunctionSymbol<*>>,
|
||||
val classes: PersistentMap<Name, FirRegularClassSymbol>
|
||||
) : FirScope() {
|
||||
val properties: PersistentMap<Name, FirVariableSymbol<*>> = properties
|
||||
val functions: PersistentMultimap<Name, FirFunctionSymbol<*>> = functions
|
||||
val classes: PersistentMap<Name, FirRegularClassSymbol> = classes
|
||||
|
||||
constructor() : this(persistentMapOf(), PersistentMultimap(), persistentMapOf())
|
||||
|
||||
fun storeClass(klass: FirRegularClass): FirLocalScope {
|
||||
|
||||
+4
-2
@@ -8,7 +8,9 @@ package org.jetbrains.kotlin.fir.scopes.impl
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeParameterScope
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirMemberTypeParameterScope(callableMember: FirMemberDeclaration) : FirTypeParameterScope() {
|
||||
override val typeParameters = callableMember.typeParameters.filterIsInstance<FirTypeParameter>().groupBy { it.name }
|
||||
}
|
||||
override val typeParameters: Map<Name, List<FirTypeParameter>> =
|
||||
callableMember.typeParameters.filterIsInstance<FirTypeParameter>().groupBy { it.name }
|
||||
}
|
||||
|
||||
-1
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirNestedClassifierScope(val klass: FirClass<*>) : FirScope() {
|
||||
|
||||
private val classIndex: Map<Name, FirRegularClassSymbol> = run {
|
||||
val result = mutableMapOf<Name, FirRegularClassSymbol>()
|
||||
for (declaration in klass.declarations) {
|
||||
|
||||
+2
-6
@@ -15,12 +15,9 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirPackageMemberScope(val fqName: FqName, val session: FirSession) : FirScope() {
|
||||
|
||||
private val symbolProvider = session.firSymbolProvider
|
||||
|
||||
private val classifierCache = mutableMapOf<Name, FirClassifierSymbol<*>?>()
|
||||
|
||||
private val callableCache = mutableMapOf<Name, List<FirCallableSymbol<*>>>()
|
||||
private val classifierCache: MutableMap<Name, FirClassifierSymbol<*>?> = mutableMapOf()
|
||||
private val callableCache: MutableMap<Name, List<FirCallableSymbol<*>>> = mutableMapOf()
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(
|
||||
name: Name,
|
||||
@@ -28,7 +25,6 @@ class FirPackageMemberScope(val fqName: FqName, val session: FirSession) : FirSc
|
||||
) {
|
||||
if (name.asString().isEmpty()) return
|
||||
|
||||
|
||||
val symbol = classifierCache.getOrPut(name) {
|
||||
val unambiguousFqName = ClassId(fqName, name)
|
||||
symbolProvider.getClassLikeSymbolByFqName(unambiguousFqName)
|
||||
|
||||
+1
-3
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
|
||||
class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideChecker() {
|
||||
|
||||
private val context: ConeTypeContext = session.typeContext
|
||||
|
||||
private fun isEqualTypes(substitutedCandidateType: ConeKotlinType, substitutedBaseType: ConeKotlinType): Boolean {
|
||||
@@ -114,7 +113,6 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
||||
return overrideCandidate.valueParameters.zip(baseDeclaration.valueParameters).all { (memberParam, selfParam) ->
|
||||
isEqualTypes(memberParam.returnTypeRef, selfParam.returnTypeRef, substitutor)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun isOverriddenProperty(
|
||||
@@ -125,4 +123,4 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
||||
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
||||
return isEqualReceiverTypes(overrideCandidate.receiverTypeRef, baseDeclaration.receiverTypeRef, substitutor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,11 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirStaticScope(private val delegateScope: FirScope) : FirScope() {
|
||||
|
||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||
delegateScope.processClassifiersByNameWithSubstitution(name, processor)
|
||||
}
|
||||
|
||||
override fun processFunctionsByName(
|
||||
name: Name,
|
||||
processor: (FirFunctionSymbol<*>) -> Unit
|
||||
) {
|
||||
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) {
|
||||
delegateScope.processFunctionsByName(name) {
|
||||
if ((it.fir as? FirSimpleFunction)?.isStatic == true) {
|
||||
processor(it)
|
||||
@@ -32,14 +28,11 @@ class FirStaticScope(private val delegateScope: FirScope) : FirScope() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun processPropertiesByName(
|
||||
name: Name,
|
||||
processor: (FirVariableSymbol<*>) -> Unit
|
||||
) {
|
||||
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
||||
delegateScope.processPropertiesByName(name) {
|
||||
if ((it.fir as? FirCallableMemberDeclaration<*>)?.isStatic == true) {
|
||||
processor(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-21
@@ -32,16 +32,13 @@ class FirTypeIntersectionScope private constructor(
|
||||
overrideChecker: FirOverrideChecker,
|
||||
private val scopes: List<FirTypeScope>,
|
||||
) : AbstractFirOverrideScope(session, overrideChecker) {
|
||||
|
||||
private val absentFunctions = mutableSetOf<Name>()
|
||||
|
||||
private val absentProperties = mutableSetOf<Name>()
|
||||
|
||||
private val absentClassifiers = mutableSetOf<Name>()
|
||||
private val absentFunctions: MutableSet<Name> = mutableSetOf()
|
||||
private val absentProperties: MutableSet<Name> = mutableSetOf()
|
||||
private val absentClassifiers: MutableSet<Name> = mutableSetOf()
|
||||
|
||||
private val typeContext = ConeTypeCheckerContext(isErrorTypeEqualsToAnything = false, isStubTypeEqualsToAnything = false, session)
|
||||
|
||||
private val overriddenSymbols = mutableMapOf<FirCallableSymbol<*>, Collection<FirCallableSymbol<*>>>()
|
||||
private val overriddenSymbols: MutableMap<FirCallableSymbol<*>, Collection<FirCallableSymbol<*>>> = mutableMapOf()
|
||||
|
||||
override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) {
|
||||
if (!processCallablesByName(name, processor, absentFunctions, FirScope::processFunctionsByName)) {
|
||||
@@ -87,7 +84,6 @@ class FirTypeIntersectionScope private constructor(
|
||||
processor(member)
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -105,10 +101,8 @@ class FirTypeIntersectionScope private constructor(
|
||||
return true
|
||||
}
|
||||
|
||||
private fun <D : FirCallableSymbol<*>> selectMostSpecificMember(
|
||||
overridables: Collection<D>
|
||||
): D {
|
||||
require(overridables.isNotEmpty()) { "Should have at least one overridable descriptor" }
|
||||
private fun <D : FirCallableSymbol<*>> selectMostSpecificMember(overridables: Collection<D>): D {
|
||||
require(overridables.isNotEmpty()) { "Should have at least one overridable symbol" }
|
||||
if (overridables.size == 1) {
|
||||
return overridables.first()
|
||||
}
|
||||
@@ -126,19 +120,15 @@ class FirTypeIntersectionScope private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
when {
|
||||
candidates.isEmpty() -> {
|
||||
return transitivelyMostSpecific
|
||||
}
|
||||
candidates.size == 1 -> {
|
||||
return candidates.first()
|
||||
}
|
||||
return when {
|
||||
candidates.isEmpty() -> transitivelyMostSpecific
|
||||
candidates.size == 1 -> candidates.first()
|
||||
else -> {
|
||||
candidates.firstOrNull {
|
||||
val type = it.fir.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
||||
type != null && type !is ConeFlexibleType
|
||||
}?.let { return it }
|
||||
return candidates.first()
|
||||
candidates.first()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +262,6 @@ class FirTypeIntersectionScope private constructor(
|
||||
scopes: List<FirTypeScope>
|
||||
): FirTypeScope {
|
||||
scopes.singleOrNull()?.let { return it }
|
||||
|
||||
return FirTypeIntersectionScope(session, overrideChecker, scopes)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user