Box thir::ExprKind::Closure
.
This shrinks `thir::Expr`.
This commit is contained in:
parent
2df805fc7a
commit
b3245a8dff
@ -124,6 +124,15 @@ pub struct Adt<'tcx> {
|
||||
pub base: Option<FruInfo<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
pub struct ClosureExpr<'tcx> {
|
||||
pub closure_id: LocalDefId,
|
||||
pub substs: UpvarSubsts<'tcx>,
|
||||
pub upvars: Box<[ExprId]>,
|
||||
pub movability: Option<hir::Movability>,
|
||||
pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable)]
|
||||
pub enum BlockSafety {
|
||||
Safe,
|
||||
@ -387,13 +396,7 @@ pub enum ExprKind<'tcx> {
|
||||
user_ty: UserTy<'tcx>,
|
||||
},
|
||||
/// A closure definition.
|
||||
Closure {
|
||||
closure_id: LocalDefId,
|
||||
substs: UpvarSubsts<'tcx>,
|
||||
upvars: Box<[ExprId]>,
|
||||
movability: Option<hir::Movability>,
|
||||
fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>,
|
||||
},
|
||||
Closure(Box<ClosureExpr<'tcx>>),
|
||||
/// A literal.
|
||||
Literal {
|
||||
lit: &'tcx hir::Lit,
|
||||
@ -801,7 +804,7 @@ mod size_asserts {
|
||||
use super::*;
|
||||
// These are in alphabetical order, which is easy to maintain.
|
||||
static_assert_size!(Block, 56);
|
||||
static_assert_size!(Expr<'_>, 88);
|
||||
static_assert_size!(Expr<'_>, 80);
|
||||
static_assert_size!(Pat<'_>, 24);
|
||||
static_assert_size!(Stmt<'_>, 72);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use super::{
|
||||
Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir,
|
||||
Arm, Block, ClosureExpr, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind,
|
||||
Thir,
|
||||
};
|
||||
|
||||
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
|
||||
PlaceTypeAscription { source, user_ty: _ } | ValueTypeAscription { source, user_ty: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[source])
|
||||
}
|
||||
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
|
||||
Closure(box ClosureExpr {
|
||||
closure_id: _,
|
||||
substs: _,
|
||||
upvars: _,
|
||||
movability: _,
|
||||
fake_reads: _,
|
||||
}) => {}
|
||||
Literal { lit: _, neg: _ } => {}
|
||||
NonHirLiteral { lit: _, user_ty: _ } => {}
|
||||
ZstLiteral { user_ty: _ } => {}
|
||||
|
@ -302,7 +302,13 @@ pub(crate) fn as_rvalue(
|
||||
|
||||
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))
|
||||
}
|
||||
ExprKind::Closure { closure_id, substs, ref upvars, movability, ref fake_reads } => {
|
||||
ExprKind::Closure(box ClosureExpr {
|
||||
closure_id,
|
||||
substs,
|
||||
ref upvars,
|
||||
movability,
|
||||
ref fake_reads,
|
||||
}) => {
|
||||
// Convert the closure fake reads, if any, from `ExprRef` to mir `Place`
|
||||
// and push the fake reads.
|
||||
// This must come before creating the operands. This is required in case
|
||||
|
@ -402,13 +402,13 @@ fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
||||
(Bound::Unbounded, Bound::Unbounded) => {}
|
||||
_ => self.requires_unsafe(expr.span, InitializingTypeWith),
|
||||
},
|
||||
ExprKind::Closure {
|
||||
ExprKind::Closure(box ClosureExpr {
|
||||
closure_id,
|
||||
substs: _,
|
||||
upvars: _,
|
||||
movability: _,
|
||||
fake_reads: _,
|
||||
} => {
|
||||
}) => {
|
||||
let closure_def = if let Some((did, const_param_id)) =
|
||||
ty::WithOptConstParam::try_lookup(closure_id, self.tcx)
|
||||
{
|
||||
|
@ -548,7 +548,13 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
ExprKind::Closure { closure_id: def_id, substs, upvars, movability, fake_reads }
|
||||
ExprKind::Closure(Box::new(ClosureExpr {
|
||||
closure_id: def_id,
|
||||
substs,
|
||||
upvars,
|
||||
movability,
|
||||
fake_reads,
|
||||
}))
|
||||
}
|
||||
|
||||
hir::ExprKind::Path(ref qpath) => {
|
||||
|
Loading…
Reference in New Issue
Block a user