[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,
|
resolveTarget: LLFirResolveTarget,
|
||||||
resolvePhase: FirResolvePhase,
|
resolvePhase: FirResolvePhase,
|
||||||
protected val llImplicitBodyResolveComputationSession: LLImplicitBodyResolveComputationSession = LLImplicitBodyResolveComputationSession(),
|
protected val llImplicitBodyResolveComputationSession: LLImplicitBodyResolveComputationSession = LLImplicitBodyResolveComputationSession(),
|
||||||
requiresJumpingLock: Boolean = false,
|
) : LLFirTargetResolver(resolveTarget, resolvePhase) {
|
||||||
) : LLFirTargetResolver(resolveTarget, resolvePhase, requiresJumpingLock) {
|
|
||||||
protected fun createReturnTypeCalculator(): LLFirReturnTypeCalculatorWithJump = LLFirReturnTypeCalculatorWithJump(
|
protected fun createReturnTypeCalculator(): LLFirReturnTypeCalculatorWithJump = LLFirReturnTypeCalculatorWithJump(
|
||||||
resolveTargetScopeSession,
|
resolveTargetScopeSession,
|
||||||
llImplicitBodyResolveComputationSession,
|
llImplicitBodyResolveComputationSession,
|
||||||
|
|||||||
-1
@@ -143,7 +143,6 @@ internal class LLFirImplicitBodyTargetResolver(
|
|||||||
target,
|
target,
|
||||||
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE,
|
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE,
|
||||||
llImplicitBodyResolveComputationSession = llImplicitBodyResolveComputationSessionParameter ?: LLImplicitBodyResolveComputationSession(),
|
llImplicitBodyResolveComputationSession = llImplicitBodyResolveComputationSessionParameter ?: LLImplicitBodyResolveComputationSession(),
|
||||||
requiresJumpingLock = true,
|
|
||||||
) {
|
) {
|
||||||
override val transformer = object : FirImplicitAwareBodyResolveTransformer(
|
override val transformer = object : FirImplicitAwareBodyResolveTransformer(
|
||||||
resolveTargetSession,
|
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.FirScript
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||||
import org.jetbrains.kotlin.fir.declarations.destructuringDeclarationContainerVariable
|
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.componentFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
import org.jetbrains.kotlin.fir.declarations.utils.correspondingValueParameterFromPrimaryConstructor
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.fromPrimaryConstructor
|
import org.jetbrains.kotlin.fir.declarations.utils.fromPrimaryConstructor
|
||||||
@@ -77,11 +78,11 @@ import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment
|
|||||||
internal sealed class LLFirTargetResolver(
|
internal sealed class LLFirTargetResolver(
|
||||||
protected val resolveTarget: LLFirResolveTarget,
|
protected val resolveTarget: LLFirResolveTarget,
|
||||||
val resolverPhase: FirResolvePhase,
|
val resolverPhase: FirResolvePhase,
|
||||||
private val requiresJumpingLock: Boolean = false,
|
|
||||||
) : LLFirResolveTargetVisitor {
|
) : LLFirResolveTargetVisitor {
|
||||||
val resolveTargetSession: LLFirSession get() = resolveTarget.session
|
val resolveTargetSession: LLFirSession get() = resolveTarget.session
|
||||||
val resolveTargetScopeSession: ScopeSession get() = resolveTargetSession.getScopeSession()
|
val resolveTargetScopeSession: ScopeSession get() = resolveTargetSession.getScopeSession()
|
||||||
private val lockProvider: LLFirLockProvider get() = LLFirGlobalResolveComponents.getInstance(resolveTargetSession).lockProvider
|
private val lockProvider: LLFirLockProvider get() = LLFirGlobalResolveComponents.getInstance(resolveTargetSession).lockProvider
|
||||||
|
private val requiresJumpingLock: Boolean get() = resolverPhase.isItAllowedToCallLazyResolveToTheSamePhase
|
||||||
|
|
||||||
private val _containingDeclarations = mutableListOf<FirDeclaration>()
|
private val _containingDeclarations = mutableListOf<FirDeclaration>()
|
||||||
|
|
||||||
|
|||||||
@@ -238,18 +238,34 @@ val FirResolvePhase.isBodyResolve: Boolean
|
|||||||
* @see FirResolvePhase
|
* @see FirResolvePhase
|
||||||
* @see org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
* @see org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||||
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||||
|
* @see isItAllowedToCallLazyResolveToTheSamePhase
|
||||||
*/
|
*/
|
||||||
fun FirResolvePhase.isItAllowedToCallLazyResolveTo(requestedPhase: FirResolvePhase): Boolean = when {
|
fun FirResolvePhase.isItAllowedToCallLazyResolveTo(requestedPhase: FirResolvePhase): Boolean = when {
|
||||||
// It is fine to call lazy resolution for all phases less than our
|
// It is fine to call lazy resolution for all phases less than our
|
||||||
this > requestedPhase -> true
|
this > requestedPhase -> true
|
||||||
|
|
||||||
// It is legal only in specific cases
|
// It is legal only in specific cases
|
||||||
this == requestedPhase -> when (requestedPhase) {
|
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,
|
// 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
|
// which can jump into the Kotlin world again, and we cannot provide the initial context
|
||||||
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE -> true
|
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE -> true
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user