diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-06-02 08:59:29 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-06-30 20:42:27 +1000 |
| commit | 478f8287c0e2c35cda511fd3ac01b7ac78ee7cfe (patch) | |
| tree | 4d8f19b4e4e440ed8a22ee809ce2a565707d4c27 /compiler/rustc_builtin_macros/src | |
| parent | ed2d759783dc9de134bbb3f01085b1e6dbf539f3 (diff) | |
| download | rust-478f8287c0e2c35cda511fd3ac01b7ac78ee7cfe.tar.gz rust-478f8287c0e2c35cda511fd3ac01b7ac78ee7cfe.zip | |
Introduce `ByteSymbol`.
It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings. This change does slow down compilation of programs that use `include_bytes!` on large files, because the contents of those files are now interned (hashed). This makes `include_bytes!` more similar to `include_str!`, though `include_bytes!` contents still aren't escaped, and hashing is still much cheaper than escaping.
Diffstat (limited to 'compiler/rustc_builtin_macros/src')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/concat_bytes.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_builtin_macros/src/source_util.rs | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_builtin_macros/src/concat_bytes.rs b/compiler/rustc_builtin_macros/src/concat_bytes.rs index 92d011fb9d1..fd2d740c020 100644 --- a/compiler/rustc_builtin_macros/src/concat_bytes.rs +++ b/compiler/rustc_builtin_macros/src/concat_bytes.rs @@ -177,15 +177,15 @@ pub(crate) fn expand_concat_bytes( Ok(LitKind::Byte(val)) => { accumulator.push(val); } - Ok(LitKind::ByteStr(ref bytes, _)) => { - accumulator.extend_from_slice(bytes); + Ok(LitKind::ByteStr(ref byte_sym, _)) => { + accumulator.extend_from_slice(byte_sym.as_byte_str()); } _ => { guar.get_or_insert_with(|| invalid_type_err(cx, token_lit, e.span, false)); } }, - ExprKind::IncludedBytes(bytes) => { - accumulator.extend_from_slice(bytes); + ExprKind::IncludedBytes(byte_sym) => { + accumulator.extend_from_slice(byte_sym.as_byte_str()); } ExprKind::Err(guarantee) => { guar = Some(*guarantee); diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs index 8142f1518dd..cebfffa1e16 100644 --- a/compiler/rustc_builtin_macros/src/source_util.rs +++ b/compiler/rustc_builtin_macros/src/source_util.rs @@ -16,7 +16,7 @@ use rustc_parse::parser::{ForceCollect, Parser}; use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal, utf8_error}; use rustc_session::lint::builtin::INCOMPLETE_INCLUDE; use rustc_span::source_map::SourceMap; -use rustc_span::{Pos, Span, Symbol}; +use rustc_span::{ByteSymbol, Pos, Span, Symbol}; use smallvec::SmallVec; use crate::errors; @@ -237,7 +237,7 @@ pub(crate) fn expand_include_bytes( Ok((bytes, _bsp)) => { // Don't care about getting the span for the raw bytes, // because the console can't really show them anyway. - let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes)); + let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(ByteSymbol::intern(&bytes))); MacEager::expr(expr) } Err(dummy) => dummy, |
