1
Fork 0

Add an indirection for closures in hir::ExprKind

This helps bring `hir::Expr` size down, `Closure` was the biggest
variant, especially after `for<>` additions.
This commit is contained in:
Maybe Waffle 2022-07-11 23:39:53 +04:00
parent 3ebb852956
commit df4fee9841
26 changed files with 101 additions and 79 deletions

View file

@ -12,6 +12,7 @@ macro_rules! arena_types {
[] asm_operand: (rustc_hir::InlineAsmOperand<'tcx>, rustc_span::Span),
[] asm_template: rustc_ast::InlineAsmTemplatePiece,
[] attribute: rustc_ast::Attribute,
[] closure: rustc_hir::Closure<'tcx>,
[] block: rustc_hir::Block<'tcx>,
[] bare_fn_ty: rustc_hir::BareFnTy<'tcx>,
[] body: rustc_hir::Body<'tcx>,

View file

@ -922,6 +922,17 @@ pub struct Crate<'hir> {
pub hir_hash: Fingerprint,
}
#[derive(Debug, HashStable_Generic)]
pub struct Closure<'hir> {
pub binder: ClosureBinder,
pub capture_clause: CaptureBy,
pub bound_generic_params: &'hir [GenericParam<'hir>],
pub fn_decl: &'hir FnDecl<'hir>,
pub body: BodyId,
pub fn_decl_span: Span,
pub movability: Option<Movability>,
}
/// A block of statements `{ .. }`, which may have a label (in this case the
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
/// the `rules` being anything but `DefaultBlock`.
@ -1930,15 +1941,7 @@ pub enum ExprKind<'hir> {
///
/// This may also be a generator literal or an `async block` as indicated by the
/// `Option<Movability>`.
Closure {
binder: &'hir ClosureBinder,
capture_clause: CaptureBy,
bound_generic_params: &'hir [GenericParam<'hir>],
fn_decl: &'hir FnDecl<'hir>,
body: BodyId,
fn_decl_span: Span,
movability: Option<Movability>,
},
Closure(&'hir Closure<'hir>),
/// A block (e.g., `'label: { ... }`).
Block(&'hir Block<'hir>, Option<Label>),

View file

@ -1144,23 +1144,17 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
visitor.visit_expr(subexpression);
walk_list!(visitor, visit_arm, arms);
}
ExprKind::Closure {
ExprKind::Closure(&Closure {
binder: _,
bound_generic_params,
ref fn_decl,
fn_decl,
body,
capture_clause: _,
fn_decl_span: _,
movability: _,
} => {
}) => {
walk_list!(visitor, visit_generic_param, bound_generic_params);
visitor.visit_fn(
FnKind::Closure,
fn_decl,
body,
expression.span,
expression.hir_id,
)
visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, expression.hir_id)
}
ExprKind::Block(ref block, ref opt_label) => {
walk_list!(visitor, visit_label, opt_label);