Skip to content

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Mar 25, 2025

Final chapter closes #1948.

default() includes all the handlers, new_empty() does not.

acl-cqc added 30 commits March 17, 2025 19:14
@acl-cqc acl-cqc requested a review from a team as a code owner April 8, 2025 20:12
@acl-cqc acl-cqc requested review from jake-arkinstall and mark-koch and removed request for jake-arkinstall April 8, 2025 20:12
Copy link

codecov bot commented Apr 8, 2025

Codecov Report

Attention: Patch coverage is 95.92593% with 11 lines in your changes missing coverage. Please review.

Project coverage is 83.05%. Comparing base (9ad9e6d) to head (63dc9a1).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
hugr-passes/src/replace_types/handlers.rs 95.43% 4 Missing and 6 partials ⚠️
hugr-passes/src/replace_types.rs 96.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2023      +/-   ##
==========================================
- Coverage   83.31%   83.05%   -0.26%     
==========================================
  Files         217      218       +1     
  Lines       41864    41783      -81     
  Branches    38078    37961     -117     
==========================================
- Hits        34877    34703     -174     
- Misses       5033     5275     +242     
+ Partials     1954     1805     -149     
Flag Coverage Δ
python 85.40% <ø> (-0.53%) ⬇️
rust 82.81% <95.92%> (-0.24%) ⬇️

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.

Comment on lines 38 to 41
// If none of the values has changed, assume the Type hasn't (Values have a single known type)
if !ch {
return Ok(None);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this break for empty lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good spot.
list_const was originally more for checking the framework did the right thing(s) for constants, rather than being a definitive handler for lists, but given it was pub it should have been better ;-). I've fixed this, although I haven't added a test with an empty list - the array_const test does include such a case and the SUT is identical.... (I did try commoning list_const and array_const up but it needed 3 different impl Fns so was not worth it!)

Comment on lines +655 to +656
#[rstest]
fn array(#[values(2, 3, 4)] num_outports: usize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are lists constants already tested somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The loop_const does some fairly funky things with them, although is not exhaustive

@@ -0,0 +1,240 @@
//! Callbacks for use with [ReplaceTypes::replace_consts_parametrized]
//! and [ReplaceTypes::linearize_parametric]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this reference breaks the docs build?

h.signature(h.root()).unwrap().runtime_reqs.clone()
}

/// Handler for copying/discarding arrays, for use with [ReplaceTypes::linearize_parametric] of
Copy link
Contributor

Choose a reason for hiding this comment

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

Also this one

@doug-q doug-q added this to the hugr-rs 0.16 milestone Apr 15, 2025
@ss2165 ss2165 modified the milestones: hugr-rs 0.16, hugr-rs 0.15.x Apr 15, 2025
@acl-cqc acl-cqc requested a review from mark-koch April 15, 2025 12:02
@acl-cqc
Copy link
Contributor Author

acl-cqc commented Apr 15, 2025

@mark-koch added an array_const handler, fixed the bug in list_const (looks just like array, tho that case isn't tested), added a ConstTypeError variant to ReplaceTypesError (thankfully non-breaking as RTErr is non-exhaustive). Can you take another look?

Any thoughts on what to do with the handlers? I do feel including them in ReplaceTypes::default is tempting, although indeed I'm not keen on "remove handlers if you don't want them". (Why would one not want them, though - basically that's saying, you just want to break sooner and harder if you find a Hugr with lists/arrays...) Could be another method, although in which case naming is an issue (default with handlers and minimal without? default and new_with_collections? I wouldn't want to imply new_with_collections provided a complete set of handlers...)

@acl-cqc acl-cqc changed the title feat: Provide ReplaceTypes handlers for linearizing arrays feat:ReplaceTypes: handlers for array constants + linearization Apr 15, 2025
@acl-cqc acl-cqc changed the title feat:ReplaceTypes: handlers for array constants + linearization feat: ReplaceTypes: handlers for array constants + linearization Apr 15, 2025
Copy link
Contributor

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

Thanks, looks good 👍

Any thoughts on what to do with the handlers?

I think handlers for std extensions should be included in default(). Maybe ReplaceTypes::empty() to get one without any handlers?

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Apr 15, 2025

Thanks, looks good 👍

Any thoughts on what to do with the handlers?

I think handlers for std extensions should be included in default(). Maybe ReplaceTypes::empty() to get one without any handlers?

That was not quite as neat as I'd have liked, 'coz we can't get the Default-derive macro to do the work, but done.

EDIT: so, hmmm, I am considering pub fn with_std(&mut self) -> () or pub fn with_std(self) -> Self

@acl-cqc acl-cqc enabled auto-merge April 16, 2025 10:18
@acl-cqc acl-cqc added this pull request to the merge queue Apr 16, 2025
Merged via the queue into main with commit a4f5196 Apr 16, 2025
27 checks passed
@acl-cqc acl-cqc deleted the acl/lower_types_linearize_array branch April 16, 2025 10:22
@hugrbot hugrbot mentioned this pull request Apr 16, 2025
@hugrbot hugrbot mentioned this pull request Apr 28, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 7, 2025
## 🤖 New release

* `hugr-model`: 0.19.0 -> 0.19.1 (✓ API compatible changes)
* `hugr-core`: 0.15.3 -> 0.15.4 (✓ API compatible changes)
* `hugr-llvm`: 0.15.3 -> 0.15.4 (~⚠ API breaking changes~ overwriten)
* `hugr-passes`: 0.15.3 -> 0.15.4 (✓ API compatible changes)
* `hugr`: 0.15.3 -> 0.15.4 (✓ API compatible changes)
* `hugr-cli`: 0.15.3 -> 0.15.4 (✓ API compatible changes)

### ⚠ `hugr-llvm` breaking changes

```text
--- failure trait_missing: pub trait removed or renamed ---

Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_missing.ron

Failed in:
  trait hugr_llvm::utils::array_op_builder::ArrayOpBuilder, previously in file /tmp/.tmpyTFqSG/hugr-llvm/src/utils/array_op_builder.rs:10
  trait hugr_llvm::utils::ArrayOpBuilder, previously in file /tmp/.tmpyTFqSG/hugr-llvm/src/utils/array_op_builder.rs:10
```

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr-model`

<blockquote>

##
[0.19.0](hugr-model-v0.18.1...hugr-model-v0.19.0)
- 2025-04-02

### New Features

- Python bindings for `hugr-model`.
([#1959](#1959))
- Remove extension sets from `hugr-model`.
([#2031](#2031))
- Packages in `hugr-model` and envelope support.
([#2026](#2026))
- Represent order edges in `hugr-model` as metadata.
([#2027](#2027))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.16.0](hugr-core-v0.15.3...hugr-core-v0.16.0)
- 2025-04-30

### New Features

- Export the portgraph hierarchy in HugrInternals
([#2057](#2057))
- Implement Debug for generic Wire<N>s
([#2068](#2068))
- Add ExtensionOp helpers
([#2072](#2072))
- ReplaceTypes: handlers for array constants + linearization
([#2023](#2023))
- move `ArrayOpBuilder` to hugr-core
([#2115](#2115))

### Testing

- Disable IO-dependent tests when running miri
([#2123](#2123))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.16.0](hugr-llvm-v0.15.3...hugr-llvm-v0.16.0)
- 2025-04-30

### New Features

- move `ArrayOpBuilder` to hugr-core
([#2115](#2115))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.16.0](hugr-passes-v0.15.3...hugr-passes-v0.16.0)
- 2025-04-30

### New Features

- ReplaceTypes: handlers for array constants + linearization
([#2023](#2023))
</blockquote>

## `hugr`

<blockquote>

##
[0.16.0](hugr-v0.15.3...hugr-v0.16.0)
- 2025-04-30

### New Features

- Export the portgraph hierarchy in HugrInternals
([#2057](#2057))
- Implement Debug for generic Wire<N>s
([#2068](#2068))
- Add ExtensionOp helpers
([#2072](#2072))
- ReplaceTypes: handlers for array constants + linearization
([#2023](#2023))
- move `ArrayOpBuilder` to hugr-core
([#2115](#2115))

### Testing

- Disable IO-dependent tests when running miri
([#2123](#2123))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.15.3](hugr-cli-v0.15.2...hugr-cli-v0.15.3)
- 2025-04-02

### Documentation

- Add usage info to hugr-cli's rustdocs
([#2044](#2044))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: Agustín Borgna <agustin.borgna@quantinuum.com>
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.

Hugr Type Lowering
4 participants