[LL FIR] add api to FirLazyDeclarationResolver to resolve class with callable members
^KT-56543
This commit is contained in:
committed by
Space Team
parent
25cb03b707
commit
23e40693a3
+9
@@ -7,9 +7,11 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir
|
||||
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirResolvableModuleSession
|
||||
import org.jetbrains.kotlin.fir.ThreadSafeMutableState
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
|
||||
@ThreadSafeMutableState
|
||||
internal class LLFirLazyDeclarationResolver : FirLazyDeclarationResolver() {
|
||||
@@ -27,4 +29,11 @@ internal class LLFirLazyDeclarationResolver : FirLazyDeclarationResolver() {
|
||||
toPhase = toPhase,
|
||||
)
|
||||
}
|
||||
|
||||
override fun lazyResolveToPhaseWithCallableMembers(symbol: FirClassSymbol<*>, toPhase: FirResolvePhase) {
|
||||
val fir = symbol.fir as? FirRegularClass ?: return
|
||||
val session = fir.moduleData.session
|
||||
if (session !is LLFirResolvableModuleSession) return
|
||||
// TODO: should be implemented in the context of KT-56543
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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,10 +8,12 @@ package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
|
||||
object FirDummyCompilerLazyDeclarationResolver : FirLazyDeclarationResolver() {
|
||||
override fun startResolvingPhase(phase: FirResolvePhase) {}
|
||||
override fun finishResolvingPhase(phase: FirResolvePhase) {}
|
||||
|
||||
override fun lazyResolveToPhase(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase) {}
|
||||
override fun lazyResolveToPhaseWithCallableMembers(symbol: FirClassSymbol<*>, toPhase: FirResolvePhase) {}
|
||||
}
|
||||
|
||||
+40
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.fir.symbols
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
|
||||
/**
|
||||
* A component to lazy resolve [FirBasedSymbol] to the required phase.
|
||||
@@ -24,7 +26,7 @@ abstract class FirLazyDeclarationResolver : FirSessionComponent {
|
||||
|
||||
abstract fun finishResolvingPhase(phase: FirResolvePhase)
|
||||
|
||||
fun disableLazyResolveContractChecks(){
|
||||
fun disableLazyResolveContractChecks() {
|
||||
lazyResolveContractChecksEnabled = false
|
||||
}
|
||||
|
||||
@@ -39,10 +41,13 @@ abstract class FirLazyDeclarationResolver : FirSessionComponent {
|
||||
}
|
||||
|
||||
abstract fun lazyResolveToPhase(symbol: FirBasedSymbol<*>, toPhase: FirResolvePhase)
|
||||
abstract fun lazyResolveToPhaseWithCallableMembers(symbol: FirClassSymbol<*>, toPhase: FirResolvePhase)
|
||||
}
|
||||
|
||||
val FirSession.lazyDeclarationResolver: FirLazyDeclarationResolver by FirSession.sessionComponentAccessor()
|
||||
|
||||
private val FirDeclaration.lazyDeclarationResolver get() = moduleData.session.lazyDeclarationResolver
|
||||
|
||||
/**
|
||||
* Lazy resolve [FirBasedSymbol] to [FirResolvePhase].
|
||||
*
|
||||
@@ -58,9 +63,7 @@ val FirSession.lazyDeclarationResolver: FirLazyDeclarationResolver by FirSession
|
||||
* @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)
|
||||
fir.lazyDeclarationResolver.lazyResolveToPhase(this, toPhase)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,3 +74,35 @@ fun FirBasedSymbol<*>.lazyResolveToPhase(toPhase: FirResolvePhase) {
|
||||
fun FirDeclaration.lazyResolveToPhase(toPhase: FirResolvePhase) {
|
||||
symbol.lazyResolveToPhase(toPhase)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy resolve [FirClassSymbol] and its callable members to [FirResolvePhase].
|
||||
*
|
||||
* Might resolve additional required declarations.
|
||||
*
|
||||
* @receiver [FirClassSymbol] which should be resolved and which callable members should be resolved
|
||||
* @param toPhase the minimum phase, the declaration and callable members should be resolved
|
||||
* to after an execution of the [lazyResolveToPhaseWithCallableMembers]
|
||||
*
|
||||
* Can be used instead of [lazyResolveToPhase] to avoid extra resolve calls.
|
||||
* Effectively the same as:
|
||||
* ```
|
||||
* kclass.lazyResolveToPhase(phase)
|
||||
* kclass.callableDeclarations.forEach { it.lazyResolveToPhase(phase) }
|
||||
* ```
|
||||
*
|
||||
* @see lazyResolveToPhase
|
||||
*/
|
||||
|
||||
fun FirClassSymbol<*>.lazyResolveToPhaseWithCallableMembers(toPhase: FirResolvePhase) {
|
||||
fir.lazyDeclarationResolver.lazyResolveToPhaseWithCallableMembers(this, toPhase)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy resolve [FirClass] and its callable members to [FirResolvePhase].
|
||||
*
|
||||
* @see lazyResolveToPhaseWithCallableMembers
|
||||
*/
|
||||
fun FirClass.lazyResolveToPhaseWithCallableMembers(toPhase: FirResolvePhase) {
|
||||
symbol.lazyResolveToPhaseWithCallableMembers(toPhase)
|
||||
}
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirLazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
|
||||
|
||||
class FirCompilerLazyDeclarationResolverWithPhaseChecking : FirLazyDeclarationResolver() {
|
||||
@@ -22,6 +23,10 @@ class FirCompilerLazyDeclarationResolverWithPhaseChecking : FirLazyDeclarationRe
|
||||
checkIfCanLazyResolveToPhase(symbol, toPhase)
|
||||
}
|
||||
|
||||
override fun lazyResolveToPhaseWithCallableMembers(symbol: FirClassSymbol<*>, toPhase: FirResolvePhase) {
|
||||
checkIfCanLazyResolveToPhase(symbol, toPhase)
|
||||
}
|
||||
|
||||
override fun startResolvingPhase(phase: FirResolvePhase) {
|
||||
check(currentTransformerPhase == null)
|
||||
currentTransformerPhase = phase
|
||||
|
||||
Reference in New Issue
Block a user