Skip to content

Codegen debug info: DWARF variables; specializations and closures are subprograms (#1348) - #1515

Merged
ehartford merged 1 commit into
fix-1334-oneliner-literal-indentfrom
fix-1348-dwarf-variables
Sep 23, 2026
Merged

ehartford merged 1 commit into
fix-1334-oneliner-literal-indentfrom
fix-1348-dwarf-variables

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #1348.

Root cause. Nothing called the bound LLVMDIBuilderCreateAutoVariable / CreateParameterVariable / InsertDeclareRecord, so no With program had variables (frame variable: "no variable information is available in debug info for this compile unit"). Only gen_function_dispatch_at entered a subprogram: gen_function_mir_mono (every generic specialization) and gen_closure had none, set no lines of their own, and inherited the enclosing function's scope and location because they are emitted in the middle of it. Built by the installed compiler, a program with a generic function, a generic method and a closure: br set -f prog2.w -l 11 (in largest[T]) and -l 7 (in a Pair[T] method) have no locations; -l 17 (the closure body) resolves only into main.

Fix (Codegen).

  • debug_declare_mir_locals: every MIR local with a source name that is a parameter or a user binding (let/var, pattern, capture) and lives in a stack slot of this function, or in the argument that carries its address, gets a DILocalVariable (parameters numbered from 1) and a #dbg_declare before the entry block's terminator; a slot holding the value's address (a spilled pointer parameter, a by-reference capture) is described through DW_OP_deref. Only a function with its own subprogram gets them; a let is declared at its first assignment's line.
  • gen_function_mir_mono: a subprogram in its template's file and line (concrete_specialization_nodes / fn_symbol_decl_node), statement/terminator locations and lexical blocks like gen_function_mir; with no declaration to name, no subprogram and no borrowed location.
  • gen_closure: a subprogram at the closure's node, statement locations, variables for its captures and parameters.
  • Both save and restore the enclosing function's scope, file and builder location.
  • str is a { ptr, len } composite: (str) label = (ptr = "points", len = 6).

After. Tree stage2 build of the same program: all three breakpoints stop; frame variable shows bias = 5 in largest and n = 3 in the closure. In with-stage2, Sema.check_mutation_against_views has self, place_node, err_node, ref_name, diag.

Determinism. src/main build :fixpoint: [fixpoint] stage2 == stage3 over all 16 units of the compiler. Cost, stage1 compiling out/gen/main.w (--emit-obj -O1, four bundles), interleaved without/with: 98 s / 91 s, 77 s / 84 s; object 1,796,096 → 1,877,512 bytes.

Tests. test/behavior/behav_debug_info_variables.w checks with ir for the three subprograms at their lines and each one's variables and #dbg_declare records. The stage2-debug-lines gate (:fixpoint) gains vars=Sema.check_mutation_against_views|self,place_node,err_node,ref_name: ok Sema.check_mutation_against_views: variables self,place_node,err_node,ref_name.

@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1516 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main + #1509 → … → #1515 (head 63e8340): build ok, :fixpoint ok (stage2 == stage3 with DWARF variables), :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merge the stack: gh stack merge 1515 --squash.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 16:30
…ecialization and a closure are subprograms of their own (#1348)

Nothing called the bound LLVMDIBuilderCreateAutoVariable /
CreateParameterVariable / InsertDeclareRecord, so every With program's debug
info had no variables: lldb `frame variable` said "no variable information is
available in debug info for this compile unit". Only
gen_function_dispatch_at entered a subprogram: gen_function_mir_mono (every
generic specialization) and gen_closure had none and set no line of their
own, and both inherited the enclosing function's scope and location because
they are emitted in the middle of it. Built by the installed compiler, a
program with a generic function, a generic method and a closure:

    br set -f prog2.w -l 11   (in largest[T])     no locations (pending)
    br set -f prog2.w -l 7    (in Pair[T] method)  no locations (pending)
    br set -f prog2.w -l 17   (the closure body)   main + 156 only

Codegen:
- debug_declare_mir_locals: after a body is emitted, every MIR local with a
  source name that is a parameter or a user binding (let/var, pattern,
  capture) and lives in a stack slot of this function, or in the argument
  that carries its address, gets a DILocalVariable (a parameter numbered from
  1) and a #dbg_declare before the entry block's terminator; a slot that
  holds the value's address (a spilled pointer parameter, a by-reference
  capture) is described through DW_OP_deref. Only a function with its own
  subprogram gets them. A `let` is declared at its first assignment's line.
- gen_function_mir_mono: a subprogram in its template's file and line
  (Sema.concrete_specialization_nodes / fn_symbol_decl_node), per-statement
  and terminator locations and lexical blocks like gen_function_mir; with no
  declaration to name, no subprogram and no borrowed location.
- gen_closure: a subprogram named after the LLVM function at the closure's
  node, statement locations, variables for its captures and parameters.
- Both save and restore the enclosing function's scope, file and the
  builder's debug location (debug_save_state / debug_restore_state).
- str is a { ptr, len } composite, so lldb prints `(str) label = (ptr =
  "points", len = 6)`.

With the tree's stage2 the same session stops at all three lines;
`frame variable` shows `bias = 5` in largest and `n = 3` in the closure. In
with-stage2, Sema.check_mutation_against_views has self, place_node,
err_node, ref_name, diag.

Determinism: `src/main build :fixpoint` — "[fixpoint] stage2 == stage3 over
all 16 units of the compiler". Cost, stage1 compiling out/gen/main.w
(--emit-obj -O1, the four bundles), interleaved without/with: 98 s / 91 s,
77 s / 84 s; the object grows 1,796,096 -> 1,877,512 bytes.

Tests: test/behavior/behav_debug_info_variables.w checks `with ir` of that
program for the three subprograms at their lines and each one's variables
(self/extra/widened, first/bias/doubled, n/base, label/total) and
#dbg_declare records. The stage2-debug-lines gate (:fixpoint) gains
`vars=Sema.check_mutation_against_views|self,place_node,err_node,ref_name`:
"ok Sema.check_mutation_against_views: variables
self,place_node,err_node,ref_name".
@ehartford
ehartford force-pushed the fix-1348-dwarf-variables branch from 63e8340 to d5ea2e1 Compare September 23, 2026 19:37
@ehartford
ehartford merged commit 3cda6eb into main Sep 23, 2026
@ehartford
ehartford deleted the fix-1348-dwarf-variables branch September 23, 2026 19:38
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.

Codegen debug info: no DWARF variables anywhere; generic (mono) and closure functions get no subprogram

1 participant