Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorino

Box the `MacCall` in various types.

r? `@spastorino`
This commit is contained in:
bors 2022-08-20 10:26:54 +00:00
commit dd01122b5c
12 changed files with 94 additions and 94 deletions

View File

@ -770,7 +770,7 @@ pub enum PatKind {
Paren(P<Pat>),
/// A macro pattern; pre-expansion.
MacCall(MacCall),
MacCall(P<MacCall>),
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
@ -980,7 +980,7 @@ pub enum StmtKind {
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct MacCallStmt {
pub mac: MacCall,
pub mac: P<MacCall>,
pub style: MacStmtStyle,
pub attrs: AttrVec,
pub tokens: Option<LazyTokenStream>,
@ -1437,7 +1437,7 @@ pub enum ExprKind {
InlineAsm(P<InlineAsm>),
/// A macro invocation; pre-expansion.
MacCall(MacCall),
MacCall(P<MacCall>),
/// A struct literal expression.
///
@ -2040,7 +2040,7 @@ pub enum TyKind {
/// Inferred type of a `self` or `&self` argument in a method.
ImplicitSelf,
/// A macro in the type position.
MacCall(MacCall),
MacCall(P<MacCall>),
/// Placeholder for a kind that has failed to be defined.
Err,
/// Placeholder for a `va_list`.
@ -2877,7 +2877,7 @@ pub enum ItemKind {
/// A macro invocation.
///
/// E.g., `foo!(..)`.
MacCall(MacCall),
MacCall(P<MacCall>),
/// A macro definition.
MacroDef(MacroDef),
@ -2951,7 +2951,7 @@ pub enum AssocItemKind {
/// An associated type.
TyAlias(Box<TyAlias>),
/// A macro expanding to associated items.
MacCall(MacCall),
MacCall(P<MacCall>),
}
impl AssocItemKind {
@ -3000,7 +3000,7 @@ pub enum ForeignItemKind {
/// An foreign type.
TyAlias(Box<TyAlias>),
/// A macro expanding to foreign items.
MacCall(MacCall),
MacCall(P<MacCall>),
}
impl From<ForeignItemKind> for ItemKind {
@ -3036,15 +3036,15 @@ mod size_asserts {
use super::*;
use rustc_data_structures::static_assert_size;
// These are in alphabetical order, which is easy to maintain.
static_assert_size!(AssocItem, 160);
static_assert_size!(AssocItemKind, 72);
static_assert_size!(AssocItem, 120);
static_assert_size!(AssocItemKind, 32);
static_assert_size!(Attribute, 32);
static_assert_size!(Block, 48);
static_assert_size!(Expr, 104);
static_assert_size!(ExprKind, 72);
static_assert_size!(Fn, 192);
static_assert_size!(ForeignItem, 160);
static_assert_size!(ForeignItemKind, 72);
static_assert_size!(ForeignItem, 112);
static_assert_size!(ForeignItemKind, 24);
static_assert_size!(GenericBound, 88);
static_assert_size!(Generics, 72);
static_assert_size!(Impl, 200);

View File

@ -52,7 +52,7 @@ pub fn expand_assert<'cx>(
let expr = if let Some(tokens) = custom_message {
let then = cx.expr(
call_site_span,
ExprKind::MacCall(MacCall {
ExprKind::MacCall(P(MacCall {
path: panic_path(),
args: P(MacArgs::Delimited(
DelimSpan::from_single(call_site_span),
@ -60,7 +60,7 @@ pub fn expand_assert<'cx>(
tokens,
)),
prior_type_ascription: None,
}),
})),
);
expr_if_not(cx, call_site_span, cond_expr, then, None)
}

View File

@ -177,7 +177,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
});
self.cx.expr(
self.span,
ExprKind::MacCall(MacCall {
ExprKind::MacCall(P(MacCall {
path: panic_path,
args: P(MacArgs::Delimited(
DelimSpan::from_single(self.span),
@ -185,7 +185,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
initial.into_iter().chain(captures).collect::<TokenStream>(),
)),
prior_type_ascription: None,
}),
})),
)
}

View File

@ -48,7 +48,7 @@ fn expand<'cx>(
MacEager::expr(
cx.expr(
sp,
ExprKind::MacCall(MacCall {
ExprKind::MacCall(P(MacCall {
path: Path {
span: sp,
segments: cx
@ -64,7 +64,7 @@ fn expand<'cx>(
tts,
)),
prior_type_ascription: None,
}),
})),
),
)
}

View File

@ -306,7 +306,7 @@ pub struct Invocation {
pub enum InvocationKind {
Bang {
mac: ast::MacCall,
mac: P<ast::MacCall>,
span: Span,
},
Attr {
@ -1017,7 +1017,7 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
fn is_mac_call(&self) -> bool {
false
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
unreachable!()
}
fn pre_flat_map_node_collect_attr(_cfg: &StripUnconfigured<'_>, _attr: &ast::Attribute) {}
@ -1046,7 +1046,7 @@ impl InvocationCollectorNode for P<ast::Item> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1154,7 +1154,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let item = self.wrapped.into_inner();
match item.kind {
AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
@ -1179,7 +1179,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let item = self.wrapped.into_inner();
match item.kind {
AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
@ -1202,7 +1202,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ForeignItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ForeignItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1323,7 +1323,7 @@ impl InvocationCollectorNode for ast::Stmt {
StmtKind::Local(..) | StmtKind::Empty => false,
}
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
// We pull macro invocations (both attributes and fn-like macro calls) out of their
// `StmtKind`s and treat them as statement macro invocations, not as items or expressions.
let (add_semicolon, mac, attrs) = match self.kind {
@ -1387,7 +1387,7 @@ impl InvocationCollectorNode for P<ast::Ty> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ast::TyKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
TyKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
@ -1411,7 +1411,7 @@ impl InvocationCollectorNode for P<ast::Pat> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, PatKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
PatKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
@ -1439,7 +1439,7 @@ impl InvocationCollectorNode for P<ast::Expr> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ExprKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1466,7 +1466,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> {
fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, ast::ExprKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.wrapped.into_inner();
match node.kind {
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1512,7 +1512,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
placeholder(fragment_kind, NodeId::placeholder_from_expn_id(expn_id), vis)
}
fn collect_bang(&mut self, mac: ast::MacCall, kind: AstFragmentKind) -> AstFragment {
fn collect_bang(&mut self, mac: P<ast::MacCall>, kind: AstFragmentKind) -> AstFragment {
// cache the macro call span so that it can be
// easily adjusted for incremental compilation
let span = mac.span();

View File

@ -15,12 +15,12 @@ pub fn placeholder(
id: ast::NodeId,
vis: Option<ast::Visibility>,
) -> AstFragment {
fn mac_placeholder() -> ast::MacCall {
ast::MacCall {
fn mac_placeholder() -> P<ast::MacCall> {
P(ast::MacCall {
path: ast::Path { span: DUMMY_SP, segments: Vec::new(), tokens: None },
args: P(ast::MacArgs::Empty),
prior_type_ascription: None,
}
})
}
let ident = Ident::empty();

View File

@ -1492,11 +1492,11 @@ impl<'a> Parser<'a> {
self.struct_span_err(path.span, "macros cannot use qualified paths").emit();
}
let lo = path.span;
let mac = MacCall {
let mac = P(MacCall {
path,
args: self.parse_mac_args()?,
prior_type_ascription: self.last_type_ascription,
};
});
(lo.to(self.prev_token.span), ExprKind::MacCall(mac))
} else if self.check(&token::OpenDelim(Delimiter::Brace)) &&
let Some(expr) = self.maybe_parse_struct_expr(qself.as_ref(), &path) {

View File

@ -287,7 +287,7 @@ impl<'a> Parser<'a> {
return Ok(None);
} else if macros_allowed && self.check_path() {
// MACRO INVOCATION ITEM
(Ident::empty(), ItemKind::MacCall(self.parse_item_macro(vis)?))
(Ident::empty(), ItemKind::MacCall(P(self.parse_item_macro(vis)?)))
} else {
return Ok(None);
};

View File

@ -665,7 +665,7 @@ impl<'a> Parser<'a> {
fn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind> {
self.bump();
let args = self.parse_mac_args()?;
let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };
let mac = P(MacCall { path, args, prior_type_ascription: self.last_type_ascription });
Ok(PatKind::MacCall(mac))
}

View File

@ -177,7 +177,7 @@ impl<'a> Parser<'a> {
None => unreachable!(),
};
let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };
let mac = P(MacCall { path, args, prior_type_ascription: self.last_type_ascription });
let kind = if (style == MacStmtStyle::Braces
&& self.token != token::Dot

View File

@ -598,11 +598,11 @@ impl<'a> Parser<'a> {
let path = self.parse_path_inner(PathStyle::Type, ty_generics)?;
if self.eat(&token::Not) {
// Macro invocation in type position
Ok(TyKind::MacCall(MacCall {
Ok(TyKind::MacCall(P(MacCall {
path,
args: self.parse_mac_args()?,
prior_type_ascription: self.last_type_ascription,
}))
})))
} else if allow_plus == AllowPlus::Yes && self.check_plus() {
// `Trait1 + Trait2 + 'a`
self.parse_remaining_bounds_path(Vec::new(), path, lo, true)

View File

@ -3,7 +3,7 @@ PRE EXPANSION AST STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
ExprField 48 ( 0.5%) 1 48
ExprField 48 ( 0.6%) 1 48
Attribute 64 ( 0.7%) 2 32
- Normal 32 ( 0.4%) 1
- DocComment 32 ( 0.4%) 1
@ -14,48 +14,48 @@ WherePredicate 72 ( 0.8%) 1 72
- BoundPredicate 72 ( 0.8%) 1
Crate 72 ( 0.8%) 1 72
Arm 96 ( 1.1%) 2 48
ForeignItem 112 ( 1.3%) 1 112
- Fn 112 ( 1.3%) 1
FieldDef 160 ( 1.8%) 2 80
ForeignItem 160 ( 1.8%) 1 160
- Fn 160 ( 1.8%) 1
Stmt 160 ( 1.8%) 5 32
- Local 32 ( 0.4%) 1
- MacCall 32 ( 0.4%) 1
- Expr 96 ( 1.1%) 3
Param 160 ( 1.8%) 4 40
FnDecl 200 ( 2.2%) 5 40
Variant 240 ( 2.7%) 2 120
Block 288 ( 3.2%) 6 48
FnDecl 200 ( 2.3%) 5 40
Variant 240 ( 2.8%) 2 120
Block 288 ( 3.3%) 6 48
GenericBound 352 ( 4.0%) 4 88
- Trait 352 ( 4.0%) 4
GenericParam 520 ( 5.8%) 5 104
AssocItem 640 ( 7.2%) 4 160
- TyAlias 320 ( 3.6%) 2
- Fn 320 ( 3.6%) 2
PathSegment 720 ( 8.1%) 30 24
Expr 832 ( 9.3%) 8 104
AssocItem 480 ( 5.5%) 4 120
- TyAlias 240 ( 2.8%) 2
- Fn 240 ( 2.8%) 2
GenericParam 520 ( 6.0%) 5 104
PathSegment 720 ( 8.3%) 30 24
Expr 832 ( 9.6%) 8 104
- Path 104 ( 1.2%) 1
- Match 104 ( 1.2%) 1
- Struct 104 ( 1.2%) 1
- Lit 208 ( 2.3%) 2
- Block 312 ( 3.5%) 3
Pat 840 ( 9.4%) 7 120
- Struct 120 ( 1.3%) 1
- Wild 120 ( 1.3%) 1
- Ident 600 ( 6.7%) 5
Ty 1_344 (15.1%) 14 96
- Lit 208 ( 2.4%) 2
- Block 312 ( 3.6%) 3
Pat 840 ( 9.7%) 7 120
- Struct 120 ( 1.4%) 1
- Wild 120 ( 1.4%) 1
- Ident 600 ( 6.9%) 5
Ty 1_344 (15.5%) 14 96
- Rptr 96 ( 1.1%) 1
- Ptr 96 ( 1.1%) 1
- ImplicitSelf 192 ( 2.2%) 2
- Path 960 (10.8%) 10
Item 1_800 (20.2%) 9 200
- Trait 200 ( 2.2%) 1
- Enum 200 ( 2.2%) 1
- ForeignMod 200 ( 2.2%) 1
- Impl 200 ( 2.2%) 1
- Fn 400 ( 4.5%) 2
- Use 600 ( 6.7%) 3
- Path 960 (11.0%) 10
Item 1_800 (20.7%) 9 200
- Trait 200 ( 2.3%) 1
- Enum 200 ( 2.3%) 1
- ForeignMod 200 ( 2.3%) 1
- Impl 200 ( 2.3%) 1
- Fn 400 ( 4.6%) 2
- Use 600 ( 6.9%) 3
----------------------------------------------------------------
Total 8_904
Total 8_696
POST EXPANSION AST STATS
@ -65,18 +65,18 @@ Name Accumulated Size Count Item Size
ExprField 48 ( 0.5%) 1 48
GenericArgs 64 ( 0.7%) 1 64
- AngleBracketed 64 ( 0.7%) 1
Local 72 ( 0.7%) 1 72
WherePredicate 72 ( 0.7%) 1 72
- BoundPredicate 72 ( 0.7%) 1
Crate 72 ( 0.7%) 1 72
Local 72 ( 0.8%) 1 72
WherePredicate 72 ( 0.8%) 1 72
- BoundPredicate 72 ( 0.8%) 1
Crate 72 ( 0.8%) 1 72
Arm 96 ( 1.0%) 2 48
InlineAsm 120 ( 1.2%) 1 120
Attribute 128 ( 1.3%) 4 32
ForeignItem 112 ( 1.2%) 1 112
- Fn 112 ( 1.2%) 1
InlineAsm 120 ( 1.3%) 1 120
Attribute 128 ( 1.4%) 4 32
- DocComment 32 ( 0.3%) 1
- Normal 96 ( 1.0%) 3
FieldDef 160 ( 1.7%) 2 80
ForeignItem 160 ( 1.7%) 1 160
- Fn 160 ( 1.7%) 1
Stmt 160 ( 1.7%) 5 32
- Local 32 ( 0.3%) 1
- Semi 32 ( 0.3%) 1
@ -85,39 +85,39 @@ Param 160 ( 1.7%) 4 40
FnDecl 200 ( 2.1%) 5 40
Variant 240 ( 2.5%) 2 120
Block 288 ( 3.0%) 6 48
GenericBound 352 ( 3.6%) 4 88
- Trait 352 ( 3.6%) 4
GenericParam 520 ( 5.4%) 5 104
AssocItem 640 ( 6.6%) 4 160
- TyAlias 320 ( 3.3%) 2
- Fn 320 ( 3.3%) 2
PathSegment 792 ( 8.2%) 33 24
Pat 840 ( 8.7%) 7 120
- Struct 120 ( 1.2%) 1
- Wild 120 ( 1.2%) 1
- Ident 600 ( 6.2%) 5
Expr 936 ( 9.7%) 9 104
GenericBound 352 ( 3.7%) 4 88
- Trait 352 ( 3.7%) 4
AssocItem 480 ( 5.1%) 4 120
- TyAlias 240 ( 2.5%) 2
- Fn 240 ( 2.5%) 2
GenericParam 520 ( 5.5%) 5 104
PathSegment 792 ( 8.4%) 33 24
Pat 840 ( 8.9%) 7 120
- Struct 120 ( 1.3%) 1
- Wild 120 ( 1.3%) 1
- Ident 600 ( 6.3%) 5
Expr 936 ( 9.9%) 9 104
- Path 104 ( 1.1%) 1
- Match 104 ( 1.1%) 1
- Struct 104 ( 1.1%) 1
- InlineAsm 104 ( 1.1%) 1
- Lit 208 ( 2.2%) 2
- Block 312 ( 3.2%) 3
Ty 1_344 (13.9%) 14 96
- Block 312 ( 3.3%) 3
Ty 1_344 (14.2%) 14 96
- Rptr 96 ( 1.0%) 1
- Ptr 96 ( 1.0%) 1
- ImplicitSelf 192 ( 2.0%) 2
- Path 960 ( 9.9%) 10
Item 2_200 (22.8%) 11 200
- Path 960 (10.2%) 10
Item 2_200 (23.3%) 11 200
- Trait 200 ( 2.1%) 1
- Enum 200 ( 2.1%) 1
- ExternCrate 200 ( 2.1%) 1
- ForeignMod 200 ( 2.1%) 1
- Impl 200 ( 2.1%) 1
- Fn 400 ( 4.1%) 2
- Use 800 ( 8.3%) 4
- Fn 400 ( 4.2%) 2
- Use 800 ( 8.5%) 4
----------------------------------------------------------------
Total 9_664
Total 9_456
HIR STATS