Get rid of unnecessary insideSafeCallChain in various contexts

This commit is contained in:
Mikhail Glukhikh
2015-11-18 15:14:17 +03:00
parent 3a4f6d8226
commit 7decca9df4
7 changed files with 37 additions and 60 deletions
@@ -227,8 +227,7 @@ public class CallExpressionResolver {
context, "trace to resolve as function call", callExpression); context, "trace to resolve as function call", callExpression);
ResolvedCall<FunctionDescriptor> resolvedCall = getResolvedCallForFunction( ResolvedCall<FunctionDescriptor> resolvedCall = getResolvedCallForFunction(
call, call,
// It's possible start of a call so we should reset safe call chain context.replaceTraceAndCache(temporaryForFunction),
context.replaceTraceAndCache(temporaryForFunction).replaceInsideCallChain(false),
CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, result); CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, result);
if (result[0]) { if (result[0]) {
FunctionDescriptor functionDescriptor = resolvedCall != null ? resolvedCall.getResultingDescriptor() : null; FunctionDescriptor functionDescriptor = resolvedCall != null ? resolvedCall.getResultingDescriptor() : null;
@@ -42,11 +42,10 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull CallChecker callChecker, @NotNull CallChecker callChecker,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain); dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates);
} }
@NotNull @NotNull
@@ -63,7 +62,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
) { ) {
return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
new ResolutionResultsCacheImpl(), null, new ResolutionResultsCacheImpl(), null,
callChecker, StatementFilter.NONE, isAnnotationContext, false, false); callChecker, StatementFilter.NONE, isAnnotationContext, false);
} }
@NotNull @NotNull
@@ -75,7 +74,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments, context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
context.resolutionResultsCache, dataFlowInfoForArguments, context.resolutionResultsCache, dataFlowInfoForArguments,
context.callChecker, context.callChecker,
context.statementFilter, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); context.statementFilter, context.isAnnotationContext, context.collectAllCandidates);
} }
@NotNull @NotNull
@@ -94,19 +93,18 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull ContextDependency contextDependency, @NotNull ContextDependency contextDependency,
@NotNull ResolutionResultsCache resolutionResultsCache, @NotNull ResolutionResultsCache resolutionResultsCache,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
return new BasicCallResolutionContext( return new BasicCallResolutionContext(
trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain); dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates);
} }
@NotNull @NotNull
public BasicCallResolutionContext replaceCall(@NotNull Call newCall) { public BasicCallResolutionContext replaceCall(@NotNull Call newCall) {
return new BasicCallResolutionContext( return new BasicCallResolutionContext(
trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideCallChain); dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates);
} }
public void performContextDependentCallChecks(@NotNull ResolvedCall<?> resolvedCall) { public void performContextDependentCallChecks(@NotNull ResolvedCall<?> resolvedCall) {
@@ -59,12 +59,11 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull Receiver explicitExtensionReceiverForInvoke, @NotNull Receiver explicitExtensionReceiverForInvoke,
@NotNull CandidateResolveMode candidateResolveMode, @NotNull CandidateResolveMode candidateResolveMode,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext,
collectAllCandidates, insideSafeCallChain); collectAllCandidates);
this.candidateCall = candidateCall; this.candidateCall = candidateCall;
this.tracing = tracing; this.tracing = tracing;
this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke; this.explicitExtensionReceiverForInvoke = explicitExtensionReceiverForInvoke;
@@ -81,7 +80,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.dataFlowInfo, context.contextDependency, context.checkArguments,
context.resolutionResultsCache, context.dataFlowInfoForArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments,
context.callChecker, context.statementFilter, explicitExtensionReceiverForInvoke, context.callChecker, context.statementFilter, explicitExtensionReceiverForInvoke,
candidateResolveMode, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); candidateResolveMode, context.isAnnotationContext, context.collectAllCandidates);
} }
@NotNull @NotNull
@@ -92,7 +91,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType, candidateCall, tracing, context.trace, context.scope, context.call, context.expectedType,
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache, context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
context.dataFlowInfoForArguments, context.callChecker, context.statementFilter, context.dataFlowInfoForArguments, context.callChecker, context.statementFilter,
ReceiverValue.NO_RECEIVER, CandidateResolveMode.FULLY, context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); ReceiverValue.NO_RECEIVER, CandidateResolveMode.FULLY, context.isAnnotationContext, context.collectAllCandidates);
} }
@Override @Override
@@ -104,12 +103,11 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull ContextDependency contextDependency, @NotNull ContextDependency contextDependency,
@NotNull ResolutionResultsCache resolutionResultsCache, @NotNull ResolutionResultsCache resolutionResultsCache,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
return new CallCandidateResolutionContext<D>( return new CallCandidateResolutionContext<D>(
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
resolutionResultsCache, dataFlowInfoForArguments, callChecker, statementFilter, resolutionResultsCache, dataFlowInfoForArguments, callChecker, statementFilter,
explicitExtensionReceiverForInvoke, candidateResolveMode, isAnnotationContext, collectAllCandidates, insideSafeCallChain); explicitExtensionReceiverForInvoke, candidateResolveMode, isAnnotationContext, collectAllCandidates);
} }
} }
@@ -50,11 +50,10 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
@NotNull CallChecker callChecker, @NotNull CallChecker callChecker,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker, super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, callChecker,
statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain); statementFilter, isAnnotationContext, collectAllCandidates);
this.call = call; this.call = call;
this.checkArguments = checkArguments; this.checkArguments = checkArguments;
if (dataFlowInfoForArguments != null) { if (dataFlowInfoForArguments != null) {
@@ -54,9 +54,6 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
public final boolean collectAllCandidates; public final boolean collectAllCandidates;
// True if we are inside call chain like x?.foo()!!.bar()?.gav()
public final boolean insideCallChain;
protected ResolutionContext( protected ResolutionContext(
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull LexicalScope scope, @NotNull LexicalScope scope,
@@ -67,8 +64,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull CallChecker callChecker, @NotNull CallChecker callChecker,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideCallChain
) { ) {
this.trace = trace; this.trace = trace;
this.scope = scope; this.scope = scope;
@@ -80,7 +76,6 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
this.statementFilter = statementFilter; this.statementFilter = statementFilter;
this.isAnnotationContext = isAnnotationContext; this.isAnnotationContext = isAnnotationContext;
this.collectAllCandidates = collectAllCandidates; this.collectAllCandidates = collectAllCandidates;
this.insideCallChain = insideCallChain;
} }
protected abstract Context create( protected abstract Context create(
@@ -91,8 +86,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull ContextDependency contextDependency, @NotNull ContextDependency contextDependency,
@NotNull ResolutionResultsCache resolutionResultsCache, @NotNull ResolutionResultsCache resolutionResultsCache,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
); );
@NotNull @NotNull
@@ -105,14 +99,14 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
public Context replaceBindingTrace(@NotNull BindingTrace trace) { public Context replaceBindingTrace(@NotNull BindingTrace trace) {
if (this.trace == trace) return self(); if (this.trace == trace) return self();
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter, return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
} }
@NotNull @NotNull
public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) { public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) {
if (newDataFlowInfo == dataFlowInfo) return self(); if (newDataFlowInfo == dataFlowInfo) return self();
return create(trace, scope, newDataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter, return create(trace, scope, newDataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
} }
@NotNull @NotNull
@@ -120,28 +114,28 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE); if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
if (expectedType == newExpectedType) return self(); if (expectedType == newExpectedType) return self();
return create(trace, scope, dataFlowInfo, newExpectedType, contextDependency, resolutionResultsCache, statementFilter, return create(trace, scope, dataFlowInfo, newExpectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
} }
@NotNull @NotNull
public Context replaceScope(@NotNull LexicalScope newScope) { public Context replaceScope(@NotNull LexicalScope newScope) {
if (newScope == scope) return self(); if (newScope == scope) return self();
return create(trace, newScope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter, return create(trace, newScope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
} }
@NotNull @NotNull
public Context replaceContextDependency(@NotNull ContextDependency newContextDependency) { public Context replaceContextDependency(@NotNull ContextDependency newContextDependency) {
if (newContextDependency == contextDependency) return self(); if (newContextDependency == contextDependency) return self();
return create(trace, scope, dataFlowInfo, expectedType, newContextDependency, resolutionResultsCache, statementFilter, return create(trace, scope, dataFlowInfo, expectedType, newContextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
} }
@NotNull @NotNull
public Context replaceResolutionResultsCache(@NotNull ResolutionResultsCache newResolutionResultsCache) { public Context replaceResolutionResultsCache(@NotNull ResolutionResultsCache newResolutionResultsCache) {
if (newResolutionResultsCache == resolutionResultsCache) return self(); if (newResolutionResultsCache == resolutionResultsCache) return self();
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, newResolutionResultsCache, statementFilter, return create(trace, scope, dataFlowInfo, expectedType, contextDependency, newResolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
} }
@NotNull @NotNull
@@ -152,19 +146,12 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull @NotNull
public Context replaceCollectAllCandidates(boolean newCollectAllCandidates) { public Context replaceCollectAllCandidates(boolean newCollectAllCandidates) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter, return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
newCollectAllCandidates, insideCallChain); newCollectAllCandidates);
} }
@NotNull @NotNull
public Context replaceStatementFilter(@NotNull StatementFilter statementFilter) { public Context replaceStatementFilter(@NotNull StatementFilter statementFilter) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter, return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain); collectAllCandidates);
}
@NotNull
public Context replaceInsideCallChain(boolean insideSafeCallChain) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideSafeCallChain);
} }
} }
@@ -58,11 +58,10 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
@NotNull Collection<MutableResolvedCall<F>> resolvedCalls, @NotNull Collection<MutableResolvedCall<F>> resolvedCalls,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache, super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain); dataFlowInfoForArguments, callChecker, statementFilter, isAnnotationContext, collectAllCandidates);
this.lazyCandidates = lazyCandidates; this.lazyCandidates = lazyCandidates;
this.resolvedCalls = resolvedCalls; this.resolvedCalls = resolvedCalls;
this.tracing = tracing; this.tracing = tracing;
@@ -79,7 +78,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
context.resolutionResultsCache, context.dataFlowInfoForArguments, context.resolutionResultsCache, context.dataFlowInfoForArguments,
context.callChecker, context.callChecker,
context.statementFilter, new SmartList<MutableResolvedCall<F>>(), context.statementFilter, new SmartList<MutableResolvedCall<F>>(),
context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain); context.isAnnotationContext, context.collectAllCandidates);
} }
@NotNull @NotNull
@@ -105,15 +104,14 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
@NotNull ContextDependency contextDependency, @NotNull ContextDependency contextDependency,
@NotNull ResolutionResultsCache resolutionResultsCache, @NotNull ResolutionResultsCache resolutionResultsCache,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
return new ResolutionTask<D, F>( return new ResolutionTask<D, F>(
lazyCandidates, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, lazyCandidates, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
resolutionResultsCache, dataFlowInfoForArguments, resolutionResultsCache, dataFlowInfoForArguments,
callChecker, callChecker,
statementFilter, resolvedCalls, statementFilter, resolvedCalls,
isAnnotationContext, collectAllCandidates, insideSafeCallChain); isAnnotationContext, collectAllCandidates);
} }
@Override @Override
@@ -61,7 +61,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
context.contextDependency, context.resolutionResultsCache, context.contextDependency, context.resolutionResultsCache,
context.callChecker, context.callChecker,
context.statementFilter, context.statementFilter,
context.isAnnotationContext, context.collectAllCandidates, context.insideCallChain context.isAnnotationContext, context.collectAllCandidates
); );
} }
@@ -79,7 +79,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
) { ) {
return new ExpressionTypingContext( return new ExpressionTypingContext(
trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, callChecker, trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, callChecker,
statementFilter, isAnnotationContext, false, false); statementFilter, isAnnotationContext, false);
} }
private ExpressionTypingContext( private ExpressionTypingContext(
@@ -92,12 +92,11 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull CallChecker callChecker, @NotNull CallChecker callChecker,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean isAnnotationContext, boolean isAnnotationContext,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache,
callChecker, callChecker,
statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain); statementFilter, isAnnotationContext, collectAllCandidates);
} }
@Override @Override
@@ -109,12 +108,11 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull ContextDependency contextDependency, @NotNull ContextDependency contextDependency,
@NotNull ResolutionResultsCache resolutionResultsCache, @NotNull ResolutionResultsCache resolutionResultsCache,
@NotNull StatementFilter statementFilter, @NotNull StatementFilter statementFilter,
boolean collectAllCandidates, boolean collectAllCandidates
boolean insideSafeCallChain
) { ) {
return new ExpressionTypingContext(trace, scope, dataFlowInfo, return new ExpressionTypingContext(trace, scope, dataFlowInfo,
expectedType, contextDependency, resolutionResultsCache, expectedType, contextDependency, resolutionResultsCache,
callChecker, callChecker,
statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain); statementFilter, isAnnotationContext, collectAllCandidates);
} }
} }