mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Use Place directly in librustc_mir_build, it's Copy
This commit is contained in:
parent
6a95bf884f
commit
f37d2b8a63
@ -9,7 +9,7 @@ use rustc_span::Span;
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
crate fn ast_block(
|
||||
&mut self,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
block: BasicBlock,
|
||||
ast_block: &'tcx hir::Block<'tcx>,
|
||||
source_info: SourceInfo,
|
||||
@ -43,7 +43,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
||||
fn ast_block_stmts(
|
||||
&mut self,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
mut block: BasicBlock,
|
||||
span: Span,
|
||||
stmts: Vec<StmtRef<'tcx>>,
|
||||
|
@ -34,12 +34,12 @@ impl<'tcx> CFG<'tcx> {
|
||||
&mut self,
|
||||
block: BasicBlock,
|
||||
source_info: SourceInfo,
|
||||
place: &Place<'tcx>,
|
||||
place: Place<'tcx>,
|
||||
rvalue: Rvalue<'tcx>,
|
||||
) {
|
||||
self.push(
|
||||
block,
|
||||
Statement { source_info, kind: StatementKind::Assign(box (*place, rvalue)) },
|
||||
Statement { source_info, kind: StatementKind::Assign(box (place, rvalue)) },
|
||||
);
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ impl<'tcx> CFG<'tcx> {
|
||||
&mut self,
|
||||
block: BasicBlock,
|
||||
source_info: SourceInfo,
|
||||
temp: &Place<'tcx>,
|
||||
temp: Place<'tcx>,
|
||||
constant: Constant<'tcx>,
|
||||
) {
|
||||
self.push_assign(block, source_info, temp, Rvalue::Use(Operand::Constant(box constant)));
|
||||
@ -57,7 +57,7 @@ impl<'tcx> CFG<'tcx> {
|
||||
&mut self,
|
||||
block: BasicBlock,
|
||||
source_info: SourceInfo,
|
||||
place: &Place<'tcx>,
|
||||
place: Place<'tcx>,
|
||||
) {
|
||||
self.push_assign(
|
||||
block,
|
||||
|
@ -341,12 +341,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let lt = self.temp(bool_ty, expr_span);
|
||||
|
||||
// len = len(slice)
|
||||
self.cfg.push_assign(block, source_info, &len, Rvalue::Len(slice));
|
||||
self.cfg.push_assign(block, source_info, len, Rvalue::Len(slice));
|
||||
// lt = idx < len
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
<,
|
||||
lt,
|
||||
Rvalue::BinaryOp(BinOp::Lt, Operand::Copy(Place::from(index)), Operand::Copy(len)),
|
||||
);
|
||||
let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) };
|
||||
@ -388,7 +388,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&fake_borrow_temp.into(),
|
||||
fake_borrow_temp.into(),
|
||||
Rvalue::Ref(
|
||||
tcx.lifetimes.re_erased,
|
||||
BorrowKind::Shallow,
|
||||
|
@ -78,7 +78,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
this.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&is_min,
|
||||
is_min,
|
||||
Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval),
|
||||
);
|
||||
|
||||
@ -109,15 +109,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
||||
// malloc some memory of suitable type (thus far, uninitialized):
|
||||
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
|
||||
this.cfg.push_assign(block, source_info, &Place::from(result), box_);
|
||||
this.cfg.push_assign(block, source_info, Place::from(result), box_);
|
||||
|
||||
// initialize the box contents:
|
||||
unpack!(
|
||||
block = this.into(
|
||||
&this.hir.tcx().mk_place_deref(Place::from(result)),
|
||||
block,
|
||||
value
|
||||
)
|
||||
block =
|
||||
this.into(this.hir.tcx().mk_place_deref(Place::from(result)), block, value)
|
||||
);
|
||||
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
|
||||
}
|
||||
@ -284,7 +281,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&result_value,
|
||||
result_value,
|
||||
Rvalue::CheckedBinaryOp(op, lhs, rhs),
|
||||
);
|
||||
let val_fld = Field::new(0);
|
||||
@ -317,7 +314,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&is_zero,
|
||||
is_zero,
|
||||
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero),
|
||||
);
|
||||
|
||||
@ -338,13 +335,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&is_neg_1,
|
||||
is_neg_1,
|
||||
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1),
|
||||
);
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&is_min,
|
||||
is_min,
|
||||
Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min),
|
||||
);
|
||||
|
||||
@ -353,7 +350,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&of,
|
||||
of,
|
||||
Rvalue::BinaryOp(BinOp::BitAnd, is_neg_1, is_min),
|
||||
);
|
||||
|
||||
@ -428,7 +425,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
this.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&Place::from(temp),
|
||||
Place::from(temp),
|
||||
Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place),
|
||||
);
|
||||
|
||||
|
@ -66,7 +66,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
}
|
||||
this.local_decls.push(local_decl)
|
||||
};
|
||||
let temp_place = &Place::from(temp);
|
||||
let temp_place = Place::from(temp);
|
||||
|
||||
match expr.kind {
|
||||
// Don't bother with StorageLive and Dead for these temporaries,
|
||||
|
@ -16,7 +16,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// is assumed to be uninitialized.
|
||||
crate fn into_expr(
|
||||
&mut self,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
mut block: BasicBlock,
|
||||
expr: Expr<'tcx>,
|
||||
) -> BlockAnd<()> {
|
||||
@ -160,7 +160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
// introduce a unit temporary as the destination for the loop body.
|
||||
let tmp = this.get_unit_temp();
|
||||
// Execute the body, branching back to the test.
|
||||
let body_block_end = unpack!(this.into(&tmp, body_block, body));
|
||||
let body_block_end = unpack!(this.into(tmp, body_block, body));
|
||||
this.cfg.goto(body_block_end, source_info, loop_block);
|
||||
},
|
||||
);
|
||||
@ -202,8 +202,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
is_block_tail: None,
|
||||
});
|
||||
let ptr_temp = Place::from(ptr_temp);
|
||||
let block = unpack!(this.into(&ptr_temp, block, ptr));
|
||||
this.into(&this.hir.tcx().mk_place_deref(ptr_temp), block, val)
|
||||
let block = unpack!(this.into(ptr_temp, block, ptr));
|
||||
this.into(this.hir.tcx().mk_place_deref(ptr_temp), block, val)
|
||||
} else {
|
||||
let args: Vec<_> = args
|
||||
.into_iter()
|
||||
@ -228,7 +228,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
destination: if expr.ty.is_never() {
|
||||
None
|
||||
} else {
|
||||
Some((*destination, success))
|
||||
Some((destination, success))
|
||||
},
|
||||
from_hir_call,
|
||||
},
|
||||
@ -373,12 +373,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Yield {
|
||||
value,
|
||||
resume,
|
||||
resume_arg: *destination,
|
||||
drop: cleanup,
|
||||
},
|
||||
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: cleanup },
|
||||
);
|
||||
resume.unit()
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
} else {
|
||||
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
|
||||
let lhs = unpack!(block = this.as_place(block, lhs));
|
||||
this.cfg.push_assign(block, source_info, &lhs, rhs);
|
||||
this.cfg.push_assign(block, source_info, lhs, rhs);
|
||||
}
|
||||
|
||||
this.block_context.pop();
|
||||
@ -82,7 +82,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
block =
|
||||
this.build_binary_op(block, op, expr_span, lhs_ty, Operand::Copy(lhs), rhs)
|
||||
);
|
||||
this.cfg.push_assign(block, source_info, &lhs, result);
|
||||
this.cfg.push_assign(block, source_info, lhs, result);
|
||||
|
||||
this.block_context.pop();
|
||||
block.unit()
|
||||
|
@ -12,7 +12,7 @@ pub(in crate::build) trait EvalInto<'tcx> {
|
||||
fn eval_into(
|
||||
self,
|
||||
builder: &mut Builder<'_, 'tcx>,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
block: BasicBlock,
|
||||
) -> BlockAnd<()>;
|
||||
}
|
||||
@ -20,7 +20,7 @@ pub(in crate::build) trait EvalInto<'tcx> {
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
crate fn into<E>(
|
||||
&mut self,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
block: BasicBlock,
|
||||
expr: E,
|
||||
) -> BlockAnd<()>
|
||||
@ -35,7 +35,7 @@ impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
|
||||
fn eval_into(
|
||||
self,
|
||||
builder: &mut Builder<'_, 'tcx>,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
block: BasicBlock,
|
||||
) -> BlockAnd<()> {
|
||||
let expr = builder.hir.mirror(self);
|
||||
@ -47,7 +47,7 @@ impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
|
||||
fn eval_into(
|
||||
self,
|
||||
builder: &mut Builder<'_, 'tcx>,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
block: BasicBlock,
|
||||
) -> BlockAnd<()> {
|
||||
builder.into_expr(destination, block, self)
|
||||
|
@ -10,16 +10,16 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder};
|
||||
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
|
||||
use crate::hair::{self, *};
|
||||
use rustc_ast::ast::Name;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::layout::VariantIdx;
|
||||
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_span::Span;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use rustc_ast::ast::Name;
|
||||
|
||||
// helper functions, broken out by category:
|
||||
mod simplify;
|
||||
@ -83,7 +83,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// * From each otherwise block to the next prebinding block.
|
||||
crate fn match_expr(
|
||||
&mut self,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
span: Span,
|
||||
mut block: BasicBlock,
|
||||
scrutinee: ExprRef<'tcx>,
|
||||
@ -218,7 +218,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// `outer_source_info` is the SourceInfo for the whole match.
|
||||
fn lower_match_arms(
|
||||
&mut self,
|
||||
destination: &Place<'tcx>,
|
||||
destination: Place<'tcx>,
|
||||
scrutinee_place: Place<'tcx>,
|
||||
scrutinee_span: Span,
|
||||
arm_candidates: Vec<(&'_ Arm<'tcx>, Candidate<'_, 'tcx>)>,
|
||||
@ -364,7 +364,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
PatKind::Binding { mode: BindingMode::ByValue, var, subpattern: None, .. } => {
|
||||
let place =
|
||||
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
|
||||
unpack!(block = self.into(&place, block, initializer));
|
||||
unpack!(block = self.into(place, block, initializer));
|
||||
|
||||
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
|
||||
let source_info = self.source_info(irrefutable_pat.span);
|
||||
@ -399,7 +399,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
} => {
|
||||
let place =
|
||||
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true);
|
||||
unpack!(block = self.into(&place, block, initializer));
|
||||
unpack!(block = self.into(place, block, initializer));
|
||||
|
||||
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
|
||||
let pattern_source_info = self.source_info(irrefutable_pat.span);
|
||||
@ -1691,7 +1691,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let scrutinee_source_info = self.source_info(scrutinee_span);
|
||||
for &(place, temp) in fake_borrows {
|
||||
let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, place);
|
||||
self.cfg.push_assign(block, scrutinee_source_info, &Place::from(temp), borrow);
|
||||
self.cfg.push_assign(block, scrutinee_source_info, Place::from(temp), borrow);
|
||||
}
|
||||
|
||||
// the block to branch to if the guard fails; if there is no
|
||||
@ -1858,7 +1858,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
match binding.binding_mode {
|
||||
BindingMode::ByValue => {
|
||||
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, binding.source);
|
||||
self.cfg.push_assign(block, source_info, &ref_for_guard, rvalue);
|
||||
self.cfg.push_assign(block, source_info, ref_for_guard, rvalue);
|
||||
}
|
||||
BindingMode::ByRef(borrow_kind) => {
|
||||
let value_for_arm = self.storage_live_binding(
|
||||
@ -1870,9 +1870,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
);
|
||||
|
||||
let rvalue = Rvalue::Ref(re_erased, borrow_kind, binding.source);
|
||||
self.cfg.push_assign(block, source_info, &value_for_arm, rvalue);
|
||||
self.cfg.push_assign(block, source_info, value_for_arm, rvalue);
|
||||
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, value_for_arm);
|
||||
self.cfg.push_assign(block, source_info, &ref_for_guard, rvalue);
|
||||
self.cfg.push_assign(block, source_info, ref_for_guard, rvalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1910,7 +1910,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
Rvalue::Ref(re_erased, borrow_kind, binding.source)
|
||||
}
|
||||
};
|
||||
self.cfg.push_assign(block, source_info, &local, rvalue);
|
||||
self.cfg.push_assign(block, source_info, local, rvalue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
);
|
||||
let discr_ty = adt_def.repr.discr_type().to_ty(tcx);
|
||||
let discr = self.temp(discr_ty, test.span);
|
||||
self.cfg.push_assign(block, source_info, &discr, Rvalue::Discriminant(place));
|
||||
self.cfg.push_assign(block, source_info, discr, Rvalue::Discriminant(place));
|
||||
assert_eq!(values.len() + 1, targets.len());
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
@ -303,7 +303,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let actual = self.temp(usize_ty, test.span);
|
||||
|
||||
// actual = len(place)
|
||||
self.cfg.push_assign(block, source_info, &actual, Rvalue::Len(place));
|
||||
self.cfg.push_assign(block, source_info, actual, Rvalue::Len(place));
|
||||
|
||||
// expected = <N>
|
||||
let expected = self.push_usize(block, source_info, len);
|
||||
@ -342,7 +342,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let result = self.temp(bool_ty, source_info.span);
|
||||
|
||||
// result = op(left, right)
|
||||
self.cfg.push_assign(block, source_info, &result, Rvalue::BinaryOp(op, left, right));
|
||||
self.cfg.push_assign(block, source_info, result, Rvalue::BinaryOp(op, left, right));
|
||||
|
||||
// branch based on result
|
||||
self.cfg.terminate(
|
||||
@ -394,7 +394,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&temp,
|
||||
temp,
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), val, ty),
|
||||
);
|
||||
val = Operand::Move(temp);
|
||||
@ -404,7 +404,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
&slice,
|
||||
slice,
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), expect, ty),
|
||||
);
|
||||
expect = Operand::Move(slice);
|
||||
|
@ -55,7 +55,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.cfg.push_assign_constant(
|
||||
block,
|
||||
source_info,
|
||||
&temp,
|
||||
temp,
|
||||
Constant {
|
||||
span: source_info.span,
|
||||
user_ty: None,
|
||||
|
@ -663,7 +663,7 @@ fn construct_const<'a, 'tcx>(
|
||||
let mut block = START_BLOCK;
|
||||
let ast_expr = &tcx.hir().body(body_id).value;
|
||||
let expr = builder.hir.mirror(ast_expr);
|
||||
unpack!(block = builder.into_expr(&Place::return_place(), block, expr));
|
||||
unpack!(block = builder.into_expr(Place::return_place(), block, expr));
|
||||
|
||||
let source_info = builder.source_info(span);
|
||||
builder.cfg.terminate(block, source_info, TerminatorKind::Return);
|
||||
@ -969,7 +969,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
}
|
||||
|
||||
let body = self.hir.mirror(ast_body);
|
||||
self.into(&Place::return_place(), block, body)
|
||||
self.into(Place::return_place(), block, body)
|
||||
}
|
||||
|
||||
fn set_correct_source_scope_for_arg(
|
||||
|
@ -520,10 +520,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
if let Some(value) = value {
|
||||
debug!("stmt_expr Break val block_context.push(SubExpr)");
|
||||
self.block_context.push(BlockFrame::SubExpr);
|
||||
unpack!(block = self.into(&destination, block, value));
|
||||
unpack!(block = self.into(destination, block, value));
|
||||
self.block_context.pop();
|
||||
} else {
|
||||
self.cfg.push_assign_unit(block, source_info, &destination)
|
||||
self.cfg.push_assign_unit(block, source_info, destination)
|
||||
}
|
||||
} else {
|
||||
assert!(value.is_none(), "`return` and `break` should have a destination");
|
||||
|
Loading…
Reference in New Issue
Block a user