-
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: Update linearity checker to use new diagnostics #601
Conversation
| ^ Variable `q` with linear type `qubit` would be consumed | ||
| multiple times when | ||
| evaluating this | ||
| comprehension |
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 a formatting bug. See #602
node.value, ty = self._synth_expr(node.value) | ||
if ty.linear: | ||
raise GuppyTypeError(f"Value with linear type `{ty}` is not used", node) | ||
node.value, _ = self._synth_expr(node.value) |
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.
Drive by: This error should be handled during linearity checking
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/diagnostics #601 +/- ##
====================================================
+ Coverage 91.74% 92.03% +0.29%
====================================================
Files 61 62 +1
Lines 6624 6832 +208
====================================================
+ Hits 6077 6288 +211
+ Misses 547 544 -3 ☔ 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.
very nice, just some small queries
"..." | ||
) | ||
place: Place | ||
kind: "UseKind" |
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.
nit: from __future__ import annotations
?
if self.is_call_arg: | ||
f = f"Function `{self.func_name}`" if self.func_name else "Function" | ||
return ( | ||
f"{f} wants to take ownership of this argument, but you don't own " |
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.
Not a fan of "you" here, maybe be more specific about the calling scope?
#: Ownership of an owned value is transferred by returning it | ||
RETURN = auto() | ||
|
||
#: An owned value is renamed or stored in a tuple/list |
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.
is tuple the same as struct here?
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.
Unfortunately not since constructing a struct is a function call, so this counts as consumption
| | ||
16 | @guppy(module) | ||
17 | def foo(qs: list[tuple[bool, qubit]] @owned) -> list[int]: | ||
18 | return [42 for b, q in qs if b if bar(q)] |
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.
does python allow chained if
s? expected an and
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.
Yep, that works in Python
We don't support and
and or
in comprehensions yet since we compile them to dataflow...
| ^ Variable `q` with linear type `qubit` cannot be moved ... | ||
| | ||
13 | return [(q, q) for q in qs] | ||
| - since it was already moved here |
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.
nice
| ... | ||
| | ||
20 | use(q) | ||
| - since it was already consumed here |
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.
"consumed" meaning enters another scope, and "moved" meaning belonging to a new name within same scope?
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.
Exactly!
20 | return s.q, t.q | ||
| ^^^ Field `s.q` with linear type `qubit` cannot be returned ... | ||
| | ||
19 | t = s |
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 find it hard to read messages where the same line is repeated, once in the original and then once in the sub. Just a note, don't think there is anything to be done.
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, the rendering can definitely be improved further. See #608
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 have created a release *beep* *boop* --- ## [0.13.0](v0.12.2...v0.13.0) (2024-11-12) ### ⚠ BREAKING CHANGES * `prelude` module renamed to `std` ### Features * add `qubit` discard/measure methods ([#580](#580)) ([242fa44](242fa44)) * Add `SizedIter` wrapper type ([#611](#611)) ([2e9da6b](2e9da6b)) * conventional results post processing ([#593](#593)) ([db96224](db96224)) * Improve compiler diagnostics ([#547](#547)) ([90d465d](90d465d)), closes [#551](#551) [#553](#553) [#586](#586) [#588](#588) [#587](#587) [#590](#590) [#600](#600) [#601](#601) [#606](#606) * restrict result tag sizes to 256 bytes ([#596](#596)) ([4e8e00f](4e8e00f)), closes [#595](#595) ### Bug Fixes * Mock guppy decorator during sphinx builds ([#622](#622)) ([1cccc04](1cccc04)) ### Documentation * Add DEVELOPMENT.md ([#584](#584)) ([1d29d39](1d29d39)) * Fix docs build ([#639](#639)) ([bd6011c](bd6011c)) ### Miscellaneous Chores * Manually set last release commit ([#643](#643)) ([b2d569b](b2d569b)) ### Code Refactoring * rename prelude to std ([#642](#642)) ([1a68e8e](1a68e8e)) --- 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: Agustín Borgna <agustin.borgna@quantinuum.com>
Closes #541