FIR IDE: reuse scope session between different resolve calls for the same file
This commit is contained in:
+2
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.ThreadSafe
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.file.builder.FirFileBuilder
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.file.builder.ModuleFileCache
|
||||
@@ -60,6 +61,7 @@ internal class FirElementBuilder {
|
||||
ktFile,
|
||||
moduleFileCache,
|
||||
FirResolvePhase.BODY_RESOLVE,
|
||||
scopeSession = ScopeSession(),
|
||||
checkPCE = true
|
||||
)
|
||||
|
||||
|
||||
+10
-3
@@ -50,6 +50,7 @@ internal class FirFileBuilder(
|
||||
ktFile: KtFile,
|
||||
cache: ModuleFileCache,
|
||||
@Suppress("SameParameterValue") toPhase: FirResolvePhase,
|
||||
scopeSession: ScopeSession,
|
||||
checkPCE: Boolean
|
||||
): FirFile {
|
||||
val needResolve = toPhase > FirResolvePhase.RAW_FIR
|
||||
@@ -57,7 +58,13 @@ internal class FirFileBuilder(
|
||||
if (needResolve) {
|
||||
cache.firFileLockProvider.withWriteLock(firFile) {
|
||||
if (firFile.resolvePhase >= toPhase) return@withWriteLock
|
||||
runResolveWithoutLock(firFile, fromPhase = firFile.resolvePhase, toPhase = toPhase, checkPCE = checkPCE)
|
||||
runResolveWithoutLock(
|
||||
firFile,
|
||||
fromPhase = firFile.resolvePhase,
|
||||
toPhase = toPhase,
|
||||
scopeSession = scopeSession,
|
||||
checkPCE = checkPCE,
|
||||
)
|
||||
}
|
||||
}
|
||||
return firFile
|
||||
@@ -76,13 +83,13 @@ internal class FirFileBuilder(
|
||||
firFile: FirFile,
|
||||
fromPhase: FirResolvePhase,
|
||||
toPhase: FirResolvePhase,
|
||||
checkPCE: Boolean
|
||||
scopeSession: ScopeSession,
|
||||
checkPCE: Boolean,
|
||||
) {
|
||||
assert(fromPhase <= toPhase) {
|
||||
"Trying to resolve file ${firFile.name} from $fromPhase to $toPhase"
|
||||
}
|
||||
var currentPhase = fromPhase
|
||||
val scopeSession = ScopeSession()
|
||||
while (currentPhase < toPhase) {
|
||||
if (checkPCE) checkCanceled()
|
||||
currentPhase = currentPhase.next
|
||||
|
||||
+4
-1
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.api.DiagnosticCheckerFilter
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.element.builder.FirTowerDataContextCollector
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.element.builder.getNonLocalContainingOrThisDeclaration
|
||||
@@ -120,13 +121,15 @@ internal class FileStructure(
|
||||
|
||||
private fun createStructureElement(container: KtAnnotated): FileStructureElement = when (container) {
|
||||
is KtFile -> {
|
||||
val scopeSession = ScopeSession()
|
||||
val firFile = firFileBuilder.getFirFileResolvedToPhaseWithCaching(
|
||||
container,
|
||||
moduleFileCache,
|
||||
FirResolvePhase.IMPORTS,
|
||||
scopeSession,
|
||||
checkPCE = true
|
||||
)
|
||||
firLazyDeclarationResolver.resolveFileAnnotations(firFile, moduleFileCache)
|
||||
firLazyDeclarationResolver.resolveFileAnnotations(firFile, moduleFileCache, scopeSession)
|
||||
RootStructureElement(
|
||||
firFile,
|
||||
container,
|
||||
|
||||
+5
-3
@@ -31,7 +31,7 @@ internal class FirLazyDeclarationResolver(
|
||||
fun resolveFileAnnotations(
|
||||
firFile: FirFile,
|
||||
moduleFileCache: ModuleFileCache,
|
||||
scopeSession: ScopeSession = ScopeSession()
|
||||
scopeSession: ScopeSession,
|
||||
) {
|
||||
firFileBuilder.runCustomResolveUnderLock(firFile, moduleFileCache) {
|
||||
val transformer = FirFileAnnotationsResolveTransformer(firFile.session, scopeSession)
|
||||
@@ -118,16 +118,19 @@ internal class FirLazyDeclarationResolver(
|
||||
) {
|
||||
if (fromPhase >= toPhase) return
|
||||
val nonLazyPhase = minOf(toPhase, LAST_NON_LAZY_PHASE)
|
||||
|
||||
val scopeSession = ScopeSession()
|
||||
if (fromPhase < nonLazyPhase) {
|
||||
firFileBuilder.runResolveWithoutLock(
|
||||
containerFirFile,
|
||||
fromPhase = fromPhase,
|
||||
toPhase = nonLazyPhase,
|
||||
scopeSession = scopeSession,
|
||||
checkPCE = checkPCE
|
||||
)
|
||||
}
|
||||
if (toPhase <= nonLazyPhase) return
|
||||
resolveFileAnnotations(containerFirFile, moduleFileCache)
|
||||
resolveFileAnnotations(containerFirFile, moduleFileCache, scopeSession)
|
||||
|
||||
val nonLocalDeclarationToResolve = firDeclarationToResolve.getNonLocalDeclarationToResolve(provider, moduleFileCache)
|
||||
val designation = nonLocalDeclarationToResolve.getDesignation(containerFirFile, provider, moduleFileCache)
|
||||
@@ -137,7 +140,6 @@ internal class FirLazyDeclarationResolver(
|
||||
}
|
||||
|
||||
var currentPhase = nonLazyPhase
|
||||
val scopeSession = ScopeSession()
|
||||
|
||||
while (currentPhase < toPhase) {
|
||||
currentPhase = currentPhase.next
|
||||
|
||||
Reference in New Issue
Block a user