Skip to content

Commit 38d9277

Browse files
committed
Shrink Statement.
This commit reduces the size of `Statement` from 80 bytes to 56 bytes on 64-bit platforms, by boxing the `AscribeUserType` variant of `StatementKind`. This change reduces instruction counts on most benchmarks by 1--3%.
1 parent f99911a commit 38d9277

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/librustc/mir/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> {
16741674
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
16751675
/// invalidating statement indices in `Location`s.
16761676
pub fn make_nop(&mut self) {
1677+
// `Statement` contributes significantly to peak memory usage. Make
1678+
// sure it doesn't get bigger.
1679+
static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
1680+
16771681
self.kind = StatementKind::Nop
16781682
}
16791683

@@ -1737,7 +1741,7 @@ pub enum StatementKind<'tcx> {
17371741
/// - `Contravariant` -- requires that `T_y :> T`
17381742
/// - `Invariant` -- requires that `T_y == T`
17391743
/// - `Bivariant` -- no effect
1740-
AscribeUserType(Place<'tcx>, ty::Variance, UserTypeAnnotation<'tcx>),
1744+
AscribeUserType(Place<'tcx>, ty::Variance, Box<UserTypeAnnotation<'tcx>>),
17411745

17421746
/// No-op. Useful for deleting instructions without affecting statement indices.
17431747
Nop,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13081308
);
13091309
};
13101310
}
1311-
StatementKind::AscribeUserType(ref place, variance, c_ty) => {
1311+
StatementKind::AscribeUserType(ref place, variance, box c_ty) => {
13121312
let place_ty = place.ty(mir, tcx).to_ty(tcx);
13131313
if let Err(terr) = self.relate_type_and_user_type(
13141314
place_ty,

src/librustc_mir/build/expr/as_place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
147147
kind: StatementKind::AscribeUserType(
148148
place.clone(),
149149
Variance::Invariant,
150-
user_ty,
150+
box user_ty,
151151
),
152152
},
153153
);
@@ -167,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
167167
kind: StatementKind::AscribeUserType(
168168
Place::Local(temp.clone()),
169169
Variance::Invariant,
170-
user_ty,
170+
box user_ty,
171171
),
172172
},
173173
);

src/librustc_mir/build/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
316316
kind: StatementKind::AscribeUserType(
317317
place.clone(),
318318
ty::Variance::Invariant,
319-
ascription_user_ty,
319+
box ascription_user_ty,
320320
),
321321
},
322322
);
@@ -1323,7 +1323,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
13231323
kind: StatementKind::AscribeUserType(
13241324
ascription.source.clone(),
13251325
ty::Variance::Covariant,
1326-
ascription.user_ty,
1326+
box ascription.user_ty,
13271327
),
13281328
},
13291329
);

0 commit comments

Comments
 (0)