[FIR] Add wrapping scopes with forced calculator in checkers and fir2ir
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
|
|
||||||
fun renderJavaClass(renderer: FirRenderer, javaClass: FirJavaClass, session: FirSession) {
|
fun renderJavaClass(renderer: FirRenderer, javaClass: FirJavaClass, session: FirSession) {
|
||||||
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession())
|
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession(), withForcedTypeCalculator = true)
|
||||||
|
|
||||||
val staticScope = javaClass.scopeProvider.getStaticScope(javaClass, session, ScopeSession())
|
val staticScope = javaClass.scopeProvider.getStaticScope(javaClass, session, ScopeSession())
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,8 @@ fun FirSimpleFunction.overriddenFunctions(
|
|||||||
): List<FirFunctionSymbol<*>> {
|
): List<FirFunctionSymbol<*>> {
|
||||||
val firTypeScope = containingClass.unsubstitutedScope(
|
val firTypeScope = containingClass.unsubstitutedScope(
|
||||||
context.sessionHolder.session,
|
context.sessionHolder.session,
|
||||||
context.sessionHolder.scopeSession
|
context.sessionHolder.scopeSession,
|
||||||
|
withForcedTypeCalculator = true
|
||||||
)
|
)
|
||||||
|
|
||||||
val overriddenFunctions = mutableListOf<FirFunctionSymbol<*>>()
|
val overriddenFunctions = mutableListOf<FirFunctionSymbol<*>>()
|
||||||
|
|||||||
+2
-1
@@ -36,7 +36,8 @@ object FirTypeMismatchOnOverrideChecker : FirRegularClassChecker() {
|
|||||||
|
|
||||||
val firTypeScope = declaration.unsubstitutedScope(
|
val firTypeScope = declaration.unsubstitutedScope(
|
||||||
context.sessionHolder.session,
|
context.sessionHolder.session,
|
||||||
context.sessionHolder.scopeSession
|
context.sessionHolder.scopeSession,
|
||||||
|
withForcedTypeCalculator = true
|
||||||
)
|
)
|
||||||
|
|
||||||
for (it in declaration.declarations) {
|
for (it in declaration.declarations) {
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ internal fun FirSimpleFunction.generateOverriddenFunctionSymbols(
|
|||||||
scopeSession: ScopeSession,
|
scopeSession: ScopeSession,
|
||||||
declarationStorage: Fir2IrDeclarationStorage
|
declarationStorage: Fir2IrDeclarationStorage
|
||||||
): List<IrSimpleFunctionSymbol> {
|
): List<IrSimpleFunctionSymbol> {
|
||||||
val scope = containingClass.unsubstitutedScope(session, scopeSession)
|
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||||
scope.processFunctionsByName(name) {}
|
scope.processFunctionsByName(name) {}
|
||||||
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
||||||
scope.processDirectlyOverriddenFunctions(symbol) {
|
scope.processDirectlyOverriddenFunctions(symbol) {
|
||||||
@@ -251,7 +251,7 @@ internal fun FirProperty.generateOverriddenAccessorSymbols(
|
|||||||
scopeSession: ScopeSession,
|
scopeSession: ScopeSession,
|
||||||
declarationStorage: Fir2IrDeclarationStorage
|
declarationStorage: Fir2IrDeclarationStorage
|
||||||
): List<IrSimpleFunctionSymbol> {
|
): List<IrSimpleFunctionSymbol> {
|
||||||
val scope = containingClass.unsubstitutedScope(session, scopeSession)
|
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||||
scope.processPropertiesByName(name) {}
|
scope.processPropertiesByName(name) {}
|
||||||
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
||||||
scope.processDirectlyOverriddenProperties(symbol) {
|
scope.processDirectlyOverriddenProperties(symbol) {
|
||||||
|
|||||||
+1
-1
@@ -368,7 +368,7 @@ class CallAndReferenceGenerator(
|
|||||||
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
||||||
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass<*>
|
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass<*>
|
||||||
var constructorSymbol: FirConstructorSymbol? = null
|
var constructorSymbol: FirConstructorSymbol? = null
|
||||||
fir?.unsubstitutedScope(session, scopeSession)?.processDeclaredConstructors {
|
fir?.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)?.processDeclaredConstructors {
|
||||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||||
constructorSymbol = it
|
constructorSymbol = it
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -146,7 +146,11 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
buildMap<Name, FirSimpleFunction> {
|
buildMap<Name, FirSimpleFunction> {
|
||||||
for (name in listOf(equalsName, hashCodeName, toStringName)) {
|
for (name in listOf(equalsName, hashCodeName, toStringName)) {
|
||||||
klass.unsubstitutedScope(components.session, components.scopeSession).processFunctionsByName(name) {
|
klass.unsubstitutedScope(
|
||||||
|
components.session,
|
||||||
|
components.scopeSession,
|
||||||
|
withForcedTypeCalculator = true
|
||||||
|
).processFunctionsByName(name) {
|
||||||
val declaration = it.fir
|
val declaration = it.fir
|
||||||
if (declaration is FirSimpleFunction &&
|
if (declaration is FirSimpleFunction &&
|
||||||
declaration.matchesDataClassSyntheticMemberSignatures
|
declaration.matchesDataClassSyntheticMemberSignatures
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ internal class DelegatedMemberGenerator(
|
|||||||
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass<*>, subClass: IrClass) {
|
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass<*>, subClass: IrClass) {
|
||||||
val subClassLookupTag = firSubClass.symbol.toLookupTag()
|
val subClassLookupTag = firSubClass.symbol.toLookupTag()
|
||||||
|
|
||||||
val subClassScope = firSubClass.unsubstitutedScope(session, scopeSession)
|
val subClassScope = firSubClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||||
subClassScope.processAllFunctions { functionSymbol ->
|
subClassScope.processAllFunctions { functionSymbol ->
|
||||||
if (functionSymbol !is FirNamedFunctionSymbol) return@processAllFunctions
|
if (functionSymbol !is FirNamedFunctionSymbol) return@processAllFunctions
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ class FakeOverrideGenerator(
|
|||||||
|
|
||||||
fun IrClass.getFakeOverrides(klass: FirClass<*>, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
|
fun IrClass.getFakeOverrides(klass: FirClass<*>, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
|
||||||
val result = mutableListOf<IrDeclaration>()
|
val result = mutableListOf<IrDeclaration>()
|
||||||
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession)
|
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||||
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
|
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
|
||||||
val realDeclarationSymbols = realDeclarations.filterIsInstance<FirSymbolOwner<*>>().mapTo(mutableSetOf(), FirSymbolOwner<*>::symbol)
|
val realDeclarationSymbols = realDeclarations.filterIsInstance<FirSymbolOwner<*>>().mapTo(mutableSetOf(), FirSymbolOwner<*>::symbol)
|
||||||
for (name in superTypesCallableNames) {
|
for (name in superTypesCallableNames) {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class Fir2IrLazyClass(
|
|||||||
val processedNames = mutableSetOf<Name>()
|
val processedNames = mutableSetOf<Name>()
|
||||||
// NB: it's necessary to take all callables from scope,
|
// NB: it's necessary to take all callables from scope,
|
||||||
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
|
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
|
||||||
val scope = fir.unsubstitutedScope(session, scopeSession)
|
val scope = fir.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||||
scope.processDeclaredConstructors {
|
scope.processDeclaredConstructors {
|
||||||
result += declarationStorage.getIrConstructorSymbol(it).owner
|
result += declarationStorage.getIrConstructorSymbol(it).owner
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ fun wrapScopeWithJvmMapped(
|
|||||||
?: return declaredMemberScope
|
?: return declaredMemberScope
|
||||||
val preparedSignatures = JvmMappedScope.prepareSignatures(javaClass)
|
val preparedSignatures = JvmMappedScope.prepareSignatures(javaClass)
|
||||||
return if (preparedSignatures.isNotEmpty()) {
|
return if (preparedSignatures.isNotEmpty()) {
|
||||||
javaClass.unsubstitutedScope(useSiteSession, scopeSession).let { javaClassUseSiteScope ->
|
javaClass.unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false).let { javaClassUseSiteScope ->
|
||||||
val jvmMappedScope = JvmMappedScope(declaredMemberScope, javaClassUseSiteScope, preparedSignatures)
|
val jvmMappedScope = JvmMappedScope(declaredMemberScope, javaClassUseSiteScope, preparedSignatures)
|
||||||
if (klass !is FirRegularClass) {
|
if (klass !is FirRegularClass) {
|
||||||
jvmMappedScope
|
jvmMappedScope
|
||||||
|
|||||||
@@ -386,7 +386,11 @@ class FirCallResolver(
|
|||||||
callInfo: CallInfo
|
callInfo: CallInfo
|
||||||
): ResolutionResult? {
|
): ResolutionResult? {
|
||||||
var constructorSymbol: FirConstructorSymbol? = null
|
var constructorSymbol: FirConstructorSymbol? = null
|
||||||
annotationClassSymbol.fir.unsubstitutedScope(session, components.scopeSession).processDeclaredConstructors {
|
annotationClassSymbol.fir.unsubstitutedScope(
|
||||||
|
session,
|
||||||
|
components.scopeSession,
|
||||||
|
withForcedTypeCalculator = false
|
||||||
|
).processDeclaredConstructors {
|
||||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||||
constructorSymbol = it
|
constructorSymbol = it
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fun FirSimpleFunction.lowestVisibilityAmongOverrides(
|
|||||||
session: FirSession,
|
session: FirSession,
|
||||||
scopeSession: ScopeSession
|
scopeSession: ScopeSession
|
||||||
): Visibility {
|
): Visibility {
|
||||||
val firTypeScope = containingClass.unsubstitutedScope(session, scopeSession)
|
val firTypeScope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
|
||||||
var visibility = visibility
|
var visibility = visibility
|
||||||
|
|
||||||
// required; otherwise processOverriddenFunctions()
|
// required; otherwise processOverriddenFunctions()
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.resolve
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
|
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
||||||
@@ -260,7 +259,7 @@ private fun FirRegularClass.findSingleAbstractMethodByNames(
|
|||||||
var resultMethod: FirSimpleFunction? = null
|
var resultMethod: FirSimpleFunction? = null
|
||||||
var metIncorrectMember = false
|
var metIncorrectMember = false
|
||||||
|
|
||||||
val classUseSiteMemberScope = this.unsubstitutedScope(session, scopeSession)
|
val classUseSiteMemberScope = this.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
|
||||||
|
|
||||||
for (candidateName in samCandidateNames) {
|
for (candidateName in samCandidateNames) {
|
||||||
if (metIncorrectMember) break
|
if (metIncorrectMember) break
|
||||||
|
|||||||
+5
-1
@@ -85,7 +85,11 @@ fun ConeClassLikeType.findBaseInvokeSymbol(session: FirSession, scopeSession: Sc
|
|||||||
require(this.isBuiltinFunctionalType(session))
|
require(this.isBuiltinFunctionalType(session))
|
||||||
val functionN = (lookupTag.toSymbol(session)?.fir as? FirClass<*>) ?: return null
|
val functionN = (lookupTag.toSymbol(session)?.fir as? FirClass<*>) ?: return null
|
||||||
var baseInvokeSymbol: FirFunctionSymbol<*>? = null
|
var baseInvokeSymbol: FirFunctionSymbol<*>? = null
|
||||||
functionN.unsubstitutedScope(session, scopeSession).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol ->
|
functionN.unsubstitutedScope(
|
||||||
|
session,
|
||||||
|
scopeSession,
|
||||||
|
withForcedTypeCalculator = false
|
||||||
|
).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol ->
|
||||||
baseInvokeSymbol = functionSymbol
|
baseInvokeSymbol = functionSymbol
|
||||||
return@processFunctionsByName
|
return@processFunctionsByName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,8 +96,14 @@ data class ConeSubstitutionScopeKey(
|
|||||||
|
|
||||||
data class DelegatedMemberScopeKey(val callableId: CallableId) : ScopeSessionKey<FirField, FirDelegatedMemberScope>()
|
data class DelegatedMemberScopeKey(val callableId: CallableId) : ScopeSessionKey<FirField, FirDelegatedMemberScope>()
|
||||||
|
|
||||||
fun FirClass<*>.unsubstitutedScope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope {
|
fun FirClass<*>.unsubstitutedScope(
|
||||||
return scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
|
useSiteSession: FirSession,
|
||||||
|
scopeSession: ScopeSession,
|
||||||
|
withForcedTypeCalculator: Boolean
|
||||||
|
): FirTypeScope {
|
||||||
|
val scope = scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
|
||||||
|
if (withForcedTypeCalculator) return FirScopeWithFakeOverrideTypeCalculator(scope, FakeOverrideTypeCalculator.Forced)
|
||||||
|
return scope
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirClass<*>.scopeForClass(
|
fun FirClass<*>.scopeForClass(
|
||||||
@@ -143,7 +149,7 @@ private fun FirClass<*>.scopeForClassImpl(
|
|||||||
containingClassForAdditionalMembers: ConeClassLikeLookupTag,
|
containingClassForAdditionalMembers: ConeClassLikeLookupTag,
|
||||||
isFromExpectClass: Boolean
|
isFromExpectClass: Boolean
|
||||||
): FirTypeScope {
|
): FirTypeScope {
|
||||||
val basicScope = unsubstitutedScope(useSiteSession, scopeSession)
|
val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false)
|
||||||
if (substitutor == ConeSubstitutor.Empty) return basicScope
|
if (substitutor == ConeSubstitutor.Empty) return basicScope
|
||||||
|
|
||||||
return scopeSession.getOrBuild(
|
return scopeSession.getOrBuild(
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ abstract class FirAbstractImportingScope(
|
|||||||
val firClass = (symbol as FirClassSymbol<*>).fir
|
val firClass = (symbol as FirClassSymbol<*>).fir
|
||||||
|
|
||||||
return if (firClass.classKind == ClassKind.OBJECT)
|
return if (firClass.classKind == ClassKind.OBJECT)
|
||||||
FirObjectImportedCallableScope(classId, firClass.unsubstitutedScope(session, scopeSession))
|
FirObjectImportedCallableScope(classId, firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false))
|
||||||
else
|
else
|
||||||
firClass.scopeProvider.getStaticScope(firClass, session, scopeSession)
|
firClass.scopeProvider.getStaticScope(firClass, session, scopeSession)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -59,7 +59,11 @@ internal class KtFirScopeProvider(
|
|||||||
val firScope =
|
val firScope =
|
||||||
classSymbol.firRef.withFir(FirResolvePhase.SUPER_TYPES) { fir ->
|
classSymbol.firRef.withFir(FirResolvePhase.SUPER_TYPES) { fir ->
|
||||||
val firSession = fir.session
|
val firSession = fir.session
|
||||||
fir.unsubstitutedScope(firSession, firResolveState.firTransformerProvider.getScopeSession(firSession))
|
fir.unsubstitutedScope(
|
||||||
|
firSession,
|
||||||
|
firResolveState.firTransformerProvider.getScopeSession(firSession),
|
||||||
|
withForcedTypeCalculator = false
|
||||||
|
)
|
||||||
}.also(firScopeStorage::register)
|
}.also(firScopeStorage::register)
|
||||||
KtFirMemberScope(classSymbol, firScope, token, builder)
|
KtFirMemberScope(classSymbol, firScope, token, builder)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -49,7 +49,8 @@ internal class KtFirSymbolDeclarationOverridesProvider(
|
|||||||
|
|
||||||
val firTypeScope = containingDeclaration.unsubstitutedScope(
|
val firTypeScope = containingDeclaration.unsubstitutedScope(
|
||||||
containingDeclaration.session,
|
containingDeclaration.session,
|
||||||
ScopeSession()
|
ScopeSession(),
|
||||||
|
withForcedTypeCalculator = false
|
||||||
)
|
)
|
||||||
|
|
||||||
val overriddenElement = mutableSetOf<KtCallableSymbol>()
|
val overriddenElement = mutableSetOf<KtCallableSymbol>()
|
||||||
|
|||||||
Reference in New Issue
Block a user