[LL FIR] drop redundant usages of LLFirResolveTarget.firFile
After 6893c44a 'target' can be used in many cases
^KT-64243
This commit is contained in:
committed by
Space Team
parent
1b557c1657
commit
a7cfbe6d50
+3
-3
@@ -24,9 +24,9 @@ internal fun FirDesignationWithFile.asResolveTarget(): LLFirSingleResolveTarget
|
|||||||
* The owning session must be a resolvable one.
|
* The owning session must be a resolvable one.
|
||||||
*/
|
*/
|
||||||
internal fun LLFirResolveTarget.resolve(phase: FirResolvePhase) {
|
internal fun LLFirResolveTarget.resolve(phase: FirResolvePhase) {
|
||||||
val session = firFile.llFirResolvableSession
|
val session = target.llFirResolvableSession
|
||||||
?: errorWithAttachment("Resolvable session expected, got '${firFile.llFirSession::class.java}'") {
|
?: errorWithAttachment("Resolvable session expected, got '${target.llFirSession::class.java}'") {
|
||||||
withEntry("firSession", firFile.llFirSession) { it.toString() }
|
withEntry("firSession", target.llFirSession) { it.toString() }
|
||||||
}
|
}
|
||||||
|
|
||||||
val lazyDeclarationResolver = session.moduleComponents.firModuleLazyDeclarationResolver
|
val lazyDeclarationResolver = session.moduleComponents.firModuleLazyDeclarationResolver
|
||||||
|
|||||||
+1
-1
@@ -253,7 +253,7 @@ private fun handleExceptionFromResolve(
|
|||||||
designation: LLFirResolveTarget,
|
designation: LLFirResolveTarget,
|
||||||
toPhase: FirResolvePhase,
|
toPhase: FirResolvePhase,
|
||||||
): Nothing {
|
): Nothing {
|
||||||
val session = designation.firFile.llFirSession
|
val session = designation.target.llFirSession
|
||||||
val moduleData = session.llFirModuleData
|
val moduleData = session.llFirModuleData
|
||||||
val module = moduleData.ktModule
|
val module = moduleData.ktModule
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.LLFirReturnTypeCalculatorWithJump
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.LLFirReturnTypeCalculatorWithJump
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
||||||
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
|||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirResolveContextCollector
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirResolveContextCollector
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.ImplicitBodyResolveComputationSession
|
|
||||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||||
|
|
||||||
internal abstract class LLFirAbstractBodyTargetResolver(
|
internal abstract class LLFirAbstractBodyTargetResolver(
|
||||||
@@ -68,8 +67,8 @@ internal abstract class LLFirAbstractBodyTargetResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun <T : FirElementWithResolveState> resolve(target: T, keeper: StateKeeper<T, FirDesignationWithFile>) {
|
protected fun <T : FirElementWithResolveState> resolve(target: T, keeper: StateKeeper<T, FirDesignation>) {
|
||||||
val firDesignation = FirDesignationWithFile(nestedClassesStack, target, resolveTarget.firFile)
|
val firDesignation = FirDesignation(nestedClassesStack, target)
|
||||||
resolveWithKeeper(target, firDesignation, keeper, { FirLazyBodiesCalculator.calculateBodies(firDesignation) }) {
|
resolveWithKeeper(target, firDesignation, keeper, { FirLazyBodiesCalculator.calculateBodies(firDesignation) }) {
|
||||||
rawResolve(target)
|
rawResolve(target)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getFirResolveSession
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getFirResolveSession
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getModule
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getModule
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
||||||
@@ -325,7 +325,7 @@ private class LLFirBodyTargetResolver(
|
|||||||
LLFirDeclarationModificationService.bodyResolved(target, resolverPhase)
|
LLFirDeclarationModificationService.bodyResolved(target, resolverPhase)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun resolveScript(script: FirScript) {
|
private fun resolveScript(script: FirScript) {
|
||||||
transformer.declarationsTransformer.withScript(script) {
|
transformer.declarationsTransformer.withScript(script) {
|
||||||
script.parameters.forEach { it.transformSingle(transformer, ResolutionMode.ContextIndependent) }
|
script.parameters.forEach { it.transformSingle(transformer, ResolutionMode.ContextIndependent) }
|
||||||
script.transformDeclarations(
|
script.transformDeclarations(
|
||||||
@@ -346,7 +346,7 @@ private class LLFirBodyTargetResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal object BodyStateKeepers {
|
internal object BodyStateKeepers {
|
||||||
val SCRIPT: StateKeeper<FirScript, FirDesignationWithFile> = stateKeeper { script, designation ->
|
val SCRIPT: StateKeeper<FirScript, FirDesignation> = stateKeeper { script, designation ->
|
||||||
val oldDeclarations = script.declarations
|
val oldDeclarations = script.declarations
|
||||||
if (oldDeclarations.none { it.isElementWhichShouldBeResolvedAsPartOfScript }) return@stateKeeper
|
if (oldDeclarations.none { it.isElementWhichShouldBeResolvedAsPartOfScript }) return@stateKeeper
|
||||||
|
|
||||||
@@ -365,7 +365,7 @@ internal object BodyStateKeepers {
|
|||||||
add(FirScript::controlFlowGraphReference, FirScript::replaceControlFlowGraphReference)
|
add(FirScript::controlFlowGraphReference, FirScript::replaceControlFlowGraphReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val RESULT_PROPERTY: StateKeeper<FirScript, FirDesignationWithFile> = stateKeeper { script, _ ->
|
private val RESULT_PROPERTY: StateKeeper<FirScript, FirDesignation> = stateKeeper { script, _ ->
|
||||||
val resultedProperty = script.findResultProperty() ?: return@stateKeeper
|
val resultedProperty = script.findResultProperty() ?: return@stateKeeper
|
||||||
add(
|
add(
|
||||||
provider = { resultedProperty.bodyResolveState },
|
provider = { resultedProperty.bodyResolveState },
|
||||||
@@ -383,16 +383,16 @@ internal object BodyStateKeepers {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val CODE_FRAGMENT: StateKeeper<FirCodeFragment, FirDesignationWithFile> = stateKeeper { _, _ ->
|
val CODE_FRAGMENT: StateKeeper<FirCodeFragment, FirDesignation> = stateKeeper { _, _ ->
|
||||||
add(FirCodeFragment::block, FirCodeFragment::replaceBlock, ::blockGuard)
|
add(FirCodeFragment::block, FirCodeFragment::replaceBlock, ::blockGuard)
|
||||||
}
|
}
|
||||||
|
|
||||||
val ANONYMOUS_INITIALIZER: StateKeeper<FirAnonymousInitializer, FirDesignationWithFile> = stateKeeper { _, _ ->
|
val ANONYMOUS_INITIALIZER: StateKeeper<FirAnonymousInitializer, FirDesignation> = stateKeeper { _, _ ->
|
||||||
add(FirAnonymousInitializer::body, FirAnonymousInitializer::replaceBody, ::blockGuard)
|
add(FirAnonymousInitializer::body, FirAnonymousInitializer::replaceBody, ::blockGuard)
|
||||||
add(FirAnonymousInitializer::controlFlowGraphReference, FirAnonymousInitializer::replaceControlFlowGraphReference)
|
add(FirAnonymousInitializer::controlFlowGraphReference, FirAnonymousInitializer::replaceControlFlowGraphReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
val FUNCTION: StateKeeper<FirFunction, FirDesignationWithFile> = stateKeeper { function, designation ->
|
val FUNCTION: StateKeeper<FirFunction, FirDesignation> = stateKeeper { function, designation ->
|
||||||
if (function.isCertainlyResolved) {
|
if (function.isCertainlyResolved) {
|
||||||
if (!isCallableWithSpecialBody(function)) {
|
if (!isCallableWithSpecialBody(function)) {
|
||||||
entityList(function.valueParameters, VALUE_PARAMETER, designation)
|
entityList(function.valueParameters, VALUE_PARAMETER, designation)
|
||||||
@@ -413,12 +413,12 @@ internal object BodyStateKeepers {
|
|||||||
add(FirFunction::controlFlowGraphReference, FirFunction::replaceControlFlowGraphReference)
|
add(FirFunction::controlFlowGraphReference, FirFunction::replaceControlFlowGraphReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
val CONSTRUCTOR: StateKeeper<FirConstructor, FirDesignationWithFile> = stateKeeper { _, designation ->
|
val CONSTRUCTOR: StateKeeper<FirConstructor, FirDesignation> = stateKeeper { _, designation ->
|
||||||
add(FUNCTION, designation)
|
add(FUNCTION, designation)
|
||||||
add(FirConstructor::delegatedConstructor, FirConstructor::replaceDelegatedConstructor, ::delegatedConstructorCallGuard)
|
add(FirConstructor::delegatedConstructor, FirConstructor::replaceDelegatedConstructor, ::delegatedConstructorCallGuard)
|
||||||
}
|
}
|
||||||
|
|
||||||
val VARIABLE: StateKeeper<FirVariable, FirDesignationWithFile> = stateKeeper { variable, _ ->
|
val VARIABLE: StateKeeper<FirVariable, FirDesignation> = stateKeeper { variable, _ ->
|
||||||
add(FirVariable::returnTypeRef, FirVariable::replaceReturnTypeRef)
|
add(FirVariable::returnTypeRef, FirVariable::replaceReturnTypeRef)
|
||||||
|
|
||||||
if (!isCallableWithSpecialBody(variable)) {
|
if (!isCallableWithSpecialBody(variable)) {
|
||||||
@@ -427,7 +427,7 @@ internal object BodyStateKeepers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val VALUE_PARAMETER: StateKeeper<FirValueParameter, FirDesignationWithFile> = stateKeeper { valueParameter, _ ->
|
private val VALUE_PARAMETER: StateKeeper<FirValueParameter, FirDesignation> = stateKeeper { valueParameter, _ ->
|
||||||
if (valueParameter.defaultValue != null) {
|
if (valueParameter.defaultValue != null) {
|
||||||
add(FirValueParameter::defaultValue, FirValueParameter::replaceDefaultValue, ::expressionGuard)
|
add(FirValueParameter::defaultValue, FirValueParameter::replaceDefaultValue, ::expressionGuard)
|
||||||
}
|
}
|
||||||
@@ -435,12 +435,12 @@ internal object BodyStateKeepers {
|
|||||||
add(FirValueParameter::controlFlowGraphReference, FirValueParameter::replaceControlFlowGraphReference)
|
add(FirValueParameter::controlFlowGraphReference, FirValueParameter::replaceControlFlowGraphReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
val FIELD: StateKeeper<FirField, FirDesignationWithFile> = stateKeeper { _, designation ->
|
val FIELD: StateKeeper<FirField, FirDesignation> = stateKeeper { _, designation ->
|
||||||
add(VARIABLE, designation)
|
add(VARIABLE, designation)
|
||||||
add(FirField::controlFlowGraphReference, FirField::replaceControlFlowGraphReference)
|
add(FirField::controlFlowGraphReference, FirField::replaceControlFlowGraphReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
val PROPERTY: StateKeeper<FirProperty, FirDesignationWithFile> = stateKeeper { property, designation ->
|
val PROPERTY: StateKeeper<FirProperty, FirDesignation> = stateKeeper { property, designation ->
|
||||||
if (property.bodyResolveState >= FirPropertyBodyResolveState.ALL_BODIES_RESOLVED) {
|
if (property.bodyResolveState >= FirPropertyBodyResolveState.ALL_BODIES_RESOLVED) {
|
||||||
return@stateKeeper
|
return@stateKeeper
|
||||||
}
|
}
|
||||||
@@ -459,7 +459,7 @@ internal object BodyStateKeepers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context(StateKeeperBuilder)
|
context(StateKeeperBuilder)
|
||||||
private fun StateKeeperScope<FirFunction, FirDesignationWithFile>.preserveContractBlock(function: FirFunction) {
|
private fun StateKeeperScope<FirFunction, FirDesignation>.preserveContractBlock(function: FirFunction) {
|
||||||
val oldBody = function.body
|
val oldBody = function.body
|
||||||
if (oldBody == null || oldBody is FirLazyBlock) {
|
if (oldBody == null || oldBody is FirLazyBlock) {
|
||||||
return
|
return
|
||||||
|
|||||||
+7
-7
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
||||||
@@ -193,11 +193,11 @@ private class LLFirContractsTargetResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private object ContractStateKeepers {
|
private object ContractStateKeepers {
|
||||||
private val CONTRACT_DESCRIPTION_OWNER: StateKeeper<FirContractDescriptionOwner, FirDesignationWithFile> = stateKeeper { _, _ ->
|
private val CONTRACT_DESCRIPTION_OWNER: StateKeeper<FirContractDescriptionOwner, FirDesignation> = stateKeeper { _, _ ->
|
||||||
add(FirContractDescriptionOwner::contractDescription, FirContractDescriptionOwner::replaceContractDescription)
|
add(FirContractDescriptionOwner::contractDescription, FirContractDescriptionOwner::replaceContractDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val BODY_OWNER: StateKeeper<FirFunction, FirDesignationWithFile> = stateKeeper { declaration, _ ->
|
private val BODY_OWNER: StateKeeper<FirFunction, FirDesignation> = stateKeeper { declaration, _ ->
|
||||||
if (declaration is FirContractDescriptionOwner && declaration.contractDescription is FirRawContractDescription) {
|
if (declaration is FirContractDescriptionOwner && declaration.contractDescription is FirRawContractDescription) {
|
||||||
// No need to change the body, contract is declared separately
|
// No need to change the body, contract is declared separately
|
||||||
return@stateKeeper
|
return@stateKeeper
|
||||||
@@ -208,22 +208,22 @@ private object ContractStateKeepers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val SIMPLE_FUNCTION: StateKeeper<FirSimpleFunction, FirDesignationWithFile> = stateKeeper { _, designation ->
|
val SIMPLE_FUNCTION: StateKeeper<FirSimpleFunction, FirDesignation> = stateKeeper { _, designation ->
|
||||||
add(CONTRACT_DESCRIPTION_OWNER, designation)
|
add(CONTRACT_DESCRIPTION_OWNER, designation)
|
||||||
add(BODY_OWNER, designation)
|
add(BODY_OWNER, designation)
|
||||||
}
|
}
|
||||||
|
|
||||||
val CONSTRUCTOR: StateKeeper<FirConstructor, FirDesignationWithFile> = stateKeeper { _, designation ->
|
val CONSTRUCTOR: StateKeeper<FirConstructor, FirDesignation> = stateKeeper { _, designation ->
|
||||||
add(CONTRACT_DESCRIPTION_OWNER, designation)
|
add(CONTRACT_DESCRIPTION_OWNER, designation)
|
||||||
add(BODY_OWNER, designation)
|
add(BODY_OWNER, designation)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val PROPERTY_ACCESSOR: StateKeeper<FirPropertyAccessor, FirDesignationWithFile> = stateKeeper { _, designation ->
|
private val PROPERTY_ACCESSOR: StateKeeper<FirPropertyAccessor, FirDesignation> = stateKeeper { _, designation ->
|
||||||
add(CONTRACT_DESCRIPTION_OWNER, designation)
|
add(CONTRACT_DESCRIPTION_OWNER, designation)
|
||||||
add(BODY_OWNER, designation)
|
add(BODY_OWNER, designation)
|
||||||
}
|
}
|
||||||
|
|
||||||
val PROPERTY: StateKeeper<FirProperty, FirDesignationWithFile> = stateKeeper { property, designation ->
|
val PROPERTY: StateKeeper<FirProperty, FirDesignation> = stateKeeper { property, designation ->
|
||||||
entity(property.getter, PROPERTY_ACCESSOR, designation)
|
entity(property.getter, PROPERTY_ACCESSOR, designation)
|
||||||
entity(property.setter, PROPERTY_ACCESSOR, designation)
|
entity(property.setter, PROPERTY_ACCESSOR, designation)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -20,8 +20,7 @@ internal object LLFirLazyResolverRunner {
|
|||||||
towerDataContextCollector: FirResolveContextCollector?,
|
towerDataContextCollector: FirResolveContextCollector?,
|
||||||
) {
|
) {
|
||||||
val lazyResolver = LLFirLazyPhaseResolverByPhase.getByPhase(phase)
|
val lazyResolver = LLFirLazyPhaseResolverByPhase.getByPhase(phase)
|
||||||
val firFile = target.firFile
|
val session = target.target.moduleData.session
|
||||||
val session = firFile.moduleData.session
|
|
||||||
lockProvider.withGlobalLock {
|
lockProvider.withGlobalLock {
|
||||||
lockProvider.withGlobalPhaseLock(phase) {
|
lockProvider.withGlobalPhaseLock(phase) {
|
||||||
lazyResolver.resolve(target, lockProvider, session, scopeSession, towerDataContextCollector)
|
lazyResolver.resolve(target, lockProvider, session, scopeSession, towerDataContextCollector)
|
||||||
|
|||||||
Reference in New Issue
Block a user