Introduce language feature for NI, remove old setting

This commit is contained in:
Mikhail Zarechenskiy
2017-10-20 15:46:33 +03:00
parent 27e7f13335
commit 73b4e24d54
21 changed files with 80 additions and 82 deletions
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.BindingContext.*
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
@@ -529,7 +528,7 @@ class DelegatedPropertyResolver(
trace: BindingTrace,
dataFlowInfo: DataFlowInfo
): KotlinType? {
if (!USE_NEW_INFERENCE) return null
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return null
val traceToResolveConventionMethods = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property convention methods")
@@ -672,7 +672,7 @@ public class DescriptorResolver {
BindingTrace trace,
@NotNull LexicalScope scope
) {
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(type, true);
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(type, true, languageVersionSettings);
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
scope.getOwnerDescriptor(),
annotationResolver.resolveAnnotationsWithArguments(scope, parameter.getModifierList(), trace),
@@ -1157,7 +1157,7 @@ public class DescriptorResolver {
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace, languageVersionSettings);
KotlinType type = expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor);
KotlinType publicType = transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(publicType, false);
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(publicType, false, languageVersionSettings);
KotlinType sanitizedType = declarationReturnTypeSanitizer.sanitizeReturnType(approximatedType, wrappedTypeFactory, trace, languageVersionSettings);
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, sanitizedType);
return sanitizedType;
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,5 +161,6 @@ class VariableTypeAndInitializerResolver(
return declarationReturnTypeSanitizer.sanitizeReturnType(approximatedType, wrappedTypeFactory, trace, languageVersionSettings)
}
private fun approximateType(type: KotlinType, local: Boolean): UnwrappedType = typeApproximator.approximateDeclarationType(type, local)
private fun approximateType(type: KotlinType, local: Boolean): UnwrappedType =
typeApproximator.approximateDeclarationType(type, local, expressionTypingServices.languageVersionSettings)
}
@@ -263,8 +263,7 @@ public class ArgumentTypeResolver {
if (overloadResolutionResults == null) return null;
if (isSingleAndPossibleTransformToSuccess(overloadResolutionResults)) {
ResolvedCall<?> resolvedCall =
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency);
ResolvedCall<?> resolvedCall = OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context);
if (resolvedCall == null) return null;
return DoubleColonExpressionResolver.Companion.createKCallableTypeForReference(
@@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
@@ -90,8 +91,10 @@ class CallExpressionResolver(
): Pair<Boolean, ResolvedCall<FunctionDescriptor>?> {
val results = callResolver.resolveFunctionCall(BasicCallResolutionContext.create(
context, call, checkArguments, DataFlowInfoForArgumentsImpl(initialDataFlowInfoForArguments, call)))
return if (!results.isNothing) Pair(true, OverloadResolutionResultsUtil.getResultingCall(results, context.contextDependency))
else Pair(false, null)
return if (!results.isNothing)
Pair(true, OverloadResolutionResultsUtil.getResultingCall(results, context))
else
Pair(false, null)
}
private fun getVariableType(
@@ -281,7 +284,7 @@ class CallExpressionResolver(
}
else when (resolutionResult.resultCode) {
NAME_NOT_FOUND, CANDIDATES_WITH_WRONG_RECEIVER -> false
else -> !USE_NEW_INFERENCE || resolutionResult.isSuccess
else -> !context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) || resolutionResult.isSuccess
}
}
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
@@ -571,12 +572,13 @@ public class CallResolver {
Call call = context.call;
tracing.bindCall(context.trace, call);
if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE() && (resolutionTask.resolutionKind.getKotlinCallKind() != KotlinCallKind.UNSUPPORTED)) {
boolean newInferenceEnabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference);
if (newInferenceEnabled && (resolutionTask.resolutionKind.getKotlinCallKind() != KotlinCallKind.UNSUPPORTED)) {
assert resolutionTask.name != null;
return PSICallResolver.runResolutionAndInference(context, resolutionTask.name, resolutionTask.resolutionKind, tracing);
}
if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE() && resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates) {
if (newInferenceEnabled && resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates) {
assert resolutionTask.givenCandidates != null;
return PSICallResolver.runResolutionAndInferenceForGivenCandidates(context, resolutionTask.givenCandidates, tracing);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,10 @@ package org.jetbrains.kotlin.resolve.calls.results;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.resolve.calls.KotlinResolutionConfigurationKt;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.tower.KotlinToResolvedCallTransformerKt;
@@ -41,20 +42,20 @@ public class OverloadResolutionResultsUtil {
@Nullable
public static <D extends CallableDescriptor> KotlinType getResultingType(
@NotNull OverloadResolutionResults<D> results,
@NotNull ContextDependency contextDependency
@NotNull ResolutionContext<?> context
) {
ResolvedCall<D> resultingCall = getResultingCall(results, contextDependency);
ResolvedCall<D> resultingCall = getResultingCall(results, context);
return resultingCall != null ? resultingCall.getResultingDescriptor().getReturnType() : null;
}
@Nullable
public static <D extends CallableDescriptor> ResolvedCall<D> getResultingCall(
@NotNull OverloadResolutionResults<D> results,
@NotNull ContextDependency contextDependency
@NotNull ResolutionContext<?> context
) {
if (results.isSingleResult() && contextDependency == ContextDependency.INDEPENDENT) {
if (results.isSingleResult() && context.contextDependency == ContextDependency.INDEPENDENT) {
ResolvedCall<D> resultingCall = results.getResultingCall();
if (!KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()) {
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
if (!((MutableResolvedCall<D>) resultingCall).hasInferredReturnType()) {
return null;
}
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
import org.jetbrains.kotlin.resolve.calls.DiagnosticReporterByTrackingStrategy
import org.jetbrains.kotlin.resolve.calls.REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getEffectiveExpectedType
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isFakeElement
@@ -72,6 +71,11 @@ class KotlinToResolvedCallTransformer(
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter
) {
companion object {
private val REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
get() = false
}
fun <D : CallableDescriptor> onlyTransform(
resolvedCallAtom: ResolvedCallAtom
): ResolvedCall<D> = transformToResolvedCall(resolvedCallAtom, null)
@@ -316,6 +316,9 @@ class NewResolutionOldInference(
override val lexicalScope: LexicalScope get() = resolutionContext.scope
override val isDebuggerContext: Boolean get() = resolutionContext.isDebuggerContext
override val isNewInferenceEnabled: Boolean
get() = resolutionContext.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
}
internal class MyCandidate(
@@ -282,6 +282,7 @@ class PSICallResolver(
override val syntheticScopes: SyntheticScopes get() = this@PSICallResolver.syntheticScopes
override val isDebuggerContext: Boolean get() = context.isDebuggerContext
override val isNewInferenceEnabled: Boolean get() = context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
override val lexicalScope: LexicalScope get() = context.scope
private val cache = HashMap<ReceiverParameterDescriptor, ReceiverValueWithSmartCastInfo>()
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver;
import org.jetbrains.kotlin.resolve.calls.KotlinResolutionConfigurationKt;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import org.jetbrains.kotlin.resolve.calls.checkers.*;
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
@@ -857,7 +856,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
baseTypeInfo = baseTypeInfo.replaceDataFlowInfo(dataFlowInfo.disequate(value, DataFlowValue.nullValue(components.builtIns),
components.languageVersionSettings));
}
KotlinType resultingType = KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()
KotlinType resultingType = components.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
? resolvedCall.getResultingDescriptor().getReturnType()
: TypeUtils.makeNotNullable(baseType);
if (context.contextDependency == DEPENDENT) {
@@ -1371,7 +1370,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
CallMaker.makeCall(callElement, receiver, null, operationSign, Collections.singletonList(leftArgument)),
operationSign,
OperatorNameConventions.CONTAINS);
KotlinType containsType = OverloadResolutionResultsUtil.getResultingType(resolutionResult, context.contextDependency);
KotlinType containsType = OverloadResolutionResultsUtil.getResultingType(resolutionResult, context);
ensureBooleanResult(operationSign, OperatorNameConventions.CONTAINS, containsType, context);
if (left != null) {
@@ -1517,7 +1516,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
typeInfo = typeInfo.replaceDataFlowInfo(resolutionResults.getResultingCall().getDataFlowInfoForArguments().getResultInfo());
}
return typeInfo.replaceType(OverloadResolutionResultsUtil.getResultingType(resolutionResults, context.contextDependency));
return typeInfo.replaceType(OverloadResolutionResultsUtil.getResultingType(resolutionResults, context));
}
@Override
@@ -524,7 +524,7 @@ class DoubleColonExpressionResolver(
): KotlinType? {
val descriptor =
if (resolutionResults != null && !resolutionResults.isNothing) {
val resolvedCall = OverloadResolutionResultsUtil.getResultingCall(resolutionResults, context.contextDependency)
val resolvedCall = OverloadResolutionResultsUtil.getResultingCall(resolutionResults, context)
resolvedCall?.resultingDescriptor ?: return null
}
else {
@@ -20,6 +20,7 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
@@ -27,7 +28,6 @@ import org.jetbrains.kotlin.descriptors.ScriptDescriptor;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.calls.KotlinResolutionConfigurationKt;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
@@ -336,7 +336,7 @@ public class ExpressionTypingServices {
}
ContextDependency dependency = context.contextDependency;
if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()) {
if (getLanguageVersionSettings().supportsFeature(LanguageFeature.NewInference)) {
dependency = ContextDependency.INDEPENDENT;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -226,8 +226,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
context.replaceTraceAndCache(temporaryForAssignmentOperation).replaceScope(scope),
receiver, expression, name
);
KotlinType assignmentOperationType = OverloadResolutionResultsUtil.getResultingType(assignmentOperationDescriptors,
context.contextDependency);
KotlinType assignmentOperationType = OverloadResolutionResultsUtil.getResultingType(assignmentOperationDescriptors, context);
OverloadResolutionResults<FunctionDescriptor> binaryOperationDescriptors;
KotlinType binaryOperationType;
@@ -243,7 +242,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
receiver, expression, counterpartName
);
binaryOperationType = OverloadResolutionResultsUtil.getResultingType(binaryOperationDescriptors, context.contextDependency);
binaryOperationType = OverloadResolutionResultsUtil.getResultingType(binaryOperationDescriptors, context);
}
else {
binaryOperationDescriptors = OverloadResolutionResultsImpl.nameNotFound();
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.types.expressions
import com.google.common.collect.Lists
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -36,7 +37,6 @@ import org.jetbrains.kotlin.resolve.BindingContext.EXPECTED_RETURN_TYPE
import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
import org.jetbrains.kotlin.resolve.checkers.UnderscoreChecker
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
@@ -132,7 +132,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
val resultType = functionDescriptor.createFunctionType(suspendFunctionTypeExpected)
if (USE_NEW_INFERENCE && functionalTypeExpected)
if (components.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) && functionalTypeExpected)
createTypeInfo(resultType, context)
else
components.dataFlowAnalyzer.createCheckedTypeInfo(resultType, context, function)
@@ -242,7 +242,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
val newInferenceLambdaInfo = context.trace[BindingContext.NEW_INFERENCE_LAMBDA_INFO, expression.functionLiteral]
// i.e. this lambda isn't call arguments
if (newInferenceLambdaInfo == null && USE_NEW_INFERENCE) {
if (newInferenceLambdaInfo == null && context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
newContext = newContext.replaceContextDependency(ContextDependency.INDEPENDENT)
}