Revert "[FE 1.0] Resolve special construct calls through the new type inference infra"

This reverts commit e66cc9a639.
This commit is contained in:
Mikhail Glukhikh
2022-09-12 11:28:47 +02:00
committed by Space
parent fc0058d471
commit f35cebbc25
11 changed files with 43 additions and 57 deletions
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
@@ -46,7 +45,6 @@ import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.TypeSubstitutor;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher;
@@ -293,23 +291,17 @@ public class CallResolver {
}
@NotNull
public <D extends CallableDescriptor> OverloadResolutionResults<D> resolveCallWithGivenDescriptor(
public OverloadResolutionResults<ReceiverParameterDescriptor> resolveThisOrSuperCallWithGivenDescriptor(
@NotNull ExpressionTypingContext context,
@NotNull Call call,
@NotNull D descriptor,
@NotNull TracingStrategy tracingStrategy,
@Nullable TypeSubstitutor substitutor,
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
@NotNull ReceiverParameterDescriptor descriptor
) {
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(
context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments
);
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
return PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
callResolutionContext,
Collections.singletonList(descriptor),
tracingStrategy,
substitutor
TracingStrategy.EMPTY
);
}
@@ -588,6 +580,27 @@ public class CallResolver {
return false;
}
public OverloadResolutionResults<FunctionDescriptor> resolveCallWithKnownCandidate(
@NotNull Call call,
@NotNull TracingStrategy tracing,
@NotNull ResolutionContext<?> context,
@NotNull OldResolutionCandidate<FunctionDescriptor> candidate,
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
) {
return callResolvePerfCounter.<OverloadResolutionResults<FunctionDescriptor>>time(() -> {
BasicCallResolutionContext basicCallResolutionContext =
BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments);
Set<OldResolutionCandidate<FunctionDescriptor>> candidates = Collections.singleton(candidate);
ResolutionTask<FunctionDescriptor> resolutionTask = new ResolutionTask<>(
new NewResolutionOldInference.ResolutionKind.GivenCandidates(), null, candidates
);
return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing);
});
}
private <D extends CallableDescriptor> OverloadResolutionResults<D> doResolveCallOrGetCachedResults(
@NotNull BasicCallResolutionContext context,
@NotNull ResolutionTask<D> resolutionTask,
@@ -147,8 +147,7 @@ class PSICallResolver(
fun <D : CallableDescriptor> runResolutionAndInferenceForGivenDescriptors(
context: BasicCallResolutionContext,
descriptors: Collection<CallableDescriptor>,
tracingStrategy: TracingStrategy,
substitutor: TypeSubstitutor? = null
tracingStrategy: TracingStrategy
): OverloadResolutionResults<D> {
val isSpecialFunction = descriptors.any { it.name in SPECIAL_FUNCTION_NAMES }
val kotlinCall = toKotlinCall(
@@ -160,7 +159,7 @@ class PSICallResolver(
GivenCandidate(
it,
dispatchReceiver = null,
knownTypeParametersResultingSubstitutor = substitutor
knownTypeParametersResultingSubstitutor = null
)
}
@@ -149,7 +149,7 @@ fun KtElement.getCall(context: BindingContext): Call? {
else -> element.getCalleeExpressionIfAny()
}
if (reference != null) {
return context[CALL, reference] ?: context[CALL, element]
return context[CALL, reference]
}
return context[CALL, element]
}
@@ -636,7 +636,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
BindingTrace trace = context.trace;
Call call = CallMaker.makeCall(expression, null, null, expression, Collections.emptyList());
OverloadResolutionResults<ReceiverParameterDescriptor> results =
components.callResolver.resolveCallWithGivenDescriptor(context, call, descriptor, TracingStrategy.EMPTY, null, null);
components.callResolver.resolveThisOrSuperCallWithGivenDescriptor(context, call, descriptor);
ResolvedCall<?> resolvedCall = results.getResultingCall();
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
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.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.descriptorUtil.AnnotationsForResolveUtilsKt;
@@ -161,17 +162,12 @@ public class ControlStructureTypingUtils {
) {
TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context);
TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType, context.languageVersionSettings);
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenDescriptor(
context, call, function, tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments
);
OldResolutionCandidate<FunctionDescriptor> resolutionCandidate =
OldResolutionCandidate.create(call, function, knownTypeParameterSubstitutor);
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithKnownCandidate(
call, tracing, context, resolutionCandidate, dataFlowInfoForArguments);
assert results.isSingleResult() : "Not single result after resolving one known candidate";
ResolvedCall<FunctionDescriptor> resolvedCall = results.getResultingCall();
context.trace.record(RESOLVED_CALL, call, resolvedCall);
context.trace.record(CALL, call.getCallElement(), call);
return resolvedCall;
return results.getResultingCall();
}
private static @Nullable TypeSubstitutor createKnownTypeParameterSubstitutorForSpecialCall(
@@ -9,8 +9,8 @@ class A(outer: Outer) {
var g: String by outer.getContainer().getMyProperty()
var b: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>foo(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())<!>
var r: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>foo(outer.getContainer().<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())<!>
var b: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>foo(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())<!>
var r: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>foo(outer.getContainer().<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())<!>
var e: String by <!DEBUG_INFO_MISSING_UNRESOLVED!>+<!> <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())
var f: String by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>()) <!DEBUG_INFO_MISSING_UNRESOLVED!>-<!> 1
}
@@ -7,7 +7,7 @@ class A<R>() {
operator fun <T> setValue(t: Any?, p: KProperty<*>, x: T) = Unit
}
var a1: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A<!>()<!>
var a1: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A<!>()<!>
var a2: Int by A<String>()
class B<R>() {
@@ -24,4 +24,4 @@ class C<R>() {
}
var c1: Int by C()
var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>C<Number>()<!>
var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>C<Number>()<!>
@@ -3,7 +3,7 @@
import kotlin.reflect.KProperty
var a: Int by A()
var a1 by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>A()<!>
var a1 by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>A()<!>
var b: Int by B()
@@ -6,7 +6,7 @@ class A {
var a: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
}
var aTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
var aTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
class Delegate {
fun getValue(t: Nothing, p: KProperty<*>): Int {
@@ -1,23 +0,0 @@
// FILE: J.java
import org.jetbrains.annotations.*;
public class J {
public interface DP {
String getValue(Object a, Object b);
String setValue(Object a, Object b, Object c);
}
@NotNull
public static DP staticNN;
@Nullable
public static DP staticN;
public static DP staticJ;
}
// FILE: k.kt
var A by J.staticNN
var B by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>J.staticN<!>
var C by J.staticJ
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: J.java
import org.jetbrains.annotations.*;
@@ -19,5 +20,5 @@ public class J {
// FILE: k.kt
var A by J.staticNN
var B by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>J.staticN<!>
var B by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>J.staticN<!>
var C by J.staticJ