Associate paths with nodes when tracing (#47530)

Walking up the tree to find the enclosing SourceFile would distort the
timing too much so, instead, we attach a Path in the binder.

At present, the path is determined retroactively by walking up the call
stack in the trace visualizer, but this is both inconvenient and
routinely inaccurate (checking an expression in one file may require
checking an expression in another file and there's no way to determine
from the trace where this transition occurred).
This commit is contained in:
Andrew Casey 2022-01-20 14:38:36 -08:00 committed by GitHub
parent bae0f50818
commit 7e3eccedd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -2408,6 +2408,7 @@ namespace ts {
return;
}
setParent(node, parent);
if (tracing) (node as TracingNode).tracingPath = file.path;
const saveInStrictMode = inStrictMode;
// Even though in the AST the jsdoc @typedef node belongs to the current node,

View File

@ -34028,7 +34028,7 @@ namespace ts {
}
function checkExpression(node: Expression | QualifiedName, checkMode?: CheckMode, forceTuple?: boolean): Type {
tracing?.push(tracing.Phase.Check, "checkExpression", { kind: node.kind, pos: node.pos, end: node.end });
tracing?.push(tracing.Phase.Check, "checkExpression", { kind: node.kind, pos: node.pos, end: node.end, path: (node as TracingNode).tracingPath });
const saveCurrentNode = currentNode;
currentNode = node;
instantiationCount = 0;
@ -37104,7 +37104,7 @@ namespace ts {
}
function checkVariableDeclaration(node: VariableDeclaration) {
tracing?.push(tracing.Phase.Check, "checkVariableDeclaration", { kind: node.kind, pos: node.pos, end: node.end });
tracing?.push(tracing.Phase.Check, "checkVariableDeclaration", { kind: node.kind, pos: node.pos, end: node.end, path: (node as TracingNode).tracingPath });
checkGrammarVariableDeclaration(node);
checkVariableLikeDeclaration(node);
tracing?.pop();
@ -40541,7 +40541,7 @@ namespace ts {
}
function checkDeferredNode(node: Node) {
tracing?.push(tracing.Phase.Check, "checkDeferredNode", { kind: node.kind, pos: node.pos, end: node.end });
tracing?.push(tracing.Phase.Check, "checkDeferredNode", { kind: node.kind, pos: node.pos, end: node.end, path: (node as TracingNode).tracingPath });
const saveCurrentNode = currentNode;
currentNode = node;
instantiationCount = 0;

View File

@ -341,4 +341,8 @@ namespace ts { // eslint-disable-line one-namespace-per-file
// define after tracingEnabled is initialized
export const startTracing = tracingEnabled.startTracing;
export const dumpTracingLegend = tracingEnabled.dumpLegend;
export interface TracingNode {
tracingPath?: Path;
}
}