Repository navigation
Codegen debug info: DWARF variables; specializations and closures are subprograms (#1348) - #1515
Merged
ehartford merged 1 commit intoSep 23, 2026
Conversation
This was referenced Sep 23, 2026
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: |
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
force-pushed
the
fix-1348-dwarf-variables
branch
from
September 23, 2026 19:37
63e8340 to
d5ea2e1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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"). Onlygen_function_dispatch_atentered a subprogram:gen_function_mir_mono(every generic specialization) andgen_closurehad 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(inlargest[T]) and-l 7(in aPair[T]method) have no locations;-l 17(the closure body) resolves only intomain.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 aDILocalVariable(parameters numbered from 1) and a#dbg_declarebefore the entry block's terminator; a slot holding the value's address (a spilled pointer parameter, a by-reference capture) is described throughDW_OP_deref. Only a function with its own subprogram gets them; aletis 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 likegen_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.stris a{ ptr, len }composite:(str) label = (ptr = "points", len = 6).After. Tree stage2 build of the same program: all three breakpoints stop;
frame variableshowsbias = 5inlargestandn = 3in the closure. In with-stage2,Sema.check_mutation_against_viewshasself,place_node,err_node,ref_name,diag.Determinism.
src/main build :fixpoint:[fixpoint] stage2 == stage3 over all 16 units of the compiler. Cost, stage1 compilingout/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.wcheckswith irfor the three subprograms at their lines and each one's variables and#dbg_declarerecords. Thestage2-debug-linesgate (:fixpoint) gainsvars=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.