-
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: Make True
and False
branches unconditional
#740
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #740 +/- ##
==========================================
+ Coverage 92.81% 92.84% +0.02%
==========================================
Files 71 71
Lines 8159 8200 +41
==========================================
+ Hits 7573 7613 +40
- Misses 586 587 +1 ☔ View full report in Codecov by Sentry. |
Error: Linearity violation (at $FILE:13:8) | ||
| | ||
11 | | ||
12 | @guppy(module) | ||
13 | def foo(q: qubit @owned) -> None: | ||
| ^^^^^^^^^^^^^^^ Variable `q` with linear type `qubit` is leaked |
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.
Arguably, this shouldn't be an error since non-terminating functions technically cannot leak. However, it would be difficult to generate valid Hugr for cases like this, e.g.
while True:
qubit()
Therefore, I think it's ok to still complain about leaks, even if the function provably doesn't terminate
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.
Uhm, I don't think erroring out on unreachable code is a good option.
Is there no alternative asides from implementing warnings? Even completely ignoring the unreachable code may be better.
Adding if False and ...
, mid-point return
s, and unused branches is something to be expected while coding and testing things. These errors would make development a lot more annoying.
For example, when building a CFG for
if True: ...
, build an unconditional branch. This improves linearity checking for functions involvingwhile True
loops, since dataflow analysis now understands that such loops can only exit on an explicitbreak
orreturn
.It also means that Guppy is now better at detecting unreachable code. For now, we error out in this case, but in the future it would be nice to only emit a warning (see #739).
One complication introduced by this is that Guppy can now generate CFGs where the exit block is unreachable. This lead to some problems with borrowed variables. This edge case now needs to be specially handled.
I recommend reviewing each of the three commits separately