From 7e3eccedd70de40a40425e2a1fb6bbc61965762a Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 20 Jan 2022 14:38:36 -0800 Subject: [PATCH] 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). --- src/compiler/binder.ts | 1 + src/compiler/checker.ts | 6 +++--- src/compiler/tracing.ts | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 267f4b32b5f..73e8bef6428 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -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, diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d379885a4cb..9347310350d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index 31c1c8910cf..4757ac72e1b 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -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; + } }