Skip to content

Commit c4a65be

Browse files
committed
Auto merge of #54526 - nnethercote:shrink-StatementKind, r=<try>
Shrink `StatementKind` `StatementKind` occurs in significant amounts in Massif profiles.
2 parents 5ad5aca + e221b24 commit c4a65be

25 files changed

+83
-62
lines changed

src/librustc/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ impl<'tcx> Statement<'tcx> {
16101610
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
16111611
pub enum StatementKind<'tcx> {
16121612
/// Write the RHS Rvalue to the LHS Place.
1613-
Assign(Place<'tcx>, Rvalue<'tcx>),
1613+
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),
16141614

16151615
/// This represents all the reading that a pattern match may do
16161616
/// (e.g. inspecting constants and discriminant values), and the
@@ -1633,8 +1633,8 @@ pub enum StatementKind<'tcx> {
16331633
/// Execute a piece of inline Assembly.
16341634
InlineAsm {
16351635
asm: Box<InlineAsm>,
1636-
outputs: Vec<Place<'tcx>>,
1637-
inputs: Vec<Operand<'tcx>>,
1636+
outputs: Box<[Place<'tcx>]>,
1637+
inputs: Box<[Operand<'tcx>]>,
16381638
},
16391639

16401640
/// Assert the given places to be valid inhabitants of their type. These statements are

src/librustc/ty/structural_impls.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,16 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
720720
}
721721
}
722722

723+
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
724+
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
725+
self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice()
726+
}
727+
728+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
729+
self.iter().any(|t| t.visit_with(visitor))
730+
}
731+
}
732+
723733
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
724734
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
725735
self.map_bound_ref(|ty| ty.fold_with(folder))

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12211221
);
12221222
if let StatementKind::Assign(
12231223
Place::Local(assigned_to),
1224-
rvalue,
1224+
box rvalue,
12251225
) = &stmt.kind {
12261226
debug!("annotate_argument_and_return_for_borrow: assigned_to={:?} \
12271227
rvalue={:?}", assigned_to, rvalue);
@@ -1725,7 +1725,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17251725
None => return OtherUse(self.mir.source_info(location).span),
17261726
};
17271727

1728-
if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
1728+
if let StatementKind::Assign(_, box Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
17291729
if let AggregateKind::Closure(def_id, _) = **kind {
17301730
debug!("find_closure_move_span: found closure {:?}", places);
17311731

@@ -1788,7 +1788,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17881788
}
17891789

17901790
for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {
1791-
if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
1791+
if let StatementKind::Assign(_, box Rvalue::Aggregate(ref kind, ref places))
1792+
= stmt.kind {
17921793
if let AggregateKind::Closure(def_id, _) = **kind {
17931794
debug!("find_closure_borrow_span: found closure {:?}", places);
17941795

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
528528
ref inputs,
529529
} => {
530530
let context = ContextKind::InlineAsm.new(location);
531-
for (o, output) in asm.outputs.iter().zip(outputs) {
531+
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
532532
if o.is_indirect {
533533
// FIXME(eddyb) indirect inline asm outputs should
534534
// be encoeded through MIR place derefs instead.
@@ -555,7 +555,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
555555
);
556556
}
557557
}
558-
for input in inputs {
558+
for input in inputs.iter() {
559559
self.consume_operand(context, (input, span), flow_state);
560560
}
561561
}

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
100100
// flow could be used.
101101
if let Some(StatementKind::Assign(
102102
Place::Local(local),
103-
Rvalue::Use(Operand::Move(move_from)),
103+
box Rvalue::Use(Operand::Move(move_from)),
104104
)) = self.mir.basic_blocks()[location.block]
105105
.statements
106106
.get(location.statement_index)

src/librustc_mir/borrow_check/nll/invalidation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
118118
ref inputs,
119119
} => {
120120
let context = ContextKind::InlineAsm.new(location);
121-
for (o, output) in asm.outputs.iter().zip(outputs) {
121+
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
122122
if o.is_indirect {
123123
// FIXME(eddyb) indirect inline asm outputs should
124124
// be encoeded through MIR place derefs instead.
@@ -137,7 +137,7 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
137137
);
138138
}
139139
}
140-
for input in inputs {
140+
for input in inputs.iter() {
141141
self.consume_operand(context, input);
142142
}
143143
}

src/librustc_mir/build/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> CFG<'tcx> {
7676
rvalue: Rvalue<'tcx>) {
7777
self.push(block, Statement {
7878
source_info,
79-
kind: StatementKind::Assign(place.clone(), rvalue)
79+
kind: StatementKind::Assign(place.clone(), box rvalue)
8080
});
8181
}
8282

src/librustc_mir/build/expr/stmt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
143143
let outputs = outputs
144144
.into_iter()
145145
.map(|output| unpack!(block = this.as_place(block, output)))
146-
.collect();
146+
.collect::<Vec<_>>()
147+
.into_boxed_slice();
147148
let inputs = inputs
148149
.into_iter()
149150
.map(|input| unpack!(block = this.as_local_operand(block, input)))
150-
.collect();
151+
.collect::<Vec<_>>()
152+
.into_boxed_slice();
151153
this.cfg.push(
152154
block,
153155
Statement {

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
270270
// re-consider the current implementations of the
271271
// propagate_call_return method.
272272

273-
if let mir::Rvalue::Ref(region, _, ref place) = *rhs {
273+
if let mir::Rvalue::Ref(region, _, ref place) = **rhs {
274274
if place.ignore_borrow(
275275
self.tcx,
276276
self.mir,

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
290290
self.gather_init(output, InitKind::Deep);
291291
}
292292
}
293-
for input in inputs {
293+
for input in inputs.iter() {
294294
self.gather_operand(input);
295295
}
296296
}

0 commit comments

Comments
 (0)