Skip to content

perf!: remove bound-caching from Type, do in SumType::General instead#3022

Draft
acl-cqc wants to merge 4 commits intoacl/type_wraps_termfrom
acl/boundless_type
Draft

perf!: remove bound-caching from Type, do in SumType::General instead#3022
acl-cqc wants to merge 4 commits intoacl/type_wraps_termfrom
acl/boundless_type

Conversation

@acl-cqc
Copy link
Copy Markdown
Contributor

@acl-cqc acl-cqc commented Apr 10, 2026

Follows #2895

  • Make SumType::General store a struct, with private bound cache as well as public rows
  • TODO: hide the rows too behind accessor methods. This will require more (tedious) textual changes, but otherwise if you have a &mut GeneralSum you can update the rows without updating the bound.
  • remove bound cache in Type

BREAKING CHANGE: any match on SumType::General {rows} becomes SumType::General(GeneralSum { rows }); construct GeneralSum with ::new

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 10, 2026

Merging this PR will improve performance by 19.59%

⚠️ 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

⚡ 1 improved benchmark
✅ 28 untouched benchmarks
⏩ 6 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
construction 20.4 µs 17.1 µs +19.59%

Comparing acl/boundless_type (4ceb59e) with acl/type_wraps_term (80f1934)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 89.09091% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.31%. Comparing base (80f1934) to head (4ceb59e).

Files with missing lines Patch % Lines
hugr-core/src/types.rs 85.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##           acl/type_wraps_term    #3022      +/-   ##
=======================================================
- Coverage                81.33%   81.31%   -0.02%     
=======================================================
  Files                      239      239              
  Lines                    45271    45270       -1     
  Branches                 39039    39038       -1     
=======================================================
- Hits                     36821    36813       -8     
- Misses                    6449     6455       +6     
- Partials                  2001     2002       +1     
Flag Coverage Δ
python 88.89% <ø> (ø)
rust 80.10% <89.09%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@acl-cqc acl-cqc changed the base branch from main to acl/type_wraps_term April 10, 2026 17:09
Comment thread hugr-core/src/types.rs
SumType::General(general) => {
let changed = general.rows.transform(tr)?;
if changed {
*general = GeneralSum::new(std::mem::take(&mut general.rows));
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.

Does this need a comment to say, recompute the bound?

@hugrbot
Copy link
Copy Markdown
Collaborator

hugrbot commented Apr 10, 2026

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary
    Building hugr v0.27.0 (current)
     Built [  37.870s] (current)
   Parsing hugr v0.27.0 (current)
    Parsed [   0.005s] (current)
  Building hugr v0.27.0 (baseline)
     Built [  37.699s] (baseline)
   Parsing hugr v0.27.0 (baseline)
    Parsed [   0.005s] (baseline)
  Checking hugr v0.27.0 -> v0.27.0 (assume minor change)
   Checked [   0.013s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  77.336s] hugr
  Building hugr-cli v0.27.0 (current)
     Built [  30.790s] (current)
   Parsing hugr-cli v0.27.0 (current)
    Parsed [   0.007s] (current)
  Building hugr-cli v0.27.0 (baseline)
     Built [  30.882s] (baseline)
   Parsing hugr-cli v0.27.0 (baseline)
    Parsed [   0.007s] (baseline)
  Checking hugr-cli v0.27.0 -> v0.27.0 (assume minor change)
   Checked [   0.016s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  62.983s] hugr-cli
  Building hugr-core v0.27.0 (current)
     Built [  26.509s] (current)
   Parsing hugr-core v0.27.0 (current)
    Parsed [   0.084s] (current)
  Building hugr-core v0.27.0 (baseline)
     Built [  26.565s] (baseline)
   Parsing hugr-core v0.27.0 (baseline)
    Parsed [   0.081s] (baseline)
  Checking hugr-core v0.27.0 -> v0.27.0 (assume minor change)
   Checked [   0.224s] 196 checks: 195 pass, 1 fail, 0 warn, 56 skip

--- failure enum_struct_variant_changed_kind: An enum struct variant changed kind ---

Description:
A pub enum's struct variant with at least one pub field has changed to a different kind of enum variant, breaking access to its pub fields.
      ref: https://doc.rust-lang.org/reference/items/enumerations.html
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_struct_variant_changed_kind.ron

Failed in:
variant SumType::General in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types.rs:180

   Summary semver requires new major version: 1 major and 0 minor checks failed
  Finished [  54.304s] hugr-core
  Building hugr-llvm v0.27.0 (current)
     Built [  31.410s] (current)
   Parsing hugr-llvm v0.27.0 (current)
    Parsed [   0.012s] (current)
  Building hugr-llvm v0.27.0 (baseline)
     Built [  31.481s] (baseline)
   Parsing hugr-llvm v0.27.0 (baseline)
    Parsed [   0.012s] (baseline)
  Checking hugr-llvm v0.27.0 -> v0.27.0 (assume minor change)
   Checked [   0.040s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  64.047s] hugr-llvm
  Building hugr-model v0.27.0 (current)
     Built [  11.754s] (current)
   Parsing hugr-model v0.27.0 (current)
    Parsed [   0.016s] (current)
  Building hugr-model v0.27.0 (baseline)
     Built [  11.596s] (baseline)
   Parsing hugr-model v0.27.0 (baseline)
    Parsed [   0.016s] (baseline)
  Checking hugr-model v0.27.0 -> v0.27.0 (assume minor change)
   Checked [   0.030s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  24.399s] hugr-model
  Building hugr-persistent v0.6.0 (current)
     Built [  23.331s] (current)
   Parsing hugr-persistent v0.6.0 (current)
    Parsed [   0.008s] (current)
  Building hugr-persistent v0.6.0 (baseline)
     Built [  23.549s] (baseline)
   Parsing hugr-persistent v0.6.0 (baseline)
    Parsed [   0.008s] (baseline)
  Checking hugr-persistent v0.6.0 -> v0.6.0 (assume minor change)
   Checked [   0.014s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  47.664s] hugr-persistent

@acl-cqc acl-cqc added this to the hugr-rs 0.28.0 milestone Apr 10, 2026
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.

2 participants