Skip to content

Commit 85f6025

Browse files
committed
Store Results in Formatter.
Instead of `ResultsCursor`. This partly undoes the second commit from rust-lang#132346; possible because `Results::as_result_cursor` (which doesn't consume the `Results`) is now available. Delaying the `ResultsCursor` construction will facilitate the next couple of commits.
1 parent b8c54d6 commit 85f6025

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ struct Formatter<'mir, 'tcx, A>
201201
where
202202
A: Analysis<'tcx>,
203203
{
204+
body: &'mir Body<'tcx>,
204205
// The `RefCell` is used because `<Formatter as Labeller>::node_label`
205-
// takes `&self`, but it needs to modify the cursor. This is also the
206+
// takes `&self`, but it needs to modify the results. This is also the
206207
// reason for the `Formatter`/`BlockFormatter` split; `BlockFormatter` has
207208
// the operations that involve the mutation, i.e. within the `borrow_mut`.
208-
cursor: RefCell<ResultsCursor<'mir, 'tcx, A>>,
209+
results: RefCell<&'mir mut Results<'tcx, A>>,
209210
style: OutputStyle,
210211
reachable: DenseBitSet<BasicBlock>,
211212
}
@@ -220,11 +221,7 @@ where
220221
style: OutputStyle,
221222
) -> Self {
222223
let reachable = traversal::reachable_as_bitset(body);
223-
Formatter { cursor: results.as_results_cursor(body).into(), style, reachable }
224-
}
225-
226-
fn body(&self) -> &'mir Body<'tcx> {
227-
self.cursor.borrow().body()
224+
Formatter { body, results: results.into(), style, reachable }
228225
}
229226
}
230227

@@ -253,7 +250,7 @@ where
253250
type Edge = CfgEdge;
254251

255252
fn graph_id(&self) -> dot::Id<'_> {
256-
let name = graphviz_safe_def_name(self.body().source.def_id());
253+
let name = graphviz_safe_def_name(self.body.source.def_id());
257254
dot::Id::new(format!("graph_for_def_id_{name}")).unwrap()
258255
}
259256

@@ -262,9 +259,12 @@ where
262259
}
263260

264261
fn node_label(&self, block: &Self::Node) -> dot::LabelText<'_> {
265-
let mut cursor = self.cursor.borrow_mut();
266-
let mut fmt =
267-
BlockFormatter { cursor: &mut cursor, style: self.style, bg: Background::Light };
262+
let mut results = self.results.borrow_mut();
263+
let mut fmt = BlockFormatter {
264+
cursor: results.as_results_cursor(self.body),
265+
style: self.style,
266+
bg: Background::Light,
267+
};
268268
let label = fmt.write_node_label(*block).unwrap();
269269

270270
dot::LabelText::html(String::from_utf8(label).unwrap())
@@ -275,7 +275,7 @@ where
275275
}
276276

277277
fn edge_label(&self, e: &Self::Edge) -> dot::LabelText<'_> {
278-
let label = &self.body()[e.source].terminator().kind.fmt_successor_labels()[e.index];
278+
let label = &self.body[e.source].terminator().kind.fmt_successor_labels()[e.index];
279279
dot::LabelText::label(label.clone())
280280
}
281281
}
@@ -288,7 +288,7 @@ where
288288
type Edge = CfgEdge;
289289

290290
fn nodes(&self) -> dot::Nodes<'_, Self::Node> {
291-
self.body()
291+
self.body
292292
.basic_blocks
293293
.indices()
294294
.filter(|&idx| self.reachable.contains(idx))
@@ -297,10 +297,10 @@ where
297297
}
298298

299299
fn edges(&self) -> dot::Edges<'_, Self::Edge> {
300-
let body = self.body();
301-
body.basic_blocks
300+
self.body
301+
.basic_blocks
302302
.indices()
303-
.flat_map(|bb| dataflow_successors(body, bb))
303+
.flat_map(|bb| dataflow_successors(self.body, bb))
304304
.collect::<Vec<_>>()
305305
.into()
306306
}
@@ -310,20 +310,20 @@ where
310310
}
311311

312312
fn target(&self, edge: &Self::Edge) -> Self::Node {
313-
self.body()[edge.source].terminator().successors().nth(edge.index).unwrap()
313+
self.body[edge.source].terminator().successors().nth(edge.index).unwrap()
314314
}
315315
}
316316

317-
struct BlockFormatter<'a, 'mir, 'tcx, A>
317+
struct BlockFormatter<'mir, 'tcx, A>
318318
where
319319
A: Analysis<'tcx>,
320320
{
321-
cursor: &'a mut ResultsCursor<'mir, 'tcx, A>,
321+
cursor: ResultsCursor<'mir, 'tcx, A>,
322322
bg: Background,
323323
style: OutputStyle,
324324
}
325325

326-
impl<'tcx, A> BlockFormatter<'_, '_, 'tcx, A>
326+
impl<'tcx, A> BlockFormatter<'_, 'tcx, A>
327327
where
328328
A: Analysis<'tcx>,
329329
A::Domain: DebugWithContext<A>,

0 commit comments

Comments
 (0)