Make use of Place: Copy

This commit is contained in:
Matthew Jasper 2020-01-11 20:30:42 +00:00
parent 1d90ed6370
commit 9b9dafb2c8
4 changed files with 34 additions and 42 deletions

View file

@ -93,7 +93,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let scrutinee_place =
unpack!(block = self.lower_scrutinee(block, scrutinee, scrutinee_span,));
let mut arm_candidates = self.create_match_candidates(&scrutinee_place, &arms);
let mut arm_candidates = self.create_match_candidates(scrutinee_place, &arms);
let match_has_guard = arms.iter().any(|arm| arm.guard.is_some());
let mut candidates =
@ -103,7 +103,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.lower_match_tree(block, scrutinee_span, match_has_guard, &mut candidates);
self.lower_match_arms(
&destination,
destination,
scrutinee_place,
scrutinee_span,
arm_candidates,
@ -137,7 +137,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// check safety.
let cause_matched_place = FakeReadCause::ForMatchedPlace;
let source_info = self.source_info(scrutinee_span);
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place.clone());
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place);
block.and(scrutinee_place)
}
@ -145,7 +145,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Create the initial `Candidate`s for a `match` expression.
fn create_match_candidates<'pat>(
&mut self,
scrutinee: &Place<'tcx>,
scrutinee: Place<'tcx>,
arms: &'pat [Arm<'tcx>],
) -> Vec<(&'pat Arm<'tcx>, Candidate<'pat, 'tcx>)> {
// Assemble a list of candidates: there is one candidate per pattern,
@ -153,7 +153,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
arms.iter()
.map(|arm| {
let arm_has_guard = arm.guard.is_some();
let arm_candidate = Candidate::new(*scrutinee, &arm.pattern, arm_has_guard);
let arm_candidate = Candidate::new(scrutinee, &arm.pattern, arm_has_guard);
(arm, arm_candidate)
})
.collect()
@ -391,7 +391,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Inject a fake read, see comments on `FakeReadCause::ForLet`.
let pattern_source_info = self.source_info(irrefutable_pat.span);
let cause_let = FakeReadCause::ForLet;
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place.clone());
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place);
let ty_source_info = self.source_info(user_ty_span);
let user_ty = pat_ascription_ty.user_ty(
@ -430,7 +430,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
_ => {
let place = unpack!(block = self.as_place(block, initializer));
self.place_into_pattern(block, irrefutable_pat, &place, true)
self.place_into_pattern(block, irrefutable_pat, place, true)
}
}
}
@ -439,10 +439,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
block: BasicBlock,
irrefutable_pat: Pat<'tcx>,
initializer: &Place<'tcx>,
initializer: Place<'tcx>,
set_match_place: bool,
) -> BlockAnd<()> {
let mut candidate = Candidate::new(*initializer, &irrefutable_pat, false);
let mut candidate = Candidate::new(initializer, &irrefutable_pat, false);
let fake_borrow_temps =
self.lower_match_tree(block, irrefutable_pat.span, false, &mut [&mut candidate]);
@ -461,7 +461,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. },
))) = self.local_decls[local].local_info
{
*match_place = Some(*initializer);
*match_place = Some(initializer);
} else {
bug!("Let binding to non-user variable.")
}
@ -897,7 +897,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span: Span,
start_block: BasicBlock,
otherwise_block: &mut Option<BasicBlock>,
candidates: &mut [&mut Candidate<_, 'tcx>],
candidates: &mut [&mut Candidate<'_, 'tcx>],
fake_borrows: &mut Option<FxHashSet<Place<'tcx>>>,
) {
// The candidates are sorted by priority. Check to see whether the
@ -1121,7 +1121,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
for match_pair in match_pairs {
if let PatKind::Or { ref pats } = *match_pair.pattern.kind {
let or_span = match_pair.pattern.span;
let place = &match_pair.place;
let place = match_pair.place;
first_candidate.visit_leaves(|leaf_candidate| {
self.test_or_pattern(
@ -1155,14 +1155,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
otherwise: &mut Option<BasicBlock>,
pats: &'pat [Pat<'tcx>],
or_span: Span,
place: &Place<'tcx>,
place: Place<'tcx>,
fake_borrows: &mut Option<FxHashSet<Place<'tcx>>>,
) {
debug!("test_or_pattern:\ncandidate={:#?}\npats={:#?}", candidate, pats);
let mut or_candidates: Vec<_> = pats
.iter()
.map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard))
.collect();
let mut or_candidates: Vec<_> =
pats.iter().map(|pat| Candidate::new(place, pat, candidate.has_guard)).collect();
let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect();
let otherwise = if candidate.otherwise_block.is_some() {
&mut candidate.otherwise_block
@ -1368,7 +1366,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
// Insert a Shallow borrow of any places that is switched on.
fake_borrows.as_mut().map(|fb| fb.insert(match_place.clone()));
fake_borrows.as_mut().map(|fb| fb.insert(match_place));
// perform the test, branching to one of N blocks. For each of
// those N possible outcomes, create a (initially empty)
@ -1448,7 +1446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
target_blocks
};
self.perform_test(block, &match_place, &test, make_target_blocks);
self.perform_test(block, match_place, &test, make_target_blocks);
}
/// Determine the fake borrows that are needed from a set of places that
@ -1669,9 +1667,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let re_erased = tcx.lifetimes.re_erased;
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);
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);
}
// the block to branch to if the guard fails; if there is no

View file

@ -45,7 +45,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
loop {
let match_pairs = mem::take(&mut candidate.match_pairs);
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, ref place }] =
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
*match_pairs
{
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
@ -78,12 +78,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn create_or_subcandidates<'pat>(
&mut self,
candidate: &Candidate<'pat, 'tcx>,
place: &Place<'tcx>,
place: Place<'tcx>,
pats: &'pat [Pat<'tcx>],
) -> Vec<Candidate<'pat, 'tcx>> {
pats.iter()
.map(|pat| {
let mut candidate = Candidate::new(place.clone(), pat, candidate.has_guard);
let mut candidate = Candidate::new(place, pat, candidate.has_guard);
self.simplify_candidate(&mut candidate);
candidate
})

View file

@ -155,7 +155,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
pub(super) fn perform_test(
&mut self,
block: BasicBlock,
place: &Place<'tcx>,
place: Place<'tcx>,
test: &Test<'tcx>,
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
) {
@ -205,7 +205,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,
@ -229,12 +229,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
0 => (second_bb, first_bb),
v => span_bug!(test.span, "expected boolean value but got {:?}", v),
};
TerminatorKind::if_(
self.hir.tcx(),
Operand::Copy(*place),
true_bb,
false_bb,
)
TerminatorKind::if_(self.hir.tcx(), Operand::Copy(place), true_bb, false_bb)
} else {
bug!("`TestKind::SwitchInt` on `bool` should have two targets")
}
@ -242,7 +237,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// The switch may be inexhaustive so we have a catch all block
debug_assert_eq!(options.len() + 1, target_blocks.len());
TerminatorKind::SwitchInt {
discr: Operand::Copy(*place),
discr: Operand::Copy(place),
switch_ty,
values: options.clone().into(),
targets: target_blocks,
@ -267,7 +262,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let [success, fail] = *make_target_blocks(self) {
assert_eq!(value.ty, ty);
let expect = self.literal_operand(test.span, value);
let val = Operand::Copy(*place);
let val = Operand::Copy(place);
self.compare(block, success, fail, source_info, BinOp::Eq, expect, val);
} else {
bug!("`TestKind::Eq` should have two target blocks");
@ -282,7 +277,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
let lo = self.literal_operand(test.span, lo);
let hi = self.literal_operand(test.span, hi);
let val = Operand::Copy(*place);
let val = Operand::Copy(place);
if let [success, fail] = *target_blocks {
self.compare(
@ -311,7 +306,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);
@ -367,13 +362,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
source_info: SourceInfo,
value: &'tcx ty::Const<'tcx>,
place: &Place<'tcx>,
place: Place<'tcx>,
mut ty: Ty<'tcx>,
) {
use rustc::middle::lang_items::EqTraitLangItem;
let mut expect = self.literal_operand(source_info.span, value);
let mut val = Operand::Copy(*place);
let mut val = Operand::Copy(place);
// If we're using `b"..."` as a pattern, we need to insert an
// unsizing coercion, as the byte string has the type `&[u8; N]`.
@ -751,8 +746,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let downcast_place = tcx.mk_place_elem(match_pair.place, elem); // `(x as Variant)`
let consequent_match_pairs = subpatterns.iter().map(|subpattern| {
// e.g., `(x as Variant).0`
let place =
tcx.mk_place_field(downcast_place.clone(), subpattern.field, subpattern.pattern.ty);
let place = tcx.mk_place_field(downcast_place, subpattern.field, subpattern.pattern.ty);
// e.g., `(x as Variant).0 @ P1`
MatchPair::new(place, &subpattern.pattern)
});

View file

@ -899,7 +899,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
matches::ArmHasGuard(false),
Some((Some(&place), span)),
);
unpack!(block = self.place_into_pattern(block, pattern, &place, false));
unpack!(block = self.place_into_pattern(block, pattern, place, false));
}
}
self.source_scope = original_source_scope;