1
Fork 0

cleanup with push_fake_read

This commit is contained in:
Mazdak Farrokhzad 2019-12-15 16:11:01 +01:00
parent a605441e04
commit 2d96f2097f
3 changed files with 23 additions and 48 deletions

View file

@ -59,6 +59,18 @@ impl<'tcx> CFG<'tcx> {
)); ));
} }
pub fn push_fake_read(
&mut self,
block: BasicBlock,
source_info: SourceInfo,
cause: FakeReadCause,
place: Place<'tcx>,
) {
let kind = StatementKind::FakeRead(cause, box place);
let stmt = Statement { source_info, kind };
self.push(block, stmt);
}
pub fn terminate(&mut self, pub fn terminate(&mut self,
block: BasicBlock, block: BasicBlock,
source_info: SourceInfo, source_info: SourceInfo,

View file

@ -484,7 +484,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn read_fake_borrows( fn read_fake_borrows(
&mut self, &mut self,
block: BasicBlock, bb: BasicBlock,
fake_borrow_temps: &mut Vec<Local>, fake_borrow_temps: &mut Vec<Local>,
source_info: SourceInfo, source_info: SourceInfo,
) { ) {
@ -492,16 +492,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// fake borrows so that they are live across those index // fake borrows so that they are live across those index
// expressions. // expressions.
for temp in fake_borrow_temps { for temp in fake_borrow_temps {
self.cfg.push( self.cfg.push_fake_read(bb, source_info, FakeReadCause::ForIndex, Place::from(*temp));
block,
Statement {
source_info,
kind: StatementKind::FakeRead(
FakeReadCause::ForIndex,
Box::new(Place::from(*temp)),
)
}
);
} }
} }
} }

View file

@ -132,13 +132,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// check safety. // check safety.
let source_info = self.source_info(scrutinee_span); let source_info = self.source_info(scrutinee_span);
self.cfg.push(block, Statement { let cause_matched_place = FakeReadCause::ForMatchedPlace;
source_info, self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place.clone());
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchedPlace,
box(scrutinee_place.clone()),
),
});
// Step 2. Create the otherwise and prebinding blocks. // Step 2. Create the otherwise and prebinding blocks.
@ -314,16 +309,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard); self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard);
unpack!(block = self.into(&place, block, initializer)); unpack!(block = self.into(&place, block, initializer));
// Inject a fake read, see comments on `FakeReadCause::ForLet`. // Inject a fake read, see comments on `FakeReadCause::ForLet`.
let source_info = self.source_info(irrefutable_pat.span); let source_info = self.source_info(irrefutable_pat.span);
self.cfg.push( self.cfg.push_fake_read(block, source_info, FakeReadCause::ForLet, place);
block,
Statement {
source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place)),
},
);
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard); self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
block.unit() block.unit()
@ -359,13 +347,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Inject a fake read, see comments on `FakeReadCause::ForLet`. // Inject a fake read, see comments on `FakeReadCause::ForLet`.
let pattern_source_info = self.source_info(irrefutable_pat.span); let pattern_source_info = self.source_info(irrefutable_pat.span);
self.cfg.push( let cause_let = FakeReadCause::ForLet;
block, self.cfg.push_fake_read(block, pattern_source_info, cause_let, place.clone());
Statement {
source_info: pattern_source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place.clone())),
},
);
let ty_source_info = self.source_info(user_ty_span); let ty_source_info = self.source_info(user_ty_span);
let user_ty = pat_ascription_ty.user_ty( let user_ty = pat_ascription_ty.user_ty(
@ -1516,13 +1499,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
); );
for &(_, temp) in fake_borrows { for &(_, temp) in fake_borrows {
self.cfg.push(post_guard_block, Statement { let cause = FakeReadCause::ForMatchGuard;
source_info: guard_end, self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(temp));
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchGuard,
box(Place::from(temp)),
),
});
} }
self.exit_scope( self.exit_scope(
@ -1565,14 +1543,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// place they refer to can't be modified by the guard. // place they refer to can't be modified by the guard.
for binding in by_value_bindings.clone() { for binding in by_value_bindings.clone() {
let local_id = self.var_local_id(binding.var_id, RefWithinGuard); let local_id = self.var_local_id(binding.var_id, RefWithinGuard);
let place = Place::from(local_id); let cause = FakeReadCause::ForGuardBinding;
self.cfg.push( self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(local_id));
post_guard_block,
Statement {
source_info: guard_end,
kind: StatementKind::FakeRead(FakeReadCause::ForGuardBinding, box(place)),
},
);
} }
self.bind_matched_candidate_for_arm_body( self.bind_matched_candidate_for_arm_body(
post_guard_block, post_guard_block,