From c0ae68fe9333fa63037ab78b07b1c7ad890b8fa1 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Thu, 2 Jun 2022 11:46:02 +0200 Subject: [PATCH] [FE 1.0] Remove type predicate calculation from CFG tests That logic is hard to support because it used deprecated `OldResolutionCandidate` and `ResolvedCallImpl`. Moreover FIR has own CFG utils. --- .../cfg/expressions/unresolvedCalls.values | 6 +- .../jetbrains/kotlin/cfg/pseudocodeUtils.kt | 69 ------------------- 2 files changed, 3 insertions(+), 72 deletions(-) diff --git a/compiler/testData/cfg/expressions/unresolvedCalls.values b/compiler/testData/cfg/expressions/unresolvedCalls.values index e64e39c9428..b6a000cc541 100644 --- a/compiler/testData/cfg/expressions/unresolvedCalls.values +++ b/compiler/testData/cfg/expressions/unresolvedCalls.values @@ -25,7 +25,7 @@ fun test() { --------------------- foo !: * bar !: * -bar() : OR{{<: IntArray}, {<: Int}} NEW: magic[UNRESOLVED_CALL](bar()|!) -> -foo(bar()) : * NEW: magic[UNRESOLVED_CALL](foo(bar())|, !) -> -{ foo(bar()) } : * COPY +bar() : * NEW: magic[UNRESOLVED_CALL](bar()|!) -> +foo(bar()) : * NEW: magic[UNRESOLVED_CALL](foo(bar())|, !) -> +{ foo(bar()) } : * COPY ===================== diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/pseudocodeUtils.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/pseudocodeUtils.kt index 75b325413bf..45ca5fa9c9f 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/pseudocodeUtils.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/cfg/pseudocodeUtils.kt @@ -24,26 +24,16 @@ import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.MagicKind.* import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.ConditionalJumpInstruction import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.ReturnValueInstruction import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.ThrowExceptionInstruction -import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext.* -import org.jetbrains.kotlin.resolve.DelegatingBindingTrace -import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets import org.jetbrains.kotlin.resolve.bindingContextUtil.getTargetFunctionDescriptor -import org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMapper -import org.jetbrains.kotlin.resolve.calls.util.getCall import org.jetbrains.kotlin.resolve.calls.util.isSafeCall import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.util.getExplicitReceiverValue -import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo -import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind -import org.jetbrains.kotlin.resolve.calls.tasks.OldResolutionCandidate -import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy import org.jetbrains.kotlin.resolve.findTopMostOverriddenDescriptors import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.KotlinType @@ -85,60 +75,6 @@ fun getExpectedTypePredicate( if (receiverValue != null) typePredicates.add(getReceiverTypePredicate(resolvedCall, receiverValue)) } - fun getTypePredicateForUnresolvedCallArgument(to: KtElement, inputValueIndex: Int): TypePredicate? { - if (inputValueIndex < 0) return null - val call = to.getCall(bindingContext) ?: return null - val callee = call.calleeExpression ?: return null - - val candidates = callee.getReferenceTargets(bindingContext) - .filterIsInstance() - .sortedBy { DescriptorRenderer.FQ_NAMES_IN_TYPES.render(it) } - if (candidates.isEmpty()) return null - - val explicitReceiver = call.explicitReceiver - val argValueOffset = if (explicitReceiver != null) 1 else 0 - - val predicates = ArrayList() - - for (candidate in candidates) { - val resolutionCandidate = OldResolutionCandidate.create( - call, - candidate, - null, - ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, - null - ) - val candidateCall = ResolvedCallImpl.create( - resolutionCandidate, - DelegatingBindingTrace(bindingContext, "Compute type predicates for unresolved call arguments"), - TracingStrategy.EMPTY, - DataFlowInfoForArgumentsImpl(DataFlowInfo.EMPTY, call) - ) - val status = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters( - call, TracingStrategy.EMPTY, candidateCall, LanguageVersionSettingsImpl.DEFAULT - ) - if (!status.isSuccess) continue - - val candidateArgumentMap = candidateCall.valueArguments - val callArguments = call.valueArguments - val i = inputValueIndex - argValueOffset - if (i < 0 || i >= callArguments.size) continue - - val mapping = candidateCall.getArgumentMapping(callArguments[i]) as? ArgumentMatch ?: continue - - val candidateParameter = mapping.valueParameter - val resolvedArgument = candidateArgumentMap[candidateParameter] - val expectedType = if (resolvedArgument is VarargValueArgument) - candidateParameter.varargElementType - else - candidateParameter.type - - predicates.add(if (expectedType != null) AllSubtypes(expectedType) else AllTypes) - } - - return or(predicates) - } - fun addTypePredicates(value: PseudoValue) { pseudocode.getUsages(value).forEach { when (it) { @@ -215,11 +151,6 @@ fun getExpectedTypePredicate( is KtDelegatedSuperTypeEntry -> addSubtypesOf(bindingContext[TYPE, element.typeReference]) } } - - UNRESOLVED_CALL -> { - val typePredicate = getTypePredicateForUnresolvedCallArgument(it.element, it.inputValues.indexOf(value)) - typePredicates.add(typePredicate) - } else -> {} } }