FIR IDE: run SUPER_TYPES & BODY_RESOLVE phases under global lock
This commit is contained in:
+2
-1
@@ -46,10 +46,11 @@ internal class FirIdeJavaModuleBasedSession private constructor(
|
|||||||
fun create(
|
fun create(
|
||||||
project: Project,
|
project: Project,
|
||||||
moduleInfo: ModuleSourceInfo,
|
moduleInfo: ModuleSourceInfo,
|
||||||
|
firPhaseRunner: FirPhaseRunner,
|
||||||
sessionProvider: FirSessionProvider,
|
sessionProvider: FirSessionProvider,
|
||||||
): FirIdeJavaModuleBasedSession {
|
): FirIdeJavaModuleBasedSession {
|
||||||
val scopeProvider = KotlinScopeProvider(::wrapScopeWithJvmMapped)
|
val scopeProvider = KotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||||
val firBuilder = FirFileBuilder(sessionProvider as FirIdeSessionProvider, scopeProvider)
|
val firBuilder = FirFileBuilder(sessionProvider as FirIdeSessionProvider, scopeProvider, firPhaseRunner)
|
||||||
return FirIdeJavaModuleBasedSession(moduleInfo, sessionProvider, firBuilder).apply {
|
return FirIdeJavaModuleBasedSession(moduleInfo, sessionProvider, firBuilder).apply {
|
||||||
val cache = ModuleFileCacheImpl(this)
|
val cache = ModuleFileCacheImpl(this)
|
||||||
val phasedFirFileResolver = IdePhasedFirFileResolver(firBuilder, cache)
|
val phasedFirFileResolver = IdePhasedFirFileResolver(firBuilder, cache)
|
||||||
|
|||||||
+2
@@ -18,9 +18,11 @@ internal class FirIdeResolveStateService(private val project: Project) {
|
|||||||
|
|
||||||
private fun createResolveStateFor(moduleInfo: IdeaModuleInfo): FirModuleResolveStateImpl {
|
private fun createResolveStateFor(moduleInfo: IdeaModuleInfo): FirModuleResolveStateImpl {
|
||||||
val sessionProvider = FirIdeSessionProvider(project)
|
val sessionProvider = FirIdeSessionProvider(project)
|
||||||
|
val firPhaseRunner = FirPhaseRunner()
|
||||||
val session = FirIdeJavaModuleBasedSession.create(
|
val session = FirIdeJavaModuleBasedSession.create(
|
||||||
project,
|
project,
|
||||||
moduleInfo as ModuleSourceInfo,
|
moduleInfo as ModuleSourceInfo,
|
||||||
|
firPhaseRunner,
|
||||||
sessionProvider,
|
sessionProvider,
|
||||||
).apply { sessionProvider.registerSession(moduleInfo, this) }
|
).apply { sessionProvider.registerSession(moduleInfo, this) }
|
||||||
|
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.fir.low.level.api
|
||||||
|
|
||||||
|
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.fir.resolve.transformers.createTransformerBasedProcessorByPhase
|
||||||
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
|
import kotlin.concurrent.withLock
|
||||||
|
|
||||||
|
internal class FirPhaseRunner {
|
||||||
|
private val superTypesBodyResolveLock = ReentrantLock()
|
||||||
|
private val implicitTypesResolveLock = ReentrantLock()
|
||||||
|
|
||||||
|
fun runPhase(firFile: FirFile, phase: FirResolvePhase, scopeSession: ScopeSession) = when (phase) {
|
||||||
|
FirResolvePhase.SUPER_TYPES -> superTypesBodyResolveLock.withLock {
|
||||||
|
runPhaseWithoutLock(firFile, phase, scopeSession)
|
||||||
|
}
|
||||||
|
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE -> implicitTypesResolveLock.withLock {
|
||||||
|
runPhaseWithoutLock(firFile, phase, scopeSession)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
runPhaseWithoutLock(firFile, phase, scopeSession)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runPhaseWithoutLock(firFile: FirFile, phase: FirResolvePhase, scopeSession: ScopeSession) {
|
||||||
|
val phaseProcessor = phase.createTransformerBasedProcessorByPhase(firFile.session, scopeSession)
|
||||||
|
phaseProcessor.processFile(firFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-3
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
|||||||
import org.jetbrains.kotlin.fir.resolve.transformers.createTransformerBasedProcessorByPhase
|
import org.jetbrains.kotlin.fir.resolve.transformers.createTransformerBasedProcessorByPhase
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
||||||
import org.jetbrains.kotlin.idea.fir.low.level.api.FirIdeSessionProvider
|
import org.jetbrains.kotlin.idea.fir.low.level.api.FirIdeSessionProvider
|
||||||
|
import org.jetbrains.kotlin.idea.fir.low.level.api.FirPhaseRunner
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.ThreadSafe
|
import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.ThreadSafe
|
||||||
|
|
||||||
@@ -22,7 +23,8 @@ import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.ThreadSafe
|
|||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
internal class FirFileBuilder(
|
internal class FirFileBuilder(
|
||||||
private val sessionProvider: FirIdeSessionProvider,
|
private val sessionProvider: FirIdeSessionProvider,
|
||||||
private val scopeProvider: FirScopeProvider
|
private val scopeProvider: FirScopeProvider,
|
||||||
|
private val firPhaseRunner: FirPhaseRunner
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Builds a [FirFile] by given [ktFile] and records it's parenting info if it not present in [cache]
|
* Builds a [FirFile] by given [ktFile] and records it's parenting info if it not present in [cache]
|
||||||
@@ -70,8 +72,7 @@ internal class FirFileBuilder(
|
|||||||
var currentPhase = fromPhase
|
var currentPhase = fromPhase
|
||||||
while (currentPhase < toPhase) {
|
while (currentPhase < toPhase) {
|
||||||
currentPhase = currentPhase.next
|
currentPhase = currentPhase.next
|
||||||
val phaseProcessor = currentPhase.createTransformerBasedProcessorByPhase(firFile.session, scopeSession)
|
firPhaseRunner.runPhase(firFile, currentPhase, scopeSession)
|
||||||
phaseProcessor.processFile(firFile)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user