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: Update function checker to use new diagnostics #590

Merged
merged 7 commits into from
Oct 31, 2024

Conversation

mark-koch
Copy link
Collaborator

No description provided.

@mark-koch mark-koch requested a review from a team as a code owner October 23, 2024 15:22
@mark-koch mark-koch requested review from croyzor and removed request for a team October 23, 2024 15:22
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2024

Codecov Report

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

Project coverage is 91.82%. Comparing base (8134a85) to head (6a22364).
Report is 4 commits behind head on feat/diagnostics.

Files with missing lines Patch % Lines
guppylang/definition/function.py 0.00% 3 Missing ⚠️
guppylang/checker/func_checker.py 94.11% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           feat/diagnostics     #590      +/-   ##
====================================================
+ Coverage             91.73%   91.82%   +0.09%     
====================================================
  Files                    61       61              
  Lines                  6509     6620     +111     
====================================================
+ Hits                   5971     6079     +108     
- Misses                  538      541       +3     

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

Base automatically changed from diag/linenos to feat/diagnostics October 29, 2024 09:44
| from an outer scope
|
6 | y = x + 1
| - `y` defined here
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it worth sorting the code spans based on the lines they appear in the file? it looks a little bit like this is one snippet and y is defined after baz

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's a good idea. However, we'll need to be careful because the grammar might break in some cases when reordering:

Error: Linearity violation (at $FILE:21:8)
   | 
19 | def test(q: qubit @owned) -> None:
20 |     use(q)
21 |     foo(q)
   |         ^ Variable `q` with linear type `qubit` cannot be borrowed
   |           ...
   | 
20 |     use(q)
   |         - since it was already consumed here

We'd need two version of the span labels depending on which order they are outputted. I created #608 to collect these improvement ideas

4: def foo():
^^^^^^^^^^
GuppyError: Return type must be annotated. Try adding a `-> None` annotation.
Help: Looks like `foo` doesn't return anything. Consider annotating it with `->
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥

5 | def foo(x: bool):
| ^^^^^^^^^^^^^^^^^
6 | return x
| ^^^^^^^^^^^^ Return type must be annotated
Copy link
Collaborator

Choose a reason for hiding this comment

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

it'd be nice if this could highlight the foo signature instead of the whole function...
Would it be better to have the message be "return type must be specified in method signature"?

Copy link
Collaborator Author

@mark-koch mark-koch Oct 31, 2024

Choose a reason for hiding this comment

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

Unfortunately, the Python AST doesn't give us a span for this. Taking the first line is also not valid since you could have weird stuff like

def foo(
  # No arguments, so no argument spans
)     :   # Closing paren on separate line + extra spaces before the colon

3 |
4 | @compile_guppy
5 | def foo(x: bool, y) -> int:
| ^ Argument type must be annotated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe "argument requires a type annotation"?

|
97 | apple == orange
98 | apple == orange
99 | apple == orange
Copy link
Collaborator

Choose a reason for hiding this comment

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

😁

" | from an outer scope\n",
" | \n",
"4 | def outer(x: int) -> int:\n",
" | ------ `x` defined here\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be cool to detect overlapping spans and only print the outer once like

def outer(x: int) -> int
                ----- `x` defined here
    def nested() -> None
        x += 1
        ^^^^^^ Variable `x`...

but that seems tricky...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good idea, Rust also does this! Added to #608

@mark-koch mark-koch merged commit cd73c1b into feat/diagnostics Oct 31, 2024
2 checks passed
@mark-koch mark-koch deleted the diag/func branch October 31, 2024 12:36
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
github-merge-queue bot pushed a commit that referenced this pull request Nov 12, 2024
🤖 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>
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