[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.
This commit is contained in:
Victor Petukhov
2022-06-02 11:46:02 +02:00
committed by teamcity
parent 5f5c3aa534
commit c0ae68fe93
2 changed files with 3 additions and 72 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ fun test() {
---------------------
foo !<v2>: *
bar !<v0>: *
bar() <v1>: OR{{<: IntArray}, {<: Int}} NEW: magic[UNRESOLVED_CALL](bar()|!<v0>) -> <v1>
foo(bar()) <v3>: * NEW: magic[UNRESOLVED_CALL](foo(bar())|<v1>, !<v2>) -> <v3>
{ foo(bar()) } <v3>: * COPY
bar() <v1>: * NEW: magic[UNRESOLVED_CALL](bar()|!<v0>) -> <v1>
foo(bar()) <v3>: * NEW: magic[UNRESOLVED_CALL](foo(bar())|<v1>, !<v2>) -> <v3>
{ foo(bar()) } <v3>: * COPY
=====================
@@ -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<FunctionDescriptor>()
.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<TypePredicate>()
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 -> {}
}
}