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: Improve compiler diagnostics #547

Merged
merged 23 commits into from
Nov 11, 2024
Merged

feat: Improve compiler diagnostics #547

merged 23 commits into from
Nov 11, 2024

Conversation

@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 93.79310% with 81 lines in your changes missing coverage. Please review.

Project coverage is 92.45%. Comparing base (c142cc4) to head (09a6589).

Files with missing lines Patch % Lines
guppylang/checker/expr_checker.py 77.92% 17 Missing ⚠️
guppylang/span.py 83.09% 12 Missing ⚠️
guppylang/tys/parsing.py 56.52% 10 Missing ⚠️
guppylang/checker/stmt_checker.py 76.47% 4 Missing ⚠️
guppylang/compiler/expr_compiler.py 20.00% 4 Missing ⚠️
guppylang/definition/function.py 71.42% 4 Missing ⚠️
guppylang/prelude/_internal/checker.py 91.30% 4 Missing ⚠️
guppylang/decorator.py 83.33% 3 Missing ⚠️
guppylang/module.py 62.50% 3 Missing ⚠️
guppylang/cfg/builder.py 89.47% 2 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #547      +/-   ##
==========================================
+ Coverage   91.39%   92.45%   +1.06%     
==========================================
  Files          59       66       +7     
  Lines        6481     7464     +983     
==========================================
+ Hits         5923     6901     +978     
- Misses        558      563       +5     

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

mark-koch and others added 22 commits October 9, 2024 09:44
We used to store the entire source code that was used to build an AST as
a field within *every node* of the AST. This was a hack so that we can
render the source line from an AST node when an error occurs. With our
new diagnostics system, we should do better than that!

With this PR, we cache the source of every file accessed by the compiler
in a new `SourceMap` class. Then, we can look up the source associated
with a span when rendering a diagnostic.

Note that we can't rely on Pythons `linecache` since we also need to
keep track of cells in jupyter notebooks as individual "files".
Closes #538.

* Allow to pass a `Diagnostic` object to `GuppyError` instead of an
error message
* The old error reporting system remains untouched until we have
migrated everything to the new diagnostics system
* Adds a `TypeMismatchError` diagnostic as a test to ensure that the
pipeline works
…600)

Sub-diagnostics now store a pointer to their parent main diagnostic that
is used to look up field values when formatting labels and messages.

This is achieved by subclassing `string.Formatter` to implement the
custom lookup
Closes #633

Also updates a few last errors that I overlooked in the previous
refactors
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.

🚀

@mark-koch mark-koch marked this pull request as ready for review November 11, 2024 16:37
@mark-koch mark-koch requested a review from a team as a code owner November 11, 2024 16:37
@mark-koch mark-koch requested review from croyzor and removed request for croyzor November 11, 2024 16:37
@mark-koch mark-koch added this pull request to the merge queue Nov 11, 2024
Merged via the queue into main with commit 90d465d Nov 11, 2024
3 checks passed
@mark-koch mark-koch deleted the feat/diagnostics branch November 11, 2024 16:41
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