-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Stop using intermediate macros in definition of symbols #80036
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
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The current structure was motivated by IDE experience first of all. I've just checked this branch with vscode + rust-analyzer, and the difference is pretty much the same as it was when the macro was introduced. |
I can see how that would be useful. Go-to-definition could still be supported, by having the proc-macro generate |
@sivadeilra Do we have any numbers on how much this helps memory usage? It would help to assess any possible tradeoffs in the experience of |
I think something like this would be optimal. |
That's pretty much what my second update in this PR does. It uses 2 re-exports, rather than macros. |
@sivadeilra |
That sounds good. I'll update with that. |
Thanks! |
Currently, the rustc_macros::symbols macro generates two `macro_rules!` macros as its output. These two macros are used in rustc_span/src/symbol.rs. This means that each Symbol that we define is represented in the AST of rustc_symbols twice: once in the definition of the `define_symbols!` macro (similarly for the `keywords! macro), and once in the rustc_span::symbols definition. That would be OK if there were only a handful of symbols, but currently we define over 1100 symbols. The definition of the `define_symbols!` macro contains the expanded definition of each symbol, so that's a lot of AST storage wasted on a macro that is used exactly once. This commit removes the `define_symbols` macro, and simply allows the proc macro to directly generate the `rustc_symbols::symbol::sym` module. The benefit is mainly in reducing memory wasted during compilation of rustc itself. It should also reduce memory used by Rust Analyzer. This commit also reduces the size of the AST for symbol definitions, by moving two `#[allow(...)]` attributes from the symbol constants to the `sym` module. This eliminates 2200+ attribute nodes. This commit also eliminates the need for the `digits_array` constant. There's no need to store an array of Symbol values for digits. We can simply define a constant of the base value, and add to that base value.
Rebased & squashed. Thanks! |
a615306
to
2b2462e
Compare
@bors r+ |
📌 Commit 2b2462e has been approved by |
☀️ Test successful - checks-actions |
Currently, the rustc_macros::symbols macro generates two
macro_rules!
macros as its output. These two macros areused in rustc_span/src/symbol.rs.
This means that each Symbol that we define is represented
in the AST of rustc_symbols twice: once in the definition
of the
define_symbols!
macro (similarly for the`keywords! macro), and once in the rustc_span::symbols
definition.
That would be OK if there were only a handful of symbols,
but currently we define over 1100 symbols. The definition
of the
define_symbols!
macro contains the expanded definitionof each symbol, so that's a lot of AST storage wasted on a
macro that is used exactly once.
This commit removes the
define_symbols
macro, and simplyallows the proc macro to directly generate the
rustc_symbols::symbol::sym
module.The benefit is mainly in reducing memory wasted during
compilation of rustc itself. It should also reduce memory used
by Rust Analyzer.
This commit also reduces the size of the AST for symbol
definitions, by moving two
#[allow(...)]
attributes fromthe symbol constants to the
sym
module. This eliminates 2200+attribute nodes.
This commit also eliminates the need for the
digits_array
constant. There's no need to store an array of Symbol values
for digits. We can simply define a constant of the base value,
and add to that base value.
I left the
sym::integer
function in rustc_span/src/symbol.rsinstead of moving it into rustc_macros/src/symbols.rs for two
reasons. First, because it's human-written code; it doesn't need
to be generated by the proc-macro. Second, because I didn't want
the
#[allow(...)]
attributes that I moved to thesym
modulescope to apply to this function. The
sym
module re-exports theinteger
function from its parent module.