[FIR] pre-resolve some scope callables before creating a scope
In a lot of cases, when we want to process the declaration in scope, it should be resolved to at least TYPES phase. To avoid doing it manually in all our variety of scopes, we do it when the scope it created. It was implicitly working manually before as lazy resolve did a lot of extra work on resolving a declaration it was not supposed to resolve. Now it's not the case, and we have to explicitly resolve all the declarations we need. ^KT-56543 Co-authored-by: Ilya Kirillov <ilya.kirillov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
23e40693a3
commit
706ff6b61f
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJava
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
|
||||
@@ -30,10 +31,11 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
override fun getUseSiteMemberScope(
|
||||
klass: FirClass,
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
scopeSession: ScopeSession,
|
||||
memberRequiredPhase: FirResolvePhase?,
|
||||
): FirTypeScope {
|
||||
val symbol = klass.symbol as FirRegularClassSymbol
|
||||
val enhancementScope = buildJavaEnhancementScope(useSiteSession, symbol, scopeSession)
|
||||
val enhancementScope = buildJavaEnhancementScope(useSiteSession, symbol, scopeSession, memberRequiredPhase)
|
||||
if (klass.classKind == ClassKind.ANNOTATION_CLASS) {
|
||||
return buildSyntheticScopeForAnnotations(useSiteSession, symbol, scopeSession, enhancementScope)
|
||||
}
|
||||
@@ -54,7 +56,8 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
private fun buildJavaEnhancementScope(
|
||||
useSiteSession: FirSession,
|
||||
symbol: FirRegularClassSymbol,
|
||||
scopeSession: ScopeSession
|
||||
scopeSession: ScopeSession,
|
||||
memberRequiredPhase: FirResolvePhase?,
|
||||
): JavaClassMembersEnhancementScope {
|
||||
return scopeSession.getOrBuild(symbol, JAVA_ENHANCEMENT) {
|
||||
val firJavaClass = symbol.fir
|
||||
@@ -64,7 +67,7 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
JavaClassMembersEnhancementScope(
|
||||
useSiteSession,
|
||||
symbol,
|
||||
buildUseSiteMemberScopeWithJavaTypes(firJavaClass, useSiteSession, scopeSession)
|
||||
buildUseSiteMemberScopeWithJavaTypes(firJavaClass, useSiteSession, scopeSession, memberRequiredPhase)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -81,6 +84,7 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
regularClass: FirJavaClass,
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
memberRequiredPhase: FirResolvePhase?,
|
||||
): JavaClassUseSiteMemberScope {
|
||||
return scopeSession.getOrBuild(regularClass.symbol, JAVA_USE_SITE) {
|
||||
val declaredScope = buildDeclaredMemberScope(useSiteSession, regularClass)
|
||||
@@ -93,7 +97,7 @@ object JavaScopeProvider : FirScopeProvider() {
|
||||
)
|
||||
|
||||
val superTypeScopes = superTypes.mapNotNull {
|
||||
it.scopeForSupertype(useSiteSession, scopeSession, regularClass)
|
||||
it.scopeForSupertype(useSiteSession, scopeSession, regularClass, memberRequiredPhase = memberRequiredPhase)
|
||||
}
|
||||
|
||||
JavaClassUseSiteMemberScope(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
|
||||
class JvmSupertypeUpdater(private val session: FirSession) : PlatformSupertypeUpdater() {
|
||||
@@ -98,7 +97,7 @@ class JvmSupertypeUpdater(private val session: FirSession) : PlatformSupertypeUp
|
||||
}
|
||||
|
||||
val recordConstructorSymbol = recordType.lookupTag.toFirRegularClassSymbol(session)
|
||||
?.unsubstitutedScope(session, data, withForcedTypeCalculator = false)
|
||||
?.unsubstitutedScope(session, data, withForcedTypeCalculator = false, memberRequiredPhase = null)
|
||||
?.getDeclaredConstructors()
|
||||
?.firstOrNull { it.fir.valueParameters.isEmpty() }
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
@@ -25,7 +26,8 @@ fun wrapScopeWithJvmMapped(
|
||||
klass: FirClass,
|
||||
declaredMemberScope: FirContainingNamesAwareScope,
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
scopeSession: ScopeSession,
|
||||
memberRequiredPhase: FirResolvePhase?,
|
||||
): FirContainingNamesAwareScope {
|
||||
val classId = klass.classId
|
||||
val kotlinUnsafeFqName = classId.asSingleFqName().toUnsafe()
|
||||
@@ -36,7 +38,12 @@ fun wrapScopeWithJvmMapped(
|
||||
?: return declaredMemberScope
|
||||
val preparedSignatures = JvmMappedScope.prepareSignatures(javaClass, JavaToKotlinClassMap.isMutable(kotlinUnsafeFqName))
|
||||
return if (preparedSignatures.isNotEmpty()) {
|
||||
javaClass.unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false).let { javaClassUseSiteScope ->
|
||||
javaClass.unsubstitutedScope(
|
||||
useSiteSession,
|
||||
scopeSession,
|
||||
withForcedTypeCalculator = false,
|
||||
memberRequiredPhase = memberRequiredPhase,
|
||||
).let { javaClassUseSiteScope ->
|
||||
val jvmMappedScope = JvmMappedScope(
|
||||
useSiteSession,
|
||||
klass,
|
||||
|
||||
Reference in New Issue
Block a user