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