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

+3-3
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

+10
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

+4-3
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

+2-2
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

+1-1
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

+2-2
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

+1-1
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

+4-2
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

+1-1
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

+1-1
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
}

src/librustc_mir/shim.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
407407
let ret_statement = self.make_statement(
408408
StatementKind::Assign(
409409
Place::Local(RETURN_PLACE),
410-
Rvalue::Use(Operand::Copy(rcvr))
410+
box Rvalue::Use(Operand::Copy(rcvr))
411411
)
412412
);
413413
self.block(vec![ret_statement], TerminatorKind::Return, false);
@@ -458,7 +458,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
458458
let statement = self.make_statement(
459459
StatementKind::Assign(
460460
ref_loc.clone(),
461-
Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
461+
box Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
462462
)
463463
);
464464

@@ -485,7 +485,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
485485
let compute_cond = self.make_statement(
486486
StatementKind::Assign(
487487
cond.clone(),
488-
Rvalue::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg))
488+
box Rvalue::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg))
489489
)
490490
);
491491

@@ -521,13 +521,13 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
521521
self.make_statement(
522522
StatementKind::Assign(
523523
Place::Local(beg),
524-
Rvalue::Use(Operand::Constant(self.make_usize(0)))
524+
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
525525
)
526526
),
527527
self.make_statement(
528528
StatementKind::Assign(
529529
end.clone(),
530-
Rvalue::Use(Operand::Constant(self.make_usize(len)))
530+
box Rvalue::Use(Operand::Constant(self.make_usize(len)))
531531
)
532532
)
533533
];
@@ -555,7 +555,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
555555
self.make_statement(
556556
StatementKind::Assign(
557557
Place::Local(beg),
558-
Rvalue::BinaryOp(
558+
box Rvalue::BinaryOp(
559559
BinOp::Add,
560560
Operand::Copy(Place::Local(beg)),
561561
Operand::Constant(self.make_usize(1))
@@ -578,7 +578,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
578578
let init = self.make_statement(
579579
StatementKind::Assign(
580580
Place::Local(beg),
581-
Rvalue::Use(Operand::Constant(self.make_usize(0)))
581+
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
582582
)
583583
);
584584
self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
@@ -605,7 +605,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
605605
let statement = self.make_statement(
606606
StatementKind::Assign(
607607
Place::Local(beg),
608-
Rvalue::BinaryOp(
608+
box Rvalue::BinaryOp(
609609
BinOp::Add,
610610
Operand::Copy(Place::Local(beg)),
611611
Operand::Constant(self.make_usize(1))
@@ -715,7 +715,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
715715
source_info,
716716
kind: StatementKind::Assign(
717717
Place::Local(ref_rcvr),
718-
Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
718+
box Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
719719
)
720720
});
721721
Operand::Move(Place::Local(ref_rcvr))
@@ -851,7 +851,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
851851
source_info,
852852
kind: StatementKind::Assign(
853853
Place::Local(RETURN_PLACE),
854-
Rvalue::Aggregate(
854+
box Rvalue::Aggregate(
855855
box AggregateKind::Adt(adt_def, variant_no, substs, None, None),
856856
(1..sig.inputs().len()+1).map(|i| {
857857
Operand::Move(Place::Local(Local::new(i)))

src/librustc_mir/transform/add_validation.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ impl MirPass for AddValidation {
320320
for i in (0..block_data.statements.len()).rev() {
321321
match block_data.statements[i].kind {
322322
// When the borrow of this ref expires, we need to recover validation.
323-
StatementKind::Assign(_, Rvalue::Ref(_, _, _)) => {
323+
StatementKind::Assign(_, box Rvalue::Ref(_, _, _)) => {
324324
// Due to a lack of NLL; we can't capture anything directly here.
325325
// Instead, we have to re-match and clone there.
326326
let (dest_place, re, src_place) = match block_data.statements[i].kind {
327327
StatementKind::Assign(ref dest_place,
328-
Rvalue::Ref(re, _, ref src_place)) => {
328+
box Rvalue::Ref(re, _, ref src_place)) => {
329329
(dest_place.clone(), re, src_place.clone())
330330
},
331331
_ => bug!("We already matched this."),
@@ -354,17 +354,17 @@ impl MirPass for AddValidation {
354354
block_data.statements.insert(i, release_stmt);
355355
}
356356
// Casts can change what validation does (e.g. unsizing)
357-
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Copy(_), _)) |
358-
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Move(_), _))
357+
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Copy(_), _)) |
358+
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Move(_), _))
359359
if kind != CastKind::Misc =>
360360
{
361361
// Due to a lack of NLL; we can't capture anything directly here.
362362
// Instead, we have to re-match and clone there.
363363
let (dest_place, src_place) = match block_data.statements[i].kind {
364364
StatementKind::Assign(ref dest_place,
365-
Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
365+
box Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
366366
StatementKind::Assign(ref dest_place,
367-
Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
367+
box Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
368368
{
369369
(dest_place.clone(), src_place.clone())
370370
},

src/librustc_mir/transform/copy_prop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl MirPass for CopyPropagation {
104104

105105
// That use of the source must be an assignment.
106106
match statement.kind {
107-
StatementKind::Assign(Place::Local(local), Rvalue::Use(ref operand)) if
107+
StatementKind::Assign(Place::Local(local), box Rvalue::Use(ref operand)) if
108108
local == dest_local => {
109109
let maybe_action = match *operand {
110110
Operand::Copy(ref src_place) |
@@ -155,11 +155,11 @@ fn eliminate_self_assignments<'tcx>(
155155
match stmt.kind {
156156
StatementKind::Assign(
157157
Place::Local(local),
158-
Rvalue::Use(Operand::Copy(Place::Local(src_local))),
158+
box Rvalue::Use(Operand::Copy(Place::Local(src_local))),
159159
) |
160160
StatementKind::Assign(
161161
Place::Local(local),
162-
Rvalue::Use(Operand::Move(Place::Local(src_local))),
162+
box Rvalue::Use(Operand::Move(Place::Local(src_local))),
163163
) if local == dest_local && dest_local == src_local => {}
164164
_ => {
165165
continue;

src/librustc_mir/transform/deaggregator.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl MirPass for Deaggregator {
2626
bb.expand_statements(|stmt| {
2727
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
2828
if let StatementKind::Assign(_, ref rhs) = stmt.kind {
29-
if let Rvalue::Aggregate(ref kind, _) = *rhs {
29+
if let Rvalue::Aggregate(ref kind, _) = **rhs {
3030
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
3131
if let AggregateKind::Array(_) = **kind {
3232
return None;
@@ -41,8 +41,12 @@ impl MirPass for Deaggregator {
4141
let stmt = stmt.replace_nop();
4242
let source_info = stmt.source_info;
4343
let (mut lhs, kind, operands) = match stmt.kind {
44-
StatementKind::Assign(lhs, Rvalue::Aggregate(kind, operands))
45-
=> (lhs, kind, operands),
44+
StatementKind::Assign(lhs, box rvalue) => {
45+
match rvalue {
46+
Rvalue::Aggregate(kind, operands) => (lhs, kind, operands),
47+
_ => bug!()
48+
}
49+
}
4650
_ => bug!()
4751
};
4852

@@ -82,7 +86,7 @@ impl MirPass for Deaggregator {
8286
};
8387
Statement {
8488
source_info,
85-
kind: StatementKind::Assign(lhs_field, Rvalue::Use(op)),
89+
kind: StatementKind::Assign(lhs_field, box Rvalue::Use(op)),
8690
}
8791
}).chain(set_discriminant))
8892
});

src/librustc_mir/transform/elaborate_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
478478
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");
479479

480480
let assign = Statement {
481-
kind: StatementKind::Assign(location.clone(), Rvalue::Use(value.clone())),
481+
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
482482
source_info: terminator.source_info
483483
};
484484

src/librustc_mir/transform/generator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
188188
});
189189
Statement {
190190
source_info,
191-
kind: StatementKind::Assign(state, Rvalue::Use(val)),
191+
kind: StatementKind::Assign(state, box Rvalue::Use(val)),
192192
}
193193
}
194194
}
@@ -246,7 +246,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
246246
data.statements.push(Statement {
247247
source_info,
248248
kind: StatementKind::Assign(Place::Local(RETURN_PLACE),
249-
self.make_state(state_idx, v)),
249+
box self.make_state(state_idx, v)),
250250
});
251251
let state = if let Some(resume) = resume { // Yield
252252
let state = 3 + self.suspension_points.len() as u32;

src/librustc_mir/transform/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
447447

448448
let stmt = Statement {
449449
source_info: callsite.location,
450-
kind: StatementKind::Assign(tmp.clone(), dest)
450+
kind: StatementKind::Assign(tmp.clone(), box dest)
451451
};
452452
caller_mir[callsite.bb]
453453
.statements.push(stmt);
@@ -594,7 +594,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
594594

595595
let stmt = Statement {
596596
source_info: callsite.location,
597-
kind: StatementKind::Assign(Place::Local(arg_tmp), arg),
597+
kind: StatementKind::Assign(Place::Local(arg_tmp), box arg),
598598
};
599599
caller_mir[callsite.bb].statements.push(stmt);
600600
arg_tmp

0 commit comments

Comments
 (0)