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

Make find iterate instead of recurse #61103

Merged
merged 1 commit into from
May 25, 2019
Merged
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
27 changes: 14 additions & 13 deletions src/librustc_mir/dataflow/move_paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,22 @@ impl MovePathLookup {
// unknown place, but will rather return the nearest available
// parent.
pub fn find(&self, place: &Place<'tcx>) -> LookupResult {
match *place {
Place::Base(PlaceBase::Local(local)) => LookupResult::Exact(self.locals[local]),
Place::Base(PlaceBase::Static(..)) => LookupResult::Parent(None),
Place::Projection(ref proj) => {
match self.find(&proj.base) {
LookupResult::Exact(base_path) => {
match self.projections.get(&(base_path, proj.elem.lift())) {
Some(&subpath) => LookupResult::Exact(subpath),
None => LookupResult::Parent(Some(base_path))
}
}
inexact => inexact
place.iterate(|place_base, place_projection| {
let mut result = match place_base {
PlaceBase::Local(local) => self.locals[*local],
PlaceBase::Static(..) => return LookupResult::Parent(None),
};

for proj in place_projection {
if let Some(&subpath) = self.projections.get(&(result, proj.elem.lift())) {
result = subpath;
} else {
return LookupResult::Parent(Some(result));
}
}
}

LookupResult::Exact(result)
})
}

pub fn find_local(&self, local: Local) -> MovePathIndex {
Expand Down