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

feat: Update CFG checker to use new diagnostics #589

Merged
merged 6 commits into from
Oct 29, 2024
Merged

Conversation

mark-koch
Copy link
Collaborator

No description provided.

@mark-koch mark-koch requested a review from ss2165 October 23, 2024 14:51
@mark-koch mark-koch requested a review from a team as a code owner October 23, 2024 14:51
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 93.50649% with 5 lines in your changes missing coverage. Please review.

Project coverage is 91.77%. Comparing base (8134a85) to head (6773c2b).
Report is 2 commits behind head on feat/diagnostics.

Files with missing lines Patch % Lines
guppylang/definition/function.py 0.00% 3 Missing ⚠️
guppylang/checker/cfg_checker.py 96.61% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           feat/diagnostics     #589      +/-   ##
====================================================
+ Coverage             91.73%   91.77%   +0.04%     
====================================================
  Files                    61       61              
  Lines                  6509     6579      +70     
====================================================
+ Hits                   5971     6038      +67     
- Misses                  538      541       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are some very cool errors!
Some queries about falsy loops and compound predicate expressions

| ^ `z` might be undefined ...
|
6 | if x and (z := y + 1):
| - ... if this expression is `False`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to my eye this looks like if x False rather than if x and (z := y + 1) is False ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message is correct:

If x were true then z would be defined because of the walrus assignment even if the whole thing tends out to be false.

If x is false, then z is not defined because and short circuits

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test:

@guppy
def foo(x: bool, y: int) -> int:
    if x and (z := y + 1):
        return z
    else:
        return z

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense! thanks

| ^ `y` might be undefined ...
|
6 | for _ in xs:
| -- ... if this expression is `False`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusing, do we need to say "Falsey"...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of differentiating between bools and values that are truthy. The problem is that we can no longer make this distinction here since we already inserted an implicit call to __bool__.

An additional problem is that for loops are desugared to

iter = xs.__iter__()
while True:
   b, iter = iter.__hasnext__()
   if b:
      x, it = iter.__next__()
   else:
      break
iter.__end__()

and the message actually points to the while True bit which actually is a bool.

Created issues #591 and #592 to figure out how to solve this

| ^ `z` might be undefined ...
|
6 | if x or (z := y + 1):
| - ... if this expression is `True`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous query

Base automatically changed from diag/linenos to feat/diagnostics October 29, 2024 09:44
@mark-koch mark-koch merged commit e096c53 into feat/diagnostics Oct 29, 2024
2 checks passed
@mark-koch mark-koch deleted the diag/cfg branch October 29, 2024 10:03
github-merge-queue bot pushed a commit that referenced this pull request Nov 11, 2024
This is the development branch for our new diagnostics infrastructure.
Tracked by #535.

*  #548
* #551
* #552 
* #553
* #586
* #588
* #587
* #589 
* #590
* #600
* #601
* #604 
* #605 
* #606
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.

3 participants