Skip to content

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Apr 17, 2025

There are two issues:

  • Errors. The previous NodeTemplates still always work, but the Call one can fail if the Hugr doesn't contain the target function node. ATM there is no channel for reporting that error so I've had to panic. Otherwise it's an even-more-breaking change to add an error type to NodeTemplate::add() and NodeTemplate::add_hugr(). Should we? (I note HugrMut::connect panics if the node isn't there, but could make the NodeTemplate::add builder method return a BuildError...and propagate that everywhere of course)
  • There's a big limitation in linearize_array that it'll break if the element says it should be copied/discarded via a NodeTemplate::Call, as linearize_array puts the elementwise copy/discard function into a nested Hugr (Value::Function) that won't contain the function. This could be fixed via lifting those to toplevel FuncDefns with name-mangling, but I'd rather leave that for Reduce duplication when linearizing arrays #2086 ....

BREAKING CHANGE: Add new variant NodeTemplate::Call; LinearizeError no longer derives Eq.

@acl-cqc acl-cqc changed the base branch from main to release-rs-v0.16.0 April 17, 2025 07:30
@acl-cqc acl-cqc changed the title feat! ReplaceTypes: allow lowering ops into a Call to a function already in the Hugr feat!: ReplaceTypes: allow lowering ops into a Call to a function already in the Hugr Apr 17, 2025
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 93.93939% with 12 lines in your changes missing coverage. Please review.

Project coverage is 83.30%. Comparing base (89c2680) to head (5b29b4c).
Report is 1 commits behind head on release-rs-v0.16.0.

Files with missing lines Patch % Lines
hugr-passes/src/replace_types.rs 92.53% 5 Missing and 5 partials ⚠️
hugr-passes/src/replace_types/handlers.rs 50.00% 0 Missing and 1 partial ⚠️
hugr-passes/src/replace_types/linearize.rs 98.38% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           release-rs-v0.16.0    #2094      +/-   ##
======================================================
+ Coverage               83.29%   83.30%   +0.01%     
======================================================
  Files                     219      218       -1     
  Lines                   42051    42102      +51     
  Branches                38153    38307     +154     
======================================================
+ Hits                    35026    35073      +47     
+ Misses                   5220     5218       -2     
- Partials                 1805     1811       +6     
Flag Coverage Δ
python 85.42% <ø> (-0.31%) ⬇️
rust 83.09% <93.93%> (+0.04%) ⬆️

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.

@hugrbot
Copy link
Collaborator

hugrbot commented Apr 17, 2025

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary

--- failure derive_trait_impl_removed: built-in derived trait no longer implemented ---

Description:
A public type has stopped deriving one or more traits. This can break downstream code that depends on those types implementing those traits.
      ref: https://doc.rust-lang.org/reference/attributes/derive.html#derive
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/derive_trait_impl_removed.ron

Failed in:
type LinearizeError no longer derives Eq, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-passes/src/replace_types/linearize.rs:140

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_variant_added.ron

Failed in:
variant NodeTemplate:Call in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-passes/src/replace_types.rs:51

@acl-cqc acl-cqc requested a review from ss2165 April 17, 2025 08:49
@ss2165
Copy link
Member

ss2165 commented Apr 17, 2025

  1. I think if you're breaking anyway might as well break with a proper error too (i.e. since it will have to go in a breaking release, fixing downstream is low cost)
  2. annoying edge case - document and panic on detection if possible

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Apr 21, 2025

Ok, so NodeTemplate::add_hugr already returned an error, but NodeTemplate::add needed one. And, the errors from both needed to be plumbed through ReplaceTypesError and LinearizeError.

I started trying to add my own error for add_hugr (see 5daa87b), but then realized that since I needed to plumb BuildErrors through from add I switched to just use that. The alternative would be to look for all the error cases myself (as in that linked commit, but before calling the builder) and then unwrap the builder call....nicer for our users perhaps but seems less maintainable. And I think it's a small point. But I could be arm-twisted...

@acl-cqc acl-cqc marked this pull request as ready for review April 21, 2025 12:19
@acl-cqc acl-cqc requested a review from a team as a code owner April 21, 2025 12:19
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

happy to see many unwraps go away

// TODO allow also Call to a Node in the existing Hugr
// (can't see any other way to achieve multiple calls to the same decl.
// So client should add the functions before replacement, then remove unused ones afterwards.)
/// A Call to a function (already) existing in the Hugr.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// A Call to a function (already) existing in the Hugr.
/// A Call to an existing function.

@acl-cqc acl-cqc added this to the hugr-rs 0.16 milestone Apr 23, 2025
@doug-q doug-q added the breaking-change Changes that break semver label Apr 23, 2025
@acl-cqc acl-cqc enabled auto-merge April 23, 2025 09:53
@acl-cqc acl-cqc added this pull request to the merge queue Apr 23, 2025
Merged via the queue into release-rs-v0.16.0 with commit d8a5d67 Apr 23, 2025
25 checks passed
@acl-cqc acl-cqc deleted the acl/node_tmpl_call branch April 23, 2025 10:00
aborgna-q pushed a commit that referenced this pull request May 7, 2025
…eady in the Hugr (#2094)

There are two issues:
* Errors. The previous NodeTemplates still always work, but the Call one
can fail if the Hugr doesn't contain the target function node. ATM there
is no channel for reporting that error so I've had to panic. Otherwise
it's an even-more-breaking change to add an error type to
`NodeTemplate::add()` and `NodeTemplate::add_hugr()`. Should we? (I note
`HugrMut::connect` panics if the node isn't there, but could make the
`NodeTemplate::add` builder method return a BuildError...and propagate
that everywhere of course)
* There's a big limitation in `linearize_array` that it'll break if the
*element* says it should be copied/discarded via a NodeTemplate::Call,
as `linearize_array` puts the elementwise copy/discard function into a
*nested Hugr* (`Value::Function`) that won't contain the function. This
could be fixed via lifting those to toplevel FuncDefns with
name-mangling, but I'd rather leave that for #2086 ....

BREAKING CHANGE: Add new variant NodeTemplate::Call; LinearizeError no
longer derives Eq.
This was referenced May 7, 2025
@hugrbot hugrbot mentioned this pull request May 14, 2025
This was referenced May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes that break semver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants