1
Fork 0
rust/compiler/rustc_parse/src
Nicholas Nethercote ebe1305b1e Remove the bogus special case from Parser::look_ahead.
The general case at the bottom of `look_ahead` is slow, because it
clones the token cursor. Above it there is a special case for
performance that is hit most of the time and avoids the cloning.
Unfortunately, its behaviour differs from the general case in two ways.

- When within a pair of delimiters, if you look any distance past the
  closing delimiter you get the closing delimiter instead of what comes
  after the closing delimiter.

- It uses `tree_cursor.look_ahead(dist - 1)` which totally confuses
  tokens with token trees. This means that only the first token in a
  token tree will be seen. E.g. in a sequence like `{ a }` the `a` and
  `}` will be skipped over. Bad!

It's likely that these differences weren't noticed before now because
the use of `look_ahead` in the parser is limited to small distances and
relatively few contexts.

Removing the special case causes slowdowns up of to 2% on a range of
benchmarks. The next commit will add a new, correct special case to
regain that lost performance.
2024-07-12 13:33:38 +10:00
..
lexer Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
parser Remove the bogus special case from Parser::look_ahead. 2024-07-12 13:33:38 +10:00
errors.rs Change RTN to use .. again 2024-06-28 14:20:43 -04:00
lib.rs Prefer dcx methods over fields or fields' methods 2024-06-18 13:45:08 +00:00
validate_attr.rs coverage: Tighten validation of #[coverage(off)] and #[coverage(on)] 2024-06-24 20:15:01 +10:00