Skip to content

Commit 776b90c

Browse files
committed
Rollup merge of rust-lang#53966 - ljedrz:mir_dataflow_cleanups, r=estebank
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
2 parents 7e9fb78 + b7c0d32 commit 776b90c

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

src/librustc_mir/dataflow/graphviz.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,12 @@ impl<'a, 'tcx, MWF, P> dot::GraphWalk<'a> for Graph<'a, 'tcx, MWF, P>
265265

266266
fn edges(&self) -> dot::Edges<Edge> {
267267
let mir = self.mbcx.mir();
268-
// base initial capacity on assumption every block has at
269-
// least one outgoing edge (Which should be true for all
270-
// blocks but one, the exit-block).
271-
let mut edges = Vec::with_capacity(mir.basic_blocks().len());
272-
for bb in mir.basic_blocks().indices() {
273-
let outgoing = outgoing(mir, bb);
274-
edges.extend(outgoing.into_iter());
275-
}
276-
edges.into_cow()
268+
269+
mir.basic_blocks()
270+
.indices()
271+
.flat_map(|bb| outgoing(mir, bb))
272+
.collect::<Vec<_>>()
273+
.into_cow()
277274
}
278275

279276
fn source(&self, edge: &Edge) -> Node {

src/librustc_mir/dataflow/impls/borrows.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
168168
// region, then setting that gen-bit will override any
169169
// potential kill introduced here.
170170
if let Some(indices) = self.borrows_out_of_scope_at_location.get(&location) {
171-
for index in indices {
172-
sets.kill(&index);
173-
}
171+
sets.kill_all(indices);
174172
}
175173
}
176174

src/librustc_mir/dataflow/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: Bi
250250
}
251251
}
252252

253-
fn dataflow_path(context: &str, prepost: &str, path: &str) -> PathBuf {
254-
format!("{}_{}", context, prepost);
253+
fn dataflow_path(context: &str, path: &str) -> PathBuf {
255254
let mut path = PathBuf::from(path);
256255
let new_file_name = {
257256
let orig_file_name = path.file_name().unwrap().to_str().unwrap();
@@ -267,7 +266,7 @@ impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation
267266
where P: Fn(&BD, BD::Idx) -> DebugFormatted
268267
{
269268
if let Some(ref path_str) = self.print_preflow_to {
270-
let path = dataflow_path(BD::name(), "preflow", path_str);
269+
let path = dataflow_path(BD::name(), path_str);
271270
graphviz::print_borrowck_graph_to(self, &path, p)
272271
} else {
273272
Ok(())
@@ -278,9 +277,9 @@ impl<'a, 'tcx: 'a, BD> DataflowBuilder<'a, 'tcx, BD> where BD: BitDenotation
278277
where P: Fn(&BD, BD::Idx) -> DebugFormatted
279278
{
280279
if let Some(ref path_str) = self.print_postflow_to {
281-
let path = dataflow_path(BD::name(), "postflow", path_str);
280+
let path = dataflow_path(BD::name(), path_str);
282281
graphviz::print_borrowck_graph_to(self, &path, p)
283-
} else{
282+
} else {
284283
Ok(())
285284
}
286285
}

src/librustc_mir/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
201201
"done dumping moves"
202202
});
203203

204-
if self.errors.len() > 0 {
204+
if !self.errors.is_empty() {
205205
Err((self.data, self.errors))
206206
} else {
207207
Ok(self.data)

0 commit comments

Comments
 (0)