about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-31 06:33:36 +0000
committerbors <bors@rust-lang.org>2020-01-31 06:33:36 +0000
commitb1cb3c09097767052d7a10660710b2d540b34daf (patch)
tree3c264595b27c9e939ffb52daeecb72846b079a11 /src/libsyntax
parent266ecd6625060af304adc01f38773c2f013de1c5 (diff)
parent7d2173ed27c1cddc4d4a7a9755f244b66cf1ec81 (diff)
downloadrust-b1cb3c09097767052d7a10660710b2d540b34daf.tar.gz
rust-b1cb3c09097767052d7a10660710b2d540b34daf.zip
Auto merge of #67340 - nnethercote:shrink-Nonterminal, r=petrochenkov
Shrink `Nonterminal`

These commits shrink `Nonterminal` from 240 bytes to 40 bytes. When building `serde_derive` they reduce the number of `memcpy` calls from 9.6M to 7.4M, and it's a tiny win on a few other benchmarks.

r? @petrochenkov
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs6
-rw-r--r--src/libsyntax/mut_visit.rs21
-rw-r--r--src/libsyntax/token.rs12
3 files changed, 22 insertions, 17 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 5c64cc440ce..db4fd53fe16 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -2243,7 +2243,7 @@ pub struct Mod {
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
 pub struct ForeignMod {
     pub abi: Option<StrLit>,
-    pub items: Vec<ForeignItem>,
+    pub items: Vec<P<ForeignItem>>,
 }
 
 /// Global inline assembly.
@@ -2605,7 +2605,7 @@ pub enum ItemKind {
     /// A trait declaration (`trait`).
     ///
     /// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
-    Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec<AssocItem>),
+    Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec<P<AssocItem>>),
     /// Trait alias
     ///
     /// E.g., `trait Foo = Bar + Quux;`.
@@ -2624,7 +2624,7 @@ pub enum ItemKind {
         of_trait: Option<TraitRef>,
 
         self_ty: P<Ty>,
-        items: Vec<AssocItem>,
+        items: Vec<P<AssocItem>>,
     },
     /// A macro invocation.
     ///
diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs
index 4a460c5d7b2..3bcdf8fe286 100644
--- a/src/libsyntax/mut_visit.rs
+++ b/src/libsyntax/mut_visit.rs
@@ -82,7 +82,7 @@ pub trait MutVisitor: Sized {
         noop_visit_use_tree(use_tree, self);
     }
 
-    fn flat_map_foreign_item(&mut self, ni: ForeignItem) -> SmallVec<[ForeignItem; 1]> {
+    fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> {
         noop_flat_map_foreign_item(ni, self)
     }
 
@@ -102,11 +102,11 @@ pub trait MutVisitor: Sized {
         noop_visit_item_kind(i, self);
     }
 
-    fn flat_map_trait_item(&mut self, i: AssocItem) -> SmallVec<[AssocItem; 1]> {
+    fn flat_map_trait_item(&mut self, i: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> {
         noop_flat_map_assoc_item(i, self)
     }
 
-    fn flat_map_impl_item(&mut self, i: AssocItem) -> SmallVec<[AssocItem; 1]> {
+    fn flat_map_impl_item(&mut self, i: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> {
         noop_flat_map_assoc_item(i, self)
     }
 
@@ -704,7 +704,8 @@ pub fn noop_visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis:
         token::NtIdent(ident, _is_raw) => vis.visit_ident(ident),
         token::NtLifetime(ident) => vis.visit_ident(ident),
         token::NtLiteral(expr) => vis.visit_expr(expr),
-        token::NtMeta(AttrItem { path, args }) => {
+        token::NtMeta(item) => {
+            let AttrItem { path, args } = item.deref_mut();
             vis.visit_path(path);
             visit_mac_args(args, vis);
         }
@@ -947,11 +948,11 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
 }
 
 pub fn noop_flat_map_assoc_item<T: MutVisitor>(
-    mut item: AssocItem,
+    mut item: P<AssocItem>,
     visitor: &mut T,
-) -> SmallVec<[AssocItem; 1]> {
+) -> SmallVec<[P<AssocItem>; 1]> {
     let AssocItem { id, ident, vis, defaultness: _, attrs, generics, kind, span, tokens: _ } =
-        &mut item;
+        item.deref_mut();
     visitor.visit_id(id);
     visitor.visit_ident(ident);
     visitor.visit_vis(vis);
@@ -1036,10 +1037,10 @@ pub fn noop_flat_map_item<T: MutVisitor>(
 }
 
 pub fn noop_flat_map_foreign_item<T: MutVisitor>(
-    mut item: ForeignItem,
+    mut item: P<ForeignItem>,
     visitor: &mut T,
-) -> SmallVec<[ForeignItem; 1]> {
-    let ForeignItem { ident, attrs, id, kind, vis, span, tokens: _ } = &mut item;
+) -> SmallVec<[P<ForeignItem>; 1]> {
+    let ForeignItem { ident, attrs, id, kind, vis, span, tokens: _ } = item.deref_mut();
     visitor.visit_ident(ident);
     visit_attrs(attrs, visitor);
     match kind {
diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs
index 14279561cbb..3045f147698 100644
--- a/src/libsyntax/token.rs
+++ b/src/libsyntax/token.rs
@@ -673,18 +673,22 @@ pub enum Nonterminal {
     NtLifetime(ast::Ident),
     NtLiteral(P<ast::Expr>),
     /// Stuff inside brackets for attributes
-    NtMeta(ast::AttrItem),
+    NtMeta(P<ast::AttrItem>),
     NtPath(ast::Path),
     NtVis(ast::Visibility),
     NtTT(TokenTree),
     // Used only for passing items to proc macro attributes (they are not
     // strictly necessary for that, `Annotatable` can be converted into
     // tokens directly, but doing that naively regresses pretty-printing).
-    NtTraitItem(ast::AssocItem),
-    NtImplItem(ast::AssocItem),
-    NtForeignItem(ast::ForeignItem),
+    NtTraitItem(P<ast::AssocItem>),
+    NtImplItem(P<ast::AssocItem>),
+    NtForeignItem(P<ast::ForeignItem>),
 }
 
+// `Nonterminal` is used a lot. Make sure it doesn't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+rustc_data_structures::static_assert_size!(Nonterminal, 40);
+
 impl PartialEq for Nonterminal {
     fn eq(&self, rhs: &Self) -> bool {
         match (self, rhs) {