-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor!: Separate Signature from FuncValueType by parametrizing Type(/Row)/etc. #1138
Conversation
…kes impl Into, update Dataflow/Ops etc.
Do PartialEq better, and conversions Lots of special cases in TypeParam removed as we can rule them out statically (switch representation - a row variable is a TypeArg::Variable not a TypeArg::Type)
0b608a5
to
825e911
Compare
53e1c4d
to
849fd35
Compare
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.
Brilliant. I admit I have not carefully re-reviewed every line, having done so multiple times in previous iterations. I have carefully reviewed all of create::types::*
. A few comments, but I recommend merging immediately.
hugr-core/src/extension/op_def.rs
Outdated
@@ -186,15 +186,21 @@ impl<T: CustomSignatureFunc + 'static> From<T> for SignatureFunc { | |||
} | |||
} | |||
|
|||
impl From<PolyFuncType> for SignatureFunc { | |||
fn from(v: PolyFuncType) -> Self { | |||
impl From<TypeSchemeRV> for SignatureFunc { |
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.
I think impl From<TypeScheme>
is missing. I think you could do all four instances with impl<T: Into<TypeSchemRV>> From<T> for SignatureFunc
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.
Rust complains, because some future type could define both Into (currently Into<PolyFuncTypeRV>
) and Into<CustomSignatureFunc>
and then it would be ambiguous...
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.
I tried impl <RV: MaybeRV> From<PolyFuncTypeBase<RV>> for SignatureFunc
but there is no conversion from PolyFuncTypeBase<RV>
(parametrized) to <RowVariable>
... I could add a .into_()
but would rather avoid that if I can...
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.
I can add the fourth (From<PolyFuncType>
) but I couldn't see a scenario where you're making an OpDef but didn't know to create a PolyFuncTypeRV
(rather than PolyFuncType
) in the first place...
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.
It's easy to add though, done
} | ||
} | ||
|
||
pub(super) fn validate( |
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.
I think this should be pub, doesn't need to be done in this PR.
hugr-core/src/types/type_param.rs
Outdated
@@ -185,7 +185,16 @@ pub enum TypeArg { | |||
|
|||
impl From<Type> for TypeArg { |
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.
I think this can be implemented as impl<RV: MaybeRV> From<TypeBase<RV>> for TypeArg
.
Can be done in later
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.
Sadly not - try_into
has a different Result type according to RV, the Err could be RowVariable
or Infallible
(the latter from a library blanket impl). Could add a impl<RV:MaybeRV> TypeBase<RV> { fn try_into_(self) -> Result<Type, RowVariable> }
I guess...
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.
I think that is slightly better, though
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.
Added try_into_type
Ok thanks @doug-q! :). I'm not touching serialization. I think it's all fine 🔥 we just don't extend the separation into the python world. (At least not yet, possibly never.) |
## 🤖 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>
TypeBase<NoRV>
(NoRV is a type with no instances) vsTypeBase<RowVariable>
(RowVariable is a struct i.e. index + bound)TypeBase<RV>
TypeRowBase<RV>
FuncTypeBase<RV>
PolyFuncTypeBase<RV>
Planning to rename PolyFuncType to (Op/Fn)TypeScheme in a followup PR (lots of fields want renaming too, whereas many FunctionType things are already called
signature
!)BREAKING CHANGE: (1) In OpDefs, Type/TypeRow/FunctionType/PolyFuncType will generally need replacing by TypeRV/TypeRowRV/FuncValueType/PolyFuncTypeRV. (2) FuncValueType omits the various numbered-"port" accessors, you really shouldn't be doing that except on a Signature.... (4) SignatureError::RowVarWhereTypeExpected now contains a RowVariable struct (including bound) rather than only the index