Skip to content

Commit

Permalink
FIR IDE: make some session components to be non-thread local
Browse files Browse the repository at this point in the history
To avoid memory leaks
  • Loading branch information
darthorimar committed Nov 23, 2020
1 parent c3caa3a commit 65b5e4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ private constructor(
override val scopeProvider by threadLocal { KtFirScopeProvider(this, firSymbolBuilder, project, firResolveState, token) }
override val symbolProvider: KtSymbolProvider =
KtFirSymbolProvider(this, firResolveState.rootModuleSession.firSymbolProvider, firResolveState, firSymbolBuilder, token)
override val completionCandidateChecker: KtCompletionCandidateChecker by threadLocal { KtFirCompletionCandidateChecker(this, token) }
override val symbolDeclarationOverridesProvider: KtSymbolDeclarationOverridesProvider
by threadLocal { KtFirSymbolDeclarationOverridesProvider(this, token) }
override val completionCandidateChecker: KtCompletionCandidateChecker = KtFirCompletionCandidateChecker(this, token)
override val symbolDeclarationOverridesProvider: KtSymbolDeclarationOverridesProvider =
KtFirSymbolDeclarationOverridesProvider(this, token)

override fun createContextDependentCopy(): KtAnalysisSession {
check(!isContextSession) { "Cannot create context-dependent copy of KtAnalysis session from a context dependent one" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.concurrent.ConcurrentHashMap

internal class KtFirCompletionCandidateChecker(
analysisSession: KtFirAnalysisSession,
Expand All @@ -40,7 +41,7 @@ internal class KtFirCompletionCandidateChecker(
override val analysisSession: KtFirAnalysisSession by weakRef(analysisSession)

private val completionContextCache =
HashMap<Pair<FirFile, KtCallableDeclaration>, LowLevelFirApiFacadeForCompletion.FirCompletionContext>()
ConcurrentHashMap<Pair<FirFile, KtCallableDeclaration>, LowLevelFirApiFacadeForCompletion.FirCompletionContext>()

override fun checkExtensionFitsCandidate(
firSymbolForCandidate: KtCallableSymbol,
Expand Down Expand Up @@ -94,7 +95,7 @@ internal class KtFirCompletionCandidateChecker(
): Sequence<ImplicitReceiverValue<*>?> {
val enclosingContext = EnclosingDeclarationContext.detect(originalFile, fakeNameExpression)

val completionContext = completionContextCache.getOrCreate(firFile to enclosingContext.fakeEnclosingDeclaration) {
val completionContext = completionContextCache.computeIfAbsent(firFile to enclosingContext.fakeEnclosingDeclaration) {
enclosingContext.buildCompletionContext(firFile, firResolveState)
}

Expand Down

0 comments on commit 65b5e4b

Please sign in to comment.