From fe0282809e124ff04a1db77b495c8ded76c6ba1f Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Thu, 20 Jun 2019 16:27:13 +0300 Subject: [PATCH] [NI] Skip fake call for descriptor from object in builder-inference This call have interesting rules for resolution, see `KtQualifiedExpression.elementChain` function and it's usages: resolution results for such call can be omitted and be replaced with some other information, while diagnostics will be reported from builder-inference. To mitigate this problem, we'll just skip this call from builder-inference as such calls can't have type parameters anyway #KT-32094 Fixed --- .../resolve/DelegatedPropertyInferenceSession.kt | 4 ++-- .../calls/inference/CoroutineInferenceSession.kt | 14 ++++++++++++-- .../calls/tower/KotlinToResolvedCallTransformer.kt | 2 +- .../resolve/calls/components/InferenceSession.kt | 4 ++-- .../severalCandidatesWithDifferentVisibility.kt | 3 +-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt index fdb6c744021..03603d42465 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt @@ -84,7 +84,7 @@ class DelegatedPropertyInferenceSession( initialStorage: ConstraintStorage ): Map = emptyMap() - override fun writeOnlyStubs(): Boolean = false + override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean = false } object InferenceSessionForExistingCandidates : InferenceSession { @@ -102,6 +102,6 @@ object InferenceSessionForExistingCandidates : InferenceSession { initialStorage: ConstraintStorage ): Map = emptyMap() - override fun writeOnlyStubs(): Boolean = false + override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean = false override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean = false } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt index c5297dee76c..d96fb3e3f9d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceSession.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImp import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.* +import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.types.StubType import org.jetbrains.kotlin.types.TypeConstructor @@ -58,6 +59,8 @@ class CoroutineInferenceSession( override fun addCompletedCallInfo(callInfo: CompletedCallInfo) { require(callInfo is PSICompletedCallInfo) { "Wrong instance of callInfo: $callInfo" } + if (skipCall(callInfo.callResolutionResult)) return + commonCalls.add(callInfo) val isApplicableCall = @@ -71,8 +74,15 @@ class CoroutineInferenceSession( } } - override fun writeOnlyStubs(): Boolean { - return true + override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean { + return !skipCall(callInfo) + } + + private fun skipCall(callInfo: SingleCallResolutionResult): Boolean { + // FakeCallableDescriptorForObject can't introduce new information for inference, so it's safe to complete it fully + if (callInfo.resultCallAtom.candidateDescriptor is FakeCallableDescriptorForObject) return true + + return false } override fun currentConstraintSystem(): ConstraintStorage { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 75d02c765a5..9ede95f61c4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -110,7 +110,7 @@ class KotlinToResolvedCallTransformer( val candidate = (baseResolvedCall as SingleCallResolutionResult).resultCallAtom val resultSubstitutor = baseResolvedCall.constraintSystem.buildResultingSubstitutor(typeSystemContext) - if (context.inferenceSession.writeOnlyStubs()) { + if (context.inferenceSession.writeOnlyStubs(baseResolvedCall)) { val stub = createStubResolvedCallAndWriteItToTrace( candidate, context.trace, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt index 0f256141e50..96b8f5e952d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/InferenceSession.kt @@ -24,7 +24,7 @@ interface InferenceSession { initialStorage: ConstraintStorage ): Map = emptyMap() - override fun writeOnlyStubs(): Boolean = false + override fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean = false override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean = false } } @@ -35,7 +35,7 @@ interface InferenceSession { fun addErrorCallInfo(callInfo: ErrorCallInfo) fun currentConstraintSystem(): ConstraintStorage fun inferPostponedVariables(lambda: ResolvedLambdaAtom, initialStorage: ConstraintStorage): Map - fun writeOnlyStubs(): Boolean + fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean fun callCompleted(resolvedAtom: ResolvedAtom): Boolean } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt index 209c6649c3d..becec001691 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/severalCandidatesWithDifferentVisibility.kt @@ -1,6 +1,5 @@ // !USE_EXPERIMENTAL: kotlin.Experimental // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -// !WITH_NEW_INFERENCE // FILE: a.kt @@ -36,7 +35,7 @@ fun invBuilder(@BuilderInference block: Inv.() -> Unit) {} fun test() { invBuilder { - val q = Queue.empty() + val q = Queue.empty() emit(42) } }