-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: extract parse errors as diagnostics #17552
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
Conversation
geoffw0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great (first commit, from #17543 , not reviewed).
Thank you for implementing and testing the error queries alongside the extractor changes!
| | does_not_compile.rs:2:13:2:12 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | | ||
| | does_not_compile.rs:2:21:2:20 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | | ||
| | does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | | ||
| | does_not_compile.rs:2:32:2:31 | expected field name or number | Extraction failed in does_not_compile.rs with error expected field name or number | 2 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised we don't get any results from error.rs (which contains compile_error!("An error!");).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line in error.rs isn't a syntax error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose. I feel like it should show up somewhere (and is a cleaner test than does_not_compile.rs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extractor currently only parses the code, and error.rs does not contain a syntax error.
I would expect an error to be reported once we implement macro expansion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. 👍
rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql
Outdated
Show resolved
Hide resolved
rust/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql
Outdated
Show resolved
Hide resolved
geoffw0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional commits LGTM as well. We're just waiting for #17543 I think.
| (valid, invalid) | ||
| } else { | ||
| return (Cow::Borrowed(""), None); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the special handling of the first chunk essentially an optimisation for the common case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is a way to get the location of the first UTF8 decoding error, if any. If a file is complete garbage we don't want to generate a ton of useless decoding errors, one is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the Cow (copy-on-write) stuff is an optimisation for the common case that the input is entirely valid utf8 and no replacements are needed.
Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
60677e5 to
ca7b9e1
Compare
ca7b9e1 to
5714811
Compare
geoffw0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Depends on #17543
This pull request add extraction of parse error messages, and adds some diagnostic queries.