Skip to content

Commit 87420cd

Browse files
committed
Make Place Boxed on Statement to reduce size from 64 bytes to 32 bytes
1 parent e73d189 commit 87420cd

36 files changed

+228
-176
lines changed

src/librustc/mir/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ pub struct Statement<'tcx> {
15471547

15481548
// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
15491549
#[cfg(target_arch = "x86_64")]
1550-
static_assert_size!(Statement<'_>, 64);
1550+
static_assert_size!(Statement<'_>, 32);
15511551

15521552
impl Statement<'_> {
15531553
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
@@ -1568,7 +1568,7 @@ impl Statement<'_> {
15681568
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
15691569
pub enum StatementKind<'tcx> {
15701570
/// Write the RHS Rvalue to the LHS Place.
1571-
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),
1571+
Assign(Box<(Place<'tcx>, Rvalue<'tcx>)>),
15721572

15731573
/// This represents all the reading that a pattern match may do
15741574
/// (e.g., inspecting constants and discriminant values), and the
@@ -1577,10 +1577,10 @@ pub enum StatementKind<'tcx> {
15771577
///
15781578
/// Note that this also is emitted for regular `let` bindings to ensure that locals that are
15791579
/// never accessed still get some sanity checks for, e.g., `let x: ! = ..;`
1580-
FakeRead(FakeReadCause, Place<'tcx>),
1580+
FakeRead(FakeReadCause, Box<Place<'tcx>>),
15811581

15821582
/// Write the discriminant for a variant to the enum Place.
1583-
SetDiscriminant { place: Place<'tcx>, variant_index: VariantIdx },
1583+
SetDiscriminant { place: Box<Place<'tcx>>, variant_index: VariantIdx },
15841584

15851585
/// Start a live range for the storage of the local.
15861586
StorageLive(Local),
@@ -1597,7 +1597,7 @@ pub enum StatementKind<'tcx> {
15971597
/// by miri and only generated when "-Z mir-emit-retag" is passed.
15981598
/// See <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/>
15991599
/// for more details.
1600-
Retag(RetagKind, Place<'tcx>),
1600+
Retag(RetagKind, Box<Place<'tcx>>),
16011601

16021602
/// Encodes a user's type ascription. These need to be preserved
16031603
/// intact so that NLL can respect them. For example:
@@ -1611,7 +1611,7 @@ pub enum StatementKind<'tcx> {
16111611
/// - `Contravariant` -- requires that `T_y :> T`
16121612
/// - `Invariant` -- requires that `T_y == T`
16131613
/// - `Bivariant` -- no effect
1614-
AscribeUserType(Place<'tcx>, ty::Variance, Box<UserTypeProjection>),
1614+
AscribeUserType(Box<(Place<'tcx>, UserTypeProjection)>, ty::Variance),
16151615

16161616
/// No-op. Useful for deleting instructions without affecting statement indices.
16171617
Nop,
@@ -1675,7 +1675,7 @@ impl Debug for Statement<'_> {
16751675
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
16761676
use self::StatementKind::*;
16771677
match self.kind {
1678-
Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
1678+
Assign(box(ref place, ref rv)) => write!(fmt, "{:?} = {:?}", place, rv),
16791679
FakeRead(ref cause, ref place) => write!(fmt, "FakeRead({:?}, {:?})", cause, place),
16801680
Retag(ref kind, ref place) => write!(
16811681
fmt,
@@ -1696,7 +1696,7 @@ impl Debug for Statement<'_> {
16961696
InlineAsm(ref asm) => {
16971697
write!(fmt, "asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs)
16981698
}
1699-
AscribeUserType(ref place, ref variance, ref c_ty) => {
1699+
AscribeUserType(box(ref place, ref c_ty), ref variance) => {
17001700
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
17011701
}
17021702
Nop => write!(fmt, "nop"),
@@ -2998,14 +2998,14 @@ BraceStructTypeFoldableImpl! {
29982998

29992999
EnumTypeFoldableImpl! {
30003000
impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> {
3001-
(StatementKind::Assign)(a, b),
3001+
(StatementKind::Assign)(a),
30023002
(StatementKind::FakeRead)(cause, place),
30033003
(StatementKind::SetDiscriminant) { place, variant_index },
30043004
(StatementKind::StorageLive)(a),
30053005
(StatementKind::StorageDead)(a),
30063006
(StatementKind::InlineAsm)(a),
30073007
(StatementKind::Retag)(kind, place),
3008-
(StatementKind::AscribeUserType)(a, v, b),
3008+
(StatementKind::AscribeUserType)(a, v),
30093009
(StatementKind::Nop),
30103010
}
30113011
}

src/librustc/mir/visit.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ macro_rules! make_mir_visitor {
344344

345345
self.visit_source_info(source_info);
346346
match kind {
347-
StatementKind::Assign(place, rvalue) => {
347+
StatementKind::Assign(
348+
box(ref $($mutability)? place, ref $($mutability)? rvalue)
349+
) => {
348350
self.visit_assign(place, rvalue, location);
349351
}
350352
StatementKind::FakeRead(_, place) => {
@@ -391,7 +393,10 @@ macro_rules! make_mir_visitor {
391393
StatementKind::Retag(kind, place) => {
392394
self.visit_retag(kind, place, location);
393395
}
394-
StatementKind::AscribeUserType(place, variance, user_ty) => {
396+
StatementKind::AscribeUserType(
397+
box(ref $($mutability)? place, ref $($mutability)? user_ty),
398+
variance
399+
) => {
395400
self.visit_ascribe_user_ty(place, variance, user_ty, location);
396401
}
397402
StatementKind::Nop => {}

src/librustc_codegen_ssa/mir/statement.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1616

1717
self.set_debug_loc(&mut bx, statement.source_info);
1818
match statement.kind {
19-
mir::StatementKind::Assign(ref place, ref rvalue) => {
19+
mir::StatementKind::Assign(box(ref place, ref rvalue)) => {
2020
if let mir::Place {
2121
base: mir::PlaceBase::Local(index),
2222
projection: box [],
23-
} = *place {
24-
match self.locals[index] {
23+
} = place {
24+
match self.locals[*index] {
2525
LocalRef::Place(cg_dest) => {
2626
self.codegen_rvalue(bx, cg_dest, rvalue)
2727
}
@@ -30,7 +30,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3030
}
3131
LocalRef::Operand(None) => {
3232
let (mut bx, operand) = self.codegen_rvalue_operand(bx, rvalue);
33-
if let Some(name) = self.mir.local_decls[index].name {
33+
if let Some(name) = self.mir.local_decls[*index].name {
3434
match operand.val {
3535
OperandValue::Ref(x, ..) |
3636
OperandValue::Immediate(x) => {
@@ -44,7 +44,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4444
}
4545
}
4646
}
47-
self.locals[index] = LocalRef::Operand(Some(operand));
47+
self.locals[*index] = LocalRef::Operand(Some(operand));
4848
bx
4949
}
5050
LocalRef::Operand(Some(op)) => {
@@ -64,7 +64,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6464
self.codegen_rvalue(bx, cg_dest, rvalue)
6565
}
6666
}
67-
mir::StatementKind::SetDiscriminant{ref place, variant_index} => {
67+
mir::StatementKind::SetDiscriminant{box ref place, variant_index} => {
6868
self.codegen_place(&mut bx, &place.as_ref())
6969
.codegen_set_discr(&mut bx, variant_index);
7070
bx

src/librustc_mir/borrow_check/conflict_errors.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16001600
"annotate_argument_and_return_for_borrow: location={:?}",
16011601
location
16021602
);
1603-
if let Some(&Statement { kind: StatementKind::Assign(ref reservation, _), ..})
1603+
if let Some(&Statement { kind: StatementKind::Assign(box(ref reservation, _)), ..})
16041604
= &self.body[location.block].statements.get(location.statement_index)
16051605
{
16061606
debug!(
@@ -1625,11 +1625,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16251625
target, stmt
16261626
);
16271627
if let StatementKind::Assign(
1628-
Place {
1629-
base: PlaceBase::Local(assigned_to),
1630-
projection: box [],
1631-
},
1632-
box rvalue
1628+
box(
1629+
Place {
1630+
base: PlaceBase::Local(assigned_to),
1631+
projection: box [],
1632+
},
1633+
rvalue
1634+
)
16331635
) = &stmt.kind {
16341636
debug!(
16351637
"annotate_argument_and_return_for_borrow: assigned_to={:?} \

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
4141
let mut target = place.local_or_deref_local();
4242
for stmt in &self.body[location.block].statements[location.statement_index..] {
4343
debug!("add_moved_or_invoked_closure_note: stmt={:?} target={:?}", stmt, target);
44-
if let StatementKind::Assign(into, box Rvalue::Use(from)) = &stmt.kind {
44+
if let StatementKind::Assign(box(into, Rvalue::Use(from))) = &stmt.kind {
4545
debug!("add_fnonce_closure_note: into={:?} from={:?}", into, from);
4646
match from {
4747
Operand::Copy(ref place) |
@@ -792,8 +792,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
792792

793793
debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt);
794794
if let StatementKind::Assign(
795-
_,
796-
box Rvalue::Aggregate(ref kind, ref places)
795+
box(_, Rvalue::Aggregate(ref kind, ref places))
797796
) = stmt.kind {
798797
let (def_id, is_generator) = match kind {
799798
box AggregateKind::Closure(def_id, _) => (def_id, false),
@@ -830,10 +829,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
830829
.get(location.statement_index)
831830
{
832831
Some(&Statement {
833-
kind: StatementKind::Assign(Place {
832+
kind: StatementKind::Assign(box(Place {
834833
base: PlaceBase::Local(local),
835834
projection: box [],
836-
}, _),
835+
}, _)),
837836
..
838837
}) => local,
839838
_ => return OtherUse(use_span),
@@ -846,7 +845,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
846845

847846
for stmt in &self.body[location.block].statements[location.statement_index + 1..] {
848847
if let StatementKind::Assign(
849-
_, box Rvalue::Aggregate(ref kind, ref places)
848+
box(_, Rvalue::Aggregate(ref kind, ref places))
850849
) = stmt.kind {
851850
let (def_id, is_generator) = match kind {
852851
box AggregateKind::Closure(def_id, _) => (def_id, false),

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
546546
self.check_activations(location, span, flow_state);
547547

548548
match stmt.kind {
549-
StatementKind::Assign(ref lhs, ref rhs) => {
549+
StatementKind::Assign(box(ref lhs, ref rhs)) => {
550550
self.consume_rvalue(
551551
location,
552552
(rhs, span),
@@ -561,7 +561,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
561561
flow_state,
562562
);
563563
}
564-
StatementKind::FakeRead(_, ref place) => {
564+
StatementKind::FakeRead(_, box ref place) => {
565565
// Read for match doesn't access any memory and is used to
566566
// assert that a place is safe and live. So we don't have to
567567
// do any checks here.
@@ -1387,7 +1387,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13871387
let stmt = &bbd.statements[loc.statement_index];
13881388
debug!("temporary assigned in: stmt={:?}", stmt);
13891389

1390-
if let StatementKind::Assign(_, box Rvalue::Ref(_, _, ref source)) = stmt.kind {
1390+
if let StatementKind::Assign(box(_, Rvalue::Ref(_, _, ref source))) = stmt.kind {
13911391
propagate_closure_used_mut_place(self, source);
13921392
} else {
13931393
bug!("closures should only capture user variables \

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
8989
// If that ever stops being the case, then the ever initialized
9090
// flow could be used.
9191
if let Some(StatementKind::Assign(
92-
Place {
93-
base: PlaceBase::Local(local),
94-
projection: box [],
95-
},
96-
box Rvalue::Use(Operand::Move(move_from)),
92+
box(
93+
Place {
94+
base: PlaceBase::Local(local),
95+
projection: box [],
96+
},
97+
Rvalue::Use(Operand::Move(move_from))
98+
)
9799
)) = self.body.basic_blocks()[location.block]
98100
.statements
99101
.get(location.statement_index)

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
541541
// it which simplifies the termination logic.
542542
let mut queue = vec![location];
543543
let mut target = if let Some(&Statement {
544-
kind: StatementKind::Assign(Place {
544+
kind: StatementKind::Assign(box(Place {
545545
base: PlaceBase::Local(local),
546546
projection: box [],
547-
}, _),
547+
}, _)),
548548
..
549549
}) = stmt
550550
{
@@ -567,7 +567,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
567567
debug!("was_captured_by_trait_object: stmt={:?}", stmt);
568568

569569
// The only kind of statement that we care about is assignments...
570-
if let StatementKind::Assign(place, box rvalue) = &stmt.kind {
570+
if let StatementKind::Assign(box(place, rvalue)) = &stmt.kind {
571571
let into = match place.local_or_deref_local() {
572572
Some(into) => into,
573573
None => {

src/librustc_mir/borrow_check/nll/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
6666
self.check_activations(location);
6767

6868
match statement.kind {
69-
StatementKind::Assign(ref lhs, ref rhs) => {
69+
StatementKind::Assign(box(ref lhs, ref rhs)) => {
7070
self.consume_rvalue(
7171
location,
7272
rhs,

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13431343
debug!("check_stmt: {:?}", stmt);
13441344
let tcx = self.tcx();
13451345
match stmt.kind {
1346-
StatementKind::Assign(ref place, ref rv) => {
1346+
StatementKind::Assign(box(ref place, ref rv)) => {
13471347
// Assignments to temporaries are not "interesting";
13481348
// they are not caused by the user, but rather artifacts
13491349
// of lowering. Assignments to other sorts of places *are* interesting
@@ -1450,7 +1450,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14501450
);
14511451
};
14521452
}
1453-
StatementKind::AscribeUserType(ref place, variance, box ref projection) => {
1453+
StatementKind::AscribeUserType(box(ref place, ref projection), variance) => {
14541454
let place_ty = place.ty(body, tcx).ty;
14551455
if let Err(terr) = self.relate_type_and_user_type(
14561456
place_ty,

0 commit comments

Comments
 (0)