Skip to content

feat: Add configuration settings to mermaid render - #3207

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

feat: Add configuration settings to mermaid render#3207
nicolaassolini-qntm wants to merge 12 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.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.82126% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.54%. Comparing base (601ee49) to head (233cff3).

Files with missing lines Patch % Lines
hugr-core/src/ops/controlflow.rs 50.00% 9 Missing ⚠️
hugr-core/src/ops/dataflow.rs 62.50% 9 Missing ⚠️
hugr-core/src/hugr/views/render.rs 89.33% 8 Missing ⚠️
hugr-core/src/ops/module.rs 60.00% 6 Missing ⚠️
hugr-core/src/hugr/views.rs 0.00% 3 Missing ⚠️
hugr-core/src/types/custom.rs 0.00% 0 Missing and 2 partials ⚠️
hugr-core/src/types/poly_func.rs 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3207      +/-   ##
==========================================
+ Coverage   81.45%   81.54%   +0.09%     
==========================================
  Files         243      243              
  Lines       47061    47449     +388     
  Branches    40702    41090     +388     
==========================================
+ Hits        38334    38693     +359     
- Misses       6725     6754      +29     
  Partials     2002     2002              
Flag Coverage Δ
python 89.25% <ø> (ø)
rust 80.35% <90.82%> (+0.11%) ⬆️

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 on lines +433 to 441
/// Return the mermaid representation of the underlying hierarchical graph
/// using the provided rendering configuration.
///
/// This method allows customizing the appearance of node labels and other
/// elements in the mermaid diagram.
fn mermaid_string_with_config(&self, config: RenderStringConfig) -> String {
self.mermaid_string_with_formatter(self.mermaid_format().with_render_string_config(config))
}

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.

Not sure if a method like this may be useful

@@ -2,7 +2,7 @@

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.

Most of the Op here contains types, not sure for which one should I change the rendering, since the information about the type is in the edge and the name is self explicable

Comment thread hugr-core/src/ops/sum.rs
Comment on lines 39 to +42

fn render_str(&self, _config: RenderStringConfig) -> String {
self.name().to_string()
}

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 it fine? should I render the types of the Type row?

@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 on lines 180 to 187
impl Display for CustomType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.id)?;
if !self.args.is_empty() {
write!(f, "(")?;
write!(f, "<")?;
crate::utils::display_list(&self.args, f)?;
write!(f, ")")?;
write!(f, ">")?;
}

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 changed it for consistency, but we can change it back

Comment on lines +433 to +440
/// Return the mermaid representation of the underlying hierarchical graph
/// using the provided rendering configuration.
///
/// This method allows customizing the appearance of node labels and other
/// elements in the mermaid diagram.
fn mermaid_string_with_config(&self, config: RenderStringConfig) -> String {
self.mermaid_string_with_formatter(self.mermaid_format().with_render_string_config(config))
}

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 dot_string() used for real in rust?

@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
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

3 participants