adds tracing (--generateTrace)#2914
Conversation
There was a problem hiding this comment.
Pull request overview
Adds end-to-end tracing support to the TypeScript-Go compiler/tsc execution path so running with --generateTrace <dir> emits trace_*.json, types_*.json, and legend.json (similar to the upstream TypeScript trace output), including optional per-checker type recording and phase/event instrumentation across parse/bind/check/emit.
Changes:
- Wire up a
tracing.Tracingsession fromtscCLI (--generateTrace) throughcompiler.Program, checker creation, and emit/diagnostics phases. - Add a checker-side
TypeTracerabstraction + adapter layer to record types into the tracing subsystem. - Update a large set of baselines to reflect new/changed outputs (including new diagnostics/format changes in multiple submodule baseline files).
Reviewed changes
Copilot reviewed 117 out of 118 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/baselines/reference/submodule/conformance/resolutionModeImportType1(moduleresolution=bundler).types.diff | Baseline update for resolutionModeImportType1 type output diff. |
| testdata/baselines/reference/submodule/conformance/resolutionModeImportType1(moduleresolution=bundler).types | Baseline update for resolutionModeImportType1 type output. |
| testdata/baselines/reference/submodule/conformance/resolutionModeImportType1(moduleresolution=bundler).symbols | Baseline update for resolutionModeImportType1 symbol output. |
| testdata/baselines/reference/submodule/conformance/resolutionModeImportType1(moduleresolution=bundler).errors.txt.diff | Adds/updates baseline diff for error output. |
| testdata/baselines/reference/submodule/conformance/resolutionModeImportType1(moduleresolution=bundler).errors.txt | Adds baseline error output file. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).types | Baseline update for nodenext variant type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).symbols | Baseline update for nodenext variant symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js.diff | Baseline diff update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).js | Baseline update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=nodenext).errors.txt | Baseline update for error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node20).types | Baseline update for node20 variant type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node20).symbols | Baseline update for node20 variant symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node20).js.diff | Baseline diff update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node20).js | Baseline update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node20).errors.txt.diff | Baseline diff update for error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node20).errors.txt | Baseline update for error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node18).types | Baseline update for node18 variant type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node18).symbols | Baseline update for node18 variant symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node18).js.diff | Baseline diff update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node18).js | Baseline update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node18).errors.txt.diff | Baseline diff update for error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node18).errors.txt | Baseline update for error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).types | Baseline update for node16 variant type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).symbols | Baseline update for node16 variant symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).js.diff | Baseline diff update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).js | Baseline update for emitted JS/DTs outputs. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node16).errors.txt | Baseline update for error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).types | Baseline update for nodenext “Emit1” type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).symbols | Baseline update for nodenext “Emit1” symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js.diff | Baseline diff update for nodenext “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).js | Baseline update for nodenext “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).errors.txt.diff | Baseline diff update for nodenext “Emit1” errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=nodenext).errors.txt | Adds baseline error output for nodenext “Emit1”. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node20).types | Baseline update for node20 “Emit1” type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node20).symbols | Baseline update for node20 “Emit1” symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node20).js.diff | Baseline diff update for node20 “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node20).js | Baseline update for node20 “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node20).errors.txt.diff | Baseline diff update for node20 “Emit1” errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node20).errors.txt | Adds baseline error output for node20 “Emit1”. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node18).types | Baseline update for node18 “Emit1” type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node18).symbols | Baseline update for node18 “Emit1” symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node18).js.diff | Baseline diff update for node18 “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node18).js | Baseline update for node18 “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node18).errors.txt.diff | Baseline diff update for node18 “Emit1” errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node18).errors.txt | Adds baseline error output for node18 “Emit1”. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node16).types | Baseline update for node16 “Emit1” type output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node16).symbols | Baseline update for node16 “Emit1” symbol output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js.diff | Baseline diff update for node16 “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js | Baseline update for node16 “Emit1” output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node16).errors.txt.diff | Baseline diff update for node16 “Emit1” errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesImportTypeModeDeclarationEmit1(module=node16).errors.txt | Adds baseline error output for node16 “Emit1”. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsSourceTs(module=nodenext).errors.txt.diff | Baseline diff update for exports/source TS error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsSourceTs(module=node20).errors.txt.diff | Baseline diff update for exports/source TS error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsSourceTs(module=node18).errors.txt.diff | Baseline diff update for exports/source TS error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsSourceTs(module=node16).errors.txt.diff | Baseline diff update for exports/source TS error output. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksSpecifierResolution(module=nodenext).errors.txt.diff | Baseline diff update for exports blocks specifier resolution errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksSpecifierResolution(module=node20).errors.txt.diff | Baseline diff update for exports blocks specifier resolution errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksSpecifierResolution(module=node18).errors.txt.diff | Baseline diff update for exports blocks specifier resolution errors. |
| testdata/baselines/reference/submodule/conformance/nodeModulesExportsBlocksSpecifierResolution(module=node16).errors.txt.diff | Baseline diff update for exports blocks specifier resolution errors. |
| testdata/baselines/reference/submodule/conformance/legacyNodeModulesExportsSpecifierGenerationConditions.errors.txt.diff | Baseline diff update for legacy exports specifier generation conditions. |
| testdata/baselines/reference/submodule/compiler/temporal.types | Baseline update for temporal compiler test types. |
| testdata/baselines/reference/submodule/compiler/temporal.js | Baseline update for temporal compiler test output. |
| testdata/baselines/reference/submodule/compiler/temporal.errors.txt | Baseline update for temporal compiler test errors. |
| testdata/baselines/reference/submodule/compiler/subtypeReductionWithAnyFunctionType.types | Removes/updates baseline for subtype-reduction test types output. |
| testdata/baselines/reference/submodule/compiler/subtypeReductionWithAnyFunctionType.symbols | Removes/updates baseline for subtype-reduction test symbols output. |
| testdata/baselines/reference/submodule/compiler/subtypeReductionWithAnyFunctionType.errors.txt | Removes/updates baseline for subtype-reduction test errors. |
| testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.types | Baseline update for parse assert entries error test types output. |
| testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.symbols | Baseline update for parse assert entries error test symbols output. |
| testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.js.diff | Baseline diff update for parse assert entries error output. |
| testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.js | Baseline update for parse assert entries error output. |
| testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.errors.txt.diff | Baseline diff update for parse assert entries error diagnostics. |
| testdata/baselines/reference/submodule/compiler/parseAssertEntriesError.errors.txt | Baseline update for parse assert entries error diagnostics. |
| testdata/baselines/reference/submodule/compiler/jsxFunctionTypeChildren.types | Removes/updates baseline for JSX function-type-children test types output. |
| testdata/baselines/reference/submodule/compiler/jsxFunctionTypeChildren.symbols | Removes/updates baseline for JSX function-type-children test symbols output. |
| testdata/baselines/reference/submodule/compiler/importTypeAssertionDeprecationIgnored.errors.txt.diff | Removes/updates baseline diff for ignored deprecation test. |
| testdata/baselines/reference/submodule/compiler/importTypeAssertionDeprecationIgnored.errors.txt | Removes/updates baseline output for ignored deprecation test. |
| testdata/baselines/reference/submodule/compiler/importTypeAssertionDeprecation.errors.txt.diff | Removes/updates baseline diff for deprecation test. |
| testdata/baselines/reference/submodule/compiler/importTypeAssertionDeprecation.errors.txt | Removes/updates baseline output for deprecation test. |
| testdata/baselines/reference/submodule/compiler/declarationEmitUsingTypeAlias1.errors.txt.diff | Baseline diff update for declaration emit using type alias diagnostics. |
| testdata/baselines/reference/submodule/compiler/declarationEmitUnsafeImportSymbolName.types | Removes/updates baseline for unsafe import symbol name types output. |
| testdata/baselines/reference/submodule/compiler/declarationEmitUnsafeImportSymbolName.symbols | Removes/updates baseline for unsafe import symbol name symbols output. |
| testdata/baselines/reference/submodule/compiler/declarationEmitUnsafeImportSymbolName.js.diff | Removes/updates baseline diff for unsafe import symbol name output. |
| testdata/baselines/reference/submodule/compiler/declarationEmitUnsafeImportSymbolName.js | Removes/updates baseline output for unsafe import symbol name. |
| testdata/baselines/reference/submodule/compiler/declarationEmitUnsafeImportSymbolName.errors.txt | Removes/updates baseline diagnostics for unsafe import symbol name. |
| testdata/baselines/reference/submodule/compiler/declarationEmitReexportedSymlinkReference3.errors.txt.diff | Baseline diff update for reexported symlink reference diagnostics. |
| testdata/baselines/reference/submodule/compiler/declarationEmitObjectAssignedDefaultExport.errors.txt.diff | Baseline diff update for default export assignment diagnostics. |
| testdata/baselines/reference/submodule/compiler/declarationEmitNestedBindingPattern.types | Removes/updates baseline for nested binding pattern types output. |
| testdata/baselines/reference/submodule/compiler/declarationEmitNestedBindingPattern.symbols | Removes/updates baseline for nested binding pattern symbols output. |
| testdata/baselines/reference/submodule/compiler/declarationEmitNestedBindingPattern.js | Removes/updates baseline output for nested binding pattern. |
| testdata/baselines/reference/submodule/compiler/declarationEmitNestedBindingPattern.errors.txt | Removes/updates baseline diagnostics for nested binding pattern. |
| testdata/baselines/reference/submodule/compiler/declarationEmitCommonJsModuleReferencedType.errors.txt.diff | Baseline diff update for CommonJS module referenced type diagnostics. |
| testdata/baselines/reference/submodule/compiler/contextuallyTypedJsxChildren2.types.diff | Removes/updates baseline diff for contextually typed JSX children test. |
| testdata/baselines/reference/submodule/compiler/contextuallyTypedJsxChildren2.types | Removes/updates baseline for contextually typed JSX children types output. |
| testdata/baselines/reference/submodule/compiler/contextuallyTypedJsxChildren2.symbols | Removes/updates baseline for contextually typed JSX children symbols output. |
| internal/execute/tsctests/tsc_test.go | Adds --generateTrace CLI integration tests (tsc harness). |
| internal/execute/tsc/emit.go | Adds tracing around bind/check diagnostic collection phases. |
| internal/execute/tsc.go | Starts/stops tracing around program creation/compile; plumbs tracing into NewProgram. |
| internal/execute/incremental/program.go | Adds tracing around incremental build-info emit. |
| internal/compiler/program.go | Adds program-level tracing hooks; plumbs tracing into emitter/checker pool. |
| internal/compiler/filesparser.go | Adds tracing around source file resolution + type directive processing. |
| internal/compiler/fileloader.go | Adds tracing around root file processing, parse, and directive/module resolution. |
| internal/compiler/emitter.go | Adds tracing around emit and per-file emit steps. |
| internal/compiler/checkerpool.go | Constructs checkers with optional tracing/type recording support. |
| internal/checker/typetracer.go | New: checker-side type tracing adapter layer for types_*.json. |
| internal/checker/types.go | Adds type flag formatting helpers used by tracing (and a String() for TypeFlags). |
| internal/checker/relater.go | Adds tracing events for depth/complexity limits and structured type comparison boundaries. |
| internal/checker/flow.go | Adds tracing event for control-flow recursion depth limit. |
| internal/checker/checker.go | Adds optional tracer + per-checker tracing and records types as they’re created. |
- Add internal/tracing package with Tracing, CheckerTracing, EventTracer, TypeTracer - Add internal/checker/typetracer.go for type recording during checking - Wire tracing through checker, program, emitter, and tsc execution - Add tracing calls in checker for checkSourceFile, checkDeferredNode, checkTypeParameterDeferred, checkVariableDeclaration, checkExpressionEx, checkTypeRelatedTo, getVariancesWorker, recursiveTypeRelatedTo, typeRelatedToDiscriminatedType, getTypeAtFlowNode - Add generateTrace tsc tests - Add RecursionId type to checker types
Replace per-checker CheckerTracing type with context-based tracing using tracing.WithTracing/FromContext. Tracing is now injected into the context at the entry point (EmitFilesAndReportErrors) and retrieved via tracing.FromContext(ctx) at each call site. Key changes: - Remove CheckerTracing type and per-checker tracing fields - Add WithTracing/FromContext for context-based tracing propagation - Push now returns a cleanup func() for use with defer - Args changed from variadic strings to map[string]any - All checker/relater/flow tracing uses tracing.FromContext(ctx) - Program/emitter/fileloader tracing uses map[string]any args
bec1c6c to
56f3a9f
Compare
There was a problem hiding this comment.
Pull request overview
Adds a --generateTrace tracing facility to the Go TypeScript port so it can emit trace.json (Chrome trace events) and types.json (serialized checker types), similar to upstream TypeScript, and wires it through the compiler pipeline using context.Context.
Changes:
- Introduces
internal/tracingwith trace event recording, legend output, and per-checker type dumping. - Wires tracing through
execute,compiler.Program, checker pool creation, binder/checker/emit phases, and adds type recording hooks. - Adds
tscintegration tests + reference baselines for--generateTrace.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/baselines/reference/tsc/generateTrace/generateTrace-with-multiple-files-and-complex-types.js | Adds reference baseline for multi-file trace + types output. |
| testdata/baselines/reference/tsc/generateTrace/generateTrace-generates-types-file.js | Adds reference baseline for basic trace + types output. |
| internal/tracing/tracing.go | New tracing implementation: event buffer, sampling, legend + types dumping. |
| internal/execute/tsctests/tsc_test.go | Adds TestGenerateTrace scenarios that exercise --generateTrace. |
| internal/execute/tsc/emit.go | Injects program tracing into context; emits bind/check phase trace spans. |
| internal/execute/tsc.go | Starts/stops tracing based on compiler options; passes tracer into program creation. |
| internal/execute/incremental/program.go | Adds trace span around build info emission. |
| internal/compiler/program.go | Stores tracing on Program, traces program creation, binding, and emit; passes tracer into emitter. |
| internal/compiler/filesparser.go | Adds trace spans for file discovery + automatic type directive processing. |
| internal/compiler/fileloader.go | Adds trace spans for root file processing, parsing, and type reference/module resolution. |
| internal/compiler/emitter.go | Adds emit-phase trace spans (per-source-file and per-output kind). |
| internal/compiler/checkerpool.go | Creates checkers with optional type tracer tied to tracing session. |
| internal/checker/typetracer.go | Adds adapter layer to record checker types into tracing’s types.json. |
| internal/checker/types.go | Adds FormatTypeFlags + TypeFlags.String() to support stable serialized flag names. |
| internal/checker/relater.go | Adds trace instants/spans for depth/complexity limits and key type-relation operations. |
| internal/checker/flow.go | Adds trace instant for flow depth-limit disabling. |
| internal/checker/checker.go | Adds optional per-checker type tracer; traces key checking operations; records every new type when enabled. |
| if p.tracing != nil { | ||
| tracer = checker.NewTracingTypeTracer(p.tracing.NewTypeTracer(i)) | ||
| } | ||
| p.checkers[i], p.locks[i] = checker.NewCheckerWithTracer(p.program, tracer) |
There was a problem hiding this comment.
I don't think we need "new checker with tracer" if we only ever trace during checkSourceFile?
| } | ||
|
|
||
| // writeArgsJSON constructs a deterministic JSON object from a map of key-value pairs. | ||
| func writeArgsJSON(args map[string]any) string { |
There was a problem hiding this comment.
is there a reason to do it this way as compared to using json/jsontext to directly writer a stream of tokens? Doing it that way should be free, though maybe it's down to the newlines? (I think the lib supports that)
There was a problem hiding this comment.
For writeArgsJSON, I've switched to using json.Marshal for string escaping, which fixes the correctness issue. For the broader trace event output (writeEventTo), the manual string building is intentional for performance — the values there are all controlled (phase names, event names) with no user content that needs escaping. I'm open to switching the full event builder to use jsontext.Encoder in a follow-up if you'd prefer, but the manual approach avoids the encoder overhead for the hot path.
There was a problem hiding this comment.
I would be very surprised if this manual building were faster than a direct encoder. It's also a lot more error prone, IMO. I would recommend switching.
There was a problem hiding this comment.
especially since you both string build and use json.Marshal? It's a weird combo
|
Yeah, baselines are unstable: diff --git a/testdata/baselines/reference/tsc/generateTrace/generateTrace-with-multiple-files-and-complex-types.js b/testdata/baselines/reference/tsc/generateTrace/generateTrace-with-multiple-files-and-complex-types.js
index b79d7c8f..d48ad2d3 100644
--- a/testdata/baselines/reference/tsc/generateTrace/generateTrace-with-multiple-files-and-complex-types.js
+++ b/testdata/baselines/reference/tsc/generateTrace/generateTrace-with-multiple-files-and-complex-types.js
@@ -96,6 +96,8 @@ declare const console: { log(msg: any): void; };
{"pid":1,"tid":1,"ph":"B","cat":"check","ts":21,"name":"checkSourceFile","args":{"path":"/home/src/workspaces/project/types.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":22,"name":"checkSourceFile","args":{"path":"/home/src/workspaces/project/types.ts"}},
{"pid":1,"tid":1,"ph":"B","cat":"check","ts":23,"name":"checkSourceFile","args":{"path":"/home/src/workspaces/project/main.ts"}},
+{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1072.7570,"name":"checkExpression","dur":23361.6560,"args":{"end":133,"kind":218,"path":"/home/src/workspaces/project/main.ts","pos":101}},
+{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1069.8220,"name":"checkDeferredNode","dur":23369.2300,"args":{"end":133,"kind":220,"path":"/home/src/workspaces/project/main.ts","pos":93}},
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":24,"name":"checkSourceFile","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":25,"name":"checkSourceFiles"},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":26,"name":"emit"}, |
Instead of calling tracing.FromContext(c.ctx) on every tracing call site in the checker, cache the result once in checkSourceFile and use the c.tracing field throughout checker.go, relater.go, and flow.go.
In deterministic mode, sampled events (separateBeginAndEnd=false) relied on wall-clock time for duration and sampling-boundary checks, producing non-deterministic output that caused flaky test baselines. Now sampled events are skipped entirely in deterministic mode, since only B/E events use the deterministic timestamp counter.
writeArgsJSON previously built JSON strings manually without escaping string values, which could produce invalid JSON for paths with backslashes, strings with quotes, or control characters. Now uses json.Marshal for proper escaping of both keys and string values.
Deterministic mode for tracing (which uses a counter instead of wall-clock timestamps) was previously tied to CompilerOptions.SingleThreaded. This couples unrelated concerns - deterministic output should be chosen based on whether we are in a testing context, not threading mode. Changed to use testing != nil as the deterministic flag.
When tracing is not enabled (the common case), the Push/Pop calls on a nil receiver are safe but the map[string]any argument literals are still allocated on the heap. Add nil pre-checks to all tracing call sites in fileloader.go, filesparser.go, program.go, and emitter.go to skip the allocation entirely when not tracing.
The Program.Tracing() accessor exposed internal state unnecessarily when tracing already flows via contexts. Add a Tracing field to EmitInput and use it directly in EmitFilesAndReportErrors, removing the only caller of Program.Tracing().
|
Fixed — sampled events (the "X" events with wall-clock timestamps shown in the diff) are now skipped entirely in deterministic mode. Only B/E pairs with the deterministic counter remain, which produces stable baselines. |
this is a work in progress PR to add tracing so we can get types.json and trace.json files as was in the TypeScript codebase.
note, I took all the previous work and squashed it into one commit, then the second commit (56f3a9f) is for switching to a context-based approach.