-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Update expr
matcher for Edition 2024 and add expr_2021
nonterminal
#123865
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
512458e
to
0777912
Compare
expr_2021
nonterminal and feature flagexpr
matcher for Edition 2024 and add expr_2021
nonterminal
I think the biggest question left is what exactly should be included in Rust 2024's |
This comment has been minimized.
This comment has been minimized.
@fmease - I addressed your simpler comments, so I think this should be ready for another look. |
This comment has been minimized.
This comment has been minimized.
Looks like we should update the tests
This should be the diff that it is needed diff --git a/tests/ui/macros/expr_2021_inline_const.rs b/tests/ui/macros/expr_2021_inline_const.rs
index ffce1f2b908..ebc5ea36421 100644
--- a/tests/ui/macros/expr_2021_inline_const.rs
+++ b/tests/ui/macros/expr_2021_inline_const.rs
@@ -4,7 +4,6 @@
// This test ensures that the inline const match only on edition 2024
#![feature(expr_fragment_specifier_2024)]
-#![feature(inline_const)]
#![allow(incomplete_features)]
macro_rules! m2021 { and then |
This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. For now, `expr` and `expr_2021` are treated the same, but in future PRs we will update `expr` to match to new grammar. Co-authored-by: Vincezo Palazzo <vincenzopalazzodev@gmail.com>
Co-authored-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Co-authored-by: Eric Holk <eric@theincredibleholk.org> Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
- use feature_err to report unstable expr_2021 - Update downlevel expr_2021 diagnostics Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
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.
Thanks! My suggestion https://github.com/rust-lang/rust/pull/123865/files#r1577167279 wasn't applied, I assume that's an oversight because you've applied suggestions of mine that are similar to this.
Should be good to go after that, work like double-checking the behavior of weird nested macro decls can be done in follow-ups as suggested by you.
r=me then.
= help: fragment specifier `expr_2021` requires Rust 2021 or later | ||
valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis` |
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 would probably split this into two separate help
messages but er, doesn't matter
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.
Yeah, I think that'd be better. Let me poke around at it some more, I'm still getting the hang of the diagnostics system.
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.
Actually, I'd rather save this for another PR so we can wrap this one up. I feel like otherwise I'll sit on this for another week or two, and I'd like to get this in as a foundation for similar edition-related changes.
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 (intentional) behavior is a bit unfortunate but it makes sense. Well, it makes the most sense when edition-dependent keywords are involved.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Finished benchmarking commit (9b75a43): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary 0.0%, secondary -4.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -3.1%, secondary 2.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 668.756s -> 668.325s (-0.06%) |
@eholk @vincenzopalazzo @fmease the regression seems legit. It seems the primary benchmark affected by this |
[perf-only] Revert "Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal" CC rust-lang#123865 r? ghost
Update: In #125389 I've checked the perf of a full revert. Doing a naive inversion / deduction, this PR "might've only had" 8 counts of secondary regressions (mean: +0.3%, range: [+0.5%, +0.3%]). Anyways, if I find the time I will look deeper into this. Otherwise, I'll just wait for #123865 (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.
I finally had a look at the code and I post my analysis, I am not sure how to solve this BTW :/
token.can_begin_expr() | ||
// This exception is here for backwards compatibility. | ||
&& !token.is_keyword(kw::Let) | ||
&& (token.span.edition().at_least_rust_2024() || !token.is_keyword(kw::Const)) |
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 am not a performance expert, so I might be wrong here, but I think the only thing that could cause a performance issue is the token.span.edition().
If we follow the call stack, the edition() will resolve in the following call: https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L877-L879.
If we repeat this call for every expression token, we could see a performance decrease.
…egression, r=<try> [perf-only] rustc_parser: avoid checking the edition as much as possible CC rust-lang#123865 r? ghost
Inside rust-lang#123865, we are adding support for the new semantics for expr2024, but we have noted a performance issue. We realized there is a redundant check for each token regarding an edition. This commit moves the edition check to the end, avoiding some extra checks that can slow down compilation time. Link: rust-lang#123865 Co-Developed-by: @eholk Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Inside rust-lang#123865, we are adding support for the new semantics for expr2024, but we have noted a performance issue. We realized there is a redundant check for each token regarding an edition. This commit moves the edition check to the end, avoiding some extra checks that can slow down compilation time. Link: rust-lang#123865 Co-Developed-by: @eholk Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Inside rust-lang#123865, we are adding support for the new semantics for expr2024, but we have noted a performance issue. We realized there is a redundant check for each token regarding an edition. This commit moves the edition check to the end, avoiding some extra checks that can slow down compilation time. Link: rust-lang#123865 Co-Developed-by: @eholk Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
…egression, r=fmease Avoid checking the edition as much as possible Inside rust-lang#123865, we are adding support for the new semantics for expr2024, but we have noted a performance issue. While talking with `@eholk,` we realized there is a redundant check for each token regarding an edition. This commit moves the edition check to the end, avoiding some extra checks that can slow down compilation time. However, we should keep this issue under observation because we may want to improve the edition check if we are unable to significantly improve compiler performance. r? ghost
…, r=fmease Avoid checking the edition as much as possible Inside rust-lang/rust#123865, we are adding support for the new semantics for expr2024, but we have noted a performance issue. While talking with `@eholk,` we realized there is a redundant check for each token regarding an edition. This commit moves the edition check to the end, avoiding some extra checks that can slow down compilation time. However, we should keep this issue under observation because we may want to improve the edition check if we are unable to significantly improve compiler performance. r? ghost
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? `@fmease` `@eholk` cc `@vincenzopalazzo` cc rust-lang#123865 Tracking: - rust-lang#123742
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? ``@fmease`` ``@eholk`` cc ``@vincenzopalazzo`` cc rust-lang#123865 Tracking: - rust-lang#123742
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo``` cc rust-lang#123865 Tracking: - rust-lang#123742
Rollup merge of rust-lang#126700 - compiler-errors:fragment, r=fmease Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo``` cc rust-lang#123865 Tracking: - rust-lang#123742
…acros-between-edition, r=compiler-errors test: cross-edition metavar fragment specifiers There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions. See the original suggestion rust-lang#123865 (comment) Tracking: - rust-lang#123742
…ros-between-edition, r=compiler-errors test: cross-edition metavar fragment specifiers There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions. See the original suggestion rust-lang#123865 (comment) Tracking: - rust-lang#123742
…acros-between-edition, r=compiler-errors test: cross-edition metavar fragment specifiers There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions. See the original suggestion rust-lang#123865 (comment) Tracking: - rust-lang#123742
Rollup merge of rust-lang#129755 - vincenzopalazzo:macros/recursive-macros-between-edition, r=compiler-errors test: cross-edition metavar fragment specifiers There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions. See the original suggestion rust-lang#123865 (comment) Tracking: - rust-lang#123742
This commit adds a new nonterminal
expr_2021
in macro patterns, andexpr_fragment_specifier_2024
feature flag.This change also updates
expr
so that on Edition 2024 it will also matchconst { ... }
blocks, whileexpr_2021
preserves the current behavior ofexpr
, matching expressions withoutconst
blocks.Joint work with @vincenzopalazzo.
Issue #123742