Skip to content

Commit

Permalink
Rollup merge of rust-lang#53966 - ljedrz:mir_dataflow_cleanups, r=est…
Browse files Browse the repository at this point in the history
…ebank

A few cleanups and minor improvements to mir/dataflow

- simplify `dot::GraphWalk::edges` and optimize its vector's allocation
- turn a `kill` loop into `kill_all`
- remove the `prepost` parameter from `dataflow_path` (it doesn't seem to do anything)
- a couple of other minor improvements
  • Loading branch information
kennytm committed Sep 7, 2018
2 parents 7e9fb78 + b7c0d32 commit 776b90c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
15 changes: 6 additions & 9 deletions src/librustc_mir/dataflow/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,12 @@ impl<'a, 'tcx, MWF, P> dot::GraphWalk<'a> for Graph<'a, 'tcx, MWF, P>

fn edges(&self) -> dot::Edges<Edge> {
let mir = self.mbcx.mir();
// base initial capacity on assumption every block has at
// least one outgoing edge (Which should be true for all
// blocks but one, the exit-block).
let mut edges = Vec::with_capacity(mir.basic_blocks().len());
for bb in mir.basic_blocks().indices() {
let outgoing = outgoing(mir, bb);
edges.extend(outgoing.into_iter());
}
edges.into_cow()

mir.basic_blocks()
.indices()
.flat_map(|bb| outgoing(mir, bb))
.collect::<Vec<_>>()
.into_cow()
}

fn source(&self, edge: &Edge) -> Node {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
// region, then setting that gen-bit will override any
// potential kill introduced here.
if let Some(indices) = self.borrows_out_of_scope_at_location.get(&location) {
for index in indices {
sets.kill(&index);
}
sets.kill_all(indices);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/librustc_mir/dataflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: Bi
}
}

fn dataflow_path(context: &str, prepost: &str, path: &str) -> PathBuf {
format!("{}_{}", context, prepost);
fn dataflow_path(context: &str, path: &str) -> PathBuf {
let mut path = PathBuf::from(path);
let new_file_name = {
let orig_file_name = path.file_name().unwrap().to_str().unwrap();
Expand All @@ -267,7 +266,7 @@ impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation
where P: Fn(&BD, BD::Idx) -> DebugFormatted
{
if let Some(ref path_str) = self.print_preflow_to {
let path = dataflow_path(BD::name(), "preflow", path_str);
let path = dataflow_path(BD::name(), path_str);
graphviz::print_borrowck_graph_to(self, &path, p)
} else {
Ok(())
Expand All @@ -278,9 +277,9 @@ impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation
where P: Fn(&BD, BD::Idx) -> DebugFormatted
{
if let Some(ref path_str) = self.print_postflow_to {
let path = dataflow_path(BD::name(), "postflow", path_str);
let path = dataflow_path(BD::name(), path_str);
graphviz::print_borrowck_graph_to(self, &path, p)
} else{
} else {
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
"done dumping moves"
});

if self.errors.len() > 0 {
if !self.errors.is_empty() {
Err((self.data, self.errors))
} else {
Ok(self.data)
Expand Down

0 comments on commit 776b90c

Please sign in to comment.