-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from 8 commits
4f3cda8
7948129
c520ece
d03d990
143e507
dd3bc4b
865ecfb
118152d
3742ddd
db6534b
e119e26
b5008f0
f319896
0aa0a30
1a5f330
a0a0cab
13d898c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,9 +392,14 @@ pub fn resolve_opaque_op( | |
r.name().clone(), | ||
)); | ||
}; | ||
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)?; | ||
// ops always require their own extensions, so we do not force OpaqueOps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ** indeed better, unless we want to make OpaqueOps automatically include such... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
// to add their extension to their signature | ||
let opaque_sig = opaque | ||
.signature | ||
.clone() | ||
.with_extension_delta(opaque.extension().clone()); | ||
if opaque_sig != ext_op.signature { | ||
return Err(CustomOpError::SignatureMismatch { | ||
extension: opaque.extension.clone(), | ||
op: def.name().clone(), | ||
|
@@ -425,6 +430,9 @@ pub enum CustomOpError { | |
stored: FunctionType, | ||
computed: FunctionType, | ||
}, | ||
/// An error in computing the signature of the ExtensionOp | ||
#[error(transparent)] | ||
SignatureError(#[from] SignatureError), | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -459,7 +467,6 @@ mod test { | |
} | ||
|
||
#[test] | ||
#[should_panic] // https://github.com/CQCL/hugr/issues/1315 | ||
fn resolve_opaque_op() { | ||
let registry = &INT_OPS_REGISTRY; | ||
let i0 = &INT_TYPES[0]; | ||
|
There was a problem hiding this comment.
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 ofCustomOpError::SignatureError
? Good move :)