Skip to content

Conversation

@tatiana-s
Copy link
Contributor

@tatiana-s tatiana-s commented Aug 7, 2025

Closes #1072

BREAKING CHANGE: (guppy-internals) Arrays are now lowered to borrow_arrays instead of value_arrays so elements do no longer need to be wrapped in options during lowering.

Requires a tket2 release with CQCL/tket2#975 for the execution tests to pass Requires a hugr-llvm release for the lowering + hugr with copy discard handler + tket2 with adjustments + hugr-qis compiler with adjustments

@tatiana-s tatiana-s changed the title Use borrow_array instead of value_array for array lowering feat!: Use borrow_array instead of value_array for array lowering Sep 3, 2025
@tatiana-s tatiana-s marked this pull request as ready for review October 3, 2025 14:08
@tatiana-s tatiana-s requested a review from a team as a code owner October 3, 2025 14:08
Copy link
Contributor

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

Looks Good enough To Merge into main but must not release until #1306 is fixed.

@hugrbot
Copy link
Collaborator

hugrbot commented Oct 21, 2025

This PR contains breaking changes to the public Python API.

Breaking changes summary
guppylang-internals/src/guppylang_internals/compiler/expr_compiler.py:0: ARRAY_COMPREHENSION_INIT:
Public object was removed

guppylang-internals/src/guppylang_internals/compiler/expr_compiler.py:0: array_comprehension_init_func:
Public object was removed

guppylang-internals/src/guppylang_internals/compiler/expr_compiler.py:0: array_unwrap_elem:
Public object was removed

guppylang-internals/src/guppylang_internals/compiler/expr_compiler.py:0: array_wrap_elem:
Public object was removed

guppylang-internals/src/guppylang_internals/compiler/core.py:653: AFFINE_EXTENSION_TYS:
Attribute value was changed:
Old: [qualified_name(ARRAY_EXTENSION.get_type('array'))]
New: [qualified_name(ARRAY_EXTENSION.get_type('array')), qualified_name(BORROW_ARRAY_EXTENSION.get_type('borrow_array'))]

guppylang-internals/src/guppylang_internals/definition/parameter.py:0: TypeVarDef.must_be_copyable:
Public object was removed

guppylang-internals/src/guppylang_internals/definition/parameter.py:0: TypeVarDef.must_be_droppable:
Public object was removed

guppylang-internals/src/guppylang_internals/definition/parameter.py:0: TypeVarDef.__init__(must_be_copyable):
Parameter was removed

guppylang-internals/src/guppylang_internals/definition/parameter.py:0: TypeVarDef.__init__(must_be_droppable):
Parameter was removed

guppylang-internals/src/guppylang_internals/definition/parameter.py:0: TypeVarDef.__init__(copyable):
Parameter was added as required

guppylang-internals/src/guppylang_internals/definition/parameter.py:0: TypeVarDef.__init__(droppable):
Parameter was added as required


@github-actions
Copy link
Contributor

🐰 Bencher Report

Branchts/borrow-arrays
TestbedLinux
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_check📈 view plot
🚷 view threshold
662,023.73 µs
(-13.74%)Baseline: 767,437.81 µs
805,809.70 µs
(82.16%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,536,932.32 µs
(-51.61%)Baseline: 3,176,070.64 µs
3,334,874.17 µs
(46.09%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
7,254,392.88 µs
(-20.69%)Baseline: 9,146,336.34 µs
9,603,653.15 µs
(75.54%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
47,103.69 µs
(-31.81%)Baseline: 69,078.00 µs
72,531.90 µs
(64.94%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
83,618.05 µs
(-15.26%)Baseline: 98,676.50 µs
103,610.33 µs
(80.70%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
581,379.01 µs
(-26.20%)Baseline: 787,784.60 µs
827,173.83 µs
(70.28%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
24.23 µs
(-9.05%)Baseline: 26.64 µs
27.97 µs
(86.62%)
🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link
Contributor

🐰 Bencher Report

Branchts/borrow-arrays
TestbedLinux

🚨 2 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compilehugr_nodes
nodes x 1e3
📈 plot
🚷 threshold
🚨 alert (🔔)
6.59 x 1e3
(+33.89%)Baseline: 4.92 x 1e3
4.97 x 1e3
(132.56%)

tests/benchmarks/test_big_array.py::test_big_array_compilehugr_bytes
bytes x 1e3
📈 plot
🚷 threshold
🚨 alert (🔔)
135.90 x 1e3
(+5.14%)Baseline: 129.26 x 1e3
130.55 x 1e3
(104.10%)

Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
🚨 view alert (🔔)
135.90 x 1e3
(+5.14%)Baseline: 129.26 x 1e3
130.55 x 1e3
(104.10%)

📈 view plot
🚷 view threshold
🚨 view alert (🔔)
6,590.00
(+33.89%)Baseline: 4,922.06
4,971.28
(132.56%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
19.77 x 1e3
(-9.85%)Baseline: 21.92 x 1e3
22.14 x 1e3
(89.26%)
📈 view plot
🚷 view threshold
606.00
(-12.24%)Baseline: 690.51
697.42
(86.89%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 95.91837% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.44%. Comparing base (6990d85) to head (c1c0808).

Files with missing lines Patch % Lines
...rnals/src/guppylang_internals/definition/custom.py 87.50% 2 Missing ⚠️
.../src/guppylang_internals/compiler/expr_compiler.py 90.90% 1 Missing ⚠️
guppylang/src/guppylang/std/array.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1166      +/-   ##
==========================================
- Coverage   93.50%   93.44%   -0.06%     
==========================================
  Files         123      123              
  Lines       11522    11432      -90     
==========================================
- Hits        10774    10683      -91     
- Misses        748      749       +1     

☔ 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.

@ss2165 ss2165 added this pull request to the merge queue Oct 21, 2025
Merged via the queue into main with commit f9ef42b Oct 21, 2025
6 of 7 checks passed
@ss2165 ss2165 deleted the ts/borrow-arrays branch October 21, 2025 14:28
github-merge-queue bot pushed a commit that referenced this pull request Oct 21, 2025
github-merge-queue bot pushed a commit that referenced this pull request Oct 22, 2025
fixes #1306

The first part of the fix is to make affine-bounded type parameters
(declared `[T : Drop]`) compile to Hugr TypeParams bounded by linear
rather than Copyable; this fixes the error in the issue (invalid
instantiation of Copyable-bounded function with type-arg
`borrow_array<....>`), but raises a different problem: guppy does not
insert the necessary `drop` operations, thus leading to
`UnconnectedPort` validation errors (as the ports are now linear).

This was because the `requires_drop` function used when inserting drops
(#1090) inspects the `hugr_bound` property of type variables which also
needs updating that affine-in-guppy things should become linear-in-Hugr.
In this area, update some docs (RIP equatable), refactor using
`super()`, and standardize use of `ht` for `hugr.tys`.

Note that (contrary to python-semver-checks) this is not breaking: the
APIs removed (optional extra parameter to TypeParam, and settable
TypeParam::is_affine field) were only added in #1166, which has not yet
been released.
github-merge-queue bot pushed a commit that referenced this pull request Oct 29, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.25.0](guppylang-internals-v0.24.0...guppylang-internals-v0.25.0)
(2025-10-28)


### ⚠ BREAKING CHANGES

* (guppy-internals) Arrays are now lowered to `borrow_array`s instead of
`value_array`s so elements do no longer need to be wrapped in options
during lowering.
* `checker.core.requires_monomorphization` renamed into
`require_monomorphization` and now operating on all parameters
simultaneously `tys.subst.BoundVarFinder` removed. Instead, use the new
`bound_vars` property on types, arguments, and consts.
`tys.parsing.parse_parameter` now requires a `param_var_mapping`.

### Features

* compiler for modifiers
([#1287](#1287))
([439ff1a](439ff1a))
* modifiers in CFG and its type checker (experimental)
([#1281](#1281))
([fe85018](fe85018))
* Turn type parameters into dependent telescopes
([#1154](#1154))
([b56e056](b56e056))
* update hugr, tket-exts and tket
([#1305](#1305))
([6990d85](6990d85))
* Use `borrow_array` instead of `value_array` for array lowering
([#1166](#1166))
([f9ef42b](f9ef42b))


### Bug Fixes

* compilation of affine-bounded type variables
([#1308](#1308))
([49ecb49](49ecb49))
* Detect unsolved generic parameters even if they are unused
([#1279](#1279))
([f830db0](f830db0)),
closes [#1273](#1273)
* Fix bug in symbolic pytket circuit loading with arrays
([#1302](#1302))
([e6b90e8](e6b90e8)),
closes [#1298](#1298)
* Improve track_hugr_side_effects, adding Order edges from/to
Input/Output ([#1311](#1311))
([3c6ce7a](3c6ce7a))
* multiline loop arguments
([#1309](#1309))
([836ef72](836ef72))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Seyon Sivarajah <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Oct 30, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.21.6](guppylang-v0.21.5...guppylang-v0.21.6)
(2025-10-29)



### Features

* implement str() for PartialVector
([d85efc9](d85efc9)),
closes [#1225](#1225)
* **qsystem:** add `RNG.random_advance()`
([#1295](#1295))
([f6271a2](f6271a2))
* Use `borrow_array` instead of `value_array` for array lowering
([#1166](#1166))
([f9ef42b](f9ef42b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Seyon Sivarajah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wait to merge This PR to be merged after all dependencies are ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use borrow_array instead of value_array extension for array lowering

7 participants