Skip to content

Commit

Permalink
Shrink StatementKind::Assign.
Browse files Browse the repository at this point in the history
This shrinks StatementKind from 80 bytes to 64 bytes on 64-bit.
  • Loading branch information
nnethercote committed Sep 24, 2018
1 parent f49f6e7 commit a577f90
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ impl<'tcx> Statement<'tcx> {
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum StatementKind<'tcx> {
/// Write the RHS Rvalue to the LHS Place.
Assign(Place<'tcx>, Rvalue<'tcx>),
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),

/// This represents all the reading that a pattern match may do
/// (e.g. inspecting constants and discriminant values), and the
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);
if let StatementKind::Assign(
Place::Local(assigned_to),
rvalue,
box rvalue,
) = &stmt.kind {
debug!("annotate_argument_and_return_for_borrow: assigned_to={:?} \
rvalue={:?}", assigned_to, rvalue);
Expand Down Expand Up @@ -1725,7 +1725,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
None => return OtherUse(self.mir.source_info(location).span),
};

if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
if let StatementKind::Assign(_, box Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
if let AggregateKind::Closure(def_id, _) = **kind {
debug!("find_closure_move_span: found closure {:?}", places);

Expand Down Expand Up @@ -1788,7 +1788,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}

for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {
if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
if let StatementKind::Assign(_, box Rvalue::Aggregate(ref kind, ref places))
= stmt.kind {
if let AggregateKind::Closure(def_id, _) = **kind {
debug!("find_closure_borrow_span: found closure {:?}", places);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
// flow could be used.
if let Some(StatementKind::Assign(
Place::Local(local),
Rvalue::Use(Operand::Move(move_from)),
box Rvalue::Use(Operand::Move(move_from)),
)) = self.mir.basic_blocks()[location.block]
.statements
.get(location.statement_index)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'tcx> CFG<'tcx> {
rvalue: Rvalue<'tcx>) {
self.push(block, Statement {
source_info,
kind: StatementKind::Assign(place.clone(), rvalue)
kind: StatementKind::Assign(place.clone(), box rvalue)
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
// re-consider the current implementations of the
// propagate_call_return method.

if let mir::Rvalue::Ref(region, _, ref place) = *rhs {
if let mir::Rvalue::Ref(region, _, ref place) = **rhs {
if place.ignore_borrow(
self.tcx,
self.mir,
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let ret_statement = self.make_statement(
StatementKind::Assign(
Place::Local(RETURN_PLACE),
Rvalue::Use(Operand::Copy(rcvr))
box Rvalue::Use(Operand::Copy(rcvr))
)
);
self.block(vec![ret_statement], TerminatorKind::Return, false);
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let statement = self.make_statement(
StatementKind::Assign(
ref_loc.clone(),
Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
box Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
)
);

Expand All @@ -485,7 +485,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let compute_cond = self.make_statement(
StatementKind::Assign(
cond.clone(),
Rvalue::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg))
box Rvalue::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg))
)
);

Expand Down Expand Up @@ -521,13 +521,13 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::Use(Operand::Constant(self.make_usize(0)))
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
)
),
self.make_statement(
StatementKind::Assign(
end.clone(),
Rvalue::Use(Operand::Constant(self.make_usize(len)))
box Rvalue::Use(Operand::Constant(self.make_usize(len)))
)
)
];
Expand Down Expand Up @@ -555,7 +555,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::BinaryOp(
box Rvalue::BinaryOp(
BinOp::Add,
Operand::Copy(Place::Local(beg)),
Operand::Constant(self.make_usize(1))
Expand All @@ -578,7 +578,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let init = self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::Use(Operand::Constant(self.make_usize(0)))
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
)
);
self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
Expand All @@ -605,7 +605,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let statement = self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::BinaryOp(
box Rvalue::BinaryOp(
BinOp::Add,
Operand::Copy(Place::Local(beg)),
Operand::Constant(self.make_usize(1))
Expand Down Expand Up @@ -715,7 +715,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source_info,
kind: StatementKind::Assign(
Place::Local(ref_rcvr),
Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
box Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
)
});
Operand::Move(Place::Local(ref_rcvr))
Expand Down Expand Up @@ -851,7 +851,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
source_info,
kind: StatementKind::Assign(
Place::Local(RETURN_PLACE),
Rvalue::Aggregate(
box Rvalue::Aggregate(
box AggregateKind::Adt(adt_def, variant_no, substs, None, None),
(1..sig.inputs().len()+1).map(|i| {
Operand::Move(Place::Local(Local::new(i)))
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/transform/add_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ impl MirPass for AddValidation {
for i in (0..block_data.statements.len()).rev() {
match block_data.statements[i].kind {
// When the borrow of this ref expires, we need to recover validation.
StatementKind::Assign(_, Rvalue::Ref(_, _, _)) => {
StatementKind::Assign(_, box Rvalue::Ref(_, _, _)) => {
// Due to a lack of NLL; we can't capture anything directly here.
// Instead, we have to re-match and clone there.
let (dest_place, re, src_place) = match block_data.statements[i].kind {
StatementKind::Assign(ref dest_place,
Rvalue::Ref(re, _, ref src_place)) => {
box Rvalue::Ref(re, _, ref src_place)) => {
(dest_place.clone(), re, src_place.clone())
},
_ => bug!("We already matched this."),
Expand Down Expand Up @@ -354,17 +354,17 @@ impl MirPass for AddValidation {
block_data.statements.insert(i, release_stmt);
}
// Casts can change what validation does (e.g. unsizing)
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Copy(_), _)) |
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Move(_), _))
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Copy(_), _)) |
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Move(_), _))
if kind != CastKind::Misc =>
{
// Due to a lack of NLL; we can't capture anything directly here.
// Instead, we have to re-match and clone there.
let (dest_place, src_place) = match block_data.statements[i].kind {
StatementKind::Assign(ref dest_place,
Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
box Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
StatementKind::Assign(ref dest_place,
Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
box Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
{
(dest_place.clone(), src_place.clone())
},
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/copy_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl MirPass for CopyPropagation {

// That use of the source must be an assignment.
match statement.kind {
StatementKind::Assign(Place::Local(local), Rvalue::Use(ref operand)) if
StatementKind::Assign(Place::Local(local), box Rvalue::Use(ref operand)) if
local == dest_local => {
let maybe_action = match *operand {
Operand::Copy(ref src_place) |
Expand Down Expand Up @@ -155,11 +155,11 @@ fn eliminate_self_assignments<'tcx>(
match stmt.kind {
StatementKind::Assign(
Place::Local(local),
Rvalue::Use(Operand::Copy(Place::Local(src_local))),
box Rvalue::Use(Operand::Copy(Place::Local(src_local))),
) |
StatementKind::Assign(
Place::Local(local),
Rvalue::Use(Operand::Move(Place::Local(src_local))),
box Rvalue::Use(Operand::Move(Place::Local(src_local))),
) if local == dest_local && dest_local == src_local => {}
_ => {
continue;
Expand Down
12 changes: 8 additions & 4 deletions src/librustc_mir/transform/deaggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl MirPass for Deaggregator {
bb.expand_statements(|stmt| {
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
if let StatementKind::Assign(_, ref rhs) = stmt.kind {
if let Rvalue::Aggregate(ref kind, _) = *rhs {
if let Rvalue::Aggregate(ref kind, _) = **rhs {
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
if let AggregateKind::Array(_) = **kind {
return None;
Expand All @@ -41,8 +41,12 @@ impl MirPass for Deaggregator {
let stmt = stmt.replace_nop();
let source_info = stmt.source_info;
let (mut lhs, kind, operands) = match stmt.kind {
StatementKind::Assign(lhs, Rvalue::Aggregate(kind, operands))
=> (lhs, kind, operands),
StatementKind::Assign(lhs, box rvalue) => {
match rvalue {
Rvalue::Aggregate(kind, operands) => (lhs, kind, operands),
_ => bug!()
}
}
_ => bug!()
};

Expand Down Expand Up @@ -82,7 +86,7 @@ impl MirPass for Deaggregator {
};
Statement {
source_info,
kind: StatementKind::Assign(lhs_field, Rvalue::Use(op)),
kind: StatementKind::Assign(lhs_field, box Rvalue::Use(op)),
}
}).chain(set_discriminant))
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");

let assign = Statement {
kind: StatementKind::Assign(location.clone(), Rvalue::Use(value.clone())),
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
source_info: terminator.source_info
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
});
Statement {
source_info,
kind: StatementKind::Assign(state, Rvalue::Use(val)),
kind: StatementKind::Assign(state, box Rvalue::Use(val)),
}
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
data.statements.push(Statement {
source_info,
kind: StatementKind::Assign(Place::Local(RETURN_PLACE),
self.make_state(state_idx, v)),
box self.make_state(state_idx, v)),
});
let state = if let Some(resume) = resume { // Yield
let state = 3 + self.suspension_points.len() as u32;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {

let stmt = Statement {
source_info: callsite.location,
kind: StatementKind::Assign(tmp.clone(), dest)
kind: StatementKind::Assign(tmp.clone(), box dest)
};
caller_mir[callsite.bb]
.statements.push(stmt);
Expand Down Expand Up @@ -594,7 +594,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {

let stmt = Statement {
source_info: callsite.location,
kind: StatementKind::Assign(Place::Local(arg_tmp), arg),
kind: StatementKind::Assign(Place::Local(arg_tmp), box arg),
};
caller_mir[callsite.bb].statements.push(stmt);
arg_tmp
Expand Down
17 changes: 10 additions & 7 deletions src/librustc_mir/transform/lower_128bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ impl Lower128Bit {
let bin_statement = block.statements.pop().unwrap();
let source_info = bin_statement.source_info;
let (place, lhs, mut rhs) = match bin_statement.kind {
StatementKind::Assign(place, Rvalue::BinaryOp(_, lhs, rhs))
| StatementKind::Assign(place, Rvalue::CheckedBinaryOp(_, lhs, rhs)) => {
(place, lhs, rhs)
StatementKind::Assign(place, box rvalue) => {
match rvalue {
Rvalue::BinaryOp(_, lhs, rhs)
| Rvalue::CheckedBinaryOp(_, lhs, rhs) => (place, lhs, rhs),
_ => bug!(),
}
}
_ => bug!("Statement doesn't match pattern any more?"),
_ => bug!()
};

if let Some(local) = cast_local {
Expand All @@ -95,7 +98,7 @@ impl Lower128Bit {
source_info: source_info,
kind: StatementKind::Assign(
Place::Local(local),
Rvalue::Cast(
box Rvalue::Cast(
CastKind::Misc,
rhs,
rhs_override_ty.unwrap())),
Expand Down Expand Up @@ -154,13 +157,13 @@ fn lower_to<'a, 'tcx, D>(statement: &Statement<'tcx>, local_decls: &D, tcx: TyCt
where D: HasLocalDecls<'tcx>
{
match statement.kind {
StatementKind::Assign(_, Rvalue::BinaryOp(bin_op, ref lhs, _)) => {
StatementKind::Assign(_, box Rvalue::BinaryOp(bin_op, ref lhs, _)) => {
let ty = lhs.ty(local_decls, tcx);
if let Some(is_signed) = sign_of_128bit(ty) {
return item_for_op(bin_op, is_signed);
}
},
StatementKind::Assign(_, Rvalue::CheckedBinaryOp(bin_op, ref lhs, _)) => {
StatementKind::Assign(_, box Rvalue::CheckedBinaryOp(bin_op, ref lhs, _)) => {
let ty = lhs.ty(local_decls, tcx);
if let Some(is_signed) = sign_of_128bit(ty) {
return item_for_checked_op(bin_op, is_signed);
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
span,
scope: OUTERMOST_SOURCE_SCOPE
},
kind: StatementKind::Assign(Place::Local(dest), rvalue)
kind: StatementKind::Assign(Place::Local(dest), box rvalue)
});
}

Expand Down Expand Up @@ -217,7 +217,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
// First, take the Rvalue or Call out of the source MIR,
// or duplicate it, depending on keep_original.
if loc.statement_index < no_stmts {
let (mut rvalue, source_info) = {
let (rvalue, source_info) = {
let statement = &mut self.source[loc.block].statements[loc.statement_index];
let rhs = match statement.kind {
StatementKind::Assign(_, ref mut rhs) => rhs,
Expand All @@ -230,11 +230,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
(if self.keep_original {
rhs.clone()
} else {
let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
let unit = box Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
mem::replace(rhs, unit)
}, statement.source_info)
};

let mut rvalue = *rvalue;
self.visit_rvalue(&mut rvalue, loc);
self.assign(new_temp, rvalue, source_info.span);
} else {
Expand Down Expand Up @@ -301,7 +302,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
Candidate::Ref(loc) => {
let ref mut statement = blocks[loc.block].statements[loc.statement_index];
match statement.kind {
StatementKind::Assign(_, Rvalue::Ref(_, _, ref mut place)) => {
StatementKind::Assign(_, box Rvalue::Ref(_, _, ref mut place)) => {
// Find the underlying local for this (necessarily interior) borrow.
// HACK(eddyb) using a recursive function because of mutable borrows.
fn interior_base<'a, 'tcx>(place: &'a mut Place<'tcx>)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
match *candidate {
Candidate::Ref(Location { block: bb, statement_index: stmt_idx }) => {
match self.mir[bb].statements[stmt_idx].kind {
StatementKind::Assign(_, Rvalue::Ref(_, _, Place::Local(index))) => {
StatementKind::Assign(_, box Rvalue::Ref(_, _, Place::Local(index))) => {
promoted_temps.insert(index);
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/remove_noop_landing_pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl RemoveNoopLandingPads {
// instructions, but this should all run after borrowck).
}

StatementKind::Assign(Place::Local(_), Rvalue::Use(_)) => {
StatementKind::Assign(Place::Local(_), box Rvalue::Use(_)) => {
// Writing to a local (e.g. a drop flag) does not
// turn a landing pad to a non-nop
}
Expand Down
Loading

0 comments on commit a577f90

Please sign in to comment.