Skip to content

[TVMSCRIPT][TIRx] Preserve parser source spans in IR - #20073

Merged
spectrometerHBH merged 1 commit into
apache:mainfrom
jinhongyii:upstream/tirx-parser-source-spans
Jul 29, 2026
Merged

[TVMSCRIPT][TIRx] Preserve parser source spans in IR#20073
spectrometerHBH merged 1 commit into
apache:mainfrom
jinhongyii:upstream/tirx-parser-source-spans

Conversation

@jinhongyii

Copy link
Copy Markdown
Contributor

Motivation and context

The TVMScript parser already tracks Python AST locations for diagnostics, but TIRx statements and expression results emitted through IRBuilder did not retain those locations. After parsing, a direct intrinsic call, an inlined helper body, or a TilePrimitiveCall therefore could not be traced back to the source range that produced it.

Inline expansion also needs more than a single flat location. The generated IR should retain both the caller location and the helper-definition location, while ordinary nested AST evaluation within one source should not accumulate redundant enclosing spans.

Changes

  • Add an active source-span stack to IRBuilder, with scoped push/pop support.
  • Make the parser activate the current AST source range while visiting statements and evaluating expressions.
  • Attach the active span to emitted TIRx statements and to expression results that do not already carry an explicit span.
  • Normalize nested spans from the same source to the innermost relevant range.
  • Preserve cross-source inline expansion history as a SequentialSpan, ordered from the call site to the expanded definition.
  • Reuse the same source-coordinate calculation for diagnostics and IR spans so their line and column conventions remain consistent.

Source spans remain diagnostic metadata: functions parsed from different source locations keep the same structural hash and remain structurally equal.

Testing

  • Verify exact parser source coordinates against diagnostic coordinates.
  • Verify spans on direct intrinsic calls and TilePrimitiveCall nodes.
  • Verify that inline expansion produces a SequentialSpan containing caller and callee ranges.
  • Verify direct IRBuilder.with_source_span behavior.
  • Verify that source spans do not affect structural identity.
  • Run changed-files pre-commit checks, including clang-format.

Focused result: 9 tests passed.

Track nested frontend source ranges through IRBuilder and attach them to emitted TIRx statements and expression results. Normalize same-source nesting while retaining cross-source inline expansion history as SequentialSpan.

Add exact coordinate, direct-call, inline expansion, tile primitive, and structural identity regression coverage.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@spectrometerHBH
spectrometerHBH merged commit ae99c3f into apache:main Jul 29, 2026
8 checks passed
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