-
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
feat: No polymorphic closures #906
Conversation
Rm nested-binder tests (cannot make such a testcase anymore) Const: generalize error in case value is a polymorphic function impl TryFrom<PolyFuncType> for FunctionType
inline apply_typevar
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #906 +/- ##
==========================================
- Coverage 85.63% 85.46% -0.18%
==========================================
Files 78 78
Lines 14444 14176 -268
Branches 14444 14176 -268
==========================================
- Hits 12369 12115 -254
+ Misses 1436 1432 -4
+ Partials 639 629 -10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
quantinuum-hugr/src/hugr/validate.rs
Outdated
|| OpTag::Function.is_superset(from_optype.tag())) | ||
{ | ||
return Err(InterGraphEdgeError::InvalidConstSrc { | ||
let reqd_optype = match typ { |
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.
TBH I think this check is more of an assertion about the spec, than something we really need to check at runtime; there is no other way to construct nodes with such out-ports, and as such I don't think it's even possible to test the error path here. So I'd be happy to remove both these checks and the relevant error variant....?
quantinuum-hugr/src/types.rs
Outdated
/// A reference to a static value definition. | ||
Static(Type), | ||
/// A reference to a static value definition - Const or Function | ||
Static(StaticEdgeData), |
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.
This is the bit I'm least sure about. The other possibility is to have two distinct EdgeKinds (i.e. one new) - ideally I'd call them Const (rather than Static) and Function, or perhaps StaticValue and StaticFunction. We even had ConstE edges in the spec at one point....
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 like Const
and Function
. I think that would make some of the code clearer, versus this hierarchy of edge types. You do comment that many statements about Static
edges in the spec apply equally to both kinds, so not entirely sure, but even so a little repetition in the spec may be a price worth paying.
specification/hugr.md
Outdated
@@ -124,7 +124,9 @@ carry an edge weight: | |||
- `Value` edges carry typed data at runtime. They have a *port* at each end, associated | |||
with the source and target nodes. They have an `AnyType`as an edge weight. | |||
- `Static` edges are similar to `Value` edges but carry static data (knowable at | |||
compilation time). They have a `CopyableType` as an edge weight. | |||
compilation time). These come in two subkinds with different edge weights: |
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.
See also https://github.com/CQCL/hugr/pull/906/files#r1549924162, although there is no requirement to go the same way in the spec as the code. However I found many references to Static edges in the spec that were true for both value and function subkinds!
quantinuum-hugr/src/hugr/validate.rs
Outdated
|| OpTag::Function.is_superset(from_optype.tag())) | ||
{ | ||
return Err(InterGraphEdgeError::InvalidConstSrc { | ||
let reqd_optype = match typ { |
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.
Yeah I agree if the error path is unreachable we should delete the check.
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.
Done!
quantinuum-hugr/src/types.rs
Outdated
/// A reference to a static value definition. | ||
Static(Type), | ||
/// A reference to a static value definition - Const or Function | ||
Static(StaticEdgeData), |
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 like Const
and Function
. I think that would make some of the code clearer, versus this hierarchy of edge types. You do comment that many statements about Static
edges in the spec apply equally to both kinds, so not entirely sure, but even so a little repetition in the spec may be a price worth paying.
specification/hugr.md
Outdated
``` | ||
|
||
Note that both TypeArgs of kind both Type and Extensions may also include variables. |
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.
Note that both TypeArgs of kind both Type and Extensions may also include variables. | |
Note that TypeArgs of kind both Type and Extensions may also include variables. |
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.
Good, but I realized these lines were just repeating the --
comments in the fragment above, so went with the comments
quite possible that test coverage wasn't there. I'm out of date on the serialization I think, tagging in @aborgna-q |
My changes only made sure that the schema we are checking against is up-to-date, but the tests remain quite spotty. @doug-q was working on adding more coverage over all serialisable hugrs. |
specification/hugr.md
Outdated
- `Static` edges are similar to `Value` edges but carry static data (knowable at | ||
compilation time). They have a `CopyableType` as an edge weight. | ||
- `Const` edges are similar to `Value` edges but carry static data (knowable at | ||
compilation time). These has as edge weight a `CopyableType`. |
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.
compilation time). These has as edge weight a `CopyableType`. | |
compilation time). These have as edge weight a `CopyableType`. |
specification/hugr.md
Outdated
* *Static* edges are the union of the `Const` and `Function` edges | ||
* *dataflow* edges are the union of `Value` and Static (thus, `Value`, `Const` and `Function`) |
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.
* *Static* edges are the union of the `Const` and `Function` edges | |
* *dataflow* edges are the union of `Value` and Static (thus, `Value`, `Const` and `Function`) | |
* *Static* edges are the union of the `Const` and `Function` edges. | |
* *Dataflow* edges are the union of `Value` and Static (thus, `Value`, `Const` and `Function`). |
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.
Yes, I guess so. Quite a few existing uses of "dataflow edges" thus also capitalized.
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.
Actually I was only suggesting to make each bullet here a full sentence, hence the capitalization. But capitalizing Dataflow more generally seems reasonable.
specification/hugr.md
Outdated
The operation declares the arguments required by the `compute_signature` function as a list | ||
of TypeParams; if this successfully returns a `Function` type, then that may then require | ||
additional TypeParams. | ||
of TypeParams; if this successfully returns a typ scheme, that may have additional TypeParams |
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.
of TypeParams; if this successfully returns a typ scheme, that may have additional TypeParams | |
of TypeParams; if this successfully returns a type scheme, that may have additional TypeParams |
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.
Ha (thank you!) - maybe I meant a tip scheme, for dividing gratuities between team members
specification/hugr.md
Outdated
| `LoadConstant` | 0, 1 | +, ✱ | 1, 0 | 0, 0 | 0, 0 | 1, 0 | | | ||
| `Input` | 0, ✱ | 0, ✱ | 0, 0 | 0, 0 | 0, 0 | 1, 0 | | | ||
| `Output` | ✱, 0 | ✱, 0 | 0, 0 | 0, 0 | 0, 0 | 1, 0 | | | ||
| `LeafOp` | ✱, ✱ | ✱, ✱ | ✱, 0 | *, 0 | 0, 0 | 1, 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.
Can a LeafOp
have Function
inputs?
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.
Good spot! At the time I wasn't really sure what a LeafOp was, and thought it might include some of the other rows such as LoadConstant or Call, hence Static: *,0
. However I now see that LeafOp should be MakeTuple, UnpackTuple, Tag, Lift, Noop and extension ops, so indeed, no Const or Function inputs or outputs. Done, thanks :-)
Thanks, Alec! I've added a new roundtrip serialization test with an op on function values, which test was passing on main but failing to satisfy the schema here; and then updated the schema so it passes. So I think everything I originally wanted to include is now in here. @aborgna-q serial_hugr.py was introduced at |
Correct. We still haven't released any new (non-alpha) version with the v1 schema, so no need to bump it. |
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 notice that the description
of PolyFuncType
is identical to that of FunctionType
. Perhaps this was a copy-and-paste error?
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.
Good spot, these were autogenerated from the python which has its own docstrings independent of the rust. I've done some updating of all of these.
## 🤖 New release * `hugr`: 0.3.0-alpha.1 -> 0.3.0-alpha.2 (⚠️ API breaking changes) ###⚠️ `hugr` breaking changes ``` --- failure enum_missing: pub enum removed or renamed --- Description: A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.30.0/src/lints/enum_missing.ron Failed in: enum hugr::ops::custom::ExternalOp, previously in file /tmp/.tmpZslYkR/hugr/src/ops/custom.rs:20 enum hugr::ops::leaf::LeafOp, previously in file /tmp/.tmpZslYkR/hugr/src/ops/leaf.rs:21 enum hugr::ops::LeafOp, previously in file /tmp/.tmpZslYkR/hugr/src/ops/leaf.rs:21 --- failure enum_variant_added: enum variant added on exhaustive enum --- Description: A publicly-visible enum without #[non_exhaustive] has a new variant. ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.30.0/src/lints/enum_variant_added.ron Failed in: variant ConstTypeError:NotMonomorphicFunction in /tmp/.tmpoZAGEw/hugr/hugr/src/ops/constant.rs:98 variant ConstTypeError:NotMonomorphicFunction in /tmp/.tmpoZAGEw/hugr/hugr/src/ops/constant.rs:98 variant SignatureError:CallIncorrectlyAppliesType in /tmp/.tmpoZAGEw/hugr/hugr/src/extension.rs:172 --- failure enum_variant_missing: pub enum variant removed or renamed --- Description: A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.30.0/src/lints/enum_variant_missing.ron Failed in: variant InterGraphEdgeError::InvalidConstSrc, previously in file /tmp/.tmpZslYkR/hugr/src/hugr/validate.rs:774 variant OpType::LeafOp, previously in file /tmp/.tmpZslYkR/hugr/src/ops.rs:30 variant SignatureError::TypeApplyIncorrectCache, previously in file /tmp/.tmpZslYkR/hugr/src/extension.rs:171 variant EdgeKind::Static, previously in file /tmp/.tmpZslYkR/hugr/src/types.rs:44 variant ConstTypeError::FunctionTypeMissing, previously in file /tmp/.tmpZslYkR/hugr/src/ops/constant.rs:99 variant ConstTypeError::FunctionTypeMissing, previously in file /tmp/.tmpZslYkR/hugr/src/ops/constant.rs:99 --- failure inherent_method_missing: pub method removed or renamed --- Description: A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.30.0/src/lints/inherent_method_missing.ron Failed in: OpType::as_leaf_op, previously in file /tmp/.tmpZslYkR/hugr/src/ops.rs:103 OpType::is_leaf_op, previously in file /tmp/.tmpZslYkR/hugr/src/ops.rs:103 --- failure method_parameter_count_changed: pub method parameter count changed --- Description: A publicly-visible method now takes a different number of parameters. ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.30.0/src/lints/method_parameter_count_changed.ron Failed in: hugr::types::PolyFuncType::validate now takes 2 parameters instead of 3, in /tmp/.tmpoZAGEw/hugr/hugr/src/types/poly_func.rs:76 --- failure struct_missing: pub struct removed or renamed --- Description: A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.30.0/src/lints/struct_missing.ron Failed in: struct hugr::ops::leaf::TypeApplication, previously in file /tmp/.tmpZslYkR/hugr/src/ops/leaf.rs:82 ``` <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## 0.3.0-alpha.2 (2024-04-15) ### Documentation - Specify direct children in `HugrView::children` ([#921](#921)) - Add logo svg to readme and spec ([#925](#925)) ### Features - [**breaking**] No polymorphic closures ([#906](#906)) - [**breaking**] Flatten `LeafOp` ([#922](#922)) ### Refactor - Combine ExtensionSolutions (no separate closure) ([#884](#884)) - [**breaking**] Merge `CustomOp` and `ExternalOp`. ([#923](#923)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/MarcoIeni/release-plz/). --------- Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Agustin Borgna <agustin.borgna@quantinuum.com>
🤖 I have created a release *beep* *boop* --- ## 0.1.0 (2024-04-15) ### ⚠ BREAKING CHANGES * Flatten `LeafOp` ([#922](#922)) * EdgeKind::{Static -> Const}, add new EdgeKind::Function, Type contains only monomorphic functions, remove TypeApply. * **py:** Rename package to `hugr` ([#913](#913)) ### Features * Flatten `LeafOp` ([#922](#922)) ([3598913](3598913)) * No polymorphic closures ([#906](#906)) ([b05dd6b](b05dd6b)) * **py:** Rename package to `hugr` ([#913](#913)) ([9fe65db](9fe65db)) --- 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: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com>
🤖 I have created a release *beep* *boop* --- ## 0.1.0 (2024-04-15) ### ⚠ BREAKING CHANGES * Flatten `LeafOp` ([#922](#922)) * EdgeKind::{Static -> Const}, add new EdgeKind::Function, Type contains only monomorphic functions, remove TypeApply. * **py:** Rename package to `hugr` ([#913](#913)) ### Features * Flatten `LeafOp` ([#922](#922)) ([3598913](3598913)) * No polymorphic closures ([#906](#906)) ([b05dd6b](b05dd6b)) * **py:** Rename package to `hugr` ([#913](#913)) ([9fe65db](9fe65db)) --- 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: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com>
impl Substitution
s except forstruct SubstValues
, which can become Substitutionfixes #904
This should enable resolving #788 and related capture/closure issues if we forbid edges into a FuncDefn from outside (@doug-q)
BREAKING CHANGE: EdgeKind::{Static -> Const}, add new EdgeKind::Function, Type contains only monomorphic functions, remove TypeApply.