Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup with push_fake_read #67325

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
block: BasicBlock,
source_info: SourceInfo,
Expand Down
13 changes: 2 additions & 11 deletions src/librustc_mir/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,24 +484,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

fn read_fake_borrows(
&mut self,
block: BasicBlock,
bb: BasicBlock,
fake_borrow_temps: &mut Vec<Local>,
source_info: SourceInfo,
) {
// All indexes have been evaluated now, read all of the
// fake borrows so that they are live across those index
// expressions.
for temp in fake_borrow_temps {
self.cfg.push(
block,
Statement {
source_info,
kind: StatementKind::FakeRead(
FakeReadCause::ForIndex,
Box::new(Place::from(*temp)),
)
}
);
self.cfg.push_fake_read(bb, source_info, FakeReadCause::ForIndex, Place::from(*temp));
}
}
}
46 changes: 9 additions & 37 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// check safety.

let source_info = self.source_info(scrutinee_span);
self.cfg.push(block, Statement {
source_info,
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchedPlace,
box(scrutinee_place.clone()),
),
});
let cause_matched_place = FakeReadCause::ForMatchedPlace;
self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place.clone());

// Step 2. Create the otherwise and prebinding blocks.

Expand Down Expand Up @@ -314,16 +309,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard);
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);
self.cfg.push(
block,
Statement {
source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place)),
},
);
self.cfg.push_fake_read(block, source_info, FakeReadCause::ForLet, place);

self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
block.unit()
Expand Down Expand Up @@ -359,13 +347,8 @@ 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);
self.cfg.push(
block,
Statement {
source_info: pattern_source_info,
kind: StatementKind::FakeRead(FakeReadCause::ForLet, box(place.clone())),
},
);
let cause_let = FakeReadCause::ForLet;
self.cfg.push_fake_read(block, pattern_source_info, cause_let, place.clone());

let ty_source_info = self.source_info(user_ty_span);
let user_ty = pat_ascription_ty.user_ty(
Expand Down Expand Up @@ -1516,13 +1499,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
);

for &(_, temp) in fake_borrows {
self.cfg.push(post_guard_block, Statement {
source_info: guard_end,
kind: StatementKind::FakeRead(
FakeReadCause::ForMatchGuard,
box(Place::from(temp)),
),
});
let cause = FakeReadCause::ForMatchGuard;
self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(temp));
}

self.exit_scope(
Expand Down Expand Up @@ -1565,14 +1543,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// place they refer to can't be modified by the guard.
for binding in by_value_bindings.clone() {
let local_id = self.var_local_id(binding.var_id, RefWithinGuard);
let place = Place::from(local_id);
self.cfg.push(
post_guard_block,
Statement {
source_info: guard_end,
kind: StatementKind::FakeRead(FakeReadCause::ForGuardBinding, box(place)),
},
);
let cause = FakeReadCause::ForGuardBinding;
self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(local_id));
}
self.bind_matched_candidate_for_arm_body(
post_guard_block,
Expand Down