feat(hugr-llvm)!: Add support for emitting debug locations#3026
feat(hugr-llvm)!: Add support for emitting debug locations#3026
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3026 +/- ##
==========================================
+ Coverage 81.31% 81.36% +0.04%
==========================================
Files 240 242 +2
Lines 45399 45984 +585
Branches 39167 39752 +585
==========================================
+ Hits 36918 37413 +495
- Misses 6491 6566 +75
- Partials 1990 2005 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add two unit tests to the existing test module in hugr-llvm/src/emit/debug_info.rs that cover compilation of a HUGR with all three supported debug info record types attached: - CompileUnitRecord on the module root - SubprogramRecord on a FuncDefn - LocationRecord on an ExtensionOp Tests verify that emit_module succeeds and produces a valid LLVM module both with and without debug info emission enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Test that compilation fails when an incorrect debug info record type is attached to a node, covering all three node types: - Module root with SubprogramRecord instead of CompileUnitRecord - FuncDefn with LocationRecord instead of SubprogramRecord - ExtensionOp with SubprogramRecord instead of LocationRecord All three cases result in a deserialization error since all record types share the same metadata key. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Refactor the error path tests to start from the fully-annotated HUGR produced by build_hugr_with_all_debug_info() and only override the specific metadata entry under test, rather than rebuilding the HUGR from scratch in each test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
16cfc08 to
3376256
Compare
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
Add three tests verifying compilation fails when the JSON stored under the debug info metadata key does not match the expected schema for each of the three node types: - CompileUnitRecord on the Module root - SubprogramRecord on a FuncDefn - LocationRecord on an ExtensionOp Uses set_metadata_any with DEBUGINFO_META_KEY to inject arbitrary JSON directly, bypassing the typed setter. Adds serde_json as a dev-dependency to construct the malformed values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds end-to-end support for emitting LLVM IR debug locations derived from HUGR debug metadata, and surfaces/debugs that metadata in tooling and tests.
Changes:
- Emit LLVM debug locations for relevant ops (e.g., calls) and update IR snapshot expectations to include
!dbgattachments and module-level debug metadata. - Extend test harnesses to inject deterministic “random” debug info into existing HUGR-based tests to broaden coverage of debug emission.
- Add a debug-metadata spec/module in
hugr-coreand enable printing node-attached debug metadata viahugr mermaid -D.
Reviewed changes
Copilot reviewed 226 out of 227 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| hugr-persistent/src/trait_impls.rs | Updates persistent HUGR rendering to handle new NodeLabel variants (currently panics for MetadataKey). |
| hugr-llvm/src/test.rs | Injects random debug info into test HUGRs and enables debug emission in Emission::emit_hugr(...) calls. |
| hugr-llvm/src/extension/logic.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/int.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/float.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/conversions.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/collections/static_array.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/collections/stack_array.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/collections/list.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/collections/borrow_array.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/extension/collections/array.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/src/emit/ops.rs | Sets/unsets debug locations around call emission (direct and indirect). |
| hugr-llvm/src/emit/ops/cfg.rs | Marks test HUGRs mut to allow debug-info injection. |
| hugr-llvm/Cargo.toml | Adds rand for debug-info test helpers; adds serde_json for dev usage. |
| hugr-core/src/metadata.rs | Re-exports the new debug_info metadata module. |
| hugr-core/src/hugr/views/render.rs | Adds NodeLabel::MetadataKey to render node metadata as JSON in Mermaid output. |
| hugr-core/src/core.rs | Adds Node::from_portgraph constructor used by rendering. |
| hugr-cli/src/mermaid.rs | Adds -D/--debug-info to render node debug metadata in Mermaid output. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_unpack_tuple@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_print@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_print@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_noop@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_noop@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_make_tuple@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_make_error@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_load_nat@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_load_nat@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_const_usize@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_const_usize@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_const_external_symbol@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__prelude__test__prelude_const_external_symbol@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__xor@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__xor@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__or@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__or@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__not@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__not@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__eq@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__eq@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__and@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__logic__test__and@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_u_2_3@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_u_2_3@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_u_1_6@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_u_1_6@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_s_2_3@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_s_2_3@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_s_1_6@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iwiden_s_1_6@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__isub@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__isub@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ilt_s@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ieq@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iadd@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__iadd@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__emission@pre-mem2reg@llvm21_ineg_[2].snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__emission@llvm21_ineg_[2].snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fsub@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fsub@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fpow@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fneg@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fneg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fne@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fmul@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fmul@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__flt@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fle@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fgt@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fge@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__feq@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fdiv@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fdiv@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fadd@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fadd@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__const_float@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__const_float@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__conversions__test__itobool@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__conversions__test__ifrombool@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__conversions__test__convert_u@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__conversions__test__convert_u@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__conversions__test__convert_s@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/snapshots/hugr_llvm__extension__conversions__test__convert_s@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm21_3.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm21_2.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm21_3.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm21_2.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm21_1.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm21_0.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm21_3.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm21_2.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm21_1.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm21_0.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__list__test__push@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__list__test__length@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__list__test__const@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__list__test__const@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__borrow_array__test__emit_array_value@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__borrow_array__test__emit_array_value@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__array__test__emit_array_value@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__array__test__emit_array_value@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop_simple@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop_simple@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__load_function@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__load_function@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_tag@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_tag@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_dfg@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_dfg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_conditional@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_module_children@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_module_children@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_cfg_children@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_cfg_children@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/ops/snapshots/hugr_llvm__emit__ops__cfg__test__nested@pre-mem2reg@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/ops/snapshots/hugr_llvm__emit__ops__cfg__test__nested@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
| hugr-llvm/src/emit/ops/snapshots/hugr_llvm__emit__ops__cfg__test__diverse_outputs@llvm21.snap | Snapshot updated to include debug metadata and !dbg locations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…_with_formatter Previously, rendering a PersistentHugr with NodeLabel::MetadataKey (e.g. via `hugr mermaid -D <key>`) would panic with unimplemented!(). Since apply_all() produces a materialized Hugr that preserves node metadata, the key can simply be passed through to the extracted Hugr's formatter. Fixes: #3026 (comment) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract the inline name-unmangling logic from DebugInfoBuilder::add_di_func into a standalone free function unmangle_hugr_func_name, and add unit tests covering both the happy path (well-formed mangled names) and preservation of names not in the expected form. Also fixes a pre-existing edge-case bug: the old unwrap_or(0) fallback for the second-dot index caused single-component names (no dots) to have their first character stripped, since lpar=0 and rpar=name.len() made the slice condition true. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| /// Inspect the debug metadata attached to the HUGR node. | ||
| /// | ||
| /// If there is no debug metadata, return Ok(None). If it is present but does not | ||
| /// deserialize into `T`, return DRTypeMismatchError. Otherwise, return the deserialized | ||
| /// Some(`T`). | ||
| pub fn try_get_debug_meta< |
There was a problem hiding this comment.
Why can't we use get_metadata directly?
There was a problem hiding this comment.
I need to distinguish between the "key not present" case and the "value does not deserialize into T" case, I believe get_metadata just returns None in both cases
There was a problem hiding this comment.
I can move this into the core HugrView implementation if you'd like, as get_metadata_checked or similar.
There was a problem hiding this comment.
Yeah, let's add a
fn try_get_metadata<M: Metadata>(&self, node: Self::Node) -> Result<Option<...>, serde_json::Error>| /// Display the node index and JSON metadata for a given key. | ||
| MetadataKey(String), |
There was a problem hiding this comment.
-
Document what is the string doing here.
-
If we're printing metadata, why not print more than one entry? The python renders metadata entries one-per line. Could we have something similar? Perhaps we want a "print all entries" option and a "print these white-listed ones".
- It'd be easier to read if this used struct variants;
MetadataKey {
metadata_entries: Vec<String>,
}There was a problem hiding this comment.
Sure, I'll extend the functionality as you described.
There was a problem hiding this comment.
Actually, looks like adding the ability to enumerate the metadata map to print all entries would perturb a lot of interfaces so I won't do that. But taking a list of keys is easy.
This reverts commit 3bd16c6.
Reverted this change after further discussion with the HW compiler team |
- DEBUGINFO_META_KEY python binding - Remove Node::from_portgraph
- Remove combined str+usize parsing - Validate the `kind` field now that it is present
|
@aborgna-q review reminder |
This PR adds support for emitting LLVM IR with debug locations taken from the HUGR debug info implemented in Quantinuum/guppylang#1554.
Beyond a few basic unit tests, test coverage is extended by adding random debug info to all existing tests which use
hugr-llvm::test::emit::check_emission. This requires marking a lot of test HUGRsmutwhich were not previously so. I have also externally verified that the emitted IR compiles to a binary with debug info which supports stepping through Guppy lines inlldb.The PR also adds a Rust specification of the supported metadata in
hugr-core::metadata::debug_info, and adds support for dumping HUGR debug info usinghugr mermaid -D.Mermaid format example
Below is an example mermaid diagram with the new
MetadataValuesstyle - see the root node for an example of the style when multiple metadata keys are requested. This is just for illustration, the actual implementation ofmermaid -Ddisplays only thecore.debug_infokey.graph LR subgraph 0 ["(0) Module; core.debug_info={'directory':'file:///path/to/compile/dir','file_table':['/path/to/planqc_1.gpy.py'],'filename':0,'kind':'compile_unit'}; core.generator={'name':'guppylang (guppylang-internals-v0.33.0)','version':'0.21.12'}; core.used_extensions=[{'name':'tket.quantum','version':'0.2.1'},{'name':'prelude','version':'0.2.1'},{'name':'arithmetic.float.types','version':'0.1.0'},{'name':'tket.bool','version':'0.2.0'},{'name':'tket.result','version':'0.2.0'},{'name':'tket.rotation','version':'0.2.0'},{'name':'collections.array','version':'0.1.1'},{'name':'arithmetic.int.types','version':'0.1.0'}]"] direction LR subgraph 1 ["(1) [**FuncDefn: #quot;__main__.main#quot;**]; core.debug_info={'file':0,'kind':'subprogram','line_no':21,'scope_line':22}"] direction LR style 1 stroke:#832561,stroke-width:3px 2["(2) Input; "] 3["(3) Output; "] subgraph 4 ["(4) CFG; "] direction LR subgraph 5 ["(5) DataflowBlock; "] direction LR 6["(6) Input; "] 7["(7) Output; "] 8["(8) tket.quantum.QAlloc; core.debug_info={'column':8,'kind':'location','line_no':22}"] 9["(9) LoadConstant; "] 10["(10) const:custom:f64(1.5); "] 11["(11) prelude.MakeTuple; core.debug_info={'column':10,'kind':'location','line_no':23}"] 12["(12) Call; core.debug_info={'column':4,'kind':'location','line_no':23}"] 13["(13) prelude.MakeTuple; core.debug_info={'column':4,'kind':'location','line_no':23}"] 14["(14) tket.quantum.MeasureFree; core.debug_info={'column':16,'kind':'location','line_no':24}"] 15["(15) tket.bool.read; core.debug_info={'column':4,'kind':'location','line_no':24}"] 16["(16) tket.result.result_bool; core.debug_info={'column':4,'kind':'location','line_no':24}"] 17["(17) prelude.MakeTuple; core.debug_info={'column':4,'kind':'location','line_no':24}"] 18["(18) Tag; "] 6-."0:0".->8 8--"0:0<br>qubit"-->12 8-."1:3".->12 9--"0:0<br>float64"-->11 10--"0:0<br>float64"-->9 11--"0:1<br>[float64]"-->12 12--"0:0<br>qubit"-->14 12-."1:1".->14 14--"0:0<br>bool"-->15 14-."1:1".->16 15--"0:0<br>Bool"-->16 16-."0:1".->7 18--"0:0<br>Unit"-->7 end 19["(19) ExitBlock; "] 5-."0:0".->19 end 2-."0:0".->4 4-."0:0".->3 end subgraph 20 ["(20) FuncDefn: #quot;__main__.rx#quot;; core.debug_info={'file':0,'kind':'subprogram','line_no':12,'scope_line':14}"] direction LR 21["(21) Input; "] 22["(22) Output; "] subgraph 23 ["(23) CFG; "] direction LR subgraph 24 ["(24) DataflowBlock; "] direction LR 25["(25) Input; "] 26["(26) Output; "] 27["(27) prelude.UnpackTuple; "] 28["(28) tket.quantum.H; core.debug_info={'column':4,'kind':'location','line_no':14}"] 29["(29) prelude.MakeTuple; core.debug_info={'column':4,'kind':'location','line_no':14}"] 30["(30) prelude.MakeTuple; core.debug_info={'column':10,'kind':'location','line_no':15}"] 31["(31) prelude.UnpackTuple; core.debug_info={'column':4,'kind':'location','line_no':15}"] 32["(32) tket.rotation.from_halfturns_unchecked; core.debug_info={'column':4,'kind':'location','line_no':15}"] 33["(33) tket.quantum.Rz; core.debug_info={'column':4,'kind':'location','line_no':15}"] 34["(34) prelude.MakeTuple; core.debug_info={'column':4,'kind':'location','line_no':15}"] 35["(35) tket.quantum.H; core.debug_info={'column':4,'kind':'location','line_no':16}"] 36["(36) prelude.MakeTuple; core.debug_info={'column':4,'kind':'location','line_no':16}"] 37["(37) Tag; "] 25--"0:0<br>qubit"-->28 25--"1:0<br>[float64]"-->27 27--"0:0<br>float64"-->30 28--"0:0<br>qubit"-->33 30--"0:0<br>[float64]"-->31 31--"0:0<br>float64"-->32 32--"0:1<br>rotation"-->33 33--"0:0<br>qubit"-->35 35--"0:1<br>qubit"-->26 37--"0:0<br>Unit"-->26 end 38["(38) ExitBlock; "] 24-."0:0".->38 end 21--"0:0<br>qubit"-->23 21--"1:1<br>[float64]"-->23 23--"0:0<br>qubit"-->22 end 20--"0:2<br>[qubit, [float64]] -> [qubit]"-->12 endBREAKING CHANGE:
hugr-llvm::emit::EmitHugr::emit_hugr::emit_moduletakes two new args:emit_debug: boolandptr_size: u32. In addition,hugr_core::views::render::NodeLabelhas a new variantMetadataValueswhich combines a numeric label and JSON metadata values.Closes #2978