[FIR] FirResolvePhase: introduce isItAllowedToCallLazyResolveTo
To explicitly declare when it is possible to call lazy resolve
This commit is contained in:
committed by
Space Team
parent
f036954ac0
commit
c7765258d1
@@ -46,6 +46,7 @@ package org.jetbrains.kotlin.fir.declarations
|
||||
* 2. The compiler **must not request and cannot rely on any information from the higher phases**.
|
||||
* For example, during the [STATUS] phase, we cannot access information regarding implicit types
|
||||
* as they will only be calculated during the [IMPLICIT_TYPES_BODY_RESOLVE] phase.
|
||||
* See [isItAllowedToCallLazyResolveTo] as a reference.
|
||||
*
|
||||
* 3. The compiler **can request and rely on the information from the current phase only during *jumping phases***.
|
||||
* For example, during the [TYPES] phase,
|
||||
@@ -227,3 +228,28 @@ val FirResolvePhase.isBodyResolve: Boolean
|
||||
FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
/**
|
||||
* See [FirResolvePhase] KDoc for more details about resolution contacts.
|
||||
*
|
||||
* @param this The current phase
|
||||
* @param requestedPhase The requested phase
|
||||
*
|
||||
* @see FirResolvePhase
|
||||
* @see org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
* @see org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
import org.jetbrains.kotlin.fir.FirElementWithResolveState
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.isItAllowedToCallLazyResolveTo
|
||||
import org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.fir.symbols.FirLazyResolveContractViolationException
|
||||
|
||||
@@ -53,7 +54,7 @@ class FirCompilerLazyDeclarationResolverWithPhaseChecking : FirLazyDeclarationRe
|
||||
// However, now we keep more strict invariant here,
|
||||
// because we don't want to hide some cases when transformers violate phase contract directly
|
||||
// but due to usage of already resolved stdlib classes we don't see it
|
||||
if (requestedPhase >= currentPhase) {
|
||||
if (!currentPhase.isItAllowedToCallLazyResolveTo(requestedPhase)) {
|
||||
exceptions += FirLazyResolveContractViolationException(
|
||||
currentPhase = currentPhase,
|
||||
requestedPhase = requestedPhase,
|
||||
|
||||
Reference in New Issue
Block a user