Skip to content

feat: Add configuration settings to mermaid render - #3207

Open
nicolaassolini-qntm wants to merge 15 commits into
mainfrom
na/3001-render-ext-ver-mermaid
Open

nicolaassolini-qntm wants to merge 15 commits into
mainfrom
na/3001-render-ext-ver-mermaid

Conversation

@nicolaassolini-qntm

@nicolaassolini-qntm nicolaassolini-qntm commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

closes #3001
by updating the mermaid rendering.

This PR allows you to decide when to print the qualified name, extension version and type arguments of nodes and edges during mermaid rendering.

This PR also deprecate fn dot_string in HugrView

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.17568% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.97%. Comparing base (cf16d6f) to head (e9a9ef7).

Files with missing lines Patch % Lines
hugr-core/src/hugr/views/rerooted.rs 46.87% 17 Missing ⚠️
hugr-core/src/hugr/views/render.rs 88.23% 16 Missing ⚠️
hugr-core/src/ops/dataflow.rs 57.69% 11 Missing ⚠️
hugr-core/src/ops/controlflow.rs 50.00% 9 Missing ⚠️
hugr-core/src/types/custom.rs 79.48% 0 Missing and 8 partials ⚠️
hugr-core/src/ops/module.rs 60.00% 6 Missing ⚠️
hugr-core/src/ops.rs 0.00% 2 Missing ⚠️
hugr-core/src/types/poly_func.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3207      +/-   ##
==========================================
+ Coverage   81.87%   81.97%   +0.09%     
==========================================
  Files         242      242              
  Lines       46824    47335     +511     
  Branches    40417    40928     +511     
==========================================
+ Hits        38336    38801     +465     
- Misses       6594     6638      +44     
- Partials     1894     1896       +2     
Flag Coverage Δ
python 89.38% <ø> (ø)
rust 80.81% <88.17%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicolaassolini-qntm nicolaassolini-qntm changed the title draft render ext ver mermaid feat: Add configuration settings to mermaid render Aug 13, 2026
Comment thread hugr-core/src/hugr/views.rs Outdated
Comment thread hugr-core/src/ops/dataflow.rs
Comment thread hugr-core/src/ops/sum.rs
@hugrbot

hugrbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

This PR contains breaking changes to the public Rust API.
Please deprecate the old API instead (if possible), or mark the PR with a ! to indicate a breaking change.

cargo-semver-checks summary
    Building hugr v0.29.3 (current)
     Built [  41.463s] (current)
   Parsing hugr v0.29.3 (current)
    Parsed [   0.004s] (current)
  Building hugr v0.29.3 (baseline)
     Built [  38.853s] (baseline)
   Parsing hugr v0.29.3 (baseline)
    Parsed [   0.004s] (baseline)
  Checking hugr v0.29.3 -> v0.29.3 (assume minor change)
   Checked [   0.012s] 196 checks: 196 pass, 58 skip
   Summary no semver update required
  Finished [  82.031s] hugr
  Building hugr-cli v0.29.3 (current)
     Built [  32.342s] (current)
   Parsing hugr-cli v0.29.3 (current)
    Parsed [   0.006s] (current)
  Building hugr-cli v0.29.3 (baseline)
     Built [  31.080s] (baseline)
   Parsing hugr-cli v0.29.3 (baseline)
    Parsed [   0.006s] (baseline)
  Checking hugr-cli v0.29.3 -> v0.29.3 (assume minor change)
   Checked [   0.016s] 196 checks: 196 pass, 58 skip
   Summary no semver update required
  Finished [  64.424s] hugr-cli
  Building hugr-core v0.29.3 (current)
     Built [  27.511s] (current)
   Parsing hugr-core v0.29.3 (current)
    Parsed [   0.089s] (current)
  Building hugr-core v0.29.3 (baseline)
     Built [  27.919s] (baseline)
   Parsing hugr-core v0.29.3 (baseline)
    Parsed [   0.079s] (baseline)
  Checking hugr-core v0.29.3 -> v0.29.3 (assume minor change)
   Checked [   0.238s] 196 checks: 195 pass, 1 fail, 0 warn, 58 skip

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/trait_method_added.ron

Failed in:
trait method hugr_core::ops::OpTrait::render_str in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops.rs:569
trait method hugr_core::ops::dataflow::DataflowOpTrait::render_str in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/dataflow.rs:26
trait method hugr_core::ops::DataflowOpTrait::render_str in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/dataflow.rs:26

   Summary semver requires new major version: 1 major and 0 minor checks failed
  Finished [  56.620s] hugr-core
  Building hugr-llvm v0.29.3 (current)
     Built [  33.152s] (current)
   Parsing hugr-llvm v0.29.3 (current)
    Parsed [   0.012s] (current)
  Building hugr-llvm v0.29.3 (baseline)
     Built [  33.231s] (baseline)
   Parsing hugr-llvm v0.29.3 (baseline)
    Parsed [   0.012s] (baseline)
  Checking hugr-llvm v0.29.3 -> v0.29.3 (assume minor change)
   Checked [   0.042s] 196 checks: 196 pass, 58 skip
   Summary no semver update required
  Finished [  67.347s] hugr-llvm
  Building hugr-model v0.29.3 (current)
     Built [  12.289s] (current)
   Parsing hugr-model v0.29.3 (current)
    Parsed [   0.017s] (current)
  Building hugr-model v0.29.3 (baseline)
     Built [  12.117s] (baseline)
   Parsing hugr-model v0.29.3 (baseline)
    Parsed [   0.016s] (baseline)
  Checking hugr-model v0.29.3 -> v0.29.3 (assume minor change)
   Checked [   0.031s] 196 checks: 196 pass, 58 skip
   Summary no semver update required
  Finished [  24.933s] hugr-model
  Building hugr-persistent v0.7.7 (current)
     Built [  25.313s] (current)
   Parsing hugr-persistent v0.7.7 (current)
    Parsed [   0.008s] (current)
  Building hugr-persistent v0.7.7 (baseline)
     Built [  25.421s] (baseline)
   Parsing hugr-persistent v0.7.7 (baseline)
    Parsed [   0.008s] (baseline)
  Checking hugr-persistent v0.7.7 -> v0.7.7 (assume minor change)
   Checked [   0.014s] 196 checks: 196 pass, 58 skip
   Summary no semver update required
  Finished [  51.494s] hugr-persistent

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a configurable string-rendering pathway for HUGR operations and types, and wires that configuration into Mermaid (and partially into dot) graph rendering so callers can control whether node/edge labels include qualified names, extension versions, and type arguments.

Changes:

  • Add RenderStringConfig and new render_str(...) APIs across ops/types to support configurable string rendering.
  • Update Mermaid rendering to use render_str(...) for node and edge labels, and expose mermaid_string_with_config(...) for callers.
  • Update/add tests and snapshots to reflect the new rendering behavior.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
hugr-persistent/src/trait_impls.rs Propagates Mermaid render-string configuration into persistent HUGR view config.
hugr-core/src/types/type_row.rs Extends TypeRowLike with config-driven render_str(...) and implements it for rows.
hugr-core/src/types/type_param.rs Adds config-driven Term::render_str(...) and tests for nested/composite term rendering.
hugr-core/src/types/poly_func.rs Adds config-driven PolyFuncTypeBase::render_str(...) and a propagation test.
hugr-core/src/types/custom.rs Changes CustomType Display formatting for type arguments.
hugr-core/src/types.rs Adds Type::render_str(...) convenience wrapper.
hugr-core/src/ops/sum.rs Adds render_str(...) for Tag op under the new rendering trait.
hugr-core/src/ops/module.rs Adds render_str(...) implementations for module-related ops (Module, FuncDefn, etc.).
hugr-core/src/ops/dataflow.rs Adds render_str(...) to DataflowOpTrait and forwards through OpTrait.
hugr-core/src/ops/custom.rs Implements config-driven rendering for extension and opaque ops, including version/type-arg handling and tests.
hugr-core/src/ops/controlflow.rs Adds render_str(...) implementations for controlflow ops and blocks.
hugr-core/src/ops/constant.rs Adds render_str(...) implementation for constants.
hugr-core/src/ops.rs Introduces RenderStringConfig and adds render_str(...) requirement to OpTrait.
hugr-core/src/hugr/views/render.rs Wires RenderStringConfig into Mermaid node/edge label rendering; adds formatter option + test.
hugr-core/src/hugr/views.rs Adds mermaid_string_with_config(...) to expose configurable Mermaid rendering.
hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap Updates Mermaid snapshot output to match new default label rendering.
hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap Updates dot snapshot output to match new default node label rendering.
hugr-core/src/hugr/views/root_checked/snapshots/hugr_core__hugr__views__root_checked__dfg__test__map_io_cycle_3qb.snap Updates root-checked Mermaid snapshot output for new node labels.
hugr-core/src/hugr/views/root_checked/snapshots/hugr_core__hugr__views__root_checked__dfg__test__map_io_cx_gate.snap Updates root-checked Mermaid snapshot output for new node labels.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread hugr-core/src/types/type_param.rs Outdated
Comment thread hugr-core/src/hugr/views/render.rs
Comment thread hugr-core/src/types/custom.rs Outdated
Comment thread hugr-core/src/hugr/views.rs Outdated
@nicolaassolini-qntm
nicolaassolini-qntm marked this pull request as ready for review August 14, 2026 09:20
@nicolaassolini-qntm
nicolaassolini-qntm requested a review from a team as a code owner August 14, 2026 09:20
@codspeed-hq

codspeed-hq Bot commented Sep 2, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 8.17%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 3 improved benchmarks
✅ 40 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
serialization/big_hugr/1048576/sexpr/without_extensions/decode 28.6 ms 26.2 ms +9.26%
serialization/big_hugr/1048576/sexpr/with_extensions/decode 28.7 ms 26.3 ms +9.22%
insert_view_forest 86.8 µs 81.9 µs +6.06%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing na/3001-render-ext-ver-mermaid (e9a9ef7) with main (cf16d6f)

Open in CodSpeed

@aborgna-q aborgna-q left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add some ```mermaid examples to the main comment?

Comment thread hugr-core/src/ops.rs Outdated
Comment thread hugr-core/src/ops.rs Outdated
/// Returns a string representation of this term.
///
/// Composite terms recursively render each of their nested terms.
pub fn render_str(&self, config: RenderStringConfig) -> String {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some of this should be dispatched to the internal structs instead.

We have Display impls for SumType, CustomType, etc. that do almost-but-not-quite the same logic.
Those could be either merged, or at least put the impls beside each other.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changes done:

  • Custom type logic moved in CustomType.render_str and unified with the display logic
  • Sum type logic moved in SumType.render_str and unified with the display logic
  • FuncTypeBase I didnt move out the logic since it is simple (potentially we can)

Comment thread hugr-core/src/types/poly_func.rs Outdated
/// Render the polymorphic function type using the supplied configuration.
pub fn render_str(&self, config: RenderStringConfig) -> String {
let params = if self.params.is_empty() {
Cow::Borrowed("")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why the cow? Seems like a &str would be enough here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

display_params use Cow too, should I change?

Comment thread hugr-core/src/ops/sum.rs
Comment thread hugr-core/src/hugr/views.rs Outdated
Comment thread hugr-core/src/hugr/views.rs Outdated
Comment thread hugr-core/src/hugr/views/render.rs Outdated
Comment thread hugr-core/src/ops.rs Outdated
"Opaque operation"
}

fn render_str(&self, config: RenderStringConfig) -> String {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Before we prepended OpaqueOp: to the name.
OpaqueOps shouldn't appear on user hugrs, so it's nice to have the explicit marker to differentiate them from ExtensionOp.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is ok without space?


/// Configuration for rendering an operation as a string.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RenderStringConfig {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved the class here, also refactor a bit the definition, now the fields are private

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.

[Feature] Render extension version for ops

4 participants