Skip to content

Commit d8d5732

Browse files
committed
Auto merge of rust-lang#126784 - scottmcm:smaller-terminator, r=compiler-errors
Save 2 pointers in `TerminatorKind` (96 → 80 bytes) These things don't need to be `Vec`s; boxed slices are enough. The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2 parents 5a3e2a4 + b28efb1 commit d8d5732

File tree

16 files changed

+72
-72
lines changed

16 files changed

+72
-72
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,11 +1817,11 @@ mod size_asserts {
18171817
use super::*;
18181818
use rustc_data_structures::static_assert_size;
18191819
// tidy-alphabetical-start
1820-
static_assert_size!(BasicBlockData<'_>, 144);
1820+
static_assert_size!(BasicBlockData<'_>, 128);
18211821
static_assert_size!(LocalDecl<'_>, 40);
18221822
static_assert_size!(SourceScopeData<'_>, 64);
18231823
static_assert_size!(Statement<'_>, 32);
1824-
static_assert_size!(Terminator<'_>, 112);
1824+
static_assert_size!(Terminator<'_>, 96);
18251825
static_assert_size!(VarDebugInfo<'_>, 88);
18261826
// tidy-alphabetical-end
18271827
}

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub enum TerminatorKind<'tcx> {
730730
/// reused across function calls without duplicating the contents.
731731
/// The span for each arg is also included
732732
/// (e.g. `a` and `b` in `x.foo(a, b)`).
733-
args: Vec<Spanned<Operand<'tcx>>>,
733+
args: Box<[Spanned<Operand<'tcx>>]>,
734734
/// Where the returned value will be written
735735
destination: Place<'tcx>,
736736
/// Where to go after this call returns. If none, the call necessarily diverges.
@@ -837,7 +837,7 @@ pub enum TerminatorKind<'tcx> {
837837
template: &'tcx [InlineAsmTemplatePiece],
838838

839839
/// The operands for the inline assembly, as `Operand`s or `Place`s.
840-
operands: Vec<InlineAsmOperand<'tcx>>,
840+
operands: Box<[InlineAsmOperand<'tcx>]>,
841841

842842
/// Miscellaneous options for the inline assembly.
843843
options: InlineAsmOptions,
@@ -849,7 +849,7 @@ pub enum TerminatorKind<'tcx> {
849849
/// Valid targets for the inline assembly.
850850
/// The first element is the fallthrough destination, unless
851851
/// InlineAsmOptions::NORETURN is set.
852-
targets: Vec<BasicBlock>,
852+
targets: Box<[BasicBlock]>,
853853

854854
/// Action to be taken if the inline assembly unwinds. This is present
855855
/// if and only if InlineAsmOptions::MAY_UNWIND is set.
@@ -1561,6 +1561,6 @@ mod size_asserts {
15611561
static_assert_size!(PlaceElem<'_>, 24);
15621562
static_assert_size!(Rvalue<'_>, 40);
15631563
static_assert_size!(StatementKind<'_>, 16);
1564-
static_assert_size!(TerminatorKind<'_>, 96);
1564+
static_assert_size!(TerminatorKind<'_>, 80);
15651565
// tidy-alphabetical-end
15661566
}

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
170170
.map(|arg|
171171
Ok(Spanned { node: self.parse_operand(*arg)?, span: self.thir.exprs[*arg].span } )
172172
)
173-
.collect::<PResult<Vec<_>>>()?;
173+
.collect::<PResult<Box<[_]>>>()?;
174174
Ok(TerminatorKind::Call {
175175
func: fun,
176176
args,

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
152152
source_info,
153153
TerminatorKind::Call {
154154
func: exchange_malloc,
155-
args: vec![
155+
args: [
156156
Spanned { node: Operand::Move(size), span: DUMMY_SP },
157157
Spanned { node: Operand::Move(align), span: DUMMY_SP },
158-
],
158+
]
159+
.into(),
159160
destination: storage,
160161
target: Some(success),
161162
unwind: UnwindAction::Continue,

compiler/rustc_mir_build/src/build/expr/into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
238238
}
239239
ExprKind::Call { ty: _, fun, ref args, from_hir_call, fn_span } => {
240240
let fun = unpack!(block = this.as_local_operand(block, fun));
241-
let args: Vec<_> = args
241+
let args: Box<[_]> = args
242242
.into_iter()
243243
.copied()
244244
.map(|arg| Spanned {
@@ -485,7 +485,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
485485
operands,
486486
options,
487487
line_spans,
488-
targets,
488+
targets: targets.into_boxed_slice(),
489489
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
490490
UnwindAction::Continue
491491
} else {

compiler/rustc_mir_build/src/build/matches/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
324324
user_ty: None,
325325
const_: method,
326326
})),
327-
args: vec![Spanned { node: Operand::Move(ref_src), span }],
327+
args: [Spanned { node: Operand::Move(ref_src), span }].into(),
328328
destination: temp,
329329
target: Some(target_block),
330330
unwind: UnwindAction::Continue,
@@ -486,10 +486,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
486486

487487
const_: method,
488488
})),
489-
args: vec![
489+
args: [
490490
Spanned { node: Operand::Copy(val), span: DUMMY_SP },
491491
Spanned { node: expect, span: DUMMY_SP },
492-
],
492+
]
493+
.into(),
493494
destination: eq_result,
494495
target: Some(eq_block),
495496
unwind: UnwindAction::Continue,

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,8 @@ where
650650
[ty.into()],
651651
self.source_info.span,
652652
),
653-
args: vec![Spanned {
654-
node: Operand::Move(Place::from(ref_place)),
655-
span: DUMMY_SP,
656-
}],
653+
args: [Spanned { node: Operand::Move(Place::from(ref_place)), span: DUMMY_SP }]
654+
.into(),
657655
destination: unit_temp,
658656
target: Some(succ),
659657
unwind: unwind.into_action(),

compiler/rustc_mir_dataflow/src/framework/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> {
3434
2,
3535
mir::TerminatorKind::Call {
3636
func: mir::Operand::Copy(dummy_place.clone()),
37-
args: vec![],
37+
args: [].into(),
3838
destination: dummy_place.clone(),
3939
target: Some(mir::START_BLOCK),
4040
unwind: mir::UnwindAction::Continue,
@@ -48,7 +48,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> {
4848
4,
4949
mir::TerminatorKind::Call {
5050
func: mir::Operand::Copy(dummy_place.clone()),
51-
args: vec![],
51+
args: [].into(),
5252
destination: dummy_place.clone(),
5353
target: Some(mir::START_BLOCK),
5454
unwind: mir::UnwindAction::Continue,

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
677677

678678
fn eliminate_get_context_call<'tcx>(bb_data: &mut BasicBlockData<'tcx>) -> Local {
679679
let terminator = bb_data.terminator.take().unwrap();
680-
if let TerminatorKind::Call { mut args, destination, target, .. } = terminator.kind {
681-
let arg = args.pop().unwrap();
680+
if let TerminatorKind::Call { args, destination, target, .. } = terminator.kind {
681+
let [arg] = *Box::try_from(args).unwrap();
682682
let local = arg.node.place().unwrap().local;
683683

684684
let arg = Rvalue::Use(arg.node);

compiler/rustc_mir_transform/src/coverage/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'tcx> MockBlocks<'tcx> {
134134
some_from_block,
135135
TerminatorKind::Call {
136136
func: Operand::Copy(self.dummy_place.clone()),
137-
args: vec![],
137+
args: [].into(),
138138
destination: self.dummy_place.clone(),
139139
target: Some(TEMP_BLOCK),
140140
unwind: UnwindAction::Continue,

0 commit comments

Comments
 (0)