Skip to content

Commit

Permalink
Auto merge of #52364 - ljedrz:mir_remove_clone, r=RalfJung
Browse files Browse the repository at this point in the history
Remove a clone in mir/transform/add_validation

Remove a clone of `mir.local_decls`.
  • Loading branch information
bors committed Jul 18, 2018
2 parents 38168a7 + d5219a7 commit 29ee654
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/librustc_mir/transform/add_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ impl MirPass for AddValidation {
return;
}
let restricted_validation = emit_validate == 1 && fn_contains_unsafe(tcx, src);
let local_decls = mir.local_decls.clone(); // FIXME: Find a way to get rid of this clone.
let (span, arg_count) = (mir.span, mir.arg_count);
let (basic_blocks, local_decls) = mir.basic_blocks_and_local_decls_mut();

// Convert a place to a validation operand.
let place_to_operand = |place: Place<'tcx>| -> ValidationOperand<'tcx, Place<'tcx>> {
let (re, mutbl) = place_context(&place, &local_decls, tcx);
let ty = place.ty(&local_decls, tcx).to_ty(tcx);
let (re, mutbl) = place_context(&place, local_decls, tcx);
let ty = place.ty(local_decls, tcx).to_ty(tcx);
ValidationOperand { place, ty, re, mutbl }
};

Expand Down Expand Up @@ -232,20 +233,20 @@ impl MirPass for AddValidation {
{
let source_info = SourceInfo {
scope: OUTERMOST_SOURCE_SCOPE,
span: mir.span, // FIXME: Consider using just the span covering the function
// argument declaration.
span: span, // FIXME: Consider using just the span covering the function
// argument declaration.
};
// Gather all arguments, skip return value.
let operands = mir.local_decls.iter_enumerated().skip(1).take(mir.arg_count)
let operands = local_decls.iter_enumerated().skip(1).take(arg_count)
.map(|(local, _)| place_to_operand(Place::Local(local))).collect();
emit_acquire(&mut mir.basic_blocks_mut()[START_BLOCK], source_info, operands);
emit_acquire(&mut basic_blocks[START_BLOCK], source_info, operands);
}

// PART 2
// Add ReleaseValid/AcquireValid around function call terminators. We don't use a visitor
// because we need to access the block that a Call jumps to.
let mut returns : Vec<(SourceInfo, Place<'tcx>, BasicBlock)> = Vec::new();
for block_data in mir.basic_blocks_mut() {
for block_data in basic_blocks.iter_mut() {
match block_data.terminator {
Some(Terminator { kind: TerminatorKind::Call { ref args, ref destination, .. },
source_info }) => {
Expand Down Expand Up @@ -298,7 +299,7 @@ impl MirPass for AddValidation {
// Now we go over the returns we collected to acquire the return values.
for (source_info, dest_place, dest_block) in returns {
emit_acquire(
&mut mir.basic_blocks_mut()[dest_block],
&mut basic_blocks[dest_block],
source_info,
vec![place_to_operand(dest_place)]
);
Expand All @@ -312,7 +313,7 @@ impl MirPass for AddValidation {
// PART 3
// Add ReleaseValid/AcquireValid around Ref and Cast. Again an iterator does not seem very
// suited as we need to add new statements before and after each Ref.
for block_data in mir.basic_blocks_mut() {
for block_data in basic_blocks {
// We want to insert statements around Ref commands as we iterate. To this end, we
// iterate backwards using indices.
for i in (0..block_data.statements.len()).rev() {
Expand Down

0 comments on commit 29ee654

Please sign in to comment.