debug names for temporary traces added

This commit is contained in:
Svetlana Isakova
2012-10-21 14:07:26 +04:00
parent 6c1d3aa813
commit b395d33ff0
22 changed files with 103 additions and 55 deletions
@@ -203,7 +203,7 @@ public final class PsiCodegenPredictor {
) { ) {
final Ref<DeclarationDescriptor> resultingDescriptor = Ref.create(); final Ref<DeclarationDescriptor> resultingDescriptor = Ref.create();
DelegatingBindingTrace trace = new DelegatingBindingTrace(context) { DelegatingBindingTrace trace = new DelegatingBindingTrace(context, "trace in PsiCodegenPredictor") {
@Override @Override
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) { public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
super.record(slice, key, value); super.record(slice, key, value);
@@ -91,7 +91,7 @@ public class GenerationState {
this.files = files; this.files = files;
this.classBuilderMode = builderFactory.getClassBuilderMode(); this.classBuilderMode = builderFactory.getClassBuilderMode();
bindingTrace = new DelegatingBindingTrace(exhaust.getBindingContext()); bindingTrace = new DelegatingBindingTrace(exhaust.getBindingContext(), "trace in GenerationState");
bindingContext = bindingTrace.getBindingContext(); bindingContext = bindingTrace.getBindingContext();
this.typeMapper = new JetTypeMapper(bindingTrace, builtinToJavaTypesMapping == BuiltinToJavaTypesMapping.ENABLED, classBuilderMode); this.typeMapper = new JetTypeMapper(bindingTrace, builtinToJavaTypesMapping == BuiltinToJavaTypesMapping.ENABLED, classBuilderMode);
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiErrorElement; import com.intellij.psi.PsiErrorElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
@@ -72,4 +73,14 @@ public class AnalyzingUtils {
} }
// -------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------
public static String formDebugNameForBindingTrace(@NotNull String debugName, @Nullable Object resolutionSubjectForMessage) {
if (resolutionSubjectForMessage instanceof PsiElement) {
resolutionSubjectForMessage = ((PsiElement) resolutionSubjectForMessage).getText();
}
if (resolutionSubjectForMessage != null) {
return debugName + " '" + resolutionSubjectForMessage + "'";
}
return debugName;
}
} }
@@ -16,17 +16,19 @@
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.Nullable;
/** /**
* @author svtk * @author svtk
*/ */
public class ChainedTemporaryBindingTrace extends TemporaryBindingTrace { public class ChainedTemporaryBindingTrace extends TemporaryBindingTrace {
public static ChainedTemporaryBindingTrace create(TemporaryBindingTrace trace) { public static ChainedTemporaryBindingTrace create(TemporaryBindingTrace trace, String debugName, @Nullable Object resolutionSubjectForMessage) {
return new ChainedTemporaryBindingTrace(trace); return new ChainedTemporaryBindingTrace(trace, AnalyzingUtils.formDebugNameForBindingTrace(debugName, resolutionSubjectForMessage));
} }
private ChainedTemporaryBindingTrace(TemporaryBindingTrace trace) { private ChainedTemporaryBindingTrace(TemporaryBindingTrace trace, String debugName) {
super(trace); super(trace, debugName);
} }
@Override @Override
@@ -36,6 +36,7 @@ public class DelegatingBindingTrace implements BindingTrace {
private final BindingContext parentContext; private final BindingContext parentContext;
private final MutableSlicedMap map = SlicedMapImpl.create(); private final MutableSlicedMap map = SlicedMapImpl.create();
private final List<Diagnostic> diagnostics = Lists.newArrayList(); private final List<Diagnostic> diagnostics = Lists.newArrayList();
private final String name;
private final BindingContext bindingContext = new BindingContext() { private final BindingContext bindingContext = new BindingContext() {
@Override @Override
@@ -67,8 +68,13 @@ public class DelegatingBindingTrace implements BindingTrace {
} }
}; };
public DelegatingBindingTrace(BindingContext parentContext) { public DelegatingBindingTrace(BindingContext parentContext, String debugName) {
this.parentContext = parentContext; this.parentContext = parentContext;
this.name = debugName;
}
public DelegatingBindingTrace(BindingContext parentContext, String debugName, @Nullable Object resolutionSubjectForMessage) {
this(parentContext, AnalyzingUtils.formDebugNameForBindingTrace(debugName, resolutionSubjectForMessage));
} }
@Override @Override
@@ -148,4 +154,9 @@ public class DelegatingBindingTrace implements BindingTrace {
public void report(@NotNull Diagnostic diagnostic) { public void report(@NotNull Diagnostic diagnostic) {
diagnostics.add(diagnostic); diagnostics.add(diagnostic);
} }
@Override
public String toString() {
return name;
}
} }
@@ -111,7 +111,8 @@ public class ImportsResolver {
Collection<JetImportDirective> defaultImportDirectives = Lists.newArrayList(); Collection<JetImportDirective> defaultImportDirectives = Lists.newArrayList();
configuration.addDefaultImports(defaultImportDirectives); configuration.addDefaultImports(defaultImportDirectives);
for (JetImportDirective defaultImportDirective : defaultImportDirectives) { for (JetImportDirective defaultImportDirective : defaultImportDirectives) {
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(trace); //not to trace errors of default imports TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
trace, "transient trace to resolve default imports"); //not to trace errors of default imports
qualifiedExpressionResolver.processImportReference(defaultImportDirective, rootScope, namespaceScope, delayedImporter, qualifiedExpressionResolver.processImportReference(defaultImportDirective, rootScope, namespaceScope, delayedImporter,
temporaryTrace, configuration, onlyClasses); temporaryTrace, configuration, onlyClasses);
} }
@@ -112,7 +112,7 @@ public class QualifiedExpressionResolver {
if (descriptors.size() == 1) { if (descriptors.size() == 1) {
return canImportMembersFrom(descriptors.iterator().next(), reference, trace, onlyClasses); return canImportMembersFrom(descriptors.iterator().next(), reference, trace, onlyClasses);
} }
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(trace); TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(trace, "trace to find out if members can be imported from", reference);
boolean canImport = false; boolean canImport = false;
for (DeclarationDescriptor descriptor : descriptors) { for (DeclarationDescriptor descriptor : descriptors) {
canImport |= canImportMembersFrom(descriptor, reference, temporaryTrace, onlyClasses); canImport |= canImportMembersFrom(descriptor, reference, temporaryTrace, onlyClasses);
@@ -17,7 +17,9 @@
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.util.slicedmap.WritableSlice; import org.jetbrains.jet.util.slicedmap.WritableSlice;
/** /**
@@ -25,14 +27,18 @@ import org.jetbrains.jet.util.slicedmap.WritableSlice;
*/ */
public class TemporaryBindingTrace extends DelegatingBindingTrace { public class TemporaryBindingTrace extends DelegatingBindingTrace {
public static TemporaryBindingTrace create(@NotNull BindingTrace trace) { public static TemporaryBindingTrace create(@NotNull BindingTrace trace, String debugName) {
return new TemporaryBindingTrace(trace); return new TemporaryBindingTrace(trace, debugName);
}
public static TemporaryBindingTrace create(@NotNull BindingTrace trace, String debugName, @Nullable Object resolutionSubjectForMessage) {
return create(trace, AnalyzingUtils.formDebugNameForBindingTrace(debugName, resolutionSubjectForMessage));
} }
protected final BindingTrace trace; protected final BindingTrace trace;
protected TemporaryBindingTrace(@NotNull BindingTrace trace) { protected TemporaryBindingTrace(@NotNull BindingTrace trace, String debugName) {
super(trace.getBindingContext()); super(trace.getBindingContext(), debugName);
this.trace = trace; this.trace = trace;
} }
@@ -283,12 +283,13 @@ public class CallResolver {
return cachedResults; return cachedResults;
} }
} }
TemporaryBindingTrace delegatingBindingTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace delegatingBindingTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve call", context.call);
BasicResolutionContext newContext = context.replaceTrace(delegatingBindingTrace); BasicResolutionContext newContext = context.replaceTrace(delegatingBindingTrace);
OverloadResolutionResults<F> results = doResolveCall(newContext, OverloadResolutionResults<F> results = doResolveCall(newContext,
prioritizedTasks, prioritizedTasks,
callTransformer, reference); callTransformer, reference);
DelegatingBindingTrace cloneDelta = new DelegatingBindingTrace(new BindingTraceContext().getBindingContext()); DelegatingBindingTrace cloneDelta = new DelegatingBindingTrace(
new BindingTraceContext().getBindingContext(), "delta trace for caching resolve of", context.call);
delegatingBindingTrace.addAllMyDataTo(cloneDelta); delegatingBindingTrace.addAllMyDataTo(cloneDelta);
cacheResults(resolutionResultsSlice, context, results, cloneDelta); cacheResults(resolutionResultsSlice, context, results, cloneDelta);
@@ -465,7 +466,7 @@ public class CallResolver {
TemporaryBindingTrace traceForFirstNonemptyCandidateSet = null; TemporaryBindingTrace traceForFirstNonemptyCandidateSet = null;
OverloadResolutionResultsImpl<F> resultsForFirstNonemptyCandidateSet = null; OverloadResolutionResultsImpl<F> resultsForFirstNonemptyCandidateSet = null;
for (ResolutionTask<D, F> task : prioritizedTasks) { for (ResolutionTask<D, F> task : prioritizedTasks) {
TemporaryBindingTrace taskTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace taskTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve a task for", task.reference);
OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(task.withTrace(taskTrace), OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(task.withTrace(taskTrace),
callTransformer, context.trace); callTransformer, context.trace);
if (results.isSuccess() || results.isAmbiguity()) { if (results.isSuccess() || results.isAmbiguity()) {
@@ -530,8 +531,9 @@ public class CallResolver {
// We have some candidates that failed for some reason // We have some candidates that failed for some reason
// And we have a suspect: the function literal argument // And we have a suspect: the function literal argument
// Now, we try to remove this argument and see if it helps // Now, we try to remove this argument and see if it helps
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(task.getCandidates(), task.reference, TemporaryBindingTrace.create(task.trace), task.scope, ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(task.getCandidates(), task.reference,
new DelegatingCall(task.call) { TemporaryBindingTrace.create(task.trace, "trace for resolution guarded for extra function literal arguments"),
task.scope, new DelegatingCall(task.call) {
@NotNull @NotNull
@Override @Override
public List<JetExpression> getFunctionLiteralArguments() { public List<JetExpression> getFunctionLiteralArguments() {
@@ -554,7 +556,8 @@ public class CallResolver {
@NotNull BindingTrace traceForResolutionCache) { @NotNull BindingTrace traceForResolutionCache) {
for (ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) { for (ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
TemporaryBindingTrace candidateTrace = TemporaryBindingTrace.create(task.trace); TemporaryBindingTrace candidateTrace = TemporaryBindingTrace.create(
task.trace, "trace to resolve candidate", resolutionCandidate);
Collection<CallResolutionContext<D, F>> contexts = callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace); Collection<CallResolutionContext<D, F>> contexts = callTransformer.createCallContexts(resolutionCandidate, task, candidateTrace);
for (CallResolutionContext<D, F> context : contexts) { for (CallResolutionContext<D, F> context : contexts) {
@@ -799,14 +802,17 @@ public class CallResolver {
@NotNull ResolutionContext context) { @NotNull ResolutionContext context) {
JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument); JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument);
TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(context.trace);
JetExpression argumentExpression = valueArgument.getArgumentExpression(); JetExpression argumentExpression = valueArgument.getArgumentExpression();
JetType type = argumentExpression != null JetType type;
? expressionTypingServices.getType( if (argumentExpression != null) {
context.scope, argumentExpression, TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(
substitutor.substitute(effectiveExpectedType, Variance.INVARIANT), context.trace, "transient trace to resolve argument", argumentExpression);
context.dataFlowInfo, traceForUnknown) type = expressionTypingServices.getType(context.scope, argumentExpression,
: null; substitutor.substitute(effectiveExpectedType, Variance.INVARIANT), context.dataFlowInfo, traceForUnknown);
}
else {
type = null;
}
constraintSystem.addSupertypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition( constraintSystem.addSupertypeConstraint(effectiveExpectedType, type, ConstraintPosition.getValueParameterPosition(
valueParameterDescriptor.getIndex())); valueParameterDescriptor.getIndex()));
//todo no return //todo no return
@@ -1149,7 +1155,7 @@ public class CallResolver {
List<ResolutionCandidate<FunctionDescriptor>> candidates = findCandidatesByExactSignature(scope, receiver, name, parameterTypes); List<ResolutionCandidate<FunctionDescriptor>> candidates = findCandidatesByExactSignature(scope, receiver, name, parameterTypes);
BindingTraceContext trace = new BindingTraceContext(); BindingTraceContext trace = new BindingTraceContext();
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(trace); TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(trace, "trace for resolve exact signature call", name);
Set<ResolvedCallWithTrace<FunctionDescriptor>> calls = Sets.newLinkedHashSet(); Set<ResolvedCallWithTrace<FunctionDescriptor>> calls = Sets.newLinkedHashSet();
for (ResolutionCandidate<FunctionDescriptor> candidate : candidates) { for (ResolutionCandidate<FunctionDescriptor> candidate : candidates) {
ResolvedCallImpl<FunctionDescriptor> call = ResolvedCallImpl.create(candidate, temporaryBindingTrace); ResolvedCallImpl<FunctionDescriptor> call = ResolvedCallImpl.create(candidate, temporaryBindingTrace);
@@ -115,7 +115,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
private CallResolutionContext<CallableDescriptor, FunctionDescriptor> createContextWithChainedTrace(ResolutionCandidate<CallableDescriptor> candidate, private CallResolutionContext<CallableDescriptor, FunctionDescriptor> createContextWithChainedTrace(ResolutionCandidate<CallableDescriptor> candidate,
Call call, TemporaryBindingTrace temporaryTrace, ResolutionTask<CallableDescriptor, FunctionDescriptor> task) { Call call, TemporaryBindingTrace temporaryTrace, ResolutionTask<CallableDescriptor, FunctionDescriptor> task) {
ChainedTemporaryBindingTrace chainedTrace = ChainedTemporaryBindingTrace.create(temporaryTrace); ChainedTemporaryBindingTrace chainedTrace = ChainedTemporaryBindingTrace.create(temporaryTrace, "chained trace to resolve candidate", candidate);
ResolvedCallImpl<CallableDescriptor> resolvedCall = ResolvedCallImpl.create(candidate, chainedTrace); ResolvedCallImpl<CallableDescriptor> resolvedCall = ResolvedCallImpl.create(candidate, chainedTrace);
return CallResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call); return CallResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call);
} }
@@ -100,7 +100,8 @@ public class ResolveSessionUtils {
@NotNull final ResolveSession resolveSession, @NotNull final ResolveSession resolveSession,
@NotNull JetExpression expression @NotNull JetExpression expression
) { ) {
final DelegatingBindingTrace trace = new DelegatingBindingTrace(resolveSession.getBindingContext()); final DelegatingBindingTrace trace = new DelegatingBindingTrace(
resolveSession.getBindingContext(), "trace to resolve expression", expression);
JetFile file = (JetFile) expression.getContainingFile(); JetFile file = (JetFile) expression.getContainingFile();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -225,7 +226,8 @@ public class ResolveSessionUtils {
} }
public static JetScope getExpressionMemberScope(@NotNull ResolveSession resolveSession, @NotNull JetExpression expression) { public static JetScope getExpressionMemberScope(@NotNull ResolveSession resolveSession, @NotNull JetExpression expression) {
DelegatingBindingTrace trace = new DelegatingBindingTrace(resolveSession.getBindingContext()); DelegatingBindingTrace trace = new DelegatingBindingTrace(
resolveSession.getBindingContext(), "trace to resolve a member scope of expression", expression);
if (expression instanceof JetReferenceExpression) { if (expression instanceof JetReferenceExpression) {
QualifiedExpressionResolver qualifiedExpressionResolver = resolveSession.getInjector().getQualifiedExpressionResolver(); QualifiedExpressionResolver qualifiedExpressionResolver = resolveSession.getInjector().getQualifiedExpressionResolver();
@@ -99,7 +99,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
} }
JetType[] result = new JetType[1]; JetType[] result = new JetType[1];
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
context.trace, "trace for namespace/class object lookup of name", referencedName);
if (furtherNameLookup(expression, referencedName, result, context.replaceBindingTrace(temporaryTrace))) { if (furtherNameLookup(expression, referencedName, result, context.replaceBindingTrace(temporaryTrace))) {
temporaryTrace.commit(); temporaryTrace.commit();
return DataFlowUtils.checkType(result[0], expression, context); return DataFlowUtils.checkType(result[0], expression, context);
@@ -201,7 +202,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
boolean tryWithNoExpectedType = true; boolean tryWithNoExpectedType = true;
if (isTypeFlexible(left) || operationType == JetTokens.COLON) { if (isTypeFlexible(left) || operationType == JetTokens.COLON) {
TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(
context.trace, "trace for resolve RHSExpression", expression);
ExpressionTypingContext contextWithTemporaryTrace = context.replaceBindingTrace(temporaryTraceWithExpectedType).replaceExpectedType(targetType); ExpressionTypingContext contextWithTemporaryTrace = context.replaceBindingTrace(temporaryTraceWithExpectedType).replaceExpectedType(targetType);
JetTypeInfo typeInfo = facade.getTypeInfo(left, contextWithTemporaryTrace); JetTypeInfo typeInfo = facade.getTypeInfo(left, contextWithTemporaryTrace);
if (typeInfo.getType() != null && checkBinaryWithTypeRHS(expression, contextWithTemporaryTrace, targetType, typeInfo.getType())) { if (typeInfo.getType() != null && checkBinaryWithTypeRHS(expression, contextWithTemporaryTrace, targetType, typeInfo.getType())) {
@@ -633,7 +635,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverDescriptor receiver, private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverDescriptor receiver,
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context, @NotNull boolean[] result) { @Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context, @NotNull boolean[] result) {
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(
context.trace, "trace to resolve as local variable or property", nameExpression);
OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(traceForVariable).resolveSimpleProperty(receiver, callOperationNode, nameExpression); OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(traceForVariable).resolveSimpleProperty(receiver, callOperationNode, nameExpression);
if (!resolutionResult.isNothing()) { if (!resolutionResult.isNothing()) {
traceForVariable.commit(); traceForVariable.commit();
@@ -645,7 +648,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
ExpressionTypingContext newContext = receiver.exists() ExpressionTypingContext newContext = receiver.exists()
? context.replaceScope(receiver.getType().getMemberScope()) ? context.replaceScope(receiver.getType().getMemberScope())
: context; : context;
TemporaryBindingTrace traceForNamespaceOrClassObject = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace traceForNamespaceOrClassObject = TemporaryBindingTrace.create(
context.trace, "trace to resolve as namespace or class object", nameExpression);
JetType jetType = lookupNamespaceOrClassObject(nameExpression, nameExpression.getReferencedNameAsName(), newContext.replaceBindingTrace(traceForNamespaceOrClassObject)); JetType jetType = lookupNamespaceOrClassObject(nameExpression, nameExpression.getReferencedNameAsName(), newContext.replaceBindingTrace(traceForNamespaceOrClassObject));
if (jetType != null) { if (jetType != null) {
traceForNamespaceOrClassObject.commit(); traceForNamespaceOrClassObject.commit();
@@ -693,7 +697,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
boolean[] result = new boolean[1]; boolean[] result = new boolean[1];
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace, "trace to resolve as variable", nameExpression);
JetType type = getVariableType(nameExpression, receiver, callOperationNode, context.replaceBindingTrace(traceForVariable), result); JetType type = getVariableType(nameExpression, receiver, callOperationNode, context.replaceBindingTrace(traceForVariable), result);
if (result[0]) { if (result[0]) {
traceForVariable.commit(); traceForVariable.commit();
@@ -701,7 +705,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
Call call = CallMaker.makeCall(nameExpression, receiver, callOperationNode, nameExpression, Collections.<ValueArgument>emptyList()); Call call = CallMaker.makeCall(nameExpression, receiver, callOperationNode, nameExpression, Collections.<ValueArgument>emptyList());
TemporaryBindingTrace traceForFunction = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace traceForFunction = TemporaryBindingTrace.create(context.trace, "trace to resolve as function", nameExpression);
FunctionDescriptor functionDescriptor = getFunctionDescriptor(call, nameExpression, receiver, context, result); FunctionDescriptor functionDescriptor = getFunctionDescriptor(call, nameExpression, receiver, context, result);
if (result[0]) { if (result[0]) {
traceForFunction.commit(); traceForFunction.commit();
@@ -722,7 +726,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
boolean[] result = new boolean[1]; boolean[] result = new boolean[1];
Call call = CallMaker.makeCall(receiver, callOperationNode, callExpression); Call call = CallMaker.makeCall(receiver, callOperationNode, callExpression);
TemporaryBindingTrace traceForFunction = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace traceForFunction = TemporaryBindingTrace.create(context.trace, "trace to resolve as function call", callExpression);
FunctionDescriptor functionDescriptor = getFunctionDescriptor(call, callExpression, receiver, FunctionDescriptor functionDescriptor = getFunctionDescriptor(call, callExpression, receiver,
context.replaceBindingTrace(traceForFunction), result); context.replaceBindingTrace(traceForFunction), result);
if (result[0]) { if (result[0]) {
@@ -753,7 +757,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetExpression calleeExpression = callExpression.getCalleeExpression(); JetExpression calleeExpression = callExpression.getCalleeExpression();
if (calleeExpression instanceof JetSimpleNameExpression && callExpression.getTypeArgumentList() == null) { if (calleeExpression instanceof JetSimpleNameExpression && callExpression.getTypeArgumentList() == null) {
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(
context.trace, "trace to resolve as variable with 'invoke' call", callExpression);
JetType type = getVariableType((JetSimpleNameExpression) calleeExpression, receiver, callOperationNode, JetType type = getVariableType((JetSimpleNameExpression) calleeExpression, receiver, callOperationNode,
context.replaceBindingTrace(traceForVariable), result); context.replaceBindingTrace(traceForVariable), result);
if (result[0]) { if (result[0]) {
@@ -828,7 +833,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetExpression stubExpression = ExpressionTypingUtils.createStubExpressionOfNecessaryType(baseExpression.getProject(), type, context.trace); JetExpression stubExpression = ExpressionTypingUtils.createStubExpressionOfNecessaryType(baseExpression.getProject(), type, context.trace);
resolveArrayAccessSetMethod((JetArrayAccessExpression) baseExpression, resolveArrayAccessSetMethod((JetArrayAccessExpression) baseExpression,
stubExpression, stubExpression,
context.replaceExpectedType(NO_EXPECTED_TYPE).replaceBindingTrace(TemporaryBindingTrace.create(context.trace)), context.replaceExpectedType(NO_EXPECTED_TYPE).replaceBindingTrace(
TemporaryBindingTrace.create(context.trace, "trace to resolve array access set method for unary expression", expression)),
context.trace); context.trace);
} }
@@ -58,7 +58,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
return DataFlowUtils.checkType(type, expression, context, context.dataFlowInfo); return DataFlowUtils.checkType(type, expression, context, context.dataFlowInfo);
} }
final JetType[] result = new JetType[1]; final JetType[] result = new JetType[1];
final TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace); final TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve object literal expression", expression);
ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor> handler = new ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor>() { ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor> handler = new ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor>() {
@Override @Override
@@ -83,7 +83,8 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
TopDownAnalyzer.processClassOrObject(context.expressionTypingServices.getProject(), traceAdapter, context.scope, TopDownAnalyzer.processClassOrObject(context.expressionTypingServices.getProject(), traceAdapter, context.scope,
context.scope.getContainingDeclaration(), expression.getObjectDeclaration()); context.scope.getContainingDeclaration(), expression.getObjectDeclaration());
DelegatingBindingTrace cloneDelta = new DelegatingBindingTrace(new BindingTraceContext().getBindingContext()); DelegatingBindingTrace cloneDelta = new DelegatingBindingTrace(
new BindingTraceContext().getBindingContext(), "cached delta trace for object literal expression resolve", expression);
temporaryTrace.addAllMyDataTo(cloneDelta); temporaryTrace.addAllMyDataTo(cloneDelta);
context.trace.record(TRACE_DELTAS_CACHE, expression.getObjectDeclaration(), cloneDelta); context.trace.record(TRACE_DELTAS_CACHE, expression.getObjectDeclaration(), cloneDelta);
temporaryTrace.commit(); temporaryTrace.commit();
@@ -112,7 +113,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetType returnType = TypeUtils.NO_EXPECTED_TYPE; JetType returnType = TypeUtils.NO_EXPECTED_TYPE;
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef(); JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef();
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve function literal expression", expression);
if (returnTypeRef != null) { if (returnTypeRef != null) {
returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true); returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true);
context.expressionTypingServices.checkFunctionReturnType(expression, context.replaceScope(functionInnerScope). context.expressionTypingServices.checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
@@ -291,13 +291,13 @@ public class ExpressionTypingServices {
if (context.expectedType != NO_EXPECTED_TYPE) { if (context.expectedType != NO_EXPECTED_TYPE) {
if (coercionStrategyForLastExpression == CoercionStrategy.COERCION_TO_UNIT && KotlinBuiltIns.getInstance().isUnit(context.expectedType)) { if (coercionStrategyForLastExpression == CoercionStrategy.COERCION_TO_UNIT && KotlinBuiltIns.getInstance().isUnit(context.expectedType)) {
// This implements coercion to Unit // This implements coercion to Unit
TemporaryBindingTrace temporaryTraceExpectingUnit = TemporaryBindingTrace.create(trace); TemporaryBindingTrace temporaryTraceExpectingUnit = TemporaryBindingTrace.create(trace, "trace to resolve coercion to unit with expected type");
final boolean[] mismatch = new boolean[1]; final boolean[] mismatch = new boolean[1];
ObservableBindingTrace errorInterceptingTrace = makeTraceInterceptingTypeMismatch(temporaryTraceExpectingUnit, statementExpression, mismatch); ObservableBindingTrace errorInterceptingTrace = makeTraceInterceptingTypeMismatch(temporaryTraceExpectingUnit, statementExpression, mismatch);
newContext = createContext(newContext, errorInterceptingTrace, scope, newContext.dataFlowInfo, context.expectedType); newContext = createContext(newContext, errorInterceptingTrace, scope, newContext.dataFlowInfo, context.expectedType);
result = blockLevelVisitor.getTypeInfo(statementExpression, newContext, true); result = blockLevelVisitor.getTypeInfo(statementExpression, newContext, true);
if (mismatch[0]) { if (mismatch[0]) {
TemporaryBindingTrace temporaryTraceNoExpectedType = TemporaryBindingTrace.create(trace); TemporaryBindingTrace temporaryTraceNoExpectedType = TemporaryBindingTrace.create(trace, "trace to resolve coercion to unit without expected type");
mismatch[0] = false; mismatch[0] = false;
ObservableBindingTrace interceptingTrace = makeTraceInterceptingTypeMismatch(temporaryTraceNoExpectedType, statementExpression, mismatch); ObservableBindingTrace interceptingTrace = makeTraceInterceptingTypeMismatch(temporaryTraceNoExpectedType, statementExpression, mismatch);
newContext = createContext(newContext, interceptingTrace, scope, newContext.dataFlowInfo, NO_EXPECTED_TYPE); newContext = createContext(newContext, interceptingTrace, scope, newContext.dataFlowInfo, NO_EXPECTED_TYPE);
@@ -287,7 +287,7 @@ public class ExpressionTypingUtils {
@NotNull Name name @NotNull Name name
) { ) {
final JetReferenceExpression fake = JetPsiFactory.createSimpleName(context.expressionTypingServices.getProject(), "fake"); final JetReferenceExpression fake = JetPsiFactory.createSimpleName(context.expressionTypingServices.getProject(), "fake");
TemporaryBindingTrace fakeTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace fakeTrace = TemporaryBindingTrace.create(context.trace, "trace for resolve fake call for", name);
Call call = CallMaker.makeCall(fake, receiver, null, fake, Collections.<ValueArgument>emptyList()); Call call = CallMaker.makeCall(fake, receiver, null, fake, Collections.<ValueArgument>emptyList());
OverloadResolutionResults<FunctionDescriptor> results = OverloadResolutionResults<FunctionDescriptor> results =
context.replaceBindingTrace(fakeTrace).resolveCallWithGivenName(call, fake, name); context.replaceBindingTrace(fakeTrace).resolveCallWithGivenName(call, fake, name);
@@ -197,7 +197,8 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
if (right == null) return null; if (right == null) return null;
//There is a temporary binding trace for an opportunity to resolve set method for array if needed (the initial trace should be used there) //There is a temporary binding trace for an opportunity to resolve set method for array if needed (the initial trace should be used there)
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(contextWithExpectedType.trace); TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(
contextWithExpectedType.trace, "trace to resolve array set method for binary expression", expression);
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceBindingTrace(temporaryBindingTrace); ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceBindingTrace(temporaryBindingTrace);
JetSimpleNameExpression operationSign = expression.getOperationReference(); JetSimpleNameExpression operationSign = expression.getOperationReference();
@@ -217,13 +218,13 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
// We check that defined only one of '+=' and '+' operations, and call it (in the case '+' we then also assign) // We check that defined only one of '+=' and '+' operations, and call it (in the case '+' we then also assign)
// Check for '+=' // Check for '+='
Name name = OperatorConventions.ASSIGNMENT_OPERATIONS.get(operationType); Name name = OperatorConventions.ASSIGNMENT_OPERATIONS.get(operationType);
TemporaryBindingTrace assignmentOperationTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace assignmentOperationTrace = TemporaryBindingTrace.create(context.trace, "trace to check assignment operation like '+=' for", expression);
OverloadResolutionResults<FunctionDescriptor> assignmentOperationDescriptors = basic.getResolutionResultsForBinaryCall(scope, name, context.replaceBindingTrace(assignmentOperationTrace), expression, receiver); OverloadResolutionResults<FunctionDescriptor> assignmentOperationDescriptors = basic.getResolutionResultsForBinaryCall(scope, name, context.replaceBindingTrace(assignmentOperationTrace), expression, receiver);
JetType assignmentOperationType = OverloadResolutionResultsUtil.getResultType(assignmentOperationDescriptors); JetType assignmentOperationType = OverloadResolutionResultsUtil.getResultType(assignmentOperationDescriptors);
// Check for '+' // Check for '+'
Name counterpartName = OperatorConventions.BINARY_OPERATION_NAMES.get(OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.get(operationType)); Name counterpartName = OperatorConventions.BINARY_OPERATION_NAMES.get(OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.get(operationType));
TemporaryBindingTrace binaryOperationTrace = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace binaryOperationTrace = TemporaryBindingTrace.create(context.trace, "trace to check binary operation like '+' for", expression);
OverloadResolutionResults<FunctionDescriptor> binaryOperationDescriptors = basic.getResolutionResultsForBinaryCall(scope, counterpartName, context.replaceBindingTrace(binaryOperationTrace), expression, receiver); OverloadResolutionResults<FunctionDescriptor> binaryOperationDescriptors = basic.getResolutionResultsForBinaryCall(scope, counterpartName, context.replaceBindingTrace(binaryOperationTrace), expression, receiver);
JetType binaryOperationType = OverloadResolutionResultsUtil.getResultType(binaryOperationDescriptors); JetType binaryOperationType = OverloadResolutionResultsUtil.getResultType(binaryOperationDescriptors);
@@ -248,7 +249,8 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
binaryOperationTrace.commit(); binaryOperationTrace.commit();
context.trace.record(VARIABLE_REASSIGNMENT, expression); context.trace.record(VARIABLE_REASSIGNMENT, expression);
if (left instanceof JetArrayAccessExpression) { if (left instanceof JetArrayAccessExpression) {
ExpressionTypingContext contextForResolve = context.replaceScope(scope).replaceBindingTrace(TemporaryBindingTrace.create(contextWithExpectedType.trace)); ExpressionTypingContext contextForResolve = context.replaceScope(scope).replaceBindingTrace(TemporaryBindingTrace.create(
contextWithExpectedType.trace, "trace to resolve array set method for assignment", expression));
basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, right, contextForResolve, context.trace); basic.resolveArrayAccessSetMethod((JetArrayAccessExpression) left, right, contextForResolve, context.trace);
} }
} }
@@ -203,7 +203,7 @@ public class JetPositionManager implements PositionManager {
List<JetFile> namespaceFiles = JetFilesProvider.getInstance(file.getProject()).allNamespaceFiles().fun(file); List<JetFile> namespaceFiles = JetFilesProvider.getInstance(file.getProject()).allNamespaceFiles().fun(file);
final DelegatingBindingTrace bindingTrace = new DelegatingBindingTrace(analyzeExhaust.getBindingContext()); final DelegatingBindingTrace bindingTrace = new DelegatingBindingTrace(analyzeExhaust.getBindingContext(), "trace created in JetPositionManager");
JetTypeMapper typeMapper = new JetTypeMapper(bindingTrace, true, ClassBuilderMode.FULL); JetTypeMapper typeMapper = new JetTypeMapper(bindingTrace, true, ClassBuilderMode.FULL);
//noinspection unchecked //noinspection unchecked
CodegenBinding.initTrace(bindingTrace, namespaceFiles); CodegenBinding.initTrace(bindingTrace, namespaceFiles);
@@ -106,7 +106,7 @@ public final class AnalyzerFacadeWithCache {
file.getProject(), file.getProject(),
Collections.<AnalyzerScriptParameter>emptyList(), Collections.<AnalyzerScriptParameter>emptyList(),
new JetFilesProvider.SameJetFilePredicate(file), new JetFilesProvider.SameJetFilePredicate(file),
new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext()), new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext(), "trace to resolve bodies in file", file.getName()),
context, context,
moduleConfiguration); moduleConfiguration);
@@ -101,7 +101,7 @@ public class MigrateTuplesInProjectFix extends JetIntentionAction<PsiElement> {
initialFile.getProject(), initialFile.getProject(),
Collections.<AnalyzerScriptParameter>emptyList(), Collections.<AnalyzerScriptParameter>emptyList(),
Predicates.<PsiFile>alwaysTrue(), Predicates.<PsiFile>alwaysTrue(),
new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext()), new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext(), "trace in migrate tuples fix"),
context, context,
moduleConfiguration); moduleConfiguration);
} }
@@ -51,7 +51,7 @@ public class JetPositionManagerTest extends PositionManagerTestCase {
JetPositionManager positionManager = (JetPositionManager) jetPositionManagerFactory.createPositionManager(process); JetPositionManager positionManager = (JetPositionManager) jetPositionManagerFactory.createPositionManager(process);
assertNotNull(positionManager); assertNotNull(positionManager);
DelegatingBindingTrace bindingTrace = new DelegatingBindingTrace(state.getBindingContext()); DelegatingBindingTrace bindingTrace = new DelegatingBindingTrace(state.getBindingContext(), "trace created in JetPositionManagerTest");
JetTypeMapper typeMapper = new JetTypeMapper(bindingTrace, true, ClassBuilderMode.FULL); JetTypeMapper typeMapper = new JetTypeMapper(bindingTrace, true, ClassBuilderMode.FULL);
//noinspection unchecked //noinspection unchecked
CodegenBinding.initTrace(bindingTrace, files); CodegenBinding.initTrace(bindingTrace, files);
@@ -88,7 +88,7 @@ public final class AnalyzerFacadeForJS {
BindingContext libraryBindingContext = config.getLibraryBindingContext(); BindingContext libraryBindingContext = config.getLibraryBindingContext();
BindingTrace trace = libraryBindingContext == null ? BindingTrace trace = libraryBindingContext == null ?
new ObservableBindingTrace(new BindingTraceContext()) : new ObservableBindingTrace(new BindingTraceContext()) :
new DelegatingBindingTrace(libraryBindingContext); new DelegatingBindingTrace(libraryBindingContext, "trace for analyzing library in js");
InjectorForTopDownAnalyzerForJs injector = new InjectorForTopDownAnalyzerForJs( InjectorForTopDownAnalyzerForJs injector = new InjectorForTopDownAnalyzerForJs(
project, topDownAnalysisParameters, trace, owner, project, topDownAnalysisParameters, trace, owner,
new JsConfiguration(project, libraryBindingContext)); new JsConfiguration(project, libraryBindingContext));
@@ -110,7 +110,7 @@ public final class CallBuilder {
resolvedCall = ResolvedCallImpl.create(ResolutionCandidate.create(descriptor, descriptor.getExpectedThisObject(), resolvedCall = ResolvedCallImpl.create(ResolutionCandidate.create(descriptor, descriptor.getExpectedThisObject(),
descriptor.getReceiverParameter(), descriptor.getReceiverParameter(),
ExplicitReceiverKind.THIS_OBJECT, false), ExplicitReceiverKind.THIS_OBJECT, false),
TemporaryBindingTrace.create(new BindingTraceContext())); TemporaryBindingTrace.create(new BindingTraceContext(), "trace to resolve call (in js)"));
} }
if (descriptor == null) { if (descriptor == null) {
descriptor = resolvedCall.getCandidateDescriptor().getOriginal(); descriptor = resolvedCall.getCandidateDescriptor().getOriginal();