Skip to content

Commit

Permalink
Reverse postorder instead of using reversed postorder
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Sep 28, 2023
1 parent 3b75db7 commit a4d11d9
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions clippy_utils/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,26 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) -
locals.len()
];

traversal::ReversePostorder::new(mir, location.block).try_fold(init, |usage, (tbb, tdata)| {
// Give up on loops
if tdata.terminator().successors().any(|s| s == location.block) {
return None;
}
traversal::Postorder::new(&mir.basic_blocks, location.block)
.collect::<Vec<_>>()
.into_iter()
.rev()
.try_fold(init, |usage, tbb| {
let tdata = &mir.basic_blocks[tbb];

// Give up on loops
if tdata.terminator().successors().any(|s| s == location.block) {
return None;
}

let mut v = V {
locals,
location,
results: usage,
};
v.visit_basic_block_data(tbb, tdata);
Some(v.results)
})
let mut v = V {
locals,
location,
results: usage,
};
v.visit_basic_block_data(tbb, tdata);
Some(v.results)
})
}

struct V<'a> {
Expand Down

0 comments on commit a4d11d9

Please sign in to comment.