Skip to content

Commit 4415195

Browse files
committed
Auto merge of #54526 - nnethercote:shrink-StatementKind, r=nagisa
Shrink `StatementKind` `StatementKind` occurs in significant amounts in Massif profiles.
2 parents ae7fe84 + e221b24 commit 4415195

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
@@ -1631,7 +1631,7 @@ impl<'tcx> Statement<'tcx> {
16311631
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
16321632
pub enum StatementKind<'tcx> {
16331633
/// Write the RHS Rvalue to the LHS Place.
1634-
Assign(Place<'tcx>, Rvalue<'tcx>),
1634+
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),
16351635

16361636
/// This represents all the reading that a pattern match may do
16371637
/// (e.g. inspecting constants and discriminant values), and the
@@ -1654,8 +1654,8 @@ pub enum StatementKind<'tcx> {
16541654
/// Execute a piece of inline Assembly.
16551655
InlineAsm {
16561656
asm: Box<InlineAsm>,
1657-
outputs: Vec<Place<'tcx>>,
1658-
inputs: Vec<Operand<'tcx>>,
1657+
outputs: Box<[Place<'tcx>]>,
1658+
inputs: Box<[Operand<'tcx>]>,
16591659
},
16601660

16611661
/// 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
@@ -1319,7 +1319,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13191319
);
13201320
if let StatementKind::Assign(
13211321
Place::Local(assigned_to),
1322-
rvalue,
1322+
box rvalue,
13231323
) = &stmt.kind {
13241324
debug!("annotate_argument_and_return_for_borrow: assigned_to={:?} \
13251325
rvalue={:?}", assigned_to, rvalue);
@@ -1823,7 +1823,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18231823
None => return OtherUse(self.mir.source_info(location).span),
18241824
};
18251825

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

@@ -1886,7 +1886,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18861886
}
18871887

18881888
for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {
1889-
if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref places)) = stmt.kind {
1889+
if let StatementKind::Assign(_, box Rvalue::Aggregate(ref kind, ref places))
1890+
= stmt.kind {
18901891
if let AggregateKind::Closure(def_id, _) = **kind {
18911892
debug!("find_closure_borrow_span: found closure {:?}", places);
18921893

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
534534
ref inputs,
535535
} => {
536536
let context = ContextKind::InlineAsm.new(location);
537-
for (o, output) in asm.outputs.iter().zip(outputs) {
537+
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
538538
if o.is_indirect {
539539
// FIXME(eddyb) indirect inline asm outputs should
540540
// be encoeded through MIR place derefs instead.
@@ -561,7 +561,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
561561
);
562562
}
563563
}
564-
for input in inputs {
564+
for input in inputs.iter() {
565565
self.consume_operand(context, (input, span), flow_state);
566566
}
567567
}

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
@@ -109,7 +109,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
109109
ref inputs,
110110
} => {
111111
let context = ContextKind::InlineAsm.new(location);
112-
for (o, output) in asm.outputs.iter().zip(outputs) {
112+
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
113113
if o.is_indirect {
114114
// FIXME(eddyb) indirect inline asm outputs should
115115
// be encoeded through MIR place derefs instead.
@@ -128,7 +128,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
128128
);
129129
}
130130
}
131-
for input in inputs {
131+
for input in inputs.iter() {
132132
self.consume_operand(context, input);
133133
}
134134
}

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)