1
Fork 0

ast: Reduce size of ExprKind by boxing fields of ExprKind::Struct

This commit is contained in:
Vadim Petrochenkov 2021-03-16 03:15:53 +03:00
parent b25d3ba781
commit d1522b39dd
12 changed files with 48 additions and 28 deletions

View file

@ -1074,7 +1074,7 @@ pub struct Expr {
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Expr, 120);
rustc_data_structures::static_assert_size!(Expr, 104);
impl Expr {
/// Returns `true` if this expression would be valid somewhere that expects a value;
@ -1244,6 +1244,13 @@ pub enum StructRest {
None,
}
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct StructExpr {
pub path: Path,
pub fields: Vec<ExprField>,
pub rest: StructRest,
}
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum ExprKind {
/// A `box x` expression.
@ -1369,7 +1376,7 @@ pub enum ExprKind {
/// A struct literal expression.
///
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. rest}`.
Struct(Path, Vec<ExprField>, StructRest),
Struct(P<StructExpr>),
/// An array literal constructed from one repeated element.
///

View file

@ -1286,10 +1286,11 @@ pub fn noop_visit_expr<T: MutVisitor>(
visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr));
}
ExprKind::MacCall(mac) => vis.visit_mac_call(mac),
ExprKind::Struct(path, fields, expr) => {
ExprKind::Struct(se) => {
let StructExpr { path, fields, rest } = se.deref_mut();
vis.visit_path(path);
fields.flat_map_in_place(|field| vis.flat_map_expr_field(field));
match expr {
match rest {
StructRest::Base(expr) => vis.visit_expr(expr),
StructRest::Rest(_span) => {}
StructRest::None => {}

View file

@ -721,10 +721,10 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
visitor.visit_expr(element);
visitor.visit_anon_const(count)
}
ExprKind::Struct(ref path, ref fields, ref optional_base) => {
visitor.visit_path(path, expression.id);
walk_list!(visitor, visit_expr_field, fields);
match optional_base {
ExprKind::Struct(ref se) => {
visitor.visit_path(&se.path, expression.id);
walk_list!(visitor, visit_expr_field, &se.fields);
match &se.rest {
StructRest::Base(expr) => visitor.visit_expr(expr),
StructRest::Rest(_span) => {}
StructRest::None => {}