[LL FIR] lazy resolve imports under a separate lock

^KT-56543
This commit is contained in:
Ilya Kirillov
2022-12-29 15:49:19 +01:00
committed by Space Team
parent c1fb6528aa
commit 930708ebb0
2 changed files with 12 additions and 2 deletions
@@ -1,10 +1,11 @@
/*
* Copyright 2010-2020 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.
*/
package org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder
import com.intellij.util.containers.ContainerUtil
import com.intellij.openapi.progress.ProcessCanceledException
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.llFirSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.lockWithPCECheck
@@ -19,6 +20,8 @@ internal class LLFirLockProvider {
//We temporarily disable multi-locks to fix deadlocks problem
private val globalLock = ReentrantLock()
private val locksForImports = ContainerUtil.createConcurrentSoftMap<FirFile, ReentrantLock>()
inline fun <R> withLock(
key: FirFile,
lockingIntervalMs: Long = DEFAULT_LOCKING_INTERVAL,
@@ -32,6 +35,13 @@ internal class LLFirLockProvider {
action()
}
}
inline fun <R> withLocksForImportResolution(
file: FirFile,
action: () -> R
): R {
return locksForImports.getOrPut(file) { ReentrantLock() }.lockWithPCECheck(DEFAULT_LOCKING_INTERVAL) { action() }
}
}
private const val DEFAULT_LOCKING_INTERVAL = 50L
@@ -68,7 +68,7 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
if (target.resolvePhase >= FirResolvePhase.IMPORTS) return
val firFile = target.getContainingFile() ?: return
if (firFile.resolvePhase >= FirResolvePhase.IMPORTS) return
moduleComponents.globalResolveComponents.lockProvider.withLock(firFile) {
moduleComponents.globalResolveComponents.lockProvider.withLocksForImportResolution(firFile) {
resolveFileToImportsWithoutLock(firFile)
}
}