Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink StatementKind #54526

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ impl<'tcx> Statement<'tcx> {
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum StatementKind<'tcx> {
/// Write the RHS Rvalue to the LHS Place.
Assign(Place<'tcx>, Rvalue<'tcx>),
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),

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

/// Assert the given places to be valid inhabitants of their type. These statements are
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,16 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
}
}

impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice()
}

fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
self.iter().any(|t| t.visit_with(visitor))
}
}

impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
self.map_bound_ref(|ty| ty.fold_with(folder))
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);
if let StatementKind::Assign(
Place::Local(assigned_to),
rvalue,
box rvalue,
) = &stmt.kind {
debug!("annotate_argument_and_return_for_borrow: assigned_to={:?} \
rvalue={:?}", assigned_to, rvalue);
Expand Down Expand Up @@ -1725,7 +1725,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
None => return OtherUse(self.mir.source_info(location).span),
};

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

Expand Down Expand Up @@ -1788,7 +1788,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
ref inputs,
} => {
let context = ContextKind::InlineAsm.new(location);
for (o, output) in asm.outputs.iter().zip(outputs) {
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
if o.is_indirect {
// FIXME(eddyb) indirect inline asm outputs should
// be encoeded through MIR place derefs instead.
Expand All @@ -555,7 +555,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
);
}
}
for input in inputs {
for input in inputs.iter() {
self.consume_operand(context, (input, span), flow_state);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
// flow could be used.
if let Some(StatementKind::Assign(
Place::Local(local),
Rvalue::Use(Operand::Move(move_from)),
box Rvalue::Use(Operand::Move(move_from)),
)) = self.mir.basic_blocks()[location.block]
.statements
.get(location.statement_index)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/nll/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
ref inputs,
} => {
let context = ContextKind::InlineAsm.new(location);
for (o, output) in asm.outputs.iter().zip(outputs) {
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
if o.is_indirect {
// FIXME(eddyb) indirect inline asm outputs should
// be encoeded through MIR place derefs instead.
Expand All @@ -137,7 +137,7 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
);
}
}
for input in inputs {
for input in inputs.iter() {
self.consume_operand(context, input);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'tcx> CFG<'tcx> {
rvalue: Rvalue<'tcx>) {
self.push(block, Statement {
source_info,
kind: StatementKind::Assign(place.clone(), rvalue)
kind: StatementKind::Assign(place.clone(), box rvalue)
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/librustc_mir/build/expr/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let outputs = outputs
.into_iter()
.map(|output| unpack!(block = this.as_place(block, output)))
.collect();
.collect::<Vec<_>>()
.into_boxed_slice();
let inputs = inputs
.into_iter()
.map(|input| unpack!(block = this.as_local_operand(block, input)))
.collect();
.collect::<Vec<_>>()
.into_boxed_slice();
this.cfg.push(
block,
Statement {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
// re-consider the current implementations of the
// propagate_call_return method.

if let mir::Rvalue::Ref(region, _, ref place) = *rhs {
if let mir::Rvalue::Ref(region, _, ref place) = **rhs {
if place.ignore_borrow(
self.tcx,
self.mir,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
self.gather_init(output, InitKind::Deep);
}
}
for input in inputs {
for input in inputs.iter() {
self.gather_operand(input);
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let ret_statement = self.make_statement(
StatementKind::Assign(
Place::Local(RETURN_PLACE),
Rvalue::Use(Operand::Copy(rcvr))
box Rvalue::Use(Operand::Copy(rcvr))
)
);
self.block(vec![ret_statement], TerminatorKind::Return, false);
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let statement = self.make_statement(
StatementKind::Assign(
ref_loc.clone(),
Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
box Rvalue::Ref(tcx.types.re_erased, BorrowKind::Shared, src)
)
);

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

Expand Down Expand Up @@ -521,13 +521,13 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::Use(Operand::Constant(self.make_usize(0)))
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
)
),
self.make_statement(
StatementKind::Assign(
end.clone(),
Rvalue::Use(Operand::Constant(self.make_usize(len)))
box Rvalue::Use(Operand::Constant(self.make_usize(len)))
)
)
];
Expand Down Expand Up @@ -555,7 +555,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::BinaryOp(
box Rvalue::BinaryOp(
BinOp::Add,
Operand::Copy(Place::Local(beg)),
Operand::Constant(self.make_usize(1))
Expand All @@ -578,7 +578,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let init = self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::Use(Operand::Constant(self.make_usize(0)))
box Rvalue::Use(Operand::Constant(self.make_usize(0)))
)
);
self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
Expand All @@ -605,7 +605,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
let statement = self.make_statement(
StatementKind::Assign(
Place::Local(beg),
Rvalue::BinaryOp(
box Rvalue::BinaryOp(
BinOp::Add,
Operand::Copy(Place::Local(beg)),
Operand::Constant(self.make_usize(1))
Expand Down Expand Up @@ -715,7 +715,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source_info,
kind: StatementKind::Assign(
Place::Local(ref_rcvr),
Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
box Rvalue::Ref(tcx.types.re_erased, borrow_kind, rcvr_l)
)
});
Operand::Move(Place::Local(ref_rcvr))
Expand Down Expand Up @@ -851,7 +851,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
source_info,
kind: StatementKind::Assign(
Place::Local(RETURN_PLACE),
Rvalue::Aggregate(
box Rvalue::Aggregate(
box AggregateKind::Adt(adt_def, variant_no, substs, None, None),
(1..sig.inputs().len()+1).map(|i| {
Operand::Move(Place::Local(Local::new(i)))
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/transform/add_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ impl MirPass for AddValidation {
for i in (0..block_data.statements.len()).rev() {
match block_data.statements[i].kind {
// When the borrow of this ref expires, we need to recover validation.
StatementKind::Assign(_, Rvalue::Ref(_, _, _)) => {
StatementKind::Assign(_, box Rvalue::Ref(_, _, _)) => {
// Due to a lack of NLL; we can't capture anything directly here.
// Instead, we have to re-match and clone there.
let (dest_place, re, src_place) = match block_data.statements[i].kind {
StatementKind::Assign(ref dest_place,
Rvalue::Ref(re, _, ref src_place)) => {
box Rvalue::Ref(re, _, ref src_place)) => {
(dest_place.clone(), re, src_place.clone())
},
_ => bug!("We already matched this."),
Expand Down Expand Up @@ -354,17 +354,17 @@ impl MirPass for AddValidation {
block_data.statements.insert(i, release_stmt);
}
// Casts can change what validation does (e.g. unsizing)
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Copy(_), _)) |
StatementKind::Assign(_, Rvalue::Cast(kind, Operand::Move(_), _))
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Copy(_), _)) |
StatementKind::Assign(_, box Rvalue::Cast(kind, Operand::Move(_), _))
if kind != CastKind::Misc =>
{
// Due to a lack of NLL; we can't capture anything directly here.
// Instead, we have to re-match and clone there.
let (dest_place, src_place) = match block_data.statements[i].kind {
StatementKind::Assign(ref dest_place,
Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
box Rvalue::Cast(_, Operand::Copy(ref src_place), _)) |
StatementKind::Assign(ref dest_place,
Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
box Rvalue::Cast(_, Operand::Move(ref src_place), _)) =>
{
(dest_place.clone(), src_place.clone())
},
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/copy_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl MirPass for CopyPropagation {

// That use of the source must be an assignment.
match statement.kind {
StatementKind::Assign(Place::Local(local), Rvalue::Use(ref operand)) if
StatementKind::Assign(Place::Local(local), box Rvalue::Use(ref operand)) if
local == dest_local => {
let maybe_action = match *operand {
Operand::Copy(ref src_place) |
Expand Down Expand Up @@ -155,11 +155,11 @@ fn eliminate_self_assignments<'tcx>(
match stmt.kind {
StatementKind::Assign(
Place::Local(local),
Rvalue::Use(Operand::Copy(Place::Local(src_local))),
box Rvalue::Use(Operand::Copy(Place::Local(src_local))),
) |
StatementKind::Assign(
Place::Local(local),
Rvalue::Use(Operand::Move(Place::Local(src_local))),
box Rvalue::Use(Operand::Move(Place::Local(src_local))),
) if local == dest_local && dest_local == src_local => {}
_ => {
continue;
Expand Down
12 changes: 8 additions & 4 deletions src/librustc_mir/transform/deaggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl MirPass for Deaggregator {
bb.expand_statements(|stmt| {
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
if let StatementKind::Assign(_, ref rhs) = stmt.kind {
if let Rvalue::Aggregate(ref kind, _) = *rhs {
if let Rvalue::Aggregate(ref kind, _) = **rhs {
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
if let AggregateKind::Array(_) = **kind {
return None;
Expand All @@ -41,8 +41,12 @@ impl MirPass for Deaggregator {
let stmt = stmt.replace_nop();
let source_info = stmt.source_info;
let (mut lhs, kind, operands) = match stmt.kind {
StatementKind::Assign(lhs, Rvalue::Aggregate(kind, operands))
=> (lhs, kind, operands),
StatementKind::Assign(lhs, box rvalue) => {
match rvalue {
Rvalue::Aggregate(kind, operands) => (lhs, kind, operands),
_ => bug!()
}
}
_ => bug!()
};

Expand Down Expand Up @@ -82,7 +86,7 @@ impl MirPass for Deaggregator {
};
Statement {
source_info,
kind: StatementKind::Assign(lhs_field, Rvalue::Use(op)),
kind: StatementKind::Assign(lhs_field, box Rvalue::Use(op)),
}
}).chain(set_discriminant))
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");

let assign = Statement {
kind: StatementKind::Assign(location.clone(), Rvalue::Use(value.clone())),
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
source_info: terminator.source_info
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
});
Statement {
source_info,
kind: StatementKind::Assign(state, Rvalue::Use(val)),
kind: StatementKind::Assign(state, box Rvalue::Use(val)),
}
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
data.statements.push(Statement {
source_info,
kind: StatementKind::Assign(Place::Local(RETURN_PLACE),
self.make_state(state_idx, v)),
box self.make_state(state_idx, v)),
});
let state = if let Some(resume) = resume { // Yield
let state = 3 + self.suspension_points.len() as u32;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {

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

let stmt = Statement {
source_info: callsite.location,
kind: StatementKind::Assign(Place::Local(arg_tmp), arg),
kind: StatementKind::Assign(Place::Local(arg_tmp), box arg),
};
caller_mir[callsite.bb].statements.push(stmt);
arg_tmp
Expand Down
Loading