[LL FIR] introduce lazyResolveRecursively API

FirFile after KT-56683 has its own phases and resolution logic,
so we should have a separate API for lazy resolution for FirFile and for
the entire file

^KT-61296 Fixed
This commit is contained in:
Dmitrii Gridin
2023-09-11 20:13:40 +02:00
committed by Space Team
parent b77ae5d275
commit 31b36ee766
16 changed files with 120 additions and 55 deletions
@@ -16,4 +16,5 @@ object FirDummyCompilerLazyDeclarationResolver : FirLazyDeclarationResolver() {
override fun lazyResolveToPhase(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase) {}
override fun lazyResolveToPhaseWithCallableMembers(symbol: FirClassSymbol<*>, toPhase: FirResolvePhase) {}
override fun lazyResolveToPhaseRecursively(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase) {}
}
@@ -40,8 +40,20 @@ abstract class FirLazyDeclarationResolver : FirSessionComponent {
}
}
/**
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
*/
abstract fun lazyResolveToPhase(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase)
/**
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhaseWithCallableMembers
*/
abstract fun lazyResolveToPhaseWithCallableMembers(symbol: FirClassSymbol<*>, toPhase: FirResolvePhase)
/**
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhaseRecursively
*/
abstract fun lazyResolveToPhaseRecursively(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase)
}
class FirLazyResolveContractViolationException(
@@ -104,7 +116,6 @@ fun FirDeclaration.lazyResolveToPhase(toPhase: FirResolvePhase) {
*
* @see lazyResolveToPhase
*/
fun FirClassSymbol<*>.lazyResolveToPhaseWithCallableMembers(toPhase: FirResolvePhase) {
fir.lazyDeclarationResolver.lazyResolveToPhaseWithCallableMembers(this, toPhase)
}
@@ -117,3 +128,31 @@ fun FirClassSymbol<*>.lazyResolveToPhaseWithCallableMembers(toPhase: FirResolveP
fun FirClass.lazyResolveToPhaseWithCallableMembers(toPhase: FirResolvePhase) {
symbol.lazyResolveToPhaseWithCallableMembers(toPhase)
}
/**
* Lazy resolve [FirBasedSymbol] and all nested declarations to [FirResolvePhase].
*
* In the case of lazy resolution (inside Analysis API), it checks that the declaration phase `>= toPhase`.
* If not, it resolves the declaration for the requested phase.
*
* If the [lazyResolveToPhase] is called inside a fir transformer,
* it should always request the phase which is strictly lower than the current transformer phase,
* otherwise a deadlock/StackOverflow is possible.
*
* For the compiler mode, it does nothing, as the compiler is non-lazy.
*
* @receiver [FirBasedSymbol] which should be resolved
* @param toPhase the minimum phase, the declaration and all nested declarations should be resolved to after an execution of the [lazyResolveToPhase]
*/
fun FirBasedSymbol<*>.lazyResolveToPhaseRecursively(toPhase: FirResolvePhase) {
fir.lazyDeclarationResolver.lazyResolveToPhaseRecursively(this, toPhase)
}
/**
* Lazy resolve [FirDeclaration] and all nested declarations to [FirResolvePhase].
*
* @see lazyResolveToPhaseRecursively
*/
fun FirDeclaration.lazyResolveToPhaseRecursively(toPhase: FirResolvePhase) {
symbol.lazyResolveToPhaseRecursively(toPhase)
}
@@ -1,5 +1,4 @@
// IGNORE_REVERSED_RESOLVE
// IGNORE_CONTRACT_VIOLATIONS
// FIR_IDENTICAL
@Retention(AnnotationRetention.SOURCE)
@Repeatable
@@ -28,6 +28,10 @@ class FirCompilerLazyDeclarationResolverWithPhaseChecking : FirLazyDeclarationRe
checkIfCanLazyResolveToPhase(toPhase)
}
override fun lazyResolveToPhaseRecursively(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase) {
checkIfCanLazyResolveToPhase(toPhase)
}
override fun startResolvingPhase(phase: FirResolvePhase) {
check(currentTransformerPhase == null)
currentTransformerPhase = phase