Skip to content
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

Merged
merged 4 commits into from
Jun 27, 2024

Conversation

mark-koch
Copy link
Collaborator

Closes #272

@mark-koch mark-koch requested a review from a team as a code owner June 27, 2024 14:28
@mark-koch mark-koch requested a review from aborgna-q June 27, 2024 14:28
b ^= measure(q)
b &= measure(q)
Copy link
Collaborator Author

@mark-koch mark-koch Jun 27, 2024

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-commenter
Copy link

Codecov Report

Attention: Patch coverage is 97.88732% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.47%. Comparing base (792fb87) to head (f0dec41).

Files Patch % Lines
guppylang/checker/linearity_checker.py 97.50% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@aborgna-q aborgna-q left a 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.

Comment on lines +274 to +276
assign = ast.Assign(
targets=[copy.deepcopy(node.target)], value=self.visit(node.value)
)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

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

@mark-koch mark-koch added this pull request to the merge queue Jun 27, 2024
Merged via the queue into main with commit 99320b1 Jun 27, 2024
3 checks passed
@mark-koch mark-koch deleted the refactor/linearity-checker branch June 27, 2024 15:08
@mark-koch mark-koch mentioned this pull request Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Turn linearity check into separate compiler stage
3 participants