Skip to content

fix: two problems in array linearization from #2749#2779

Merged
acl-cqc merged 5 commits intomainfrom
acl/fix_linearization
Dec 29, 2025
Merged

fix: two problems in array linearization from #2749#2779
acl-cqc merged 5 commits intomainfrom
acl/fix_linearization

Conversation

@acl-cqc
Copy link
Copy Markdown
Contributor

@acl-cqc acl-cqc commented Dec 23, 2025

#2749 suffered from poor test coverage, and although I thought I had run the guppy test suite using a modified selene-hugr-qis-compiler I failed to reveal the first bug here (and the rest were not covered by the guppy test suite of the time).

  • Avoid generating polymorphic __unwrap and __mk_none helper functions; ReplaceTypes generally runs after monomorphization so this avoids needing to rerun the latter.
  • copy_scan_func_name did not depend on the size of the array, yet the generated helper function took and returned an array (of options, plus an index) - this means linking raises a conflicting-signature error if you are linearizing copies of two different-size arrays of the same element type
  • add test of the latter

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.72%. Comparing base (d996690) to head (180f020).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-passes/src/replace_types/linearize.rs 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2779      +/-   ##
==========================================
+ Coverage   83.44%   83.72%   +0.27%     
==========================================
  Files         263      263              
  Lines       52734    52725       -9     
  Branches    47490    47481       -9     
==========================================
+ Hits        44005    44144     +139     
+ Misses       6342     6192     -150     
- Partials     2387     2389       +2     
Flag Coverage Δ
python 88.82% <ø> (ø)
rust 83.16% <88.88%> (+0.30%) ⬆️

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 marked this pull request as ready for review December 24, 2025 11:51
@acl-cqc acl-cqc requested a review from a team as a code owner December 24, 2025 11:51
@acl-cqc acl-cqc changed the title fix: two problems in array linearization fix: two problems in array linearization fro #2749 Dec 24, 2025
@acl-cqc acl-cqc changed the title fix: two problems in array linearization fro #2749 fix: two problems in array linearization from #2749 Dec 29, 2025
@acl-cqc acl-cqc enabled auto-merge December 29, 2025 13:37
@acl-cqc acl-cqc added this pull request to the merge queue Dec 29, 2025
Merged via the queue into main with commit d55afde Dec 29, 2025
34 checks passed
@acl-cqc acl-cqc deleted the acl/fix_linearization branch December 29, 2025 14:11
@hugrbot hugrbot mentioned this pull request Dec 23, 2025
github-merge-queue bot pushed a commit that referenced this pull request Dec 29, 2025
## 🤖 New release

* `hugr-model`: 0.25.0 -> 0.25.1 (✓ API compatible changes)
* `hugr-core`: 0.25.0 -> 0.25.1 (✓ API compatible changes)
* `hugr-llvm`: 0.25.0 -> 0.25.1 (✓ API compatible changes)
* `hugr-passes`: 0.25.0 -> 0.25.1 (✓ API compatible changes)
* `hugr-persistent`: 0.4.0 -> 0.4.1 (✓ API compatible changes)
* `hugr`: 0.25.0 -> 0.25.1 (✓ API compatible changes)
* `hugr-cli`: 0.25.0 -> 0.25.1

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

## `hugr-model`

<blockquote>

##
[0.25.0](hugr-model-v0.24.3...hugr-model-v0.25.0)
- 2025-12-22

### Bug Fixes

- *(model)* avoid non abi-compatible pyo3 calls
([#2679](#2679))

### New Features

- [**breaking**] Upgrade pyo3 dependency to 0.27
([#2736](#2736))

### Refactor

- Direct import of model representation to Python
([#2683](#2683))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.25.0](hugr-core-v0.24.3...hugr-core-v0.25.0)
- 2025-12-22

### Bug Fixes

- *(hugr-core)* [**breaking**] Return error instead of panicking in
`MakeRegisteredOp::to_extension_op()`
([#2701](#2701))
- register packaged extensions before model_ast import
([#2702](#2702))
- ModuleGraph misses static edges to non-container entrypoints
([#2745](#2745))

### New Features

- return description output to python on error
([#2681](#2681))
- add hugr-core StaticGraph, deprecate hugr-passes CallGraph
([#2698](#2698))
- [**breaking**] Remove `RootCheckable`
([#2704](#2704))
- Add method to link Hugr modules (linking pt3)
([#2529](#2529))
- `insert_link_hugr` adds entrypoint subtree and links, with
reachability ([#2555](#2555))
- [**breaking**] Upgrade pyo3 dependency to 0.27
([#2736](#2736))
- [**breaking**] Bump MSRV to Rust 1.89
([#2747](#2747))
- [**breaking**] Allow disconnecting specific edges in a hugr
([#2737](#2737))
- Optype iterators over value ports
([#2738](#2738))
- [**breaking**] Type-safe access for node metadata
([#2755](#2755))
- [**breaking**] GeneratorDesc metadata definition
([#2759](#2759))

### Refactor

- [**breaking**] move envelope reading to dedicated module with
dedicated errors ([#2689](#2689))
- Direct import of model representation to Python
([#2683](#2683))
- *(linking.rs)* [**breaking**] (tiny) avoid type_complexity
([#2721](#2721))
- [**breaking**] Remove multiple deprecated definitions
([#2751](#2751))
- [**breaking**] Delete ValueArray
([#2760](#2760))
- Deprecate Value::Function and inline_constant_functions
([#2770](#2770))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.25.0](hugr-llvm-v0.24.3...hugr-llvm-v0.25.0)
- 2025-12-22

### New Features

- *(llvm)* [**breaking**] upgrade to inkwell 0.7
([#2695](#2695))

### Refactor

- Deprecate Value::Function and inline_constant_functions
([#2770](#2770))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.25.1](hugr-passes-v0.25.0...hugr-passes-v0.25.1)
- 2025-12-29

### Bug Fixes

- two problems in array linearization from #2749
([#2779](#2779))
</blockquote>

## `hugr-persistent`

<blockquote>

##
[0.4.0](hugr-persistent-v0.3.4...hugr-persistent-v0.4.0)
- 2025-12-22

### New Features

- [**breaking**] Remove `RootCheckable`
([#2704](#2704))
- [**breaking**] Bump MSRV to Rust 1.89
([#2747](#2747))
- [**breaking**] Type-safe access for node metadata
([#2755](#2755))

### Refactor

- [**breaking**] Remove multiple deprecated definitions
([#2751](#2751))
</blockquote>

## `hugr`

<blockquote>

##
[0.25.1](hugr-v0.25.0...hugr-v0.25.1)
- 2025-12-29

### Bug Fixes

- two problems in array linearization from #2749
([#2779](#2779))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.25.0](hugr-cli-v0.24.3...hugr-cli-v0.25.0)
- 2025-12-22

### New Features

- *(cli, python)* programmatic interface to cli with python bindings
([#2677](#2677))
- return description output to python on error
([#2681](#2681))
- [**breaking**] Type-safe access for node metadata
([#2755](#2755))
- [**breaking**] GeneratorDesc metadata definition
([#2759](#2759))

### Refactor

- [**breaking**] move envelope reading to dedicated module with
dedicated errors ([#2689](#2689))
- *(cli)* [**breaking**] remove deprecated hugr_json handling
([#2690](#2690))
- [**breaking**] Remove multiple deprecated definitions
([#2751](#2751))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
@hugrbot hugrbot mentioned this pull request Dec 30, 2025
github-merge-queue bot pushed a commit to Quantinuum/guppylang that referenced this pull request Dec 30, 2025
This odd `guppy.comptime` + `result` combo seems to invoke the
BorrowArray *copying* handler in a way that I haven't managed to
otherwise.

The two calls with different-length arrays caused linking problems
following https:://github.com/Quantinuum/hugr/pull/2749, fixed in
https:://github.com/Quantinuum/hugr/pull/2779.

Note, all testing was based on guppylang 0.21.6, I realize there has
been a 0.21.7 since but the testing was quite a faff so I will not
repeat it unless you think there is reason guppy compilation may have
changed....
github-merge-queue bot pushed a commit that referenced this pull request Dec 30, 2025
## 🤖 New release

* `hugr-model`: 0.25.1 -> 0.25.2
* `hugr-core`: 0.25.1 -> 0.25.2 (✓ API compatible changes)
* `hugr-llvm`: 0.25.1 -> 0.25.2
* `hugr-passes`: 0.25.1 -> 0.25.2
* `hugr`: 0.25.1 -> 0.25.2 (✓ API compatible changes)
* `hugr-cli`: 0.25.1 -> 0.25.2
* `hugr-persistent`: 0.4.1 -> 0.4.2

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

## `hugr-model`

<blockquote>

##
[0.25.0](hugr-model-v0.24.3...hugr-model-v0.25.0)
- 2025-12-22

### Bug Fixes

- *(model)* avoid non abi-compatible pyo3 calls
([#2679](#2679))

### New Features

- [**breaking**] Upgrade pyo3 dependency to 0.27
([#2736](#2736))

### Refactor

- Direct import of model representation to Python
([#2683](#2683))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.25.2](hugr-core-v0.25.1...hugr-core-v0.25.2)
- 2025-12-30

### Bug Fixes

- *(determinism)* use BTreeMap in ModuleGraph
([#2783](#2783))

### New Features

- Re-export hugr_core::hugr::linking from hugr::
([#2781](#2781))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.25.0](hugr-llvm-v0.24.3...hugr-llvm-v0.25.0)
- 2025-12-22

### New Features

- *(llvm)* [**breaking**] upgrade to inkwell 0.7
([#2695](#2695))

### Refactor

- Deprecate Value::Function and inline_constant_functions
([#2770](#2770))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.25.1](hugr-passes-v0.25.0...hugr-passes-v0.25.1)
- 2025-12-29

### Bug Fixes

- two problems in array linearization from #2749
([#2779](#2779))
</blockquote>

## `hugr`

<blockquote>

##
[0.25.2](hugr-v0.25.1...hugr-v0.25.2)
- 2025-12-30

### Bug Fixes

- *(determinism)* use BTreeMap in ModuleGraph
([#2783](#2783))

### New Features

- Re-export hugr_core::hugr::linking from hugr::
([#2781](#2781))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.25.0](hugr-cli-v0.24.3...hugr-cli-v0.25.0)
- 2025-12-22

### New Features

- *(cli, python)* programmatic interface to cli with python bindings
([#2677](#2677))
- return description output to python on error
([#2681](#2681))
- [**breaking**] Type-safe access for node metadata
([#2755](#2755))
- [**breaking**] GeneratorDesc metadata definition
([#2759](#2759))

### Refactor

- [**breaking**] move envelope reading to dedicated module with
dedicated errors ([#2689](#2689))
- *(cli)* [**breaking**] remove deprecated hugr_json handling
([#2690](#2690))
- [**breaking**] Remove multiple deprecated definitions
([#2751](#2751))
</blockquote>

## `hugr-persistent`

<blockquote>

##
[0.4.0](hugr-persistent-v0.3.4...hugr-persistent-v0.4.0)
- 2025-12-22

### New Features

- [**breaking**] Remove `RootCheckable`
([#2704](#2704))
- [**breaking**] Bump MSRV to Rust 1.89
([#2747](#2747))
- [**breaking**] Type-safe access for node metadata
([#2755](#2755))

### Refactor

- [**breaking**] Remove multiple deprecated definitions
([#2751](#2751))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
@hugrbot hugrbot mentioned this pull request Jan 6, 2026
github-merge-queue bot pushed a commit to Quantinuum/tket2 that referenced this pull request Jan 6, 2026
So following #1325 I was finally able to (/finally succeeded) in
evaluating the effect of Quantinuum/hugr#2749 on
guppy tests. (There was some question on that PR as to whether we needed
to add new facility, see #2766; here is the data.)

Three tests were affected (indeed the same ones as were broken and then
fixed by Quantinuum/hugr#2779 but that is a
separate issue). The sizes of the LLVM output as follows:

| | Original (hugr 0.24.3) | Hugr
0.25+[fix](Quantinuum/hugr#2779) | Hugr
0.25+[fix](Quantinuum/hugr#2779) + this PR |
|----|----|----|----|
| [new test](Quantinuum/guppylang#1411) | 9568 |
11856 | 9888 |
| basic_type | 10224 | 11616 | 10400 |
| notebook2 | 15680 | 17184 | 15936 |
| notebook5 (Hugr 1) | 10832 | 12304 | 11072 |
| notebook5 (Hugr 2) | 10480 | 11840 | 10656 |

Inspection of the hugrs in the middle row revealed the helper functions
from Quantinuum/hugr#2749 were indeed present in
the LLVM output as `define` (not `define private`). Hence, this PR,
following which LLVM is able to remove the `define`s. (I have not looked
into the remaining +2-3% increase. (The numbers include many other
changes between hugr-0.24.3 and hugr-0.25.0.)
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.

3 participants