Skip to content

Commit b3245a8

Browse files
committed
Box thir::ExprKind::Closure.
This shrinks `thir::Expr`.
1 parent 2df805f commit b3245a8

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ pub struct Adt<'tcx> {
124124
pub base: Option<FruInfo<'tcx>>,
125125
}
126126

127+
#[derive(Clone, Debug, HashStable)]
128+
pub struct ClosureExpr<'tcx> {
129+
pub closure_id: LocalDefId,
130+
pub substs: UpvarSubsts<'tcx>,
131+
pub upvars: Box<[ExprId]>,
132+
pub movability: Option<hir::Movability>,
133+
pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>,
134+
}
135+
127136
#[derive(Copy, Clone, Debug, HashStable)]
128137
pub enum BlockSafety {
129138
Safe,
@@ -387,13 +396,7 @@ pub enum ExprKind<'tcx> {
387396
user_ty: UserTy<'tcx>,
388397
},
389398
/// A closure definition.
390-
Closure {
391-
closure_id: LocalDefId,
392-
substs: UpvarSubsts<'tcx>,
393-
upvars: Box<[ExprId]>,
394-
movability: Option<hir::Movability>,
395-
fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>,
396-
},
399+
Closure(Box<ClosureExpr<'tcx>>),
397400
/// A literal.
398401
Literal {
399402
lit: &'tcx hir::Lit,
@@ -801,7 +804,7 @@ mod size_asserts {
801804
use super::*;
802805
// These are in alphabetical order, which is easy to maintain.
803806
static_assert_size!(Block, 56);
804-
static_assert_size!(Expr<'_>, 88);
807+
static_assert_size!(Expr<'_>, 80);
805808
static_assert_size!(Pat<'_>, 24);
806809
static_assert_size!(Stmt<'_>, 72);
807810
}

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{
2-
Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir,
2+
Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind,
3+
Thir,
34
};
45

56
pub trait Visitor<'a, 'tcx: 'a>: Sized {
@@ -126,7 +127,13 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
126127
PlaceTypeAscription { source, user_ty: _ } | ValueTypeAscription { source, user_ty: _ } => {
127128
visitor.visit_expr(&visitor.thir()[source])
128129
}
129-
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
130+
Closure(box ClosureExpr {
131+
closure_id: _,
132+
substs: _,
133+
upvars: _,
134+
movability: _,
135+
fake_reads: _,
136+
}) => {}
130137
Literal { lit: _, neg: _ } => {}
131138
NonHirLiteral { lit: _, user_ty: _ } => {}
132139
ZstLiteral { user_ty: _ } => {}

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
302302

303303
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))
304304
}
305-
ExprKind::Closure { closure_id, substs, ref upvars, movability, ref fake_reads } => {
305+
ExprKind::Closure(box ClosureExpr {
306+
closure_id,
307+
substs,
308+
ref upvars,
309+
movability,
310+
ref fake_reads,
311+
}) => {
306312
// Convert the closure fake reads, if any, from `ExprRef` to mir `Place`
307313
// and push the fake reads.
308314
// This must come before creating the operands. This is required in case

compiler/rustc_mir_build/src/check_unsafety.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,13 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
402402
(Bound::Unbounded, Bound::Unbounded) => {}
403403
_ => self.requires_unsafe(expr.span, InitializingTypeWith),
404404
},
405-
ExprKind::Closure {
405+
ExprKind::Closure(box ClosureExpr {
406406
closure_id,
407407
substs: _,
408408
upvars: _,
409409
movability: _,
410410
fake_reads: _,
411-
} => {
411+
}) => {
412412
let closure_def = if let Some((did, const_param_id)) =
413413
ty::WithOptConstParam::try_lookup(closure_id, self.tcx)
414414
{

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,13 @@ impl<'tcx> Cx<'tcx> {
548548
None => Vec::new(),
549549
};
550550

551-
ExprKind::Closure { closure_id: def_id, substs, upvars, movability, fake_reads }
551+
ExprKind::Closure(Box::new(ClosureExpr {
552+
closure_id: def_id,
553+
substs,
554+
upvars,
555+
movability,
556+
fake_reads,
557+
}))
552558
}
553559

554560
hir::ExprKind::Path(ref qpath) => {

0 commit comments

Comments
 (0)