Skip to content

Compiler debug info: every function names its own file and line; stage2-debug-lines gate - #1351

Merged
ehartford merged 3 commits into
mainfrom
fix-stage-debug-info
Sep 22, 2026
Merged

ehartford merged 3 commits into
mainfrom
fix-stage-debug-info

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

The compiler's own binaries had no usable debug info. Every function in every module was attributed to main.w. The fix is in three commits.

Root cause (exact lines)

  1. src/Codegen.w debug_enter_function / debug_set_location / debug_push_lexical_block (main at 5fd93bc): every DISubprogram, lexical block and location used self.di_file (the root's DIFile) and self.di_source.offset_to_location(span) (the root's text). Spans are byte offsets into the file a node was parsed from, so an imported module's function got the root's file and a line computed against the wrong text.
  2. src/Parser.w parse_interpolated_expr_attempt: Parser.init_with_pool(..., 0, ...). The f-string sub-parser stamped the shared pool's current file id to 0 and never restored it, so every node after the first {expr} in any imported module had AstPool.file == 0. Fixing (1) alone still left 5255 subprograms in main.w. The same class was in ComptimeTransform's derive and comptime-expansion loops, whose appended nodes took whatever file the deep clone stamped last. For example, BuilderError.debug_str was attributed to the last-parsed user file.
  3. build/compiler.w run_with_compiler_build_action: dsymutil ran on the .tmp link output, so the dSYM's DWARF file was named with-stage2.tmp.

CCodegen's #line directives had the same root-only defect as (1). They now follow the body's declaration file.

Before (main, out/stage/bin/with-stage2)

0x00056de4: DW_TAG_subprogram
              DW_AT_low_pc	(0x0000000100627340)
              DW_AT_high_pc	(0x0000000100627c2c)
              DW_AT_APPLE_omit_frame_ptr	(true)
              DW_AT_frame_base	(DW_OP_reg31 WSP)
              DW_AT_linkage_name	("Sema.check_mutation_against_views")
              DW_AT_name	("Sema.check_mutation_against_views")
              DW_AT_decl_file	("/with-src/out/gen/main.w")
              DW_AT_decl_line	(1)
              DW_AT_external	(true)
Line info: file 'main.w', line 1, column 0, start file 'main.w', start line 1
(lldb) image lookup -n Sema.check_mutation_against_views
        Summary: with-stage2`Sema.check_mutation_against_views at main.w:1
dSYM: with-stage2.dSYM/Contents/Resources/DWARF/with-stage2.tmp

After (this branch, stage2 built by the fixed stage1)

0x00060d2f: DW_TAG_subprogram
              DW_AT_low_pc	(0x00000001006927c4)
              DW_AT_high_pc	(0x00000001006930b0)
              DW_AT_APPLE_omit_frame_ptr	(true)
              DW_AT_frame_base	(DW_OP_reg31 WSP)
              DW_AT_linkage_name	("Sema.check_mutation_against_views")
              DW_AT_name	("Sema.check_mutation_against_views")
              DW_AT_decl_file	("/with-src/src/SemaCheck.w")
              DW_AT_decl_line	(22867)
              DW_AT_external	(true)
        Summary: with-stage2`Sema.check_mutation_against_views at SemaCheck.w:22867
Breakpoint 1: where = with-stage2`Sema.check_mutation_against_views + 40 at SemaCheck.w:22868:44, address = 0x00000001006927ec
    frame #0: 0x00000001006927ec with-stage2`Sema.check_mutation_against_views at SemaCheck.w:22868:44
  * frame #0: 0x00000001006927ec with-stage2`Sema.check_mutation_against_views at SemaCheck.w:22868:44
    frame #1: 0x000000010002644c with-stage2`Sema.check_method_call_parts at SemaCheck.w:21114:57
    frame #2: 0x0000000100827cf0 with-stage2`Sema.check_call at SemaCheck.w:15791:105
dSYM: with-stage2.dSYM/Contents/Resources/DWARF/with-stage2

Two-module user program: helper at Helper.w:9:24 (it was app.w), a function after an f-string reads Helper.w:9, and br set -f app.w -l 5 stops in the inlined user main, which used to have no line.

Regression gate

stage2-debug-lines (a dependency of :fixpoint) runs the SDK's llvm-dwarfdump on with-stage2 for two anchors (Sema.check_mutation_against_views, Lexer.skip_whitespace). It requires DW_AT_decl_file == /with-src/<source>, DW_AT_decl_line equal to the declaration's line in the source, and the line-table row at low_pc to name that file. On Windows (CodeView) it prints an explicit skip.

ok Sema.check_mutation_against_views: /with-src/src/SemaCheck.w:22867, line table at 0x00000001006927c4 in SemaCheck.w
ok Lexer.skip_whitespace: /with-src/src/Lexer.w:420, line table at 0x00000001004ca278 in Lexer.w

Determinism

:fixpoint-compare: stage2 == stage3 over all 16 units of the compiler. DIFile paths go through codegen_canonical_module_path (absolute, then WITH_FILE_PREFIX_MAP). Module names are recorded relative to the working directory, and DWARF would have resolved them against the root's directory, which gave /with-src/out/gen/src/.... An rt object built by the new compiler now reads /with-src/rt. The ones stage2 links today are out/bootstrap-lib objects from the pinned seed, and they still carry the checkout path until the seed moves.

Not in this change

Iterate-tier evidence only (:dev, :stage2, :stage2-debug-lines, :fixpoint-compare). The full battery has not been run yet.

Eric Hartford added 3 commits September 22, 2026 19:01
…eclaring file

Parser.parse_interpolated_expr_attempt built its sub-parser with file id 0.
Parser.init_with_pool stamps the shared pool's current file id, and nothing
restored it, so every node after the first `{expr}` in an imported module was
attributed to the root (file 0). ComptimeTransform's derive and comptime
expansion loops appended nodes under whatever file the deep clone stamped
last. AstPool.file feeds D39's interface-file node runs and Codegen's DWARF
file (next commit).
… file

debug_enter_function named the root's DIFile for every function and measured
every span against the root's text (di_source), so every function of every
imported module read as main.w:<line of some other file> in lldb. For
with-stage2, Sema.check_mutation_against_views read main.w:1.
The function's file now comes from AstPool.file(fn_node): a cached DIFile per
file id, with its canonical path (absolute, WITH_FILE_PREFIX_MAP, D50), and
lines from Sema.source_location_for_file_id. The OS entry wrapper gets its own
line-0 subprogram, so an inlined user main keeps its lines. CCodegen's #line
directives had the same root-only defect and now follow the body's
declaration file.
…ies the binary's name

run_debug_lines_check_action reads with-stage2's DWARF with the SDK's
llvm-dwarfdump. For each anchor (Sema.check_mutation_against_views in
src/SemaCheck.w, Lexer.skip_whitespace in src/Lexer.w), DW_AT_decl_file must
be /with-src/<source>, DW_AT_decl_line must be the line of the declaration,
and the line table at low_pc must name the file. Before this, the compiler's
debug info named main.w for every module and nothing failed.
The stage build ran dsymutil on the .tmp link output and moved the bundle, so
its DWARF file was named with-stage2.tmp. The build now renames it.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery (seed-driven, rebased on main 8c859a7, 2d3daf5 — force-pushed so the PR is the tested tree): build ok, :fixpoint ok (incl. the new stage2-debug-lines gate), :test ok (no reds), :test-green ok, :last-green ok.

@ehartford
ehartford marked this pull request as ready for review September 22, 2026 23:26
@ehartford
ehartford merged commit dd786a4 into main Sep 22, 2026
@ehartford
ehartford deleted the fix-stage-debug-info branch September 22, 2026 23:31
ehartford pushed a commit that referenced this pull request Oct 2, 2026
…ical_block (#1356)

The #1351 workaround for #1349 (`let (a, b) = if c: f() else: (1, 0)`
rejected by the then-pinned seed) is retired: seed.lock has been bumped
past 1f4636d (#1355), and the pinned seed builds stage1 with the natural
spelling (`src/main build :dev` rc=0).
ehartford added a commit that referenced this pull request Oct 2, 2026
…ical_block (#1356) (#1961)

The #1351 workaround for #1349 (`let (a, b) = if c: f() else: (1, 0)`
rejected by the then-pinned seed) is retired: seed.lock has been bumped
past 1f4636d (#1355), and the pinned seed builds stage1 with the natural
spelling (`src/main build :dev` rc=0).

Co-authored-by: Eric Hartford <[email protected]>
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.

1 participant