rust/compiler/rustc_expand/src
Nicholas Nethercote b9bf0b4b10 Speed up Parser::expected_token_types.
The parser pushes a `TokenType` to `Parser::expected_token_types` on
every call to the various `check`/`eat` methods, and clears it on every
call to `bump`. Some of those `TokenType` values are full tokens that
require cloning and dropping. This is a *lot* of work for something
that is only used in error messages and it accounts for a significant
fraction of parsing execution time.

This commit overhauls `TokenType` so that `Parser::expected_token_types`
can be implemented as a bitset. This requires changing `TokenType` to a
C-style parameterless enum, and adding `TokenTypeSet` which uses a
`u128` for the bits. (The new `TokenType` has 105 variants.)

The new types `ExpTokenPair` and `ExpKeywordPair` are now arguments to
the `check`/`eat` methods. This is for maximum speed. The elements in
the pairs are always statically known; e.g. a
`token::BinOp(token::Star)` is always paired with a `TokenType::Star`.
So we now compute `TokenType`s in advance and pass them in to
`check`/`eat` rather than the current approach of constructing them on
insertion into `expected_token_types`.

Values of these pair types can be produced by the new `exp!` macro,
which is used at every `check`/`eat` call site. The macro is for
convenience, allowing any pair to be generated from a single identifier.

The ident/keyword filtering in `expected_one_of_not_found` is no longer
necessary. It was there to account for some sloppiness in
`TokenKind`/`TokenType` comparisons.

The existing `TokenType` is moved to a new file `token_type.rs`, and all
its new infrastructure is added to that file. There is more boilerplate
code than I would like, but I can't see how to make it shorter.
2024-12-19 16:05:41 +11:00
..
mbe Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino 2024-12-18 22:56:53 +08:00
base.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
build.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
config.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
errors.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
expand.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
lib.rs Add warn(unreachable_pub) to rustc_expand. 2024-08-27 12:40:38 +10:00
mbe.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
module.rs Speed up Parser::expected_token_types. 2024-12-19 16:05:41 +11:00
placeholders.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
proc_macro_server.rs Speed up Parser::expected_token_types. 2024-12-19 16:05:41 +11:00
proc_macro.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00