From c96e6e9da4773c1c9750b4922e412aab99e15b6b Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 10 Jan 2020 16:09:28 +0300 Subject: [PATCH] [FIR] Refactoring: store name in CallInfo --- .../org/jetbrains/kotlin/fir/FirCallResolver.kt | 9 +++++---- .../kotlin/fir/resolve/calls/Candidate.kt | 9 +++++---- .../kotlin/fir/resolve/calls/FirTowerResolver.kt | 15 +++++++-------- .../transformers/FirSyntheticCallGenerator.kt | 5 +++-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index ea2e3d9bf4b..15673eaa9b5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -120,6 +120,7 @@ class FirCallResolver( val info = CallInfo( CallKind.Function, + functionCall.calleeReference.name, explicitReceiver, arguments, functionCall.safe, @@ -131,7 +132,6 @@ class FirCallResolver( towerResolver.reset() val result = towerResolver.runResolver( implicitReceiverStack.receiversAsReversed(), - functionCall.calleeReference.name, info ) val bestCandidates = result.bestCandidates() @@ -154,6 +154,7 @@ class FirCallResolver( val info = CallInfo( CallKind.VariableAccess, + callee.name, qualifiedAccess.explicitReceiver, emptyList(), qualifiedAccess.safe, @@ -165,7 +166,6 @@ class FirCallResolver( towerResolver.reset() val result = towerResolver.runResolver( implicitReceiverStack.receiversAsReversed(), - callee.name, info ) @@ -246,7 +246,6 @@ class FirCallResolver( // No reset here! val result = towerResolver.runResolver( implicitReceiverStack.receiversAsReversed(), - callableReferenceAccess.calleeReference.name, info, collector = CandidateCollector(this, resolutionStageRunner) ) @@ -287,8 +286,10 @@ class FirCallResolver( typeArguments: List ): FirDelegatedConstructorCall? { val scope = symbol.fir.scope(ConeSubstitutor.Empty, session, scopeSession) ?: return null + val className = symbol.classId.shortClassName val callInfo = CallInfo( CallKind.Function, + className, explicitReceiver = null, delegatedConstructorCall.arguments, isSafeCall = false, @@ -300,7 +301,6 @@ class FirCallResolver( val candidateFactory = CandidateFactory(this, callInfo) val candidates = mutableListOf() - val className = symbol.classId.shortClassName scope.processFunctionsByName(className) { if (it is FirConstructorSymbol) { candidates += candidateFactory.createCandidate(it, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER) @@ -338,6 +338,7 @@ class FirCallResolver( ): CallInfo { return CallInfo( CallKind.CallableReference, + callableReferenceAccess.calleeReference.name, callableReferenceAccess.explicitReceiver, emptyList(), false, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt index 3c5927433f3..1ac8ab87e40 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeTypeVariable import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage @@ -26,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind class CallInfo( val callKind: CallKind, + val name: Name, val explicitReceiver: FirExpression?, val arguments: List, @@ -46,20 +48,19 @@ class CallInfo( fun replaceWithVariableAccess(): CallInfo = CallInfo( - CallKind.VariableAccess, explicitReceiver, emptyList(), + CallKind.VariableAccess, name, explicitReceiver, emptyList(), isSafeCall, typeArguments, session, containingFile, implicitReceiverStack, expectedType, outerCSBuilder, lhs ) fun replaceExplicitReceiver(explicitReceiver: FirExpression): CallInfo = CallInfo( - callKind, explicitReceiver, arguments, + callKind, name, explicitReceiver, arguments, isSafeCall, typeArguments, session, containingFile, implicitReceiverStack, expectedType, outerCSBuilder, lhs ) fun withReceiverAsArgument(receiverExpression: FirExpression): CallInfo = CallInfo( - callKind, explicitReceiver, - listOf(receiverExpression) + arguments, + callKind, name, explicitReceiver, listOf(receiverExpression) + arguments, isSafeCall, typeArguments, session, containingFile, implicitReceiverStack, expectedType, outerCSBuilder, lhs ) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt index 4fb95ed1cef..dce8a6625da 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirTowerResolver.kt @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.scopes.ProcessorAction.NONE import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralType import org.jetbrains.kotlin.fir.types.coneTypeSafe -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST enum class TowerDataKind { @@ -203,28 +202,28 @@ class FirTowerResolver( private lateinit var implicitReceiverValues: List> fun runResolver( - implicitReceiverValues: List>, name: Name, info: CallInfo, + implicitReceiverValues: List>, info: CallInfo, collector: CandidateCollector = this.collector ): CandidateCollector { this.implicitReceiverValues = implicitReceiverValues towerDataConsumer = when (info.callKind) { CallKind.VariableAccess -> { - createVariableAndObjectConsumer(session, name, info, components, collector) + createVariableAndObjectConsumer(session, info.name, info, components, collector) } CallKind.Function -> { - createFunctionConsumer(session, name, info, components, collector, this) + createFunctionConsumer(session, info.name, info, components, collector, this) } CallKind.CallableReference -> { if (info.stubReceiver == null) { - createCallableReferencesConsumer(session, name, info, components, collector) + createCallableReferencesConsumer(session, info.name, info, components, collector) } else { PrioritizedTowerDataConsumer( collector, createCallableReferencesConsumer( - session, name, info.replaceExplicitReceiver(info.stubReceiver), components, collector + session, info.name, info.replaceExplicitReceiver(info.stubReceiver), components, collector ), createCallableReferencesConsumer( - session, name, info, components, collector + session, info.name, info, components, collector ) ) } @@ -232,7 +231,7 @@ class FirTowerResolver( else -> throw AssertionError("Unsupported call kind in tower resolver: ${info.callKind}") } val shouldProcessExtensionsBeforeMembers = - info.callKind == CallKind.Function && name in HIDES_MEMBERS_NAME_LIST + info.callKind == CallKind.Function && info.name in HIDES_MEMBERS_NAME_LIST val shouldProcessExplicitReceiverScopeOnly = info.callKind == CallKind.Function && info.explicitReceiver?.typeRef?.coneTypeSafe() != null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt index 6942ad756b4..89ba3c11171 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt @@ -120,7 +120,7 @@ class FirSyntheticCallGenerator( name: Name, callKind: CallKind = CallKind.SyntheticSelect ): FirNamedReferenceWithCandidate? { - val callInfo = generateCallInfo(arguments, callKind) + val callInfo = generateCallInfo(name, arguments, callKind) val candidate = generateCandidate(callInfo, function) val applicability = resolutionStageRunner.processCandidate(candidate) if (applicability <= CandidateApplicability.INAPPLICABLE) { @@ -136,8 +136,9 @@ class FirSyntheticCallGenerator( explicitReceiverKind = ExplicitReceiverKind.NO_EXPLICIT_RECEIVER ) - private fun generateCallInfo(arguments: List, callKind: CallKind) = CallInfo( + private fun generateCallInfo(name: Name, arguments: List, callKind: CallKind) = CallInfo( callKind = callKind, + name = name, explicitReceiver = null, arguments = arguments, isSafeCall = false,