[FIR] FirResolvePhase: introduce isItAllowedToCallLazyResolveTo

To explicitly declare when it is possible to call lazy resolve
This commit is contained in:
Dmitrii Gridin
2024-03-13 17:06:18 +01:00
committed by Space Team
parent f036954ac0
commit c7765258d1
4 changed files with 36 additions and 7 deletions
@@ -200,7 +200,7 @@ internal class LLFirLockProvider(private val checker: LLFirLazyResolveContractCh
actionUnderLock: () -> Unit,
actionOnCycle: () -> Unit,
) {
checker.lazyResolveToPhaseInside(phase, isJumpingPhase = true) {
checker.lazyResolveToPhaseInside(phase) {
target.withJumpingLockImpl(phase, actionUnderLock, actionOnCycle)
}
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve
import com.intellij.openapi.diagnostic.Logger
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.isItAllowedToCallLazyResolveTo
import org.jetbrains.kotlin.fir.symbols.FirLazyResolveContractViolationException
/**
@@ -18,8 +19,9 @@ import org.jetbrains.kotlin.fir.symbols.FirLazyResolveContractViolationException
internal class LLFirLazyResolveContractChecker {
private val currentTransformerPhase = ThreadLocal.withInitial<FirResolvePhase?> { null }
inline fun lazyResolveToPhaseInside(phase: FirResolvePhase, isJumpingPhase: Boolean = false, resolve: () -> Unit) {
checkIfCanLazyResolveToPhase(phase, isJumpingPhase)
inline fun lazyResolveToPhaseInside(phase: FirResolvePhase, resolve: () -> Unit) {
checkIfCanLazyResolveToPhase(phase)
val previousPhase = currentTransformerPhase.get()
currentTransformerPhase.set(phase)
try {
@@ -29,10 +31,10 @@ internal class LLFirLazyResolveContractChecker {
}
}
internal fun checkIfCanLazyResolveToPhase(requestedPhase: FirResolvePhase, isJumpingPhase: Boolean) {
private fun checkIfCanLazyResolveToPhase(requestedPhase: FirResolvePhase) {
val currentPhase = currentTransformerPhase.get() ?: return
if (requestedPhase > currentPhase || !isJumpingPhase && requestedPhase == currentPhase) {
if (!currentPhase.isItAllowedToCallLazyResolveTo(requestedPhase)) {
val exception = FirLazyResolveContractViolationException(currentPhase = currentPhase, requestedPhase = requestedPhase)
if (System.getProperty("kotlin.suppress.lazy.resolve.contract.violation") != null) {
LoggerHolder.LOG.warn(exception)