Use Place directly in librustc_mir_build, it's Copy

上级 6a95bf88
......@@ -9,7 +9,7 @@
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 @@ fn bounds_check(
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,
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 @@ fn add_fake_borrows_of_base(
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 @@ fn expr_as_rvalue(
this.cfg.push_assign(
block,
source_info,
&is_min,
is_min,
Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval),
);
......@@ -109,15 +109,12 @@ fn expr_as_rvalue(
// 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 @@ fn expr_as_rvalue(
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 @@ fn expr_as_rvalue(
self.cfg.push_assign(
block,
source_info,
&is_zero,
is_zero,
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero),
);
......@@ -338,13 +335,13 @@ fn expr_as_rvalue(
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 @@ fn expr_as_rvalue(
self.cfg.push_assign(
block,
source_info,
&of,
of,
Rvalue::BinaryOp(BinOp::BitAnd, is_neg_1, is_min),
);
......@@ -428,7 +425,7 @@ fn limit_capture_mutability(
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 @@ fn expr_as_temp(
}
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 @@ fn eval_into(
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::{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 @@ fn lower_match_tree<'pat>(
/// `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 @@ pub(super) fn expr_into_pattern(
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 @@ pub(super) fn expr_into_pattern(
} => {
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 @@ fn bind_and_guard_matched_candidate<'pat>(
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 @@ fn bind_matched_candidate_for_guard<'b>(
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 @@ fn bind_matched_candidate_for_guard<'b>(
);
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 @@ fn bind_matched_candidate_for_arm_body<'b>(
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 @@ pub(super) fn perform_test(
);
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 @@ pub(super) fn perform_test(
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 @@ fn compare(
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 @@ fn non_scalar_compare(
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 @@ fn non_scalar_compare(
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 @@ fn args_and_body(
}
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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册