about summary refs log tree commit diff
path: root/compiler/rustc_lexer/src
AgeCommit message (Collapse)AuthorLines
2022-09-26Add `rustc_lexer::TokenKind::Eof`.Nicholas Nethercote-4/+13
For alignment with `rust_ast::TokenKind::Eof`. Plus it's a bit faster, due to less `Option` manipulation in `StringReader::next_token`.
2022-09-26Rename some things.Nicholas Nethercote-18/+18
`Cursor` keeps track of the position within the current token. But it uses confusing names that don't make it clear that the "length consumed" is just within the current token. This commit renames things to make this clearer.
2022-09-26Make `rustc_lexer::cursor::Cursor` public.Nicholas Nethercote-21/+9
`Cursor` is currently hidden, and the main tokenization path uses `rustc_lexer::first_token` which involves constructing a new `Cursor` for every single token, which is weird. Also, `first_token` also can't handle empty input, so callers have to check for that first. This commit makes `Cursor` public, so `StringReader` can contain a `Cursor`, which results in a simpler structure. The commit also changes `StringReader::advance_token` so it returns an `Option<Token>`, simplifying the the empty input case.
2022-09-08remove unnecessary `PartialOrd` and `Ord`Takayuki Maeda-1/+1
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-08-01Shrink `Token`.Nicholas Nethercote-71/+71
From 72 bytes to 12 bytes (on x86-64). There are two parts to this: - Changing various source code offsets from 64-bit to 32-bit. This is not a problem because the rest of rustc also uses 32-bit source code offsets. This means `Token` is no longer `Copy` but this causes no problems. - Removing the `RawStrError` from `LiteralKind`. Raw string literal invalidity is now indicated by a `None` value within `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be used to re-lex an invalid raw string literal to get the `RawStrError`. There is one very small change in behaviour. Previously, if a raw string literal matched both the `InvalidStarter` and `TooManyHashes` cases, the latter would override the former. This has now changed, because `raw_double_quoted_string` now uses `?` and so returns immediately upon detecting the `InvalidStarter` case. I think this is a slight improvement to report the earlier-detected error, and it explains the change in the `test_too_many_hashes` test. The commit also removes a couple of comments that refer to #77629 and say that the size of these types don't affect performance. These comments are wrong, though the performance effect is small.
2022-08-01Inline `first_token`.Nicholas Nethercote-0/+1
Because it's tiny and hot.
2022-06-28fix typo in commentProloy Mishra-1/+1
2022-03-23Reduce max hash in raw strings from u16 to u8Grisha Vartanyan-11/+11
2022-03-16Add test for >65535 hashes in lexing raw stringGrisha-0/+17
2022-02-24Improve `scan_escape`.Nicholas Nethercote-23/+22
`scan_escape` currently has a fast path (for when the first char isn't '\\') and a slow path. This commit changes `scan_escape` so it only handles the slow path, i.e. the actual escaping code. The fast path is inlined into the two call sites. This change makes the code faster, because there is no function call overhead on the fast path. (`scan_escape` is a big function and doesn't get inlined.) This change also improves readability, because it removes a bunch of mode checks on the the fast paths.
2021-12-03Auto merge of #91393 - Julian-Wollersberger:lexer_optimization, r=petrochenkovbors-25/+28
Optimize `rustc_lexer` The `cursor.first()` method in `rustc_lexer` now calls the `chars.next()` method instead of `chars.nth_char(0)`. This allows LLVM to optimize the code better. The biggest win is that `eat_while()` is now fully inlined and generates better assembly. This improves the lexer's performance by 35% in a micro-benchmark I made (Lexing all 18MB of code in the compiler directory). But lexing is only a small part of the overall compilation time, so I don't know how significant it is. Big thanks to criterion and `cargo asm`.
2021-12-01Replace `nth_char(0)` with `next()` in `cursor.first()`Julian Wollersberger-25/+28
and optimize the iterator returned by `tokenize(). This improves lexer performance by 35%
2021-11-23udpate comment to be more accurateEsteban Kuber-2/+1
2021-11-23Tokenize emoji as if they were valid indentifiersEsteban Kuber-0/+25
In the lexer, consider emojis to be valid identifiers and reject them later to avoid knock down parse errors.
2021-11-06use matches!() macro in more placesMatthias Krüger-5/+4
2021-10-15Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, ↵Matthias Krüger-5/+6
r=petrochenkov" The PR had some unforseen perf regressions that are not as easy to find. Revert the PR for now. This reverts commit 6ae8912a3e7d2c4c775024f58a7ba4b1aedc4073, reversing changes made to 86d6d2b7389fe1b339402c1798edae8b695fc9ef.
2021-10-10Apply clippy suggestionsClemens Wasser-6/+5
2021-08-22Fix more “a”/“an” typosFrank Steffahn-1/+1
2021-08-11Renamed variable str -> tail for clarityAnton Golov-5/+5
2021-08-11Warn when an escaped newline skips multiple linesAnton Golov-0/+14
2021-07-30Add warning when whitespace is not skipped after an escaped newline.Anton Golov-4/+49
2021-07-26Remove ASCII fast path from rustc_lexer::{is_id_continue, is_id_start}Ibraheem Ahmed-12/+2
2021-06-26Rename 'bad prefix' to 'unknown prefix'.Mara Bos-8/+8
2021-06-26Improve comments for reserved prefixes.Mara Bos-2/+7
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-06-26Reserve prefixed identifiers and string literals (RFC 3101)lrh2000-5/+12
This commit denies any identifiers immediately followed by one of three tokens `"`, `'` or `#`, which is stricter than the requirements of RFC 3101 but may be necessary according to the discussion at [Zulip]. [Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/268952-edition-2021/topic/reserved.20prefixes/near/238470099
2021-04-08Fix outdated crate names in compiler docspierwill-3/+3
Changes `librustc_X` to `rustc_X`, only in documentation comments. Plain code comments are left unchanged. Also fix incorrect file paths.
2021-01-07Return EOF_CHAR constant instead of magic char.Hanzhen Liang-1/+1
2020-12-18Fix typoHirochika Matsumoto-1/+1
2020-12-03Fix some clippy lintsJoshua Nelson-5/+5
2020-10-30Add back missing commentsJoshua Nelson-0/+1
2020-10-30Fix even more clippy warningsJoshua Nelson-6/+4
2020-10-09Noticed a potential bug in `eat_while()`: it doesn't account for number of ↵Julian Wollersberger-20/+14
UTF8 bytes. Fixed it by inlining it in the two places where the count is used and simplified the logic there.
2020-09-21Fix typo in rustc_lexer docsLingMan-1/+1
Also add an Oxford comma while we're editing that line.
2020-09-02lexer: Tiny improvement to shebang detectionVadim Petrochenkov-5/+9
Lexer now discerns between regular comments and doc comments, so use that. The change only affects the choice of reported errors.
2020-08-30Move lexer unit tests to rustc_lexerAleksey Kladov-20/+140
StringReader is an intornal abstraction which at the moment changes a lot, so these unit tests cause quite a bit of friction. Moving them to rustc_lexer and more ingerated-testing style should make them much less annoying, hopefully without decreasing their usefulness much. Note that coloncolon tests are removed (it's unclear what those are testing). \r\n tests are removed as well, as we normalize line endings even before lexing.
2020-08-30mv compiler to compiler/mark-0/+1687