Skip to content

Commit f242d6c

Browse files
committed
Auto merge of rust-lang#127516 - nnethercote:simplify-LazyAttrTokenStream, r=petrochenkov
Simplify `LazyAttrTokenStream` `LazyAttrTokenStream` is an unpleasant type: `Lrc<Box<dyn ToAttrTokenStream>>`. Why does it look like that? - There are two `ToAttrTokenStream` impls, one for the lazy case, and one for the case where we already have an `AttrTokenStream`. - The lazy case (`LazyAttrTokenStreamImpl`) is implemented in `rustc_parse`, but `LazyAttrTokenStream` is defined in `rustc_ast`, which does not depend on `rustc_parse`. The use of the trait lets `rustc_ast` implicitly depend on `rustc_parse`. This explains the `dyn`. - `LazyAttrTokenStream` must have a `size_of` as small as possible, because it's used in many AST nodes. This explains the `Lrc<Box<_>>`, which keeps it to one word. (It's required `Lrc<dyn _>` would be a fat pointer.) This PR moves `LazyAttrTokenStreamImpl` (and a few other token stream things) from `rustc_parse` to `rustc_ast`. This lets us replace the `ToAttrTokenStream` trait with a two-variant enum and also remove the `Box`, changing `LazyAttrTokenStream` to `Lrc<LazyAttrTokenStreamInner>`. Plus it does a few cleanups. r? `@petrochenkov`
2 parents 0fbb922 + 880e6f7 commit f242d6c

File tree

14 files changed

+399
-378
lines changed

14 files changed

+399
-378
lines changed

compiler/rustc_ast/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
test(attr(deny(warnings)))
1313
)]
1414
#![doc(rust_logo)]
15+
#![feature(array_windows)]
1516
#![feature(associated_type_defaults)]
1617
#![feature(box_patterns)]
1718
#![feature(if_let_guard)]
1819
#![feature(negative_impls)]
1920
#![feature(never_type)]
2021
#![feature(rustdoc_internals)]
2122
#![feature(stmt_expr_attributes)]
23+
#![recursion_limit = "256"]
2224
// tidy-alphabetical-end
2325

2426
pub mod util {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ fn visit_lazy_tts_opt_mut<T: MutVisitor>(vis: &mut T, lazy_tts: Option<&mut Lazy
836836
if let Some(lazy_tts) = lazy_tts {
837837
let mut tts = lazy_tts.to_attr_token_stream();
838838
visit_attr_tts(vis, &mut tts);
839-
*lazy_tts = LazyAttrTokenStream::new(tts);
839+
*lazy_tts = LazyAttrTokenStream::new_direct(tts);
840840
}
841841
}
842842
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 366 additions & 17 deletions
Large diffs are not rendered by default.

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![cfg_attr(bootstrap, feature(let_chains))]
8181
#![doc(rust_logo)]
8282
#![feature(rustdoc_internals)]
83+
#![recursion_limit = "256"]
8384
// tidy-alphabetical-end
8485

8586
#[macro_use]

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(rustdoc_internals)]
1919
#![feature(string_from_utf8_lossy_owned)]
2020
#![feature(try_blocks)]
21+
#![recursion_limit = "256"]
2122
// tidy-alphabetical-end
2223

2324
extern crate proc_macro;

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(string_from_utf8_lossy_owned)]
1515
#![feature(trait_alias)]
1616
#![feature(try_blocks)]
17+
#![recursion_limit = "256"]
1718
// tidy-alphabetical-end
1819

1920
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).

compiler/rustc_expand/src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub(crate) fn attr_into_trace(mut attr: Attribute, trace_name: Symbol) -> Attrib
162162
let NormalAttr { item, tokens } = &mut **normal;
163163
item.path.segments[0].ident.name = trace_name;
164164
// This makes the trace attributes unobservable to token-based proc macros.
165-
*tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::default()));
165+
*tokens = Some(LazyAttrTokenStream::new_direct(AttrTokenStream::default()));
166166
}
167167
AttrKind::DocComment(..) => unreachable!(),
168168
}
@@ -192,7 +192,7 @@ impl<'a> StripUnconfigured<'a> {
192192
if self.config_tokens {
193193
if let Some(Some(tokens)) = node.tokens_mut() {
194194
let attr_stream = tokens.to_attr_token_stream();
195-
*tokens = LazyAttrTokenStream::new(self.configure_tokens(&attr_stream));
195+
*tokens = LazyAttrTokenStream::new_direct(self.configure_tokens(&attr_stream));
196196
}
197197
}
198198
}
@@ -223,7 +223,7 @@ impl<'a> StripUnconfigured<'a> {
223223
target.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
224224

225225
if self.in_cfg(&target.attrs) {
226-
target.tokens = LazyAttrTokenStream::new(
226+
target.tokens = LazyAttrTokenStream::new_direct(
227227
self.configure_tokens(&target.tokens.to_attr_token_stream()),
228228
);
229229
Some(AttrTokenTree::AttrsTarget(target))
@@ -361,7 +361,7 @@ impl<'a> StripUnconfigured<'a> {
361361
.to_attr_token_stream(),
362362
));
363363

364-
let tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::new(trees)));
364+
let tokens = Some(LazyAttrTokenStream::new_direct(AttrTokenStream::new(trees)));
365365
let attr = ast::attr::mk_attr_from_item(
366366
&self.sess.psess.attr_id_generator,
367367
item,

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(never_type)]
1515
#![feature(rustc_attrs)]
1616
#![feature(variant_count)]
17+
#![recursion_limit = "256"]
1718
// tidy-alphabetical-end
1819

1920
extern crate self as rustc_hir;

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#![feature(try_trait_v2_yeet)]
6262
#![feature(type_alias_impl_trait)]
6363
#![feature(yeet_expr)]
64+
#![recursion_limit = "256"]
6465
// tidy-alphabetical-end
6566

6667
#[cfg(test)]

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#![allow(rustc::diagnostic_outside_of_impl)]
66
#![allow(rustc::untranslatable_diagnostic)]
77
#![cfg_attr(bootstrap, feature(let_chains))]
8-
#![feature(array_windows)]
98
#![feature(assert_matches)]
109
#![feature(box_patterns)]
1110
#![feature(debug_closure_helpers)]
1211
#![feature(if_let_guard)]
1312
#![feature(iter_intersperse)]
1413
#![feature(string_from_utf8_lossy_owned)]
14+
#![recursion_limit = "256"]
1515
// tidy-alphabetical-end
1616

1717
use std::path::{Path, PathBuf};

0 commit comments

Comments
 (0)