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

Add a Use-Definition Chain implementation for the MIR. #62547

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use new Place::base_direct API when possible
Its functionality is duplicated in `borrowed_locals.rs` and
`path_utils.rs`
ecstatic-morse committed Aug 8, 2019
commit 0764641e14023a62dd52c99a95f4b12145368b62
24 changes: 5 additions & 19 deletions src/librustc_mir/borrow_check/path_utils.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@ use crate::borrow_check::borrow_set::{BorrowSet, BorrowData, TwoPhaseActivation}
use crate::borrow_check::places_conflict;
use crate::borrow_check::AccessDepth;
use crate::dataflow::indexes::BorrowIndex;
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase};
use rustc::mir::{ProjectionElem, BorrowKind};
use rustc::mir::{BasicBlock, BorrowKind, Location, Body, Place, PlaceBase};
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::graph::dominators::Dominators;

@@ -132,21 +131,8 @@ pub(super) fn is_active<'tcx>(

/// Determines if a given borrow is borrowing local data
/// This is called for all Yield statements on movable generators
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
place.iterate(|place_base, place_projection| {
match place_base {
PlaceBase::Static(..) => return false,
PlaceBase::Local(..) => {},
}

for proj in place_projection {
// Reborrow of already borrowed data is ignored
// Any errors will be caught on the initial borrow
if proj.elem == ProjectionElem::Deref {
return false;
}
}

true
})
pub(super) fn borrow_of_local_data<'tcx>(place: &Place<'tcx>) -> bool {
place.base_direct()
.and_then(PlaceBase::local)
.is_some()
}
20 changes: 2 additions & 18 deletions src/librustc_mir/dataflow/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {
// Drop terminators borrows the location
TerminatorKind::Drop { location, .. } |
TerminatorKind::DropAndReplace { location, .. } => {
if let Some(local) = find_local(location) {
if let Some(local) = location.base_direct().and_then(PlaceBase::local) {
trans.gen(local);
}
}
@@ -92,28 +92,12 @@ struct BorrowedLocalsVisitor<'gk> {
trans: &'gk mut GenKillSet<Local>,
}

fn find_local(place: &Place<'_>) -> Option<Local> {
place.iterate(|place_base, place_projection| {
for proj in place_projection {
if proj.elem == ProjectionElem::Deref {
return None;
}
}

if let PlaceBase::Local(local) = place_base {
Some(*local)
} else {
None
}
})
}

impl<'tcx> Visitor<'tcx> for BorrowedLocalsVisitor<'_> {
fn visit_rvalue(&mut self,
rvalue: &Rvalue<'tcx>,
location: Location) {
if let Rvalue::Ref(_, _, ref place) = *rvalue {
if let Some(local) = find_local(place) {
if let Some(local) = place.base_direct().and_then(PlaceBase::local) {
self.trans.gen(local);
}
}