Skip to content

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jul 11, 2025

  • Add replace_parametrized_op_with and replace_op_with which allow specifying a ReplacementOptions struct
  • For now, ReplacementOptions has only one option, to allow running the linearizer on all outports of the replacement
  • Test demonstrates - of course the replacement Hugr is invalid (unconnected port) before linearization.

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 97.47899% with 3 lines in your changes missing coverage. Please review.

Project coverage is 82.59%. Comparing base (71c0e89) to head (f93fb61).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
hugr-passes/src/replace_types.rs 97.14% 0 Missing and 2 partials ⚠️
hugr-passes/src/replace_types/linearize.rs 97.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2435      +/-   ##
==========================================
+ Coverage   82.56%   82.59%   +0.03%     
==========================================
  Files         246      247       +1     
  Lines       45792    45980     +188     
  Branches    41528    41608      +80     
==========================================
+ Hits        37809    37979     +170     
- Misses       5961     5982      +21     
+ Partials     2022     2019       -3     
Flag Coverage Δ
python 91.26% <ø> (-0.25%) ⬇️
rust 81.68% <97.47%> (+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.

@acl-cqc acl-cqc requested a review from mark-koch July 14, 2025 09:48
@acl-cqc acl-cqc marked this pull request as ready for review July 14, 2025 09:48
@acl-cqc acl-cqc requested a review from a team as a code owner July 14, 2025 09:48
Comment on lines +887 to +889
// The Hugr here is invalid, so we have to pull it out manually
let mut dfb = DFGBuilder::new(Signature::new(ty.clone(), vec![])).unwrap();
let h = std::mem::take(dfb.hugr_mut());
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this feels a bit odd, however, I see your point about the explicit version becoming quite cumbersome if we want to compose stuff. Overall, the approach in this PR feels like the better way to go 👍

@acl-cqc acl-cqc changed the title feat: ReplaceTypes allows recursively running on replacements feat: ReplaceTypes allows recursively running on Op replacements Jul 15, 2025
/// This increases compositionality (in that replacements for different ops do not
/// need to account for each other), but would lead to an infinite loop if e.g.
/// changing an op for a DFG containing an instance of the same op. Also, note
/// that if the recursive processing changes the signature of the replacement,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've doc'd this gotcha, see #2442

@acl-cqc acl-cqc changed the title feat: ReplaceTypes allows recursively running on Op replacements feat: ReplaceTypes allows linearizing inside Op replacements Jul 16, 2025
@acl-cqc acl-cqc added this pull request to the merge queue Jul 16, 2025
Merged via the queue into main with commit 2e11266 Jul 16, 2025
28 checks passed
@acl-cqc acl-cqc deleted the acl/replace_recursive branch July 16, 2025 12:45
@hugrbot hugrbot mentioned this pull request Jul 16, 2025
This was referenced Jul 24, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 24, 2025
This release fixes multiple inconsistencies between the serialization
formats
and improves the error messages when loading unsupported envelopes.

We now also support nodes with up to `2^32` connections to the same port
(up from `2^16`).

---

## 🤖 New release

* `hugr-model`: 0.21.0 -> 0.22.0 (✓ API compatible changes)
* `hugr-core`: 0.21.0 -> 0.22.0 (✓ API compatible changes)
* `hugr-llvm`: 0.21.0 -> 0.22.0 (✓ API compatible changes)
* `hugr-passes`: 0.21.0 -> 0.22.0 (✓ API compatible changes)
* `hugr-persistent`: 0.1.0 -> 0.2.0 (✓ API compatible changes)
* `hugr`: 0.21.0 -> 0.22.0 (✓ API compatible changes)
* `hugr-cli`: 0.21.0 -> 0.22.0 (✓ API compatible changes)

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

## `hugr-model`

<blockquote>

##
[0.22.0](hugr-model-v0.21.0...hugr-model-v0.22.0)
- 2025-07-24

### New Features

- Names of private functions become `core.title` metadata.
([#2448](#2448))
- include generator metatada in model import and cli validate errors
([#2452](#2452))
- Version number in hugr binary format.
([#2468](#2468))
- Use semver crate for -model version, and include in docs
([#2471](#2471))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.22.0](hugr-core-v0.21.0...hugr-core-v0.22.0)
- 2025-07-24

### Bug Fixes

- Ensure SumTypes have the same json encoding in -rs and -py
([#2465](#2465))

### New Features

- Export entrypoint metadata in Python and fix bug in import
([#2434](#2434))
- Names of private functions become `core.title` metadata.
([#2448](#2448))
- [**breaking**] Use binary envelopes for operation lower_func encoding
([#2447](#2447))
- [**breaking**] Update portgraph dependency to 0.15
([#2455](#2455))
- Detect and fail on unrecognised envelope flags
([#2453](#2453))
- include generator metatada in model import and cli validate errors
([#2452](#2452))
- [**breaking**] Add `insert_region` to HugrMut
([#2463](#2463))
- Non-region entrypoints in `hugr-model`.
([#2467](#2467))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.21.0](hugr-llvm-v0.20.2...hugr-llvm-v0.21.0)
- 2025-07-09

### New Features

- [**breaking**] No nested FuncDefns (or AliasDefns)
([#2256](#2256))
- [**breaking**] Split `TypeArg::Sequence` into tuples and lists.
([#2140](#2140))
- [**breaking**] More helpful error messages in model import
([#2272](#2272))
- [**breaking**] Merge `TypeParam` and `TypeArg` into one `Term` type in
Rust ([#2309](#2309))
- Add `MakeError` op ([#2377](#2377))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.22.0](hugr-passes-v0.21.0...hugr-passes-v0.22.0)
- 2025-07-24

### New Features

- ReplaceTypes allows linearizing inside Op replacements
([#2435](#2435))
- Add pass for DFG inlining
([#2460](#2460))
</blockquote>

## `hugr-persistent`

<blockquote>

##
[0.2.0](hugr-persistent-v0.1.0...hugr-persistent-v0.2.0)
- 2025-07-24

### New Features

- [**breaking**] Update portgraph dependency to 0.15
([#2455](#2455))
</blockquote>

## `hugr`

<blockquote>

##
[0.22.0](hugr-v0.21.0...hugr-v0.22.0)
- 2025-07-24

### Bug Fixes

- Ensure SumTypes have the same json encoding in -rs and -py
([#2465](#2465))

### New Features

- ReplaceTypes allows linearizing inside Op replacements
([#2435](#2435))
- Add pass for DFG inlining
([#2460](#2460))
- Export entrypoint metadata in Python and fix bug in import
([#2434](#2434))
- Names of private functions become `core.title` metadata.
([#2448](#2448))
- [**breaking**] Use binary envelopes for operation lower_func encoding
([#2447](#2447))
- [**breaking**] Update portgraph dependency to 0.15
([#2455](#2455))
- Detect and fail on unrecognised envelope flags
([#2453](#2453))
- include generator metatada in model import and cli validate errors
([#2452](#2452))
- [**breaking**] Add `insert_region` to HugrMut
([#2463](#2463))
- Non-region entrypoints in `hugr-model`.
([#2467](#2467))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.22.0](hugr-cli-v0.21.0...hugr-cli-v0.22.0)
- 2025-07-24

### New Features

- include generator metatada in model import and cli validate errors
([#2452](#2452))
</blockquote>


</p></details>

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

---------

Co-authored-by: Agustín Borgna <[email protected]>
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