Skip to content

Preserve source spans through tokens, AST, and typed HIR #406

Closed

Description

@LunaStev

Problem

Lexer tokens currently retain only a line number, and later parser/semantic diagnostics often recover locations by scanning source text for a matching spelling. Repeated identifiers and nested expressions can therefore point at the wrong occurrence. The new typed HIR has stable expression and pattern identities but no first-class source span.

Contract

Introduce a backend-neutral source span that records byte start/end plus line/column information sufficient for human and JSON diagnostics. Preserve it through:

  • lexer tokens;
  • declarations, statements, expressions, and match patterns;
  • import expansion and generic monomorphization;
  • TypedProgram expression and pattern identities.

Synthetic nodes created during expansion must carry explicit provenance rather than pretending to be at line 1.

Scope

  • Define the span/provenance types and ownership model.
  • Thread spans through frontend construction and transformations.
  • Replace heuristic source-text lookup in diagnostics incrementally.
  • Add regressions with repeated identical spellings on one line and across imported modules.
  • Keep source spans independent of LLVM debug information.

Completion criteria

  • Every user-written AST/HIR node can report its original file and byte range.
  • Imported and monomorphized nodes retain useful origin information.
  • Diagnostics select the exact repeated occurrence.
  • UTF-8 columns remain correct.
  • No backend crate type leaks into the frontend span API.

Activity

  1. added
    enhancement
    help wanted
    technical debt
    on Aug 28, 2026
  2. LunaStev commented on Sep 5, 2026

    @LunaStev
    MemberAuthor

    Reconfirmed during the alpha-readiness audit following #474. Parser diagnostics still originate from line-only tokens and commonly report column 1; the nested-block boolean reproducer, for example, points to the start of the function rather than the rejected semicolon. This remains part of the alpha stabilization plan, and no duplicate issue was opened.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wantedtechnical debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions