Rollup merge of #123934 - WaffleLapkin:graph-mini-refactor, r=fmease
`rustc_data_structures::graph` mini refactor Who doesn't love to breathe dust from the ancient times?
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::mir::traversal::Postorder;
|
||||
use crate::mir::{BasicBlock, BasicBlockData, Successors, Terminator, TerminatorKind, START_BLOCK};
|
||||
use crate::mir::{BasicBlock, BasicBlockData, Terminator, TerminatorKind, START_BLOCK};
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::graph;
|
||||
@@ -141,42 +141,30 @@ impl<'tcx> std::ops::Deref for BasicBlocks<'tcx> {
|
||||
|
||||
impl<'tcx> graph::DirectedGraph for BasicBlocks<'tcx> {
|
||||
type Node = BasicBlock;
|
||||
}
|
||||
|
||||
impl<'tcx> graph::WithNumNodes for BasicBlocks<'tcx> {
|
||||
#[inline]
|
||||
fn num_nodes(&self) -> usize {
|
||||
self.basic_blocks.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> graph::WithStartNode for BasicBlocks<'tcx> {
|
||||
impl<'tcx> graph::StartNode for BasicBlocks<'tcx> {
|
||||
#[inline]
|
||||
fn start_node(&self) -> Self::Node {
|
||||
START_BLOCK
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> graph::WithSuccessors for BasicBlocks<'tcx> {
|
||||
impl<'tcx> graph::Successors for BasicBlocks<'tcx> {
|
||||
#[inline]
|
||||
fn successors(&self, node: Self::Node) -> <Self as graph::GraphSuccessors<'_>>::Iter {
|
||||
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
|
||||
self.basic_blocks[node].terminator().successors()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> graph::GraphSuccessors<'b> for BasicBlocks<'a> {
|
||||
type Item = BasicBlock;
|
||||
type Iter = Successors<'b>;
|
||||
}
|
||||
|
||||
impl<'tcx, 'graph> graph::GraphPredecessors<'graph> for BasicBlocks<'tcx> {
|
||||
type Item = BasicBlock;
|
||||
type Iter = std::iter::Copied<std::slice::Iter<'graph, BasicBlock>>;
|
||||
}
|
||||
|
||||
impl<'tcx> graph::WithPredecessors for BasicBlocks<'tcx> {
|
||||
impl<'tcx> graph::Predecessors for BasicBlocks<'tcx> {
|
||||
#[inline]
|
||||
fn predecessors(&self, node: Self::Node) -> <Self as graph::GraphPredecessors<'_>>::Iter {
|
||||
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
|
||||
self.predecessors()[node].iter().copied()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::io::{self, Write};
|
||||
|
||||
pub struct GraphvizWriter<
|
||||
'a,
|
||||
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode + graph::WithNumNodes,
|
||||
G: graph::DirectedGraph + graph::Successors + graph::StartNode,
|
||||
NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
|
||||
EdgeLabelsFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
|
||||
> {
|
||||
@@ -19,7 +19,7 @@ pub struct GraphvizWriter<
|
||||
|
||||
impl<
|
||||
'a,
|
||||
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode + graph::WithNumNodes,
|
||||
G: graph::DirectedGraph + graph::Successors + graph::StartNode,
|
||||
NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
|
||||
EdgeLabelsFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
|
||||
> GraphvizWriter<'a, G, NodeContentFn, EdgeLabelsFn>
|
||||
|
||||
Reference in New Issue
Block a user