[FIR] FirResolvePhase: introduce isItAllowedToCallLazyResolveToTheSamePhase
To have explicitly declared contracts
This commit is contained in:
committed by
Space Team
parent
d67dde8395
commit
a0120d28cc
+1
-2
@@ -19,8 +19,7 @@ internal sealed class LLFirAbstractBodyTargetResolver(
|
||||
resolveTarget: LLFirResolveTarget,
|
||||
resolvePhase: FirResolvePhase,
|
||||
protected val llImplicitBodyResolveComputationSession: LLImplicitBodyResolveComputationSession = LLImplicitBodyResolveComputationSession(),
|
||||
requiresJumpingLock: Boolean = false,
|
||||
) : LLFirTargetResolver(resolveTarget, resolvePhase, requiresJumpingLock) {
|
||||
) : LLFirTargetResolver(resolveTarget, resolvePhase) {
|
||||
protected fun createReturnTypeCalculator(): LLFirReturnTypeCalculatorWithJump = LLFirReturnTypeCalculatorWithJump(
|
||||
resolveTargetScopeSession,
|
||||
llImplicitBodyResolveComputationSession,
|
||||
|
||||
-1
@@ -143,7 +143,6 @@ internal class LLFirImplicitBodyTargetResolver(
|
||||
target,
|
||||
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE,
|
||||
llImplicitBodyResolveComputationSession = llImplicitBodyResolveComputationSessionParameter ?: LLImplicitBodyResolveComputationSession(),
|
||||
requiresJumpingLock = true,
|
||||
) {
|
||||
override val transformer = object : FirImplicitAwareBodyResolveTransformer(
|
||||
resolveTargetSession,
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirScript
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.destructuringDeclarationContainerVariable
|
||||
import org.jetbrains.kotlin.fir.declarations.isItAllowedToCallLazyResolveToTheSamePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.componentFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.fromPrimaryConstructor
|
||||
@@ -77,11 +78,11 @@ import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment
|
||||
internal sealed class LLFirTargetResolver(
|
||||
protected val resolveTarget: LLFirResolveTarget,
|
||||
val resolverPhase: FirResolvePhase,
|
||||
private val requiresJumpingLock: Boolean = false,
|
||||
) : LLFirResolveTargetVisitor {
|
||||
val resolveTargetSession: LLFirSession get() = resolveTarget.session
|
||||
val resolveTargetScopeSession: ScopeSession get() = resolveTargetSession.getScopeSession()
|
||||
private val lockProvider: LLFirLockProvider get() = LLFirGlobalResolveComponents.getInstance(resolveTargetSession).lockProvider
|
||||
private val requiresJumpingLock: Boolean get() = resolverPhase.isItAllowedToCallLazyResolveToTheSamePhase
|
||||
|
||||
private val _containingDeclarations = mutableListOf<FirDeclaration>()
|
||||
|
||||
|
||||
@@ -238,18 +238,34 @@ val FirResolvePhase.isBodyResolve: Boolean
|
||||
* @see FirResolvePhase
|
||||
* @see org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
* @see isItAllowedToCallLazyResolveToTheSamePhase
|
||||
*/
|
||||
fun FirResolvePhase.isItAllowedToCallLazyResolveTo(requestedPhase: FirResolvePhase): Boolean = when {
|
||||
// It is fine to call lazy resolution for all phases less than our
|
||||
this > requestedPhase -> true
|
||||
|
||||
// It is legal only in specific cases
|
||||
this == requestedPhase -> when (requestedPhase) {
|
||||
// The resolver can jump into Java initializer during this phase,
|
||||
// which can jump into the Kotlin world again, and we cannot provide the initial context
|
||||
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE -> true
|
||||
else -> false
|
||||
}
|
||||
this == requestedPhase -> isItAllowedToCallLazyResolveToTheSamePhase
|
||||
|
||||
else -> false
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: not all ***jumping phases*** can be [isItAllowedToCallLazyResolveToTheSamePhase],
|
||||
* but all [isItAllowedToCallLazyResolveToTheSamePhase] phases are ***jumping phases***
|
||||
* due to the implementation details.
|
||||
*
|
||||
* @return **true** if it is allowed to call [lazyResolveToPhase][org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase]
|
||||
* into the same phase
|
||||
*
|
||||
* @see org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
*/
|
||||
val FirResolvePhase.isItAllowedToCallLazyResolveToTheSamePhase: Boolean
|
||||
get() = when (this) {
|
||||
// The resolver can jump into Java initializer during this phase,
|
||||
// which can jump into the Kotlin world again, and we cannot provide the initial context
|
||||
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE -> true
|
||||
|
||||
else -> false
|
||||
}
|
||||
Reference in New Issue
Block a user