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

Use codespan for analyzer errors #398

Merged
merged 1 commit into from
May 31, 2021
Merged

Conversation

sbillig
Copy link
Collaborator

@sbillig sbillig commented May 9, 2021

What was wrong?

Analyzer errors weren't fancy enough.

How was it fixed?

This has become a behemoth of a pr, sorry for the hassle.

The context object now contains a vec of diagnostics. Analysis functions will return Ok with correct type information wherever possible, even if they emit an error diagnostic. In cases where correct type information can't be returned, Err(SemanticError::fatal()) is returned. There are still a lot of old errors yet to be converted. In some cases, fancy errors will be followed by an old error, so the user experience will be a little awkward for a while. When they've all been converted to codespan diagnostics, SemanticError/ErrorKind can finally be retired.

I had to do a lot of refactoring to give myself enough context to emit pretty error messages. I've been inlining some utility functions and passing around more nodes and spans, and I'm starting to wonder if there's a better way. Eg rustc's "hir" analysis uses various query functions to retrieve such info. Maybe we could structure things similarly as part of the salsa experiment and avoid passing around spans everywhere. Either way I need to take a breather from this for a while; maybe some enlightenment will come later. Y'all are more than welcome to pick away at the remaining old errors, and/or suggest better wording for the errors I did convert. The quality of the error messages is very reflective of my energy level at the time they were written :)

I added a basic check of the left-hand side of assignments; this could be extended to verify that the lhs isn't a read-only attribute of a built-in, for example. The labels of event and struct constructor args are now verified as well. The labels of function args are still ignored (I'd like extend the same checking logic of events/structs to function calls, if the ideas in #397 are agreed upon).

Along the way, I noticed that tuples inside maps weren't being lowered and would thus panic; couldn't resist fixing that, even though it could have been a separate pr.

closes #408
closes #382

To-Do

  • OPTIONAL: Update Spec if applicable
  • Add entry to the release notes (may forgo for trivial changes)
  • Clean up commit history

@sbillig sbillig changed the title Use codespan for errors in analyzer Use codespan for analyzer errors May 9, 2021
@codecov-commenter
Copy link

codecov-commenter commented May 9, 2021

Codecov Report

Merging #398 (70f0c4b) into master (42a5648) will decrease coverage by 0.34%.
The diff coverage is 85.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
- Coverage   86.43%   86.09%   -0.35%     
==========================================
  Files          69       71       +2     
  Lines        4431     4637     +206     
==========================================
+ Hits         3830     3992     +162     
- Misses        601      645      +44     
Impacted Files Coverage Δ
common/src/span.rs 72.72% <ø> (ø)
compiler/src/errors.rs 0.00% <ø> (ø)
compiler/src/yul/mappers/functions.rs 97.50% <ø> (ø)
compiler/src/yul/utils.rs 93.10% <ø> (+5.22%) ⬆️
parser/src/grammar/functions.rs 89.83% <ø> (-0.09%) ⬇️
test-utils/src/lib.rs 82.92% <0.00%> (-0.88%) ⬇️
parser/src/ast.rs 27.58% <27.58%> (ø)
parser/src/parser.rs 73.81% <50.00%> (-0.26%) ⬇️
analyzer/src/namespace/events.rs 94.73% <66.66%> (-5.27%) ⬇️
analyzer/src/traversal/assignments.rs 69.23% <69.23%> (ø)
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42a5648...70f0c4b. Read the comment docs.

@sbillig sbillig force-pushed the analyzer-errors branch from a9a5ba2 to ea3b590 Compare May 10, 2021 20:27
@sbillig sbillig force-pushed the analyzer-errors branch 3 times, most recently from 0a44764 to 78de924 Compare May 21, 2021 02:15
@sbillig sbillig requested a review from g-r-a-n-t May 21, 2021 02:55
@@ -39,6 +66,30 @@ pub fn assign(
unreachable!()
}

pub fn check_assign_target(
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 now notice that I didn't apply the same check to aug_assign. That can wait for a future pr.

@sbillig sbillig force-pushed the analyzer-errors branch from 78de924 to ff9ed29 Compare May 21, 2021 03:19
@sbillig
Copy link
Collaborator Author

sbillig commented May 21, 2021

@satyamakgec I'd be happy to hold off on this until #385 is merged and deal with the merge conflicts, if your stuff is nearly ready.

@satyamakgec
Copy link
Contributor

satyamakgec commented May 23, 2021

Thanks @sbillig, Yeah it is ready for review once it is merged then you will get a lot of conflicts 😬

params: &[(String, FixedSize)],
) -> Result<(), SemanticError> {
for ((label, param_type), arg) in params.iter().zip(args.kind.iter()) {
let val_attrs = assignable_expr(Rc::clone(&scope), Rc::clone(&context), &arg.kind.value)?;
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 just noticed that if there are more args than the fn expects, the excess args won't be analyzed. I'm inclined to fix this later.

Copy link
Member

Choose a reason for hiding this comment

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

not a big deal

@g-r-a-n-t
Copy link
Member

👁️

Copy link
Member

@g-r-a-n-t g-r-a-n-t left a comment

Choose a reason for hiding this comment

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

Looks great. Alot of nice improvements in here.

@sbillig sbillig force-pushed the analyzer-errors branch from 53846ac to 70f0c4b Compare May 31, 2021 18:32
@sbillig sbillig merged commit 1e45350 into ethereum:master May 31, 2021
@sbillig sbillig deleted the analyzer-errors branch May 31, 2021 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants