Skip to content

Commit 7e3ecce

Browse files
authored
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).
1 parent bae0f50 commit 7e3ecce

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,7 @@ namespace ts {
24082408
return;
24092409
}
24102410
setParent(node, parent);
2411+
if (tracing) (node as TracingNode).tracingPath = file.path;
24112412
const saveInStrictMode = inStrictMode;
24122413

24132414
// Even though in the AST the jsdoc @typedef node belongs to the current node,

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34028,7 +34028,7 @@ namespace ts {
3402834028
}
3402934029

3403034030
function checkExpression(node: Expression | QualifiedName, checkMode?: CheckMode, forceTuple?: boolean): Type {
34031-
tracing?.push(tracing.Phase.Check, "checkExpression", { kind: node.kind, pos: node.pos, end: node.end });
34031+
tracing?.push(tracing.Phase.Check, "checkExpression", { kind: node.kind, pos: node.pos, end: node.end, path: (node as TracingNode).tracingPath });
3403234032
const saveCurrentNode = currentNode;
3403334033
currentNode = node;
3403434034
instantiationCount = 0;
@@ -37104,7 +37104,7 @@ namespace ts {
3710437104
}
3710537105

3710637106
function checkVariableDeclaration(node: VariableDeclaration) {
37107-
tracing?.push(tracing.Phase.Check, "checkVariableDeclaration", { kind: node.kind, pos: node.pos, end: node.end });
37107+
tracing?.push(tracing.Phase.Check, "checkVariableDeclaration", { kind: node.kind, pos: node.pos, end: node.end, path: (node as TracingNode).tracingPath });
3710837108
checkGrammarVariableDeclaration(node);
3710937109
checkVariableLikeDeclaration(node);
3711037110
tracing?.pop();
@@ -40541,7 +40541,7 @@ namespace ts {
4054140541
}
4054240542

4054340543
function checkDeferredNode(node: Node) {
40544-
tracing?.push(tracing.Phase.Check, "checkDeferredNode", { kind: node.kind, pos: node.pos, end: node.end });
40544+
tracing?.push(tracing.Phase.Check, "checkDeferredNode", { kind: node.kind, pos: node.pos, end: node.end, path: (node as TracingNode).tracingPath });
4054540545
const saveCurrentNode = currentNode;
4054640546
currentNode = node;
4054740547
instantiationCount = 0;

src/compiler/tracing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,8 @@ namespace ts { // eslint-disable-line one-namespace-per-file
341341
// define after tracingEnabled is initialized
342342
export const startTracing = tracingEnabled.startTracing;
343343
export const dumpTracingLegend = tracingEnabled.dumpLegend;
344+
345+
export interface TracingNode {
346+
tracingPath?: Path;
347+
}
344348
}

0 commit comments

Comments
 (0)