From 58ed52ee1f659b4d5a05ff5c2b14041ba82ccd17 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Mon, 22 Jan 2024 17:01:59 +0100 Subject: [PATCH] [LL FIR] LLFirTargetResolver: drop withPossiblyJumpingLock function We should have explicit separation for jumping and non-jumping ^KT-56551 --- .../fir/transformers/LLFirTargetResolver.kt | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt index cccd13bd13e..bfc812f11bb 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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. */ @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry import org.jetbrains.kotlin.resolve.DataClassResolver import org.jetbrains.kotlin.utils.exceptions.checkWithAttachment import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment +import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment internal abstract class LLFirTargetResolver( protected val resolveTarget: LLFirResolveTarget, @@ -166,25 +167,44 @@ internal abstract class LLFirTargetResolver( resolveDependencies(target) if (doResolveWithoutLock(target)) return - performCustomResolveUnderLock(target) { - doLazyResolveUnderLock(target) + + if (isJumpingPhase) { + lockProvider.withJumpingLock( + target, + resolverPhase, + action = { + doLazyResolveUnderLock(target) + updatePhaseForDeclarationInternals(target) + } + ) + } else { + performCustomResolveUnderLock(target) { + doLazyResolveUnderLock(target) + } } } + /** + * Execute [action] under the write lock in the context of [target]. + * + * Allowed only for non-jumping phases. + * + * @see isJumpingPhase + */ protected inline fun performCustomResolveUnderLock(target: FirElementWithResolveState, crossinline action: () -> Unit) { checkThatResolvedAtLeastToPreviousPhase(target) - withPossiblyJumpingLock(target) { + requireWithAttachment(!isJumpingPhase, { "This function cannot be called for jumping phase" }) { + withFirEntry("target", target) + } + + lockProvider.withWriteLock(target, resolverPhase) { action() - LLFirLazyPhaseResolverByPhase.getByPhase(resolverPhase).updatePhaseForDeclarationInternals(target) + updatePhaseForDeclarationInternals(target) } } - private inline fun withPossiblyJumpingLock(target: FirElementWithResolveState, action: () -> Unit) { - if (isJumpingPhase) { - lockProvider.withJumpingLock(target, resolverPhase, action) - } else { - lockProvider.withWriteLock(target, resolverPhase, action) - } + private fun updatePhaseForDeclarationInternals(target: FirElementWithResolveState) { + LLFirLazyPhaseResolverByPhase.getByPhase(resolverPhase).updatePhaseForDeclarationInternals(target) } /**