Skip to content

[Circuit Diagrams] 1 - RIR debug metadata#2942

Merged
minestarks merged 13 commits intomainfrom
minestarks/rir-debug-metadata
Feb 25, 2026
Merged

[Circuit Diagrams] 1 - RIR debug metadata#2942
minestarks merged 13 commits intomainfrom
minestarks/rir-debug-metadata

Conversation

@minestarks
Copy link
Copy Markdown
Member

@minestarks minestarks commented Feb 12, 2026

This is part of the groundwork for supporting the visualization of classical control in circuit diagrams.

To support classical control flow (branches) in circuit diagrams, we will use the RIR representation which we will transform into a circuit. To be able to preserve source information in the circuit diagram, we first need to emit source metadata into RIR. This also sets us up nicely to potentially emit LLVM debug metadata to QIR, if ever the need arises.

  • Add a debug module to qsc_rir with structures modeled after LLVM's source-level debugging metadata (DbgLocation, DbgScope, DbgInfo). These track source offsets, callable scopes, loop body scopes (with per-iteration discriminators), and inline-at chains.
  • Rename the Instruction enum to InstructionKind and introduce a new Instruction struct that pairs an InstructionKind with optional InstructionDbgMetadata. All RIR passes, codegen, builder helpers, and tests updated accordingly.
  • During partial evaluation, populate debug metadata by tracking call site locations, callable scopes (SubProgram), and loop iteration scopes (LexicalBlockFile). Unused entries are pruned before returning the program.
  • Add PartialEvalConfig with a generate_debug_metadata flag. Enabled for fir_to_rir (used by the VS Code extension for circuit/RIR views), disabled for fir_to_qir (text QIR output).
  • Fix debug location assignment for short-circuit binary ops (&&, ||) — the continuation block now gets the correct source location.
  • New test suite in debug_metadata.rs covering gates, measurements, loops, callable inlining, and short-circuit binary ops.

@minestarks minestarks changed the title [Circuit Diagrams] RIR debug metadata [Circuit Diagrams] 1 - RIR debug metadata Feb 12, 2026
Comment thread source/compiler/qsc_partial_eval/src/tests/debug_metadata.rs Outdated
Comment thread source/compiler/qsc_partial_eval/src/tests/debug_metadata.rs
Comment thread source/compiler/qsc_partial_eval/src/lib.rs Outdated
Comment thread source/compiler/qsc_partial_eval/src/evaluation_context.rs Outdated
@minestarks minestarks marked this pull request as ready for review February 24, 2026 17:37
Comment thread source/compiler/qsc_partial_eval/src/lib.rs Outdated
Comment thread source/compiler/qsc_partial_eval/src/lib.rs Outdated
Comment thread source/compiler/qsc/src/codegen.rs Outdated
Comment thread source/compiler/qsc_partial_eval/src/lib.rs
Comment thread source/compiler/qsc_partial_eval/src/lib.rs Outdated
Comment thread source/compiler/qsc_partial_eval/src/lib.rs Outdated
Comment thread source/compiler/qsc_partial_eval/src/tests.rs
Comment thread source/compiler/qsc_frontend/src/compile.rs
Copy link
Copy Markdown
Member Author

@minestarks minestarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d

@minestarks minestarks enabled auto-merge February 25, 2026 00:53
@minestarks minestarks added this pull request to the merge queue Feb 25, 2026
Merged via the queue into main with commit 4fa10c3 Feb 25, 2026
12 checks passed
@minestarks minestarks deleted the minestarks/rir-debug-metadata branch February 25, 2026 01:10
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.

3 participants