From 0431c21f9a5194eda9e6395bb4bcb4f16824340a Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 17 Sep 2019 15:43:59 +0300 Subject: [PATCH] [NI] Remove unneeded computation of possible types for return type This call was needed at some point for smartcasts on qualified expressions but become obsolete (most likely after daa27016ca781327669b4d8bb7b7a6590cf27dd2). Now `ComplexDataFlowBenchmark` has similar results for NI and OI --- .../tower/KotlinResolutionCallbacksImpl.kt | 15 --------------- .../calls/components/ExternalComponents.kt | 2 -- .../calls/components/KotlinCallCompleter.kt | 17 ++++------------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index 95629abafee..6a1a8e42afa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -226,21 +226,6 @@ class KotlinResolutionCallbacksImpl( ) } - override fun createReceiverWithSmartCastInfo(resolvedAtom: ResolvedCallAtom): ReceiverValueWithSmartCastInfo? { - val returnType = resolvedAtom.candidateDescriptor.returnType ?: return null - val psiKotlinCall = resolvedAtom.atom.psiKotlinCall - val callElement = psiKotlinCall.psiCall.callElement.safeAs() ?: return null - val expression = findCommonParent(callElement, resolvedAtom.atom.psiKotlinCall.explicitReceiver) - - return transformToReceiverWithSmartCastInfo( - resolvedAtom.candidateDescriptor, - trace.bindingContext, - psiKotlinCall.resultDataFlowInfo, - ExpressionReceiver.create(expression, returnType, trace.bindingContext), - languageVersionSettings, dataFlowValueFactory - ) - } - override fun isCompileTimeConstant(resolvedAtom: ResolvedCallAtom, expectedType: UnwrappedType): Boolean { val descriptor = resolvedAtom.candidateDescriptor diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index d05c1c5a24e..c72bf42d617 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -56,8 +56,6 @@ interface KotlinResolutionCallbacks { fun bindStubResolvedCallForCandidate(candidate: ResolvedCallAtom) - fun createReceiverWithSmartCastInfo(resolvedAtom: ResolvedCallAtom): ReceiverValueWithSmartCastInfo? - fun isCompileTimeConstant(resolvedAtom: ResolvedCallAtom, expectedType: UnwrappedType): Boolean val inferenceSession: InferenceSession diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index fb53457c8fe..9dbeeae3b58 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -41,7 +41,7 @@ class KotlinCallCompleter( } val candidate = prepareCandidateForCompletion(factory, candidates, resolutionCallbacks) - val returnType = candidate.returnTypeWithSmartCastInfo(resolutionCallbacks) + val returnType = candidate.substitutedReturnType() candidate.addExpectedTypeConstraint(returnType, expectedType) candidate.addExpectedTypeFromCastConstraint(returnType, resolutionCallbacks) @@ -65,7 +65,7 @@ class KotlinCallCompleter( val diagnosticsHolder = KotlinDiagnosticsHolder.SimpleHolder() candidate.addExpectedTypeConstraint( - candidate.returnTypeWithSmartCastInfo(resolutionCallbacks), expectedType + candidate.substitutedReturnType(), expectedType ) runCompletion( @@ -143,10 +143,9 @@ class KotlinCallCompleter( return candidate ?: factory.createErrorCandidate().forceResolution() } - private fun KotlinResolutionCandidate.returnTypeWithSmartCastInfo(resolutionCallbacks: KotlinResolutionCallbacks): UnwrappedType? { + private fun KotlinResolutionCandidate.substitutedReturnType(): UnwrappedType? { val returnType = resolvedCall.candidateDescriptor.returnType?.unwrap() ?: return null - val returnTypeWithSmartCastInfo = computeReturnTypeWithSmartCastInfo(returnType, resolutionCallbacks) - return resolvedCall.substitutor.safeSubstitute(returnTypeWithSmartCastInfo) + return resolvedCall.substitutor.safeSubstitute(returnType) } private fun KotlinResolutionCandidate.addExpectedTypeConstraint( @@ -250,14 +249,6 @@ class KotlinCallCompleter( private inline fun Iterable.anyOrAll(requireAll: Boolean, p: (T) -> Boolean): Boolean = if (requireAll) all(p) else any(p) - private fun KotlinResolutionCandidate.computeReturnTypeWithSmartCastInfo( - returnType: UnwrappedType, - resolutionCallbacks: KotlinResolutionCallbacks - ): UnwrappedType { - if (resolvedCall.atom.callKind != KotlinCallKind.VARIABLE) return returnType - return resolutionCallbacks.createReceiverWithSmartCastInfo(resolvedCall)?.stableType ?: returnType - } - fun KotlinResolutionCandidate.asCallResolutionResult( type: ConstraintSystemCompletionMode, diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder