-
Notifications
You must be signed in to change notification settings - Fork 2
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: Turn linearity checking into separate compiler stage #273
Conversation
b ^= measure(q) | ||
b &= measure(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.
For some reason bool.__xor__
is missing (see #274).
The test worked before since the linearity violation triggered an error before we got to this point. Now we type check everything first, so this has to be fixed (similar for the remaining modified tests)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
==========================================
+ Coverage 91.39% 91.47% +0.07%
==========================================
Files 44 45 +1
Lines 5023 5116 +93
==========================================
+ Hits 4591 4680 +89
- Misses 432 436 +4 ☔ 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.
Nice and tidy.
The comments on _check_comprehension
are quite useful.
assign = ast.Assign( | ||
targets=[copy.deepcopy(node.target)], value=self.visit(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.
Is this a drive-by?
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.
No this is required now that we annotate the LHS of assignments with types
guppylang/guppylang/checker/stmt_checker.py
Lines 49 to 56 in f0dec41
def _check_assign(self, lhs: ast.expr, ty: Type, node: ast.stmt) -> None: | |
"""Helper function to check assignments with patterns.""" | |
match lhs: | |
# Easiest case is if the LHS pattern is a single variable. | |
case ast.Name(id=x): | |
# Store the type in the AST | |
with_type(ty, lhs) | |
self.ctx.locals[x] = Variable(x, ty, lhs) |
If we don't make a copy, the type checker will see that a type has been assigned when the variable is used the next time and won't bother checking again which leads incorrect behaviour
Closes #272