From 84eb0b37a2dbc08e6624ae4920bd551fb83c56ea Mon Sep 17 00:00:00 2001 From: svtk Date: Wed, 30 Oct 2013 18:51:20 +0400 Subject: [PATCH] Cache resolution results for properties as well. There is no need to complete these results with expected type and analyze arguments, as property doesn't have arguments. However, it's useful to clean internal resolution data through completion phase for properties like for functions. --- .../jet/lang/resolve/calls/CallResolver.java | 9 +++++---- .../jet/lang/resolve/calls/CandidateResolver.java | 14 +++++++------- .../calls/context/ResolutionResultsCache.java | 5 ++--- .../calls/context/ResolutionResultsCacheImpl.java | 13 +++++-------- .../context/TemporaryResolutionResultsCache.java | 10 ++++------ 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 0136b76168c..e73a5e43895 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -120,7 +120,7 @@ public class CallResolver { List> tasks = TaskPrioritizer.computePrioritizedTasks(context, name, functionReference, CallableDescriptorCollectors.FUNCTIONS_AND_VARIABLES); return doResolveCallOrGetCachedResults(ResolutionResultsCache.FUNCTION_MEMBER_TYPE, - context, tasks, CallTransformer.FUNCTION_CALL_TRANSFORMER, functionReference); + context, tasks, CallTransformer.FUNCTION_CALL_TRANSFORMER, functionReference); } @NotNull @@ -133,7 +133,8 @@ public class CallResolver { ) { return resolveFunctionCall(BasicCallResolutionContext.create( trace, scope, call, expectedType, dataFlowInfo, ContextDependency.INDEPENDENT, CheckValueArgumentsMode.ENABLED, - ExpressionPosition.FREE, ResolutionResultsCacheImpl.create(), LabelResolver.create(), null, expressionTypingServices.createExtension(scope))); + ExpressionPosition.FREE, ResolutionResultsCacheImpl.create(), LabelResolver.create(), null, + expressionTypingServices.createExtension(scope))); } @NotNull @@ -384,10 +385,10 @@ public class CallResolver { context.resolutionResultsCache.recordResolutionResults(callKey, memberType, results); context.resolutionResultsCache.recordResolutionTrace(callKey, deltasTraceToCacheResolve); - if (results.isSingleResult() && memberType == ResolutionResultsCache.FUNCTION_MEMBER_TYPE) { + if (results.isSingleResult()) { CallCandidateResolutionContext callCandidateResolutionContext = CallCandidateResolutionContext.createForCallBeingAnalyzed( results.getResultingCall().getCallToCompleteTypeArgumentInference(), context, tracing); - context.resolutionResultsCache.recordDeferredComputationForCall(callKey, callCandidateResolutionContext, memberType); + context.resolutionResultsCache.recordDeferredComputationForCall(callKey, callCandidateResolutionContext); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index b41c784b812..13330e3b107 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -347,21 +347,21 @@ public class CandidateResolver { context = context.replaceExpectedType(expectedType); JetExpression keyExpression = getDeferredComputationKeyExpression(expression); - CallCandidateResolutionContext storedContextForArgument = + CallCandidateResolutionContext storedContextForArgument = context.resolutionResultsCache.getDeferredComputation(keyExpression); + PsiElement parent = expression.getParent(); + if (parent instanceof JetWhenExpression && expression == ((JetWhenExpression) parent).getSubjectExpression() + || (expression instanceof JetFunctionLiteralExpression)) { + return; + } if (storedContextForArgument == null) { - PsiElement parent = expression.getParent(); - if (parent instanceof JetWhenExpression && expression == ((JetWhenExpression) parent).getSubjectExpression() - || (expression instanceof JetFunctionLiteralExpression)) { - return; - } JetType type = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression); checkResultArgumentType(type, argument, context); return; } - CallCandidateResolutionContext contextForArgument = storedContextForArgument + CallCandidateResolutionContext contextForArgument = storedContextForArgument .replaceContextDependency(INDEPENDENT).replaceBindingTrace(context.trace).replaceExpectedType(expectedType); JetType type; if (contextForArgument.candidateCall.hasIncompleteTypeParameters()) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCache.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCache.java index bbd39f927e2..e761d29303b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCache.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCache.java @@ -55,10 +55,9 @@ public interface ResolutionResultsCache { void recordDeferredComputationForCall( @NotNull CallKey callKey, - @NotNull CallCandidateResolutionContext deferredComputation, - @NotNull MemberType memberType + @NotNull CallCandidateResolutionContext deferredComputation ); @Nullable - CallCandidateResolutionContext getDeferredComputation(@Nullable JetExpression expression); + CallCandidateResolutionContext getDeferredComputation(@Nullable JetExpression expression); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCacheImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCacheImpl.java index 77304bbd65a..401dd992955 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCacheImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/ResolutionResultsCacheImpl.java @@ -37,7 +37,7 @@ public class ResolutionResultsCacheImpl implements ResolutionResultsCache { RESOLUTION_RESULTS_FOR_FUNCTION = Slices.createSimpleSlice(); public static final WritableSlice> RESOLUTION_RESULTS_FOR_PROPERTY = Slices.createSimpleSlice(); public static final WritableSlice TRACE_DELTAS_CACHE = Slices.createSimpleSlice(); - public static final WritableSlice> DEFERRED_COMPUTATION_FOR_CALL = Slices.createSimpleSlice(); + public static final WritableSlice> DEFERRED_COMPUTATION_FOR_CALL = Slices.createSimpleSlice(); static { BasicWritableSlice.initSliceDebugNames(ResolutionResultsCacheImpl.class); @@ -78,22 +78,19 @@ public class ResolutionResultsCacheImpl implements ResolutionResultsCache { @Override public void recordDeferredComputationForCall( @NotNull CallKey callKey, - @NotNull CallCandidateResolutionContext deferredComputation, - @NotNull MemberType memberType + @NotNull CallCandidateResolutionContext deferredComputation ) { - if (memberType == PROPERTY_MEMBER_TYPE) return; - //noinspection unchecked - trace.record(DEFERRED_COMPUTATION_FOR_CALL, callKey, (CallCandidateResolutionContext) deferredComputation); + trace.record(DEFERRED_COMPUTATION_FOR_CALL, callKey, deferredComputation); } @Override @Nullable - public CallCandidateResolutionContext getDeferredComputation(@Nullable JetExpression expression) { + public CallCandidateResolutionContext getDeferredComputation(@Nullable JetExpression expression) { if (expression == null) return null; for (Call.CallType callType : Lists .newArrayList(Call.CallType.DEFAULT, Call.CallType.ARRAY_GET_METHOD, Call.CallType.ARRAY_SET_METHOD)) { CallKey callKey = CallKey.create(callType, expression); - CallCandidateResolutionContext context = trace.get(DEFERRED_COMPUTATION_FOR_CALL, callKey); + CallCandidateResolutionContext context = trace.get(DEFERRED_COMPUTATION_FOR_CALL, callKey); if (context != null) { return context; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/TemporaryResolutionResultsCache.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/TemporaryResolutionResultsCache.java index 31f0824bd43..193d26fc9d3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/TemporaryResolutionResultsCache.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/context/TemporaryResolutionResultsCache.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.calls.context; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.CallableDescriptor; -import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.psi.CallKey; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace; @@ -77,16 +76,15 @@ public class TemporaryResolutionResultsCache implements ResolutionResultsCache { @Override public void recordDeferredComputationForCall( @NotNull CallKey callKey, - @NotNull CallCandidateResolutionContext deferredComputation, - @NotNull MemberType memberType + @NotNull CallCandidateResolutionContext deferredComputation ) { - innerCache.recordDeferredComputationForCall(callKey, deferredComputation, memberType); + innerCache.recordDeferredComputationForCall(callKey, deferredComputation); } @Nullable @Override - public CallCandidateResolutionContext getDeferredComputation(@Nullable JetExpression expression) { - CallCandidateResolutionContext computation = innerCache.getDeferredComputation(expression); + public CallCandidateResolutionContext getDeferredComputation(@Nullable JetExpression expression) { + CallCandidateResolutionContext computation = innerCache.getDeferredComputation(expression); if (computation != null) { return computation; }