Skip to content

[WIP] Adds tracing#2914

Draft
dimitropoulos wants to merge 15 commits intomicrosoft:mainfrom
dimitropoulos:jabaile/generate-trace
Draft

[WIP] Adds tracing#2914
dimitropoulos wants to merge 15 commits intomicrosoft:mainfrom
dimitropoulos:jabaile/generate-trace

Conversation

@dimitropoulos
Copy link

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.

@dimitropoulos dimitropoulos changed the base branch from jabaile/generate-trace to main February 26, 2026 18:29
Adopted from the parallel tracing branch:

- Add "path" argument to checkDeferredNode, checkVariableDeclaration, and
  checkExpression trace points, matching the TypeScript reference
  implementation which includes the source file path for these events.

- Add PopAll() method to both Tracing and CheckerTracing types, matching
  TypeScript's tracing.popAll() which closes all open events at once.
  This is used in the language server session for cleanup.
Match TypeScript's behavior of using `aliasSymbol ?? symbol` when
determining firstDeclaration for type descriptors. Previously only
the type's direct symbol was used, causing union types created via
type aliases (e.g. `type Nullable<T> = T | null | undefined`) to
be missing their firstDeclaration. Now these types correctly point
back to their alias declaration site.

On the typeslayer project this adds ~2,800 firstDeclaration entries
per checker for union types that have an aliasSymbol.
Include TypeFlagsTemplateLiteral in the Display() condition alongside
TypeFlagsLiteral, so that template literal types (e.g. `${number}`)
get their string representation in the trace output. This goes beyond
TypeScript's current behavior but provides useful diagnostic info for
these types that would otherwise have no display or firstDeclaration.
Extend Display() to compute typeToString for Union and Intersection
types in addition to Anonymous, Literal, and TemplateLiteral types.

Anonymous unions and intersections can't have firstDeclaration (they
have no symbol or aliasSymbol), but display text makes them identifiable
in trace output. For example, a previously opaque union now shows:
  display: "CodeRouteToPath<TRouter> | FileRouteToPath<...>"

This increases display coverage from ~39% to ~75% of all types.
return NewCheckerWithTracer(program, nil, nil)
}

func NewCheckerWithTracer(program Program, tracer TypeTracer, tr *tracing.CheckerTracing) (*Checker, *sync.Mutex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly like that we have this variant... what was wrong with the approach I had in my branch?

}

func (c *Checker) checkDeferredNode(node *ast.Node) {
c.tracing.Push(tracing.PhaseCheck, "checkDeferredNode", false, "kind", strconv.Itoa(int(node.Kind)), "pos", strconv.Itoa(node.Pos()), "end", strconv.Itoa(node.End()), "path", ast.GetSourceFileOfNode(node).FileName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tracing calls should do an if c.tracing != nil check; these are expensive operations to be doing on ever single node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants