diff options
| author | bors <bors@rust-lang.org> | 2021-02-02 17:34:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-02 17:34:08 +0000 |
| commit | 3182375e064b8fa90437aee1465bccafd8187d89 (patch) | |
| tree | d58213733c388e6e195b04fb0c4ae1a6a65d62b2 /compiler/rustc_parse/src/parser | |
| parent | b81f5811f96fe750ab28c15219d1b0dba6b1dc90 (diff) | |
| parent | 003fba3fdac2bcad6dbf067bc0e9eb0d1cdf7349 (diff) | |
| download | rust-3182375e064b8fa90437aee1465bccafd8187d89.tar.gz rust-3182375e064b8fa90437aee1465bccafd8187d89.zip | |
Auto merge of #81405 - bugadani:ast, r=cjgillot
Box the biggest ast::ItemKind variants This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs. The three affected item kind enums are: - `ast::ItemKind` (208 -> 112 bytes) - `ast::AssocItemKind` (176 -> 72 bytes) - `ast::ForeignItemKind` (176 -> 72 bytes)
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 1ed4d39cd05..c44ccfadda5 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -4,11 +4,11 @@ use super::{FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken}; use crate::{maybe_collect_tokens, maybe_whole}; +use rustc_ast::ast::*; use rustc_ast::ptr::P; use rustc_ast::token::{self, TokenKind}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree}; use rustc_ast::{self as ast, AttrVec, Attribute, DUMMY_NODE_ID}; -use rustc_ast::{AssocItem, AssocItemKind, ForeignItemKind, Item, ItemKind, Mod}; use rustc_ast::{Async, Const, Defaultness, IsAuto, Mutability, Unsafe, UseTree, UseTreeKind}; use rustc_ast::{BindingMode, Block, FnDecl, FnSig, Param, SelfKind}; use rustc_ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, VariantData}; @@ -229,7 +229,7 @@ impl<'a> Parser<'a> { } else if self.check_fn_front_matter() { // FUNCTION ITEM let (ident, sig, generics, body) = self.parse_fn(attrs, req_name, lo)?; - (ident, ItemKind::Fn(def(), sig, generics, body)) + (ident, ItemKind::Fn(box FnKind(def(), sig, generics, body))) } else if self.eat_keyword(kw::Extern) { if self.eat_keyword(kw::Crate) { // EXTERN CRATE @@ -556,7 +556,7 @@ impl<'a> Parser<'a> { }; let trait_ref = TraitRef { path, ref_id: ty_first.id }; - ItemKind::Impl { + ItemKind::Impl(box ImplKind { unsafety, polarity, defaultness, @@ -565,11 +565,11 @@ impl<'a> Parser<'a> { of_trait: Some(trait_ref), self_ty: ty_second, items: impl_items, - } + }) } None => { // impl Type - ItemKind::Impl { + ItemKind::Impl(box ImplKind { unsafety, polarity, defaultness, @@ -578,7 +578,7 @@ impl<'a> Parser<'a> { of_trait: None, self_ty: ty_first, items: impl_items, - } + }) } }; @@ -718,7 +718,7 @@ impl<'a> Parser<'a> { // It's a normal trait. tps.where_clause = self.parse_where_clause()?; let items = self.parse_item_list(attrs, |p| p.parse_trait_item())?; - Ok((ident, ItemKind::Trait(is_auto, unsafety, tps, bounds, items))) + Ok((ident, ItemKind::Trait(box TraitKind(is_auto, unsafety, tps, bounds, items)))) } } @@ -767,7 +767,7 @@ impl<'a> Parser<'a> { let default = if self.eat(&token::Eq) { Some(self.parse_ty()?) } else { None }; self.expect_semi()?; - Ok((ident, ItemKind::TyAlias(def, generics, bounds, default))) + Ok((ident, ItemKind::TyAlias(box TyAliasKind(def, generics, bounds, default)))) } /// Parses a `UseTree`. @@ -1013,7 +1013,9 @@ impl<'a> Parser<'a> { let mut impl_info = self.parse_item_impl(attrs, defaultness)?; match impl_info.1 { // only try to recover if this is implementing a trait for a type - ItemKind::Impl { of_trait: Some(ref trai), ref mut constness, .. } => { + ItemKind::Impl(box ImplKind { + of_trait: Some(ref trai), ref mut constness, .. + }) => { *constness = Const::Yes(const_span); let before_trait = trai.path.span.shrink_to_lo(); |
