Skip to content

Track variable locations#820

Open
djolertrk wants to merge 20 commits into0xMiden:nextfrom
walnuthq:feature/debug-variable-locations-clean
Open

Track variable locations#820
djolertrk wants to merge 20 commits into0xMiden:nextfrom
walnuthq:feature/debug-variable-locations-clean

Conversation

@djolertrk
Copy link
Copy Markdown
Collaborator

Track variable locations at HIR and MASM levels.
Add DebugVar decorator and new debug_info section in the final .masp.

Also, add miden-debugdump tool to dump .debug_info section, so we can explore the custom section from the package.

vm part: 0xMiden/miden-vm#2471

@djolertrk djolertrk marked this pull request as draft December 15, 2025 07:35
@djolertrk
Copy link
Copy Markdown
Collaborator Author

Goes on top of #812.

@djolertrk
Copy link
Copy Markdown
Collaborator Author

cc @greenhat @bitwalker

@djolertrk djolertrk changed the title Track variable locations clean Track variable locations Dec 15, 2025
@djolertrk djolertrk force-pushed the feature/debug-variable-locations-clean branch 3 times, most recently from 69877ae to a4ccd95 Compare January 9, 2026 17:27
@djolertrk djolertrk marked this pull request as ready for review January 9, 2026 17:28
@djolertrk
Copy link
Copy Markdown
Collaborator Author

It depends on the types and debug decorator defined in 0xMiden/miden-vm#2471.

@bitwalker bitwalker added the blocker This issue is one of our top priorities label Jan 9, 2026
@bitwalker
Copy link
Copy Markdown
Collaborator

I've done an initial review of the miden-vm PR, and I expect we can get that merged ASAP once all the review feedback is addressed.

@djolertrk
Copy link
Copy Markdown
Collaborator Author

Now rebased on top of #995.

cc @greenhat @bitwalker

@djolertrk
Copy link
Copy Markdown
Collaborator Author

Status on this:

VM changes merged
PR in compiler depends on the #995
PR in debugger in review: 0xMiden/miden-debug#17

@greenhat
Copy link
Copy Markdown
Contributor

Now rebased on top of #995.

Just a heads-up. I'm in the process of rebasing #995 on the fresh next branch.

@djolertrk djolertrk force-pushed the feature/debug-variable-locations-clean branch from a3fc070 to a20d993 Compare March 25, 2026 09:06
@djolertrk
Copy link
Copy Markdown
Collaborator Author

rebased on top of #995

@djolertrk djolertrk force-pushed the feature/debug-variable-locations-clean branch 2 times, most recently from 7647605 to 92b8973 Compare April 1, 2026 12:34
@djolertrk
Copy link
Copy Markdown
Collaborator Author

note that it still depends on the local miden-vm (0xMiden/miden-vm#2955 is needed).

This commit adds debug information support for tracking
variable locations through the compilation pipeline:

- Add debug info representation on HIR level (builtin.dbg_value ops,
  DIExpression, DILocalVariable attributes)
- Handle DebugVars during lowering from HIR to MASM
- Add DebugInfoBuilder for constructing debug metadata
- Add RemoveDeadDebugOps pass to clean up debug ops with dead operands
- Add miden-debugdump tool for inspecting .debug_info sections in MASP
  packages (similar to llvm-dwarfdump)
- Add documentation for the debug info format (docs/DebugInfoFormat.md,
  docs/DebugInfoMetadata.md)
- Add lit tests for debug functionality

Run tests:
$ litcheck lit run --verbose tests/lit/debugdump
$ litcheck lit run --path bin ./tests/lit/debug/
- Check if WasmLocal value is on Miden operand stack before assuming
  it's in local memory (emit Stack(pos) if on stack)
- Add post-processing in MasmFunctionBuilder::build() to patch
  Local(idx) with correct FMP offset
- Compute num_wasm_locals = params_in_felts + hir_locals for correct
  offset calculation (DWARF WasmLocal uses WASM indexing where params
  come first)
- Add patch_debug_var_locals_in_block() to recursively patch all
  DebugVar decorators in the MASM body
Confirm that cfg --> scf preserves debug info
Debug info operations (debuginfo.value, debuginfo.kill, debuginfo.declare)
are purely observational and were causing panics and assembler validation
errors when they survived through optimization passes into codegen.

- Skip operand scheduling for DebugValue (observational, not consuming)
- Gracefully skip debuginfo ops with no HirLowering in the emitter
- Make SinkOperandDefs and ControlFlowSink debug-info-aware so debug
  uses don't block sinking or prevent dead code elimination
- Strip DebugVar-only procedure bodies that would be rejected by the
  Miden assembler (decorators without instructions have no MAST effect)
Add end-to-end debug variable location tracking through the compiler
pipeline, and patch miden-vm to fix a crash when basic blocks are
deduplicated during assembly.
Fix data_offset_align and raw_entity_metadata_layout_for_value_layout
to correctly handle types with alignment > 8
- add FrameBase lowering
- DWARF parsing (parse variable/params names)
- and fix duplicate DebugVar emissions
@djolertrk djolertrk force-pushed the feature/debug-variable-locations-clean branch from 0987c07 to 468609e Compare April 14, 2026 14:11
@djolertrk
Copy link
Copy Markdown
Collaborator Author

NOTE: It uses https://github.com/walnuthq/miden-vm/tree/fix/debug-var-dedup-crash -- but 0xMiden/miden-vm#2955 should be merged soon.

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

Labels

blocker This issue is one of our top priorities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants