From da9cf1468c176201e365895292183e7ed23cf761 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Tue, 9 Aug 2022 14:14:27 +0200 Subject: [PATCH] [FIR] add KDoc to lazy resolution functions --- .../fir/symbols/FirLazyDeclarationResolver.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/FirLazyDeclarationResolver.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/FirLazyDeclarationResolver.kt index 0f10f1cceb3..7a21b428416 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/FirLazyDeclarationResolver.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/FirLazyDeclarationResolver.kt @@ -10,18 +10,44 @@ import org.jetbrains.kotlin.fir.FirSessionComponent import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirResolvePhase +/** + * A component to lazy resolve [FirBasedSymbol] to the required phase. + * + * This is needed for the Analysis API to work properly, for the compiler the implementation does nothing. + * + * @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase + */ abstract class FirLazyDeclarationResolver : FirSessionComponent { abstract fun lazyResolveToPhase(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase) } val FirSession.lazyDeclarationResolver: FirLazyDeclarationResolver by FirSession.sessionComponentAccessor() +/** + * Lazy resolve [FirBasedSymbol] 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 should be resolved to after an execution of the [lazyResolveToPhase] + */ fun FirBasedSymbol<*>.lazyResolveToPhase(toPhase: FirResolvePhase) { val session = fir.moduleData.session val phaseManager = session.lazyDeclarationResolver phaseManager.lazyResolveToPhase(this, toPhase) } +/** + * Lazy resolve [FirDeclaration] to [FirResolvePhase]. + * + * @see lazyResolveToPhase + */ fun FirDeclaration.lazyResolveToPhase(toPhase: FirResolvePhase) { symbol.lazyResolveToPhase(toPhase) }