Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add op's extension to signature check in resolve_opaque_op #1317

Merged
merged 17 commits into from
Jul 17, 2024

Conversation

doug-q
Copy link
Collaborator

@doug-q doug-q commented Jul 16, 2024

We also remove an unsafe unwrap in resolve_opaque_op while we are here.

@doug-q doug-q requested a review from a team as a code owner July 16, 2024 13:44
@doug-q doug-q requested a review from mark-koch July 16, 2024 13:44
@doug-q doug-q changed the base branch from main to doug/test-1315 July 16, 2024 13:44
Base automatically changed from doug/test-1315 to main July 16, 2024 13:49
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 98.30508% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.46%. Comparing base (b832274) to head (13d898c).

Files Patch % Lines
hugr-core/src/ops/custom.rs 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1317      +/-   ##
==========================================
+ Coverage   87.31%   87.46%   +0.14%     
==========================================
  Files         108      107       -1     
  Lines       19784    19045     -739     
  Branches    17520    16782     -738     
==========================================
- Hits        17275    16658     -617     
+ Misses       1724     1680      -44     
+ Partials      785      707      -78     
Flag Coverage Δ
python 91.42% <100.00%> (-0.01%) ⬇️

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.

ExtensionOp::new(def.clone(), opaque.args.clone(), extension_registry).unwrap();
if opaque.signature != ext_op.signature {
let ext_op = ExtensionOp::new(def.clone(), opaque.args.clone(), extension_registry)?;
// ops always require their own extensions, so we do not force OpaqueOps
Copy link
Contributor

@acl-cqc acl-cqc Jul 16, 2024

Choose a reason for hiding this comment

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

The comment I imagined was "OpaqueOps serialized prior to PR #1226 did not include their own extension. Add it manually for backwards compatibility when deserializing such early Hugr's".

Of course, my version doesn't allow that not all OpaqueOps result from serializing known ExtensionOps - you can also write OpaqueOps out by hand with any extension delta you like. So I guess your comment is fine**, but might be worth adding Especially for backwards compatibility with Hugrs serialized before PR#1226, say.

** indeed better, unless we want to make OpaqueOps automatically include such...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added some comments, see what you think. I think it's better for OpaqueOps not to include their extension in their serialised signature, just for smaller serialisation. I haven't made that change.

let ext_op =
ExtensionOp::new(def.clone(), opaque.args.clone(), extension_registry).unwrap();
if opaque.signature != ext_op.signature {
let ext_op = ExtensionOp::new(def.clone(), opaque.args.clone(), extension_registry)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

The change from unwrap to ? here necessitates the addition of CustomOpError::SignatureError? Good move :)

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 to me, thanks @doug-q

@doug-q doug-q requested a review from acl-cqc July 17, 2024 07:00
@doug-q
Copy link
Collaborator Author

doug-q commented Jul 17, 2024

I've reworked my approach, which uncovered two test failures which I have fixed. I have also, perhaps controversially, reverted #1303

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.

Yes, I think the adding in OpaqueOp is a good approach :)

hugr-core/src/ops/custom.rs Outdated Show resolved Hide resolved
FLOAT_T = tys.Opaque(
extension=FLOAT_EXT_ID,
extension="arithmetic.float.types",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: don't really see any need to revert here

unknown_ext.clone(),
)
.unwrap();
let mut case1 = cond.case_builder(0).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ? -> unwrap everywhere? It does make things a lot longer and look like you are changing more than you are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unwrap is much better than ? in tests because you get a src location on failure. I changed them all to be able to fix the test and thought I might as well leave it in a debuggable state.

@doug-q doug-q enabled auto-merge July 17, 2024 11:57
@doug-q doug-q added this pull request to the merge queue Jul 17, 2024
Merged via the queue into main with commit 01da7ba Jul 17, 2024
22 checks passed
@doug-q doug-q deleted the doug/resolve_opaque_op branch July 17, 2024 12:00
This was referenced Jul 17, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 19, 2024
## 🤖 New release
* `hugr`: 0.8.0 -> 0.9.0
* `hugr-core`: 0.5.0 -> 0.6.0
* `hugr-passes`: 0.5.0 -> 0.6.0
* `hugr-cli`: 0.1.4 -> 0.2.0

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

## `hugr`
<blockquote>

## 0.9.0 (2024-07-19)

### Bug Fixes

- Add op's extension to signature check in `resolve_opaque_op`
([#1317](#1317))
- Panic on `SimpleReplace` with multiports
([#1324](#1324))

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))

### Testing

- Verify order edges ([#1293](#1293))
- Add failing test case for
[#1315](#1315)
([#1316](#1316))
</blockquote>

## `hugr-core`
<blockquote>

## 0.6.0 (2024-07-19)

### Bug Fixes

- Add op's extension to signature check in `resolve_opaque_op`
([#1317](#1317))
- Panic on `SimpleReplace` with multiports
([#1324](#1324))

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))

### Testing

- Verify order edges ([#1293](#1293))
- Add failing test case for
[#1315](#1315)
([#1316](#1316))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.6.0 (2024-07-19)

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))
</blockquote>

## `hugr-cli`
<blockquote>

## 0.2.0 (2024-07-19)

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))
</blockquote>


</p></details>

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

---------

Co-authored-by: Douglas Wilson <douglas.wilson@quantinuum.com>
github-merge-queue bot pushed a commit that referenced this pull request Jul 29, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.5.0](hugr-py-v0.4.0...hugr-py-v0.5.0)
(2024-07-29)


### ⚠ BREAKING CHANGES

* Eq type bound removed. References to `Eq` in serialized HUGRs will be
treated as `Copyable`.
* **hugr-core:** All Hugrs serialised with earlier versions will fail to
deserialise
* opaque type parameters replaced with string parameters.

### Features

* **hugr-py:** `AsCustomOp` protocol for user-defined custom op types.
([#1290](#1290))
([1db43eb](1db43eb))
* remove the `Eq` type bound.
([#1364](#1364))
([1218d21](1218d21))
* replace opaque type arguments with String
([#1328](#1328))
([24b2217](24b2217)),
closes [#1308](#1308)
* Serialization upgrade path
([#1327](#1327))
([d493139](d493139))


### Bug Fixes

* add op's extension to signature check in `resolve_opaque_op`
([#1317](#1317))
([01da7ba](01da7ba))
* **hugr-core:** bump serialisation version with no upgrade path
([#1352](#1352))
([657cbb0](657cbb0))
* **hugr-py:** ops require their own extensions
([#1303](#1303))
([026bfcb](026bfcb)),
closes [#1301](#1301)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

resolve_opaque_op fails when OpaqueOp does not explicitly require it's own extension.
2 participants