-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Remove ast::Lit::kind
#101885
Remove ast::Lit::kind
#101885
Conversation
Some changes occurred in src/librustdoc/clean/types.rs cc @camelid Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
The best thing about this: The downside is that every literal has to be processed at least twice: once during parsing to detect errors (where we discard the converted semantic literal) and again during lowering to HIR. On some benchmarks this is noticeable:
The code is a bit rough, with some I'm not sure if this is a good idea, but I thought I'd do it to help the discussion in #101562. |
This comment has been minimized.
This comment has been minimized.
The goal of this change is exactly to stop semantically processing the literals during parsing (parsing Rust proper syntax, not syntaxes introduced by macros), and doing it only if they reach HIR, similarly to what float literals do now. macro_rules! m { ($tt:tt) => () }
m!("str"suffix); // OK right now
#[cfg(FALSE)]
fn f() {
"str"suffix; // ERROR, but probably shouldn't be
// will be OK if semantic checking of literals is delayed until HIR
}
fn main() {
"str"suffix; // ERROR, expected semantic error
} Semantic literals are sometimes needed before lowering, typically in attributes. If this is done (together with moving spans "upwards" from #101562), then most of AST will basically keep
|
I tried removing the check-and-discard code from // We need to do the conversion to detect errors, even though we
// discard the result.
_ = LitKind::from_token_lit(token_lit)?; and I got tons of
Yes, it's a tiny fraction of the cases, so shouldn't matter for performance.
I noticed that too. 👍 It sounds like you are more in favour of this PR's approach than the first commit in #101562? |
dd76cd6
to
c5a1b53
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit c5a1b53e13f7ded9f8e9a269dc3c8a865e977e38 with merge d39d569d36b74d4b16fe4a1451452b23e16ae7ff... |
@petrochenkov: I have finished this. I haven't done The places that need the semantic literal prior to lowering are a little more complicated in their error handling, and a few error messages have changed, but they are all quite obscure ones. Local measurements show that it is now performance-neutral, except for |
☀️ Try build successful - checks-actions |
Queued d39d569d36b74d4b16fe4a1451452b23e16ae7ff with parent efa717b, future comparison URL. |
Finished benchmarking commit (d39d569d36b74d4b16fe4a1451452b23e16ae7ff): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never 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)ResultsThis 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.
CyclesResultsThis 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.
Footnotes |
This comment has been minimized.
This comment has been minimized.
Some small performance ups and downs, but overall it's roughly neutral, as expected. @rustbot label: +perf-regression-triaged |
Because they are sometimes hot and each have a single call site.
This will become interesting in the next commit.
This shrinks `ast::Lit` kind considerably. The conversion to semantic literals now happens at AST lowering time, with a few exceptions where the literal values are needed before that.
c5a1b53
to
434b81e
Compare
☔ The latest upstream changes (presumably #101558) made this pull request unmergeable. Please resolve the merge conflicts. |
Maybe we should keep (If there are ways to make literal parsing in attributes more lazy too, then we can try them later, probably without further lang team approval.) |
We seem to be in agreement that
You don't seem happy with either approach, and now you're suggesting a hybrid approach where some literals (in attributes) get early lowering and some (in expressions) get late lowering. I think this would be a clumsy mix that is worse than the other two approaches. In fact, the "late lowering" approach above is also a hybrid approach, because some early lowerings are required to process attributes. It's just that the early-lowered literals aren't stored. Therefore, I think the |
I do want to change the language behavior though, that's what the removed FIXME is about, AST shrinkage by itself is a secondary goal.
Literals in attributes ( |
What's the benefit of the proposed language change? Can you give an example? |
|
We ended up taking a different approach in #102944. |
This is an alternative to the "Remove
token::Lit
fromast::Lit
commit in #101562.r? @petrochenkov