Skip to content

Commit a577f90

Browse files
committed
Shrink StatementKind::Assign.
This shrinks StatementKind from 80 bytes to 64 bytes on 64-bit.
1 parent f49f6e7 commit a577f90

20 files changed

+62
-53
lines changed

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ impl<'tcx> Statement<'tcx> {
16101610
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
16111611
pub enum StatementKind<'tcx> {
16121612
/// Write the RHS Rvalue to the LHS Place.
1613-
Assign(Place<'tcx>, Rvalue<'tcx>),
1613+
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),
16141614

16151615
/// This represents all the reading that a pattern match may do
16161616
/// (e.g. inspecting constants and discriminant values), and the

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12211221
);
12221222
if let StatementKind::Assign(
12231223
Place::Local(assigned_to),
1224-
rvalue,
1224+
box rvalue,
12251225
) = &stmt.kind {
12261226
debug!("annotate_argument_and_return_for_borrow: assigned_to={:?} \
12271227
rvalue={:?}", assigned_to, rvalue);
@@ -1725,7 +1725,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17251725
None => return OtherUse(self.mir.source_info(location).span),
17261726
};
17271727

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

@@ -1788,7 +1788,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17881788
}
17891789

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

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
100100
// flow could be used.
101101
if let Some(StatementKind::Assign(
102102
Place::Local(local),
103-
Rvalue::Use(Operand::Move(move_from)),
103+
box Rvalue::Use(Operand::Move(move_from)),
104104
)) = self.mir.basic_blocks()[location.block]
105105
.statements
106106
.get(location.statement_index)

src/librustc_mir/build/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> CFG<'tcx> {
7676
rvalue: Rvalue<'tcx>) {
7777
self.push(block, Statement {
7878
source_info,
79-
kind: StatementKind::Assign(place.clone(), rvalue)
79+
kind: StatementKind::Assign(place.clone(), box rvalue)
8080
});
8181
}
8282

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
270270
// re-consider the current implementations of the
271271
// propagate_call_return method.
272272

273-
if let mir::Rvalue::Ref(region, _, ref place) = *rhs {
273+
if let mir::Rvalue::Ref(region, _, ref place) = **rhs {
274274
if place.ignore_borrow(
275275
self.tcx,
276276
self.mir,

src/librustc_mir/shim.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
407407
let ret_statement = self.make_statement(
408408
StatementKind::Assign(
409409
Place::Local(RETURN_PLACE),
410-
Rvalue::Use(Operand::Copy(rcvr))
410+
box Rvalue::Use(Operand::Copy(rcvr))
411411
)
412412
);
413413
self.block(vec![ret_statement], TerminatorKind::Return, false);
@@ -458,7 +458,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
458458
let statement = self.make_statement(
459459
StatementKind::Assign(
460460
ref_loc.clone(),
461-
Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
461+
box Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
462462
)
463463
);
464464

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

@@ -521,13 +521,13 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
521521
self.make_statement(
522522
StatementKind::Assign(
523523
Place::Local(beg),
524-
Rvalue::Use(Operand::Constant(self.make_usize(0)))
524+
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
525525
)
526526
),
527527
self.make_statement(
528528
StatementKind::Assign(
529529
end.clone(),
530-
Rvalue::Use(Operand::Constant(self.make_usize(len)))
530+
box Rvalue::Use(Operand::Constant(self.make_usize(len)))
531531
)
532532
)
533533
];
@@ -555,7 +555,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
555555
self.make_statement(
556556
StatementKind::Assign(
557557
Place::Local(beg),
558-
Rvalue::BinaryOp(
558+
box Rvalue::BinaryOp(
559559
BinOp::Add,
560560
Operand::Copy(Place::Local(beg)),
561561
Operand::Constant(self.make_usize(1))
@@ -578,7 +578,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
578578
let init = self.make_statement(
579579
StatementKind::Assign(
580580
Place::Local(beg),
581-
Rvalue::Use(Operand::Constant(self.make_usize(0)))
581+
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
582582
)
583583
);
584584
self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
@@ -605,7 +605,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
605605
let statement = self.make_statement(
606606
StatementKind::Assign(
607607
Place::Local(beg),
608-
Rvalue::BinaryOp(
608+
box Rvalue::BinaryOp(
609609
BinOp::Add,
610610
Operand::Copy(Place::Local(beg)),
611611
Operand::Constant(self.make_usize(1))
@@ -715,7 +715,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
715715
source_info,
716716
kind: StatementKind::Assign(
717717
Place::Local(ref_rcvr),
718-
Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
718+
box Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
719719
)
720720
});
721721
Operand::Move(Place::Local(ref_rcvr))
@@ -851,7 +851,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
851851
source_info,
852852
kind: StatementKind::Assign(
853853
Place::Local(RETURN_PLACE),
854-
Rvalue::Aggregate(
854+
box Rvalue::Aggregate(
855855
box AggregateKind::Adt(adt_def, variant_no, substs, None, None),
856856
(1..sig.inputs().len()+1).map(|i| {
857857
Operand::Move(Place::Local(Local::new(i)))

src/librustc_mir/transform/add_validation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ impl MirPass for AddValidation {
320320
for i in (0..block_data.statements.len()).rev() {
321321
match block_data.statements[i].kind {
322322
// When the borrow of this ref expires, we need to recover validation.
323-
StatementKind::Assign(_, Rvalue::Ref(_, _, _)) => {
323+
StatementKind::Assign(_, box Rvalue::Ref(_, _, _)) => {
324324
// Due to a lack of NLL; we can't capture anything directly here.
325325
// Instead, we have to re-match and clone there.
326326
let (dest_place, re, src_place) = match block_data.statements[i].kind {
327327
StatementKind::Assign(ref dest_place,
328-
Rvalue::Ref(re, _, ref src_place)) => {
328+
box Rvalue::Ref(re, _, ref src_place)) => {
329329
(dest_place.clone(), re, src_place.clone())
330330
},
331331
_ => bug!("We already matched this."),
@@ -354,17 +354,17 @@ impl MirPass for AddValidation {
354354
block_data.statements.insert(i, release_stmt);
355355
}
356356
// Casts can change what validation does (e.g. unsizing)
357-
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Copy(_), _)) |
358-
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Move(_), _))
357+
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Copy(_), _)) |
358+
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Move(_), _))
359359
if kind != CastKind::Misc =>
360360
{
361361
// Due to a lack of NLL; we can't capture anything directly here.
362362
// Instead, we have to re-match and clone there.
363363
let (dest_place, src_place) = match block_data.statements[i].kind {
364364
StatementKind::Assign(ref dest_place,
365-
Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
365+
box Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
366366
StatementKind::Assign(ref dest_place,
367-
Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
367+
box Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
368368
{
369369
(dest_place.clone(), src_place.clone())
370370
},

src/librustc_mir/transform/copy_prop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl MirPass for CopyPropagation {
104104

105105
// That use of the source must be an assignment.
106106
match statement.kind {
107-
StatementKind::Assign(Place::Local(local), Rvalue::Use(ref operand)) if
107+
StatementKind::Assign(Place::Local(local), box Rvalue::Use(ref operand)) if
108108
local == dest_local => {
109109
let maybe_action = match *operand {
110110
Operand::Copy(ref src_place) |
@@ -155,11 +155,11 @@ fn eliminate_self_assignments<'tcx>(
155155
match stmt.kind {
156156
StatementKind::Assign(
157157
Place::Local(local),
158-
Rvalue::Use(Operand::Copy(Place::Local(src_local))),
158+
box Rvalue::Use(Operand::Copy(Place::Local(src_local))),
159159
) |
160160
StatementKind::Assign(
161161
Place::Local(local),
162-
Rvalue::Use(Operand::Move(Place::Local(src_local))),
162+
box Rvalue::Use(Operand::Move(Place::Local(src_local))),
163163
) if local == dest_local && dest_local == src_local => {}
164164
_ => {
165165
continue;

src/librustc_mir/transform/deaggregator.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl MirPass for Deaggregator {
2626
bb.expand_statements(|stmt| {
2727
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
2828
if let StatementKind::Assign(_, ref rhs) = stmt.kind {
29-
if let Rvalue::Aggregate(ref kind, _) = *rhs {
29+
if let Rvalue::Aggregate(ref kind, _) = **rhs {
3030
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
3131
if let AggregateKind::Array(_) = **kind {
3232
return None;
@@ -41,8 +41,12 @@ impl MirPass for Deaggregator {
4141
let stmt = stmt.replace_nop();
4242
let source_info = stmt.source_info;
4343
let (mut lhs, kind, operands) = match stmt.kind {
44-
StatementKind::Assign(lhs, Rvalue::Aggregate(kind, operands))
45-
=> (lhs, kind, operands),
44+
StatementKind::Assign(lhs, box rvalue) => {
45+
match rvalue {
46+
Rvalue::Aggregate(kind, operands) => (lhs, kind, operands),
47+
_ => bug!()
48+
}
49+
}
4650
_ => bug!()
4751
};
4852

@@ -82,7 +86,7 @@ impl MirPass for Deaggregator {
8286
};
8387
Statement {
8488
source_info,
85-
kind: StatementKind::Assign(lhs_field, Rvalue::Use(op)),
89+
kind: StatementKind::Assign(lhs_field, box Rvalue::Use(op)),
8690
}
8791
}).chain(set_discriminant))
8892
});

src/librustc_mir/transform/elaborate_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
478478
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");
479479

480480
let assign = Statement {
481-
kind: StatementKind::Assign(location.clone(), Rvalue::Use(value.clone())),
481+
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
482482
source_info: terminator.source_info
483483
};
484484

src/librustc_mir/transform/generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
188188
});
189189
Statement {
190190
source_info,
191-
kind: StatementKind::Assign(state, Rvalue::Use(val)),
191+
kind: StatementKind::Assign(state, box Rvalue::Use(val)),
192192
}
193193
}
194194
}
@@ -246,7 +246,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
246246
data.statements.push(Statement {
247247
source_info,
248248
kind: StatementKind::Assign(Place::Local(RETURN_PLACE),
249-
self.make_state(state_idx, v)),
249+
box self.make_state(state_idx, v)),
250250
});
251251
let state = if let Some(resume) = resume { // Yield
252252
let state = 3 + self.suspension_points.len() as u32;

src/librustc_mir/transform/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
447447

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

595595
let stmt = Statement {
596596
source_info: callsite.location,
597-
kind: StatementKind::Assign(Place::Local(arg_tmp), arg),
597+
kind: StatementKind::Assign(Place::Local(arg_tmp), box arg),
598598
};
599599
caller_mir[callsite.bb].statements.push(stmt);
600600
arg_tmp

src/librustc_mir/transform/lower_128bit.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ impl Lower128Bit {
7979
let bin_statement = block.statements.pop().unwrap();
8080
let source_info = bin_statement.source_info;
8181
let (place, lhs, mut rhs) = match bin_statement.kind {
82-
StatementKind::Assign(place, Rvalue::BinaryOp(_, lhs, rhs))
83-
| StatementKind::Assign(place, Rvalue::CheckedBinaryOp(_, lhs, rhs)) => {
84-
(place, lhs, rhs)
82+
StatementKind::Assign(place, box rvalue) => {
83+
match rvalue {
84+
Rvalue::BinaryOp(_, lhs, rhs)
85+
| Rvalue::CheckedBinaryOp(_, lhs, rhs) => (place, lhs, rhs),
86+
_ => bug!(),
87+
}
8588
}
86-
_ => bug!("Statement doesn't match pattern any more?"),
89+
_ => bug!()
8790
};
8891

8992
if let Some(local) = cast_local {
@@ -95,7 +98,7 @@ impl Lower128Bit {
9598
source_info: source_info,
9699
kind: StatementKind::Assign(
97100
Place::Local(local),
98-
Rvalue::Cast(
101+
box Rvalue::Cast(
99102
CastKind::Misc,
100103
rhs,
101104
rhs_override_ty.unwrap())),
@@ -154,13 +157,13 @@ fn lower_to<'a, 'tcx, D>(statement: &Statement<'tcx>, local_decls: &D, tcx: TyCt
154157
where D: HasLocalDecls<'tcx>
155158
{
156159
match statement.kind {
157-
StatementKind::Assign(_, Rvalue::BinaryOp(bin_op, ref lhs, _)) => {
160+
StatementKind::Assign(_, box Rvalue::BinaryOp(bin_op, ref lhs, _)) => {
158161
let ty = lhs.ty(local_decls, tcx);
159162
if let Some(is_signed) = sign_of_128bit(ty) {
160163
return item_for_op(bin_op, is_signed);
161164
}
162165
},
163-
StatementKind::Assign(_, Rvalue::CheckedBinaryOp(bin_op, ref lhs, _)) => {
166+
StatementKind::Assign(_, box Rvalue::CheckedBinaryOp(bin_op, ref lhs, _)) => {
164167
let ty = lhs.ty(local_decls, tcx);
165168
if let Some(is_signed) = sign_of_128bit(ty) {
166169
return item_for_checked_op(bin_op, is_signed);

src/librustc_mir/transform/promote_consts.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
182182
span,
183183
scope: OUTERMOST_SOURCE_SCOPE
184184
},
185-
kind: StatementKind::Assign(Place::Local(dest), rvalue)
185+
kind: StatementKind::Assign(Place::Local(dest), box rvalue)
186186
});
187187
}
188188

@@ -217,7 +217,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
217217
// First, take the Rvalue or Call out of the source MIR,
218218
// or duplicate it, depending on keep_original.
219219
if loc.statement_index < no_stmts {
220-
let (mut rvalue, source_info) = {
220+
let (rvalue, source_info) = {
221221
let statement = &mut self.source[loc.block].statements[loc.statement_index];
222222
let rhs = match statement.kind {
223223
StatementKind::Assign(_, ref mut rhs) => rhs,
@@ -230,11 +230,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
230230
(if self.keep_original {
231231
rhs.clone()
232232
} else {
233-
let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
233+
let unit = box Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
234234
mem::replace(rhs, unit)
235235
}, statement.source_info)
236236
};
237237

238+
let mut rvalue = *rvalue;
238239
self.visit_rvalue(&mut rvalue, loc);
239240
self.assign(new_temp, rvalue, source_info.span);
240241
} else {
@@ -301,7 +302,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
301302
Candidate::Ref(loc) => {
302303
let ref mut statement = blocks[loc.block].statements[loc.statement_index];
303304
match statement.kind {
304-
StatementKind::Assign(_, Rvalue::Ref(_, _, ref mut place)) => {
305+
StatementKind::Assign(_, box Rvalue::Ref(_, _, ref mut place)) => {
305306
// Find the underlying local for this (necessarily interior) borrow.
306307
// HACK(eddyb) using a recursive function because of mutable borrows.
307308
fn interior_base<'a, 'tcx>(place: &'a mut Place<'tcx>)

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
388388
match *candidate {
389389
Candidate::Ref(Location { block: bb, statement_index: stmt_idx }) => {
390390
match self.mir[bb].statements[stmt_idx].kind {
391-
StatementKind::Assign(_, Rvalue::Ref(_, _, Place::Local(index))) => {
391+
StatementKind::Assign(_, box Rvalue::Ref(_, _, Place::Local(index))) => {
392392
promoted_temps.insert(index);
393393
}
394394
_ => {}

src/librustc_mir/transform/remove_noop_landing_pads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl RemoveNoopLandingPads {
6060
// instructions, but this should all run after borrowck).
6161
}
6262

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

0 commit comments

Comments
 (0)