FIR: Rename CallResolutionContext -> CandidateFactoriesAndCollectors

This commit is contained in:
Denis Zharkov
2020-03-27 18:17:10 +03:00
parent 4053978609
commit 80c64207f7
3 changed files with 29 additions and 26 deletions
@@ -20,19 +20,19 @@ class FirTowerResolver(
collector: CandidateCollector = this.collector, collector: CandidateCollector = this.collector,
manager: TowerResolveManager = this.manager manager: TowerResolveManager = this.manager
): CandidateCollector { ): CandidateCollector {
val callResolutionContext = buildCallResolutionContext(info, collector) val candidateFactoriesAndCollectors = buildCandidateFactoriesAndCollectors(info, collector)
val towerResolverSession = FirTowerResolverSession(components, implicitReceiverValues, manager, callResolutionContext) val towerResolverSession = FirTowerResolverSession(components, implicitReceiverValues, manager, candidateFactoriesAndCollectors)
towerResolverSession.runResolution(info) towerResolverSession.runResolution(info)
manager.runTasks() manager.runTasks()
return collector return collector
} }
private fun buildCallResolutionContext( private fun buildCandidateFactoriesAndCollectors(
info: CallInfo, info: CallInfo,
collector: CandidateCollector collector: CandidateCollector
): CallResolutionContext { ): CandidateFactoriesAndCollectors {
val candidateFactory = CandidateFactory(components, info) val candidateFactory = CandidateFactory(components, info)
val stubReceiverCandidateFactory = val stubReceiverCandidateFactory =
if (info.callKind == CallKind.CallableReference && info.stubReceiver != null) if (info.callKind == CallKind.CallableReference && info.stubReceiver != null)
@@ -53,13 +53,13 @@ class FirTowerResolver(
} }
} }
return CallResolutionContext( return CandidateFactoriesAndCollectors(
candidateFactory, candidateFactory,
collector, collector,
invokeReceiverCandidateFactory,
invokeBuiltinExtensionReceiverCandidateFactory,
stubReceiverCandidateFactory, stubReceiverCandidateFactory,
invokeReceiverCollector invokeReceiverCandidateFactory,
invokeReceiverCollector,
invokeBuiltinExtensionReceiverCandidateFactory
) )
} }
@@ -38,7 +38,7 @@ class FirTowerResolverSession internal constructor(
val components: BodyResolveComponents, val components: BodyResolveComponents,
implicitReceiverValues: List<ImplicitReceiverValue<*>>, implicitReceiverValues: List<ImplicitReceiverValue<*>>,
private val manager: TowerResolveManager, private val manager: TowerResolveManager,
private val callResolutionContext: CallResolutionContext, private val candidateFactoriesAndCollectors: CandidateFactoriesAndCollectors,
) { ) {
private data class ImplicitReceiver( private data class ImplicitReceiver(
val receiver: ImplicitReceiverValue<*>, val receiver: ImplicitReceiverValue<*>,
@@ -94,7 +94,10 @@ class FirTowerResolverSession internal constructor(
LevelHandler( LevelHandler(
) )
return levelHandler.handleLevel(callInfo, explicitReceiverKind, group, callResolutionContext, towerLevel, invokeResolveMode) { return levelHandler.handleLevel(
callInfo, explicitReceiverKind, group,
candidateFactoriesAndCollectors, towerLevel, invokeResolveMode
) {
enqueueResolverTasksForInvokeReceiverCandidates( enqueueResolverTasksForInvokeReceiverCandidates(
invokeResolveMode, callInfo invokeResolveMode, callInfo
) )
@@ -549,7 +552,7 @@ class FirTowerResolverSession internal constructor(
) { ) {
val invokeBuiltinExtensionMode = invokeResolveMode == InvokeResolveMode.RECEIVER_FOR_INVOKE_BUILTIN_EXTENSION val invokeBuiltinExtensionMode = invokeResolveMode == InvokeResolveMode.RECEIVER_FOR_INVOKE_BUILTIN_EXTENSION
for (invokeReceiverCandidate in callResolutionContext.invokeReceiverCollector!!.bestCandidates()) { for (invokeReceiverCandidate in candidateFactoriesAndCollectors.invokeReceiverCollector!!.bestCandidates()) {
val symbol = invokeReceiverCandidate.symbol val symbol = invokeReceiverCandidate.symbol
if (symbol !is FirCallableSymbol<*> && symbol !is FirRegularClassSymbol) continue if (symbol !is FirCallableSymbol<*> && symbol !is FirRegularClassSymbol) continue
@@ -584,7 +587,7 @@ class FirTowerResolverSession internal constructor(
} }
val explicitReceiver = ExpressionReceiverValue(invokeReceiverExpression) val explicitReceiver = ExpressionReceiverValue(invokeReceiverExpression)
callResolutionContext.invokeOnGivenReceiverCandidateFactory = CandidateFactory(components, invokeFunctionInfo) candidateFactoriesAndCollectors.invokeOnGivenReceiverCandidateFactory = CandidateFactory(components, invokeFunctionInfo)
enqueueResolverTasksForInvoke( enqueueResolverTasksForInvoke(
invokeFunctionInfo, invokeFunctionInfo,
explicitReceiver, explicitReceiver,
@@ -17,13 +17,13 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.AbstractTypeChecker
internal class CallResolutionContext( internal class CandidateFactoriesAndCollectors(
val candidateFactory: CandidateFactory, val candidateFactory: CandidateFactory,
val resultCollector: CandidateCollector, val resultCollector: CandidateCollector,
val invokeReceiverCandidateFactory: CandidateFactory?,
val invokeBuiltinExtensionReceiverCandidateFactory: CandidateFactory?,
val stubReceiverCandidateFactory: CandidateFactory?, val stubReceiverCandidateFactory: CandidateFactory?,
val invokeReceiverCollector: CandidateCollector? val invokeReceiverCandidateFactory: CandidateFactory?,
val invokeReceiverCollector: CandidateCollector?,
val invokeBuiltinExtensionReceiverCandidateFactory: CandidateFactory?
) { ) {
// TODO: Get rid of the property, storing state here looks like a hack // TODO: Get rid of the property, storing state here looks like a hack
internal lateinit var invokeOnGivenReceiverCandidateFactory: CandidateFactory internal lateinit var invokeOnGivenReceiverCandidateFactory: CandidateFactory
@@ -40,12 +40,12 @@ internal class LevelHandler {
info: CallInfo, info: CallInfo,
explicitReceiverKind: ExplicitReceiverKind, explicitReceiverKind: ExplicitReceiverKind,
group: TowerGroup, group: TowerGroup,
callResolutionContext: CallResolutionContext, candidateFactoriesAndCollectors: CandidateFactoriesAndCollectors,
towerLevel: SessionBasedTowerLevel, towerLevel: SessionBasedTowerLevel,
invokeResolveMode: InvokeResolveMode?, invokeResolveMode: InvokeResolveMode?,
enqueueResolverTasksForInvokeReceiverCandidates: EnqueueTasksForInvokeReceiverCandidates enqueueResolverTasksForInvokeReceiverCandidates: EnqueueTasksForInvokeReceiverCandidates
): ProcessorAction { ): ProcessorAction {
val resultCollector = callResolutionContext.resultCollector val resultCollector = candidateFactoriesAndCollectors.resultCollector
val processor = val processor =
TowerScopeLevelProcessor( TowerScopeLevelProcessor(
info.explicitReceiver, info.explicitReceiver,
@@ -53,9 +53,9 @@ internal class LevelHandler {
resultCollector, resultCollector,
// TODO: performance? // TODO: performance?
if (invokeResolveMode == InvokeResolveMode.IMPLICIT_CALL_ON_GIVEN_RECEIVER) if (invokeResolveMode == InvokeResolveMode.IMPLICIT_CALL_ON_GIVEN_RECEIVER)
callResolutionContext.invokeOnGivenReceiverCandidateFactory candidateFactoriesAndCollectors.invokeOnGivenReceiverCandidateFactory
else else
callResolutionContext.candidateFactory, candidateFactoriesAndCollectors.candidateFactory,
group group
) )
when (info.callKind) { when (info.callKind) {
@@ -83,16 +83,16 @@ internal class LevelHandler {
val invokeReceiverProcessor = TowerScopeLevelProcessor( val invokeReceiverProcessor = TowerScopeLevelProcessor(
info.explicitReceiver, info.explicitReceiver,
explicitReceiverKind, explicitReceiverKind,
callResolutionContext.invokeReceiverCollector!!, candidateFactoriesAndCollectors.invokeReceiverCollector!!,
if (invokeBuiltinExtensionMode) callResolutionContext.invokeBuiltinExtensionReceiverCandidateFactory!! if (invokeBuiltinExtensionMode) candidateFactoriesAndCollectors.invokeBuiltinExtensionReceiverCandidateFactory!!
else callResolutionContext.invokeReceiverCandidateFactory!!, else candidateFactoriesAndCollectors.invokeReceiverCandidateFactory!!,
group group
) )
callResolutionContext.invokeReceiverCollector.newDataSet() candidateFactoriesAndCollectors.invokeReceiverCollector.newDataSet()
towerLevel.processProperties(info.name, invokeReceiverProcessor) towerLevel.processProperties(info.name, invokeReceiverProcessor)
towerLevel.processObjectsAsVariables(info.name, invokeReceiverProcessor) towerLevel.processObjectsAsVariables(info.name, invokeReceiverProcessor)
if (callResolutionContext.invokeReceiverCollector.isSuccess()) { if (candidateFactoriesAndCollectors.invokeReceiverCollector.isSuccess()) {
enqueueResolverTasksForInvokeReceiverCandidates() enqueueResolverTasksForInvokeReceiverCandidates()
} }
} }
@@ -108,7 +108,7 @@ internal class LevelHandler {
ExplicitReceiverKind.EXTENSION_RECEIVER ExplicitReceiverKind.EXTENSION_RECEIVER
}, },
resultCollector, resultCollector,
callResolutionContext.stubReceiverCandidateFactory!!, group candidateFactoriesAndCollectors.stubReceiverCandidateFactory!!, group
) )
val towerLevelWithStubReceiver = towerLevel.replaceReceiverValue(stubReceiverValue) val towerLevelWithStubReceiver = towerLevel.replaceReceiverValue(stubReceiverValue)
towerLevelWithStubReceiver.processFunctionsAndProperties(info.name, stubProcessor) towerLevelWithStubReceiver.processFunctionsAndProperties(info.name, stubProcessor)