Skip to content

Commit 27885a9

Browse files
committed
Auto merge of #82727 - oli-obk:shrinkmem, r=pnkfelix
Test the effect of shrinking the size of Rvalue by 16 bytes r? `@ghost`
2 parents 76c500e + 9a2362e commit 27885a9

File tree

29 files changed

+94
-66
lines changed

29 files changed

+94
-66
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,14 @@ fn codegen_stmt<'tcx>(
464464
let val = crate::constant::codegen_tls_ref(fx, def_id, lval.layout());
465465
lval.write_cvalue(fx, val);
466466
}
467-
Rvalue::BinaryOp(bin_op, ref lhs, ref rhs) => {
467+
Rvalue::BinaryOp(bin_op, box (ref lhs, ref rhs)) => {
468468
let lhs = codegen_operand(fx, lhs);
469469
let rhs = codegen_operand(fx, rhs);
470470

471471
let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
472472
lval.write_cvalue(fx, res);
473473
}
474-
Rvalue::CheckedBinaryOp(bin_op, ref lhs, ref rhs) => {
474+
Rvalue::CheckedBinaryOp(bin_op, box (ref lhs, ref rhs)) => {
475475
let lhs = codegen_operand(fx, lhs);
476476
let rhs = codegen_operand(fx, rhs);
477477

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
associated_type_bounds,
66
never_type,
77
try_blocks,
8+
box_patterns,
89
hash_drain_filter
910
)]
1011
#![warn(rust_2018_idioms)]

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
424424
(bx, operand)
425425
}
426426

427-
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
427+
mir::Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => {
428428
let lhs = self.codegen_operand(&mut bx, lhs);
429429
let rhs = self.codegen_operand(&mut bx, rhs);
430430
let llresult = match (lhs.val, rhs.val) {
@@ -453,7 +453,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
453453
};
454454
(bx, operand)
455455
}
456-
mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
456+
mir::Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
457457
let lhs = self.codegen_operand(&mut bx, lhs);
458458
let rhs = self.codegen_operand(&mut bx, rhs);
459459
let result = self.codegen_scalar_checked_binop(

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,9 @@ pub struct Place<'tcx> {
16831683
pub projection: &'tcx List<PlaceElem<'tcx>>,
16841684
}
16851685

1686+
#[cfg(target_arch = "x86_64")]
1687+
static_assert_size!(Place<'_>, 16);
1688+
16861689
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
16871690
#[derive(TyEncodable, TyDecodable, HashStable)]
16881691
pub enum ProjectionElem<V, T> {
@@ -1981,6 +1984,9 @@ pub enum Operand<'tcx> {
19811984
Constant(Box<Constant<'tcx>>),
19821985
}
19831986

1987+
#[cfg(target_arch = "x86_64")]
1988+
static_assert_size!(Operand<'_>, 24);
1989+
19841990
impl<'tcx> Debug for Operand<'tcx> {
19851991
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
19861992
use self::Operand::*;
@@ -2096,8 +2102,8 @@ pub enum Rvalue<'tcx> {
20962102

20972103
Cast(CastKind, Operand<'tcx>, Ty<'tcx>),
20982104

2099-
BinaryOp(BinOp, Operand<'tcx>, Operand<'tcx>),
2100-
CheckedBinaryOp(BinOp, Operand<'tcx>, Operand<'tcx>),
2105+
BinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
2106+
CheckedBinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
21012107

21022108
NullaryOp(NullOp, Ty<'tcx>),
21032109
UnaryOp(UnOp, Operand<'tcx>),
@@ -2116,6 +2122,9 @@ pub enum Rvalue<'tcx> {
21162122
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
21172123
}
21182124

2125+
#[cfg(target_arch = "x86_64")]
2126+
static_assert_size!(Rvalue<'_>, 40);
2127+
21192128
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
21202129
pub enum CastKind {
21212130
Misc,
@@ -2139,6 +2148,9 @@ pub enum AggregateKind<'tcx> {
21392148
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
21402149
}
21412150

2151+
#[cfg(target_arch = "x86_64")]
2152+
static_assert_size!(AggregateKind<'_>, 48);
2153+
21422154
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
21432155
pub enum BinOp {
21442156
/// The `+` operator (addition)
@@ -2215,8 +2227,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22152227
Cast(ref kind, ref place, ref ty) => {
22162228
write!(fmt, "{:?} as {:?} ({:?})", place, ty, kind)
22172229
}
2218-
BinaryOp(ref op, ref a, ref b) => write!(fmt, "{:?}({:?}, {:?})", op, a, b),
2219-
CheckedBinaryOp(ref op, ref a, ref b) => {
2230+
BinaryOp(ref op, box (ref a, ref b)) => write!(fmt, "{:?}({:?}, {:?})", op, a, b),
2231+
CheckedBinaryOp(ref op, box (ref a, ref b)) => {
22202232
write!(fmt, "Checked{:?}({:?}, {:?})", op, a, b)
22212233
}
22222234
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),

compiler/rustc_middle/src/mir/tcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ impl<'tcx> Rvalue<'tcx> {
182182
}
183183
Rvalue::Len(..) => tcx.types.usize,
184184
Rvalue::Cast(.., ty) => ty,
185-
Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
185+
Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => {
186186
let lhs_ty = lhs.ty(local_decls, tcx);
187187
let rhs_ty = rhs.ty(local_decls, tcx);
188188
op.ty(tcx, lhs_ty, rhs_ty)
189189
}
190-
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
190+
Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
191191
let lhs_ty = lhs.ty(local_decls, tcx);
192192
let rhs_ty = rhs.ty(local_decls, tcx);
193193
let ty = op.ty(tcx, lhs_ty, rhs_ty);

compiler/rustc_middle/src/mir/type_foldable.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
181181
AddressOf(mutability, place) => AddressOf(mutability, place.fold_with(folder)),
182182
Len(place) => Len(place.fold_with(folder)),
183183
Cast(kind, op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
184-
BinaryOp(op, rhs, lhs) => BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)),
185-
CheckedBinaryOp(op, rhs, lhs) => {
186-
CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
184+
BinaryOp(op, box (rhs, lhs)) => {
185+
BinaryOp(op, box (rhs.fold_with(folder), lhs.fold_with(folder)))
186+
}
187+
CheckedBinaryOp(op, box (rhs, lhs)) => {
188+
CheckedBinaryOp(op, box (rhs.fold_with(folder), lhs.fold_with(folder)))
187189
}
188190
UnaryOp(op, val) => UnaryOp(op, val.fold_with(folder)),
189191
Discriminant(place) => Discriminant(place.fold_with(folder)),
@@ -227,7 +229,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
227229
op.visit_with(visitor)?;
228230
ty.visit_with(visitor)
229231
}
230-
BinaryOp(_, ref rhs, ref lhs) | CheckedBinaryOp(_, ref rhs, ref lhs) => {
232+
BinaryOp(_, box (ref rhs, ref lhs)) | CheckedBinaryOp(_, box (ref rhs, ref lhs)) => {
231233
rhs.visit_with(visitor)?;
232234
lhs.visit_with(visitor)
233235
}

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ macro_rules! make_mir_visitor {
687687
self.visit_ty(ty, TyContext::Location(location));
688688
}
689689

690-
Rvalue::BinaryOp(_bin_op, lhs, rhs)
691-
| Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => {
690+
Rvalue::BinaryOp(_bin_op, box(lhs, rhs))
691+
| Rvalue::CheckedBinaryOp(_bin_op, box(lhs, rhs)) => {
692692
self.visit_operand(lhs, location);
693693
self.visit_operand(rhs, location);
694694
}

compiler/rustc_mir/src/borrow_check/invalidation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
326326
);
327327
}
328328

329-
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2)
330-
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
329+
Rvalue::BinaryOp(_bin_op, box (ref operand1, ref operand2))
330+
| Rvalue::CheckedBinaryOp(_bin_op, box (ref operand1, ref operand2)) => {
331331
self.consume_operand(location, operand1);
332332
self.consume_operand(location, operand2);
333333
}

compiler/rustc_mir/src/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13161316
);
13171317
}
13181318

1319-
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2)
1320-
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
1319+
Rvalue::BinaryOp(_bin_op, box (ref operand1, ref operand2))
1320+
| Rvalue::CheckedBinaryOp(_bin_op, box (ref operand1, ref operand2)) => {
13211321
self.consume_operand(location, (operand1, span), flow_state);
13221322
self.consume_operand(location, (operand2, span), flow_state);
13231323
}

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,8 +2299,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22992299

23002300
Rvalue::BinaryOp(
23012301
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge,
2302-
left,
2303-
right,
2302+
box (left, right),
23042303
) => {
23052304
let ty_left = left.ty(body, tcx);
23062305
match ty_left.kind() {

0 commit comments

Comments
 (0)