From 0d69fe8308a76630a104504c14e1d3d74e2a3f15 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 12 Dec 2019 16:41:18 +1100 Subject: Use `P` for `NtTraitItem`, `NtImplItem`, and `NtForeignItem`. This commit reduces the size of `Nonterminal` from a whopping 240 bytes to 72 bytes (on x86-64), which gets it below the `memcpy` threshold. It also removes some impedance mismatches with `Annotatable`, which already uses `P` for these variants. --- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/mut_visit.rs | 18 +++++++++--------- src/libsyntax/token.rs | 10 +++++++--- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/libsyntax') 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, - pub items: Vec, + pub items: Vec>, } /// Global inline assembly. @@ -2605,7 +2605,7 @@ pub enum ItemKind { /// A trait declaration (`trait`). /// /// E.g., `trait Foo { .. }`, `trait Foo { .. }` or `auto trait Foo {}`. - Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec), + Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec>), /// Trait alias /// /// E.g., `trait Foo = Bar + Quux;`. @@ -2624,7 +2624,7 @@ pub enum ItemKind { of_trait: Option, self_ty: P, - items: Vec, + items: Vec>, }, /// A macro invocation. /// diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 4a460c5d7b2..e9e1675b9b0 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) -> SmallVec<[P; 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) -> SmallVec<[P; 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) -> SmallVec<[P; 1]> { noop_flat_map_assoc_item(i, self) } @@ -947,11 +947,11 @@ pub fn noop_visit_item_kind(kind: &mut ItemKind, vis: &mut T) { } pub fn noop_flat_map_assoc_item( - mut item: AssocItem, + mut item: P, visitor: &mut T, -) -> SmallVec<[AssocItem; 1]> { +) -> SmallVec<[P; 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 +1036,10 @@ pub fn noop_flat_map_item( } pub fn noop_flat_map_foreign_item( - mut item: ForeignItem, + mut item: P, visitor: &mut T, -) -> SmallVec<[ForeignItem; 1]> { - let ForeignItem { ident, attrs, id, kind, vis, span, tokens: _ } = &mut item; +) -> SmallVec<[P; 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..c826b728f80 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -680,11 +680,15 @@ pub enum Nonterminal { // 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), + NtImplItem(P), + NtForeignItem(P), } +// `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, 72); + impl PartialEq for Nonterminal { fn eq(&self, rhs: &Self) -> bool { match (self, rhs) { -- cgit 1.4.1-3-g733a5