From 4124a4908f742a39e8852271dd034c916bddde21 Mon Sep 17 00:00:00 2001
From: Ilya Kirillov <ilya.kirillov@jetbrains.com>
Date: Wed, 4 Jan 2023 12:20:19 +0100
Subject: [PATCH] [LL FIR] remove redundant function
 `runCustomResolveUnderLock` for locking

 Conflicts:
	analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedSupertypeResolverTransformer.kt
---
 .../fir/api/LowLevelFirApiFacadeForResolveOnAir.kt   |  3 +--
 .../level/api/fir/file/builder/LLFirLockProvider.kt  | 12 +-----------
 .../resolve/LLFirModuleLazyDeclarationResolver.kt    |  5 ++---
 .../LLFirDesignatedSupertypeResolverTransformer.kt   |  5 ++---
 4 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt
index 9af3c7d181a..5f1b162abdb 100644
--- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt
+++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/api/LowLevelFirApiFacadeForResolveOnAir.kt
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirResolveSessionDepend
 import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FileTowerProvider
 import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FirTowerContextProvider
 import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FirTowerDataContextAllElementsCollector
-import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.runCustomResolveUnderLock
 import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.FirElementsRecorder
 import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.KtToFirMapping
 import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.RawFirNonLocalDeclarationBuilder
@@ -247,7 +246,7 @@ object LowLevelFirApiFacadeForResolveOnAir {
 
         val isInBodyReplacement = isInBodyReplacement(nonLocalDeclaration, replacement)
 
-        return firResolveSession.globalComponents.lockProvider.runCustomResolveUnderLock(originalFirFile) {
+        return firResolveSession.globalComponents.lockProvider.withLock(originalFirFile) {
             val copiedFirDeclaration = if (isInBodyReplacement) {
                 when (originalDeclaration) {
                     is FirSimpleFunction ->
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirLockProvider.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirLockProvider.kt
index e9ff7aff2ec..5cf35e8fab8 100644
--- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirLockProvider.kt
+++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirLockProvider.kt
@@ -26,14 +26,4 @@ internal class LLFirLockProvider {
     }
 }
 
-private const val DEFAULT_LOCKING_INTERVAL = 50L
-
-/**
- * Runs [resolve] function (which is considered to do some resolve on [firFile]) under a lock for [firFile]
- */
-internal inline fun <R> LLFirLockProvider.runCustomResolveUnderLock(
-    firFile: FirFile,
-    body: () -> R
-): R {
-    return withLock(key = firFile, lockingIntervalMs = DEFAULT_LOCKING_INTERVAL, body)
-}
\ No newline at end of file
+private const val DEFAULT_LOCKING_INTERVAL = 50L
\ No newline at end of file
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/LLFirModuleLazyDeclarationResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/LLFirModuleLazyDeclarationResolver.kt
index 8808536d284..5510a430790 100644
--- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/LLFirModuleLazyDeclarationResolver.kt
+++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/LLFirModuleLazyDeclarationResolver.kt
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirModuleResolveCompone
 import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile
 import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
 import org.jetbrains.kotlin.analysis.low.level.api.fir.api.tryCollectDesignationWithFile
-import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.runCustomResolveUnderLock
 import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.llFirModuleData
 import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSessionInvalidator
 import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.llFirSession
@@ -70,7 +69,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.runCustomResolveUnderLock(firFile) {
+        moduleComponents.globalResolveComponents.lockProvider.withLock(firFile) {
             resolveFileToImportsWithoutLock(firFile)
         }
     }
@@ -113,7 +112,7 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
         for (designation in declarationDesignationsToResolve(target)) {
             if (!designation.target.isValidForResolve()) continue
             if (designation.target.resolvePhase >= toPhase) continue
-            moduleComponents.globalResolveComponents.lockProvider.runCustomResolveUnderLock(designation.firFile) {
+            moduleComponents.globalResolveComponents.lockProvider.withLock(designation.firFile) {
                 runLazyDesignatedResolveWithoutLock(
                     designation = designation,
                     scopeSession = scopeSession,
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedSupertypeResolverTransformer.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedSupertypeResolverTransformer.kt
index e336f99d15f..a2fca947cd4 100644
--- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedSupertypeResolverTransformer.kt
+++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedSupertypeResolverTransformer.kt
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
 import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile
 import org.jetbrains.kotlin.analysis.low.level.api.fir.api.collectDesignation
 import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
-import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.runCustomResolveUnderLock
 import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.llFirResolvableSession
 import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirLazyTransformer.Companion.updatePhaseDeep
 import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkCanceled
@@ -97,7 +96,7 @@ internal class LLFirDesignatedSupertypeResolverTransformer(
             checkCanceled()
             val resolver = DesignatedFirSupertypeResolverVisitor(designation)
             designation.firFile.lazyResolveToPhase(FirResolvePhase.IMPORTS)
-            lockProvider.runCustomResolveUnderLock(designation.firFile) {
+            lockProvider.withLock(designation.firFile) {
                 designation.firFile.accept(resolver, null)
             }
             resolver.declarationTransformer.ensureDesignationPassed()
@@ -146,7 +145,7 @@ internal class LLFirDesignatedSupertypeResolverTransformer(
         val filesToDesignations = designations.groupBy { it.firFile }
         for (designationsPerFile in filesToDesignations) {
             checkCanceled()
-            lockProvider.runCustomResolveUnderLock(designationsPerFile.key) {
+            lockProvider.withLock(designationsPerFile.key) {
                 val session = designationsPerFile.key.llFirResolvableSession
                     ?: error("When FirFile exists for the declaration, the session should be resolvevablable")
                 session.moduleComponents.sessionInvalidator.withInvalidationOnException(session) {
