store 'hasInferredReturnType' in resolved call

instead of trying to compute it later
This commit is contained in:
svtk
2013-10-31 16:45:40 +04:00
parent f7be8ce953
commit 9c60430ef2
4 changed files with 21 additions and 12 deletions
@@ -104,11 +104,10 @@ public class CallResolverUtil {
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope()); return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope());
} }
private static boolean hasReturnTypeDependentOnNotInferredParams(@NotNull ResolvedCallImpl<?> callToComplete) { private static boolean hasReturnTypeDependentOnNotInferredParams(
ConstraintSystem constraintSystem = callToComplete.getConstraintSystem(); @NotNull CallableDescriptor candidateDescriptor,
if (constraintSystem == null) return false; @NotNull ConstraintSystem constraintSystem
) {
CallableDescriptor candidateDescriptor = callToComplete.getCandidateDescriptor();
JetType returnType = candidateDescriptor.getReturnType(); JetType returnType = candidateDescriptor.getReturnType();
if (returnType == null) return false; if (returnType == null) return false;
@@ -123,13 +122,14 @@ public class CallResolverUtil {
return false; return false;
} }
public static boolean hasInferredReturnType(ResolvedCallWithTrace<?> call) { public static boolean hasInferredReturnType(
ResolvedCallImpl<?> callToComplete = call.getCallToCompleteTypeArgumentInference(); @NotNull CallableDescriptor candidateDescriptor,
if (hasReturnTypeDependentOnNotInferredParams(callToComplete)) return false; @NotNull ConstraintSystem constraintSystem
) {
if (hasReturnTypeDependentOnNotInferredParams(candidateDescriptor, constraintSystem)) return false;
// Expected type mismatch was reported before as 'TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH' // Expected type mismatch was reported before as 'TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH'
ConstraintSystem constraintSystem = callToComplete.getConstraintSystem(); if (constraintSystem.getStatus().hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION)) return false;
if (constraintSystem != null && constraintSystem.getStatus().hasOnlyErrorsFromPosition(ConstraintPosition.EXPECTED_TYPE_POSITION)) return false;
return true; return true;
} }
@@ -310,7 +310,7 @@ public class CandidateResolver {
context.tracing.typeInferenceFailed(context.trace, errorData); context.tracing.typeInferenceFailed(context.trace, errorData);
resolvedCall.addStatus(ResolutionStatus.OTHER_ERROR); resolvedCall.addStatus(ResolutionStatus.OTHER_ERROR);
if (!CallResolverUtil.hasInferredReturnType(resolvedCall)) return null; if (!resolvedCall.hasInferredReturnType()) return null;
return resolvedCall.getResultingDescriptor().getReturnType(); return resolvedCall.getResultingDescriptor().getReturnType();
} }
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.ValueArgument; import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace; import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus; import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
@@ -86,6 +87,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
private ResolutionStatus status = UNKNOWN_STATUS; private ResolutionStatus status = UNKNOWN_STATUS;
private boolean hasUnknownTypeParameters = false; private boolean hasUnknownTypeParameters = false;
private ConstraintSystem constraintSystem = null; private ConstraintSystem constraintSystem = null;
private boolean hasInferredReturnType;
private boolean cleaned = false; private boolean cleaned = false;
private ResolvedCallImpl( private ResolvedCallImpl(
@@ -137,12 +139,19 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
@Override @Override
public void cleanInternalData() { public void cleanInternalData() {
if (!cleaned) {
hasInferredReturnType = CallResolverUtil.hasInferredReturnType(candidateDescriptor, constraintSystem);
}
trace = null; trace = null;
constraintSystem = null; constraintSystem = null;
tracing = null; tracing = null;
cleaned = true; cleaned = true;
} }
public boolean hasInferredReturnType() {
return hasInferredReturnType;
}
private void checkCallIsUnfinished(String elementName) { private void checkCallIsUnfinished(String elementName) {
if (cleaned) throw new IllegalStateException(elementName + " is erased after resolution completion."); if (cleaned) throw new IllegalStateException(elementName + " is erased after resolution completion.");
} }
@@ -52,7 +52,7 @@ public class OverloadResolutionResultsUtil {
@NotNull ContextDependency contextDependency @NotNull ContextDependency contextDependency
) { ) {
if (results.isSingleResult() && contextDependency == ContextDependency.INDEPENDENT) { if (results.isSingleResult() && contextDependency == ContextDependency.INDEPENDENT) {
if (!CallResolverUtil.hasInferredReturnType(results.getResultingCall())) { if (!results.getResultingCall().getCallToCompleteTypeArgumentInference().hasInferredReturnType()) {
return null; return null;
} }
} }