-
Notifications
You must be signed in to change notification settings - Fork 3
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: Lower unpacking assignment of iterables to Hugr #689
Conversation
popped_arr_ty = array_type(elem_ty, ht.BoundedNatArg(length - 1)) | ||
op = "pop_left" if from_left else "pop_right" | ||
return _instantiate_array_op( | ||
op, elem_ty, length_arg, [arr_ty], [ht.Option(elem_ty, popped_arr_ty)] |
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.
Side note: Maybe we should add an infallibe array_pop
op where we statically check that the length isn't 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.
Agree. It's not clear to me why we can't do this always, since for pop we always know the length of the array.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/unpacking #689 +/- ##
==================================================
+ Coverage 92.88% 92.93% +0.04%
==================================================
Files 68 68
Lines 7848 7902 +54
==================================================
+ Hits 7290 7344 +54
Misses 558 558 ☔ View full report in Codecov by Sentry. |
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.
Looks good. Unless there is a reason not to, I do think you should change to use _instantiate_array_op
for discard_empty
.
Is this the first time we are generating pop
ops? Can we have a test that trys to pop from an array of generic length? If so we should.
popped_arr_ty = array_type(elem_ty, ht.BoundedNatArg(length - 1)) | ||
op = "pop_left" if from_left else "pop_right" | ||
return _instantiate_array_op( | ||
op, elem_ty, length_arg, [arr_ty], [ht.Option(elem_ty, popped_arr_ty)] |
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.
Agree. It's not clear to me why we can't do this always, since for pop we always know the length of the array.
def array_discard_empty(elem_ty: ht.Type) -> ops.ExtOp: | ||
"""Returns an operation that discards an array of length zero.""" | ||
arr_ty = array_type(elem_ty, ht.BoundedNatArg(0)) | ||
return hugr.std.PRELUDE.get_op("discard_empty").instantiate( |
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 we use _instantiate_array_op
here? the extension has changed since this was written.
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 don't think so since discard_empty
doesn't take a length arg
Yes it's the first time they are emitted in Guppy. But Guppy doesn't allow you to pop if the length is generic |
Adds the Hugr lowering for #649. See #688 for the base PR that adds the checking logic