diff options
| author | kennytm <kennytm@gmail.com> | 2018-10-26 18:25:11 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-10-26 23:06:44 +0800 |
| commit | 9c55a4a8139bce312b832294a764012816e4fc44 (patch) | |
| tree | 24ecf2cbee9b5b30a74bcc5c9baa7c537eddf5c5 | |
| parent | 2e1e8d29130fe5db2e8beceb7981a0197aaff772 (diff) | |
| parent | 38d9277a77e982e49df07725b62b21c423b6428e (diff) | |
| download | rust-9c55a4a8139bce312b832294a764012816e4fc44.tar.gz rust-9c55a4a8139bce312b832294a764012816e4fc44.zip | |
Rollup merge of #55346 - nnethercote:shrink-StatementKind, r=nagisa
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%.
| -rw-r--r-- | src/librustc/mir/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/build/expr/as_place.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/build/matches/mod.rs | 4 |
4 files changed, 10 insertions, 6 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9d296e67da1..7c3d4713572 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> { /// Changes a statement to a nop. This is both faster than deleting instructions and avoids /// invalidating statement indices in `Location`s. pub fn make_nop(&mut self) { + // `Statement` contributes significantly to peak memory usage. Make + // sure it doesn't get bigger. + static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56); + self.kind = StatementKind::Nop } @@ -1737,7 +1741,7 @@ pub enum StatementKind<'tcx> { /// - `Contravariant` -- requires that `T_y :> T` /// - `Invariant` -- requires that `T_y == T` /// - `Bivariant` -- no effect - AscribeUserType(Place<'tcx>, ty::Variance, UserTypeAnnotation<'tcx>), + AscribeUserType(Place<'tcx>, ty::Variance, Box<UserTypeAnnotation<'tcx>>), /// No-op. Useful for deleting instructions without affecting statement indices. Nop, diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index bbbe02fda6a..ff4651dfb45 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1225,7 +1225,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { ); }; } - StatementKind::AscribeUserType(ref place, variance, c_ty) => { + StatementKind::AscribeUserType(ref place, variance, box c_ty) => { let place_ty = place.ty(mir, tcx).to_ty(tcx); if let Err(terr) = self.relate_type_and_user_type( place_ty, diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 820822b7f5b..8d6b6bb5c74 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -147,7 +147,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( place.clone(), Variance::Invariant, - user_ty, + box user_ty, ), }, ); @@ -167,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( Place::Local(temp.clone()), Variance::Invariant, - user_ty, + box user_ty, ), }, ); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index a864b39e157..caacc9311c6 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -316,7 +316,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( place.clone(), ty::Variance::Invariant, - ascription_user_ty, + box ascription_user_ty, ), }, ); @@ -1323,7 +1323,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { kind: StatementKind::AscribeUserType( ascription.source.clone(), ty::Variance::Covariant, - ascription.user_ty, + box ascription.user_ty, ), }, ); |
