Skip to content

feat: Do resolution while computing used_extensions#2834

Merged
aborgna-q merged 14 commits intomainfrom
ab/used_extensions_resolve
Jan 28, 2026
Merged

feat: Do resolution while computing used_extensions#2834
aborgna-q merged 14 commits intomainfrom
ab/used_extensions_resolve

Conversation

@aborgna-q
Copy link
Copy Markdown
Collaborator

Replaces the unpublished used_extensions methods on types and ops with an internal _resolve_used_extensions that

  • Replaces ops.Custom with ops.ExtOps and tys.Opaque with tys.ExtTypes that point to their resolved extension definition.
  • In the same traversal, collects all used extensions into a register.

This is necessary to solve Quantinuum/guppylang#1451 and Quantinuum/tket2#1368.

  • Hugr.used_extensions now has an optional resolve_from parameter.
  • Hugr.resolve_extensions has been deprecated.

@aborgna-q aborgna-q requested a review from ss2165 January 22, 2026 20:23
@aborgna-q aborgna-q requested a review from a team as a code owner January 22, 2026 20:23
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 80.41475% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.69%. Comparing base (8a8dc4b) to head (abffcdf).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
hugr-py/src/hugr/ops.py 87.34% 21 Missing ⚠️
hugr-py/src/hugr/std/collections/array.py 20.00% 12 Missing ⚠️
hugr-py/src/hugr/std/collections/borrow_array.py 20.00% 12 Missing ⚠️
hugr-py/src/hugr/std/collections/static_array.py 20.00% 12 Missing ⚠️
hugr-py/src/hugr/std/collections/list.py 60.00% 6 Missing ⚠️
hugr-py/src/hugr/hugr/base.py 76.19% 5 Missing ⚠️
hugr-py/src/hugr/package.py 66.66% 4 Missing ⚠️
hugr-py/src/hugr/tys.py 97.10% 4 Missing ⚠️
hugr-py/src/hugr/std/float.py 40.00% 3 Missing ⚠️
hugr-py/src/hugr/std/int.py 25.00% 3 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2834      +/-   ##
==========================================
+ Coverage   83.64%   83.69%   +0.04%     
==========================================
  Files         261      261              
  Lines       52842    53047     +205     
  Branches    47374    47374              
==========================================
+ Hits        44200    44397     +197     
- Misses       6253     6261       +8     
  Partials     2389     2389              
Flag Coverage Δ
python 88.27% <80.41%> (+0.29%) ⬆️

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.

@aborgna-q
Copy link
Copy Markdown
Collaborator Author

aborgna-q commented Jan 22, 2026

CI errors should be fixed by #2835

Fixed

@aborgna-q aborgna-q force-pushed the ab/used_extensions_resolve branch from d8b36d3 to 94dab1e Compare January 23, 2026 13:21
Copy link
Copy Markdown
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.

Partial review (short on time) but there is a major comment which you may want to address before an in-depth review anyway

Comment thread hugr-py/src/hugr/hugr/base.py Outdated
Comment thread hugr-py/src/hugr/hugr/base.py Outdated
op = self[node].op
# _resolve_used_extensions returns the resolved op and the extensions
resolved_op, reg = op._resolve_used_extensions(resolve_from)
if resolved_op is not op:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why the if guard, still an identity no?

Copy link
Copy Markdown
Collaborator Author

@aborgna-q aborgna-q Jan 23, 2026

Choose a reason for hiding this comment

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

Not for this case in particular, but I had if ... is not ... to avoid re-creating the frozen containers.

But I shouldn't be doing those optimizations here. I removed all those checks.

self, registry: ExtensionRegistry | None = None
) -> ExtensionRegistry:
resolved_ty, reg = self.ty._resolve_used_extensions(registry)
assert isinstance(resolved_ty, Array)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
assert isinstance(resolved_ty, Array)
assert isinstance(resolved_ty, Array), "HUGR internal error, expected resolved type to be array."

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added similar messages to all the asserts

@aborgna-q aborgna-q force-pushed the ab/used_extensions_resolve branch from 3a31e37 to e03afb4 Compare January 23, 2026 19:07
@aborgna-q aborgna-q requested a review from ss2165 January 26, 2026 12:26
Comment thread hugr-py/src/hugr/val.py
aborgna-q and others added 3 commits January 28, 2026 11:28
Co-authored-by: Seyon Sivarajah <seyon.sivarajah@quantinuum.com>
@aborgna-q aborgna-q requested a review from ss2165 January 28, 2026 13:31
Copy link
Copy Markdown
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.

🚀

@aborgna-q aborgna-q added this pull request to the merge queue Jan 28, 2026
Merged via the queue into main with commit 7aff29e Jan 28, 2026
29 checks passed
@aborgna-q aborgna-q deleted the ab/used_extensions_resolve branch January 28, 2026 14:54
github-merge-queue Bot pushed a commit that referenced this pull request Jan 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.15.1](hugr-py-v0.15.0...hugr-py-v0.15.1)
(2026-01-28)


### Features

* Add used_extensions method to Hugr
([#2817](#2817))
([0d88a43](0d88a43)),
closes [#2614](#2614)
* Do resolution while computing used_extensions
([#2834](#2834))
([7aff29e](7aff29e))
* **py:** add qualified_name method to TypeDef
([#2804](#2804))
([b2231b3](b2231b3)),
closes [#2426](#2426)


### Bug Fixes

* add register_updated function for registry for self-referential ops
([#2830](#2830))
([afba54f](afba54f)),
closes [#2829](#2829)

---
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: Agustín Borgna <agustin.borgna@quantinuum.com>
github-merge-queue Bot pushed a commit to Quantinuum/tket2 that referenced this pull request Jan 28, 2026
…#1371)

We'll need this for #1368, now that hugr is getting extension resolution
(Quantinuum/hugr#2834).
github-merge-queue Bot pushed a commit to Quantinuum/tket2 that referenced this pull request Jan 29, 2026
… passes (#1372)

Fixes #1368 by ensuring we bundle any additional extension in the
packages sent to the rust side.

- [x] Requires #1371
- [x] Requires Quantinuum/hugr#2834. ~I'm
keeping this as a draft until that patch is released.~
- [x] Requires #1379

---------

Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.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.

2 participants