[Analysis API] avoid having separate versions of KtFirScopeProvider for each thread
Now KtFirScopeProvider do not contain caches, so it can be reused between the threads. The only thread-local thing it had, was a ScopeSession. Now it's not stored in the KtFirScopeProvider
This commit is contained in:
+1
-2
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.analysis.api.components.*
|
||||
import org.jetbrains.kotlin.analysis.api.fir.components.*
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirOverrideInfoProvider
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbolProvider
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.threadLocal
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.components.KtAnalysisScopeProviderImpl
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
@@ -63,7 +62,7 @@ private constructor(
|
||||
|
||||
override val samResolverImpl = KtFirSamResolver(this, token)
|
||||
|
||||
override val scopeProviderImpl by threadLocal { KtFirScopeProvider(this, firSymbolBuilder, project, firResolveSession) }
|
||||
override val scopeProviderImpl = KtFirScopeProvider(this, firSymbolBuilder, project, firResolveSession)
|
||||
|
||||
override val symbolProviderImpl =
|
||||
KtFirSymbolProvider(this, firResolveSession.useSiteFirSession.symbolProvider)
|
||||
|
||||
+9
-6
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.delegateFields
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticPropertiesScope
|
||||
import org.jetbrains.kotlin.fir.resolve.scope
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
@@ -52,8 +53,10 @@ internal class KtFirScopeProvider(
|
||||
private val project: Project,
|
||||
private val firResolveSession: LLFirResolveSession,
|
||||
) : KtScopeProvider() {
|
||||
// KtFirScopeProvider is thread local, so it's okay to use the same session here
|
||||
private val scopeSession = analysisSession.getScopeSessionFor(analysisSession.useSiteSession)
|
||||
|
||||
private fun getScopeSession(): ScopeSession {
|
||||
return analysisSession.getScopeSessionFor(analysisSession.useSiteSession)
|
||||
}
|
||||
|
||||
private inline fun <T> KtSymbolWithMembers.withFirForScope(crossinline body: (FirClass) -> T): T? {
|
||||
return when (this) {
|
||||
@@ -76,7 +79,7 @@ internal class KtFirScopeProvider(
|
||||
val firSession = analysisSession.useSiteSession
|
||||
fir.unsubstitutedScope(
|
||||
firSession,
|
||||
scopeSession,
|
||||
getScopeSession(),
|
||||
withForcedTypeCalculator = false
|
||||
)
|
||||
}?.applyIf(classSymbol is KtEnumEntrySymbol, ::EnumEntryContainingNamesAwareScope)
|
||||
@@ -90,7 +93,7 @@ internal class KtFirScopeProvider(
|
||||
fir.scopeProvider.getStaticScope(
|
||||
fir,
|
||||
firSession,
|
||||
scopeSession,
|
||||
getScopeSession(),
|
||||
)
|
||||
} ?: return getEmptyScope()
|
||||
return KtFirDelegatingScope(firScope, builder)
|
||||
@@ -114,7 +117,7 @@ internal class KtFirScopeProvider(
|
||||
val firSession = analysisSession.useSiteSession
|
||||
FirDelegatedMemberScope(
|
||||
firSession,
|
||||
scopeSession,
|
||||
getScopeSession(),
|
||||
fir,
|
||||
declaredScope,
|
||||
delegateFields
|
||||
@@ -221,7 +224,7 @@ internal class KtFirScopeProvider(
|
||||
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
|
||||
return type.coneType.scope(
|
||||
firResolveSession.useSiteFirSession,
|
||||
scopeSession,
|
||||
getScopeSession(),
|
||||
FakeOverrideTypeCalculator.Forced,
|
||||
requiredPhase = FirResolvePhase.STATUS,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user