-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Rewrite the new attribute argument parser #144689
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
base: master
Are you sure you want to change the base?
Rewrite the new attribute argument parser #144689
Conversation
799d605
to
7b3bb12
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Rewrite the new attribute parser
@@ -51,12 +37,26 @@ error[E0589]: invalid alignment value: not a power of two | |||
LL | #[rustc_align(0)] | |||
| ^ | |||
|
|||
error: expected unsuffixed literal, found `-` |
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.
it would be pretty cool if we could explain here what an unsuffixed literal is. Maybe give an example of one with a short explanation. It's not required, but does teach the language better through diagnostics which is always cool
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 improved the error a lot :)
error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `-`
--> $DIR/malformed-fn-align.rs:29:15
|
LL | #[rustc_align(-1)]
| ^
|
help: negative numbers are not literals, try removing the `-` sign
|
LL - #[rustc_align(-1)]
LL + #[rustc_align(1)]
|
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (acc46aa): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -1.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 469.342s -> 468.873s (-0.10%) |
(match-stress looks currently noisy to me) |
Mhm, we came to the same conclusion (@JonathanBrouwer ) |
4c9a573
to
244cefa
Compare
@@ -4,7 +4,7 @@ macro_rules! bar ( | |||
|
|||
macro_rules! foo ( | |||
() => ( | |||
#[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps | |||
#[allow_internal_unstable()] //~ ERROR allow_internal_unstable side-steps |
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.
BREAKING CHANGE:
Previously, attributes on macro calls were partially checked for correct syntax (only what check_builtin_meta_item
can check).
After this PR, the attributes are fully parsed.
In any case, these attributes are always completely ignored, except for #[cfg]
, which was always completely parsed and still is and is not affected by this breaking change.
@@ -1095,7 +1095,7 @@ impl<'a> Parser<'a> { | |||
/// Parses a comma-separated sequence delimited by parentheses (e.g. `(x, y)`). | |||
/// The function `f` must consume tokens until reaching the next separator or | |||
/// closing bracket. | |||
fn parse_paren_comma_seq<T>( | |||
pub fn parse_paren_comma_seq<T>( |
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've had to make quite a few of these functions public, how problematic is that?
I don't think it matters right, or at least it's better than the alternative of copying them over
244cefa
to
c0f407d
Compare
@rustbot ready |
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
|
@rust-lang/lang |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
☔ The latest upstream changes (presumably #144740) made this pull request unmergeable. Please resolve the merge conflicts. |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
All regressions are spurious. The crater run did find a bug in my new implementation (in the "fixed" results), which is easy to fix. Apparently my new parser accepts |
01f29bf
to
f2087c4
Compare
^ Fixed the bug and added a regression test |
This comment has been minimized.
This comment has been minimized.
f2087c4
to
ffc2116
Compare
Well, that's nice, that should make the decision for lang easier. Still would like their opinion though. This is a by far superior way to handle errors in attribute parsing, and we emit more errors when things are wrong. That's good, as long as it doesn't break anyone and it seems the impact will be small. |
If you could please describe further what it meant for the calls to be partially checked, that would help. I.e., what were we catching and what were the limits of that? |
☔ The latest upstream changes (presumably #144814) made this pull request unmergeable. Please resolve the merge conflicts. |
Previously for attributes on macro calls we were doing the following:
Note that this only looks at the What this PR introduces, is fully validating that the arguments to the attribute actually make sense, using the attributes' individual parsers.
As a reminder, these attributes on macro calls already have a warning that they are unused and will continue to have that warning. |
Fixes #143940
This rewrites the parser, should improve performance and maintainability.
This can be reviewed commit by commit