1
Fork 0

Rename WithNumEdges => NumEdges and WithStartNode => StartNode

This commit is contained in:
Maybe Waffle 2024-04-14 15:51:29 +00:00
parent 0d5fc9bf58
commit f5144938bd
9 changed files with 21 additions and 21 deletions

View file

@ -1,4 +1,4 @@
use super::{DirectedGraph, Successors, WithStartNode}; use super::{DirectedGraph, StartNode, Successors};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use std::ops::ControlFlow; use std::ops::ControlFlow;
@ -278,7 +278,7 @@ where
impl<G> TriColorDepthFirstSearch<'_, G> impl<G> TriColorDepthFirstSearch<'_, G>
where where
G: ?Sized + DirectedGraph + Successors + WithStartNode, G: ?Sized + DirectedGraph + Successors + StartNode,
{ {
/// Performs a depth-first search, starting from `G::start_node()`. /// Performs a depth-first search, starting from `G::start_node()`.
/// ///

View file

@ -16,10 +16,14 @@ pub trait DirectedGraph {
fn num_nodes(&self) -> usize; fn num_nodes(&self) -> usize;
} }
pub trait WithNumEdges: DirectedGraph { pub trait NumEdges: DirectedGraph {
fn num_edges(&self) -> usize; fn num_edges(&self) -> usize;
} }
pub trait StartNode: DirectedGraph {
fn start_node(&self) -> Self::Node;
}
pub trait Successors: DirectedGraph { pub trait Successors: DirectedGraph {
type Successors<'g>: Iterator<Item = Self::Node> type Successors<'g>: Iterator<Item = Self::Node>
where where
@ -40,20 +44,16 @@ pub trait Predecessors: DirectedGraph {
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>; fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>;
} }
pub trait WithStartNode: DirectedGraph { pub trait ControlFlowGraph: DirectedGraph + StartNode + Predecessors + Successors {
fn start_node(&self) -> Self::Node;
}
pub trait ControlFlowGraph: DirectedGraph + WithStartNode + Predecessors + Successors {
// convenient trait // convenient trait
} }
impl<T> ControlFlowGraph for T where T: DirectedGraph + WithStartNode + Predecessors + Successors {} impl<T> ControlFlowGraph for T where T: DirectedGraph + StartNode + Predecessors + Successors {}
/// Returns `true` if the graph has a cycle that is reachable from the start node. /// Returns `true` if the graph has a cycle that is reachable from the start node.
pub fn is_cyclic<G>(graph: &G) -> bool pub fn is_cyclic<G>(graph: &G) -> bool
where where
G: ?Sized + DirectedGraph + WithStartNode + Successors, G: ?Sized + DirectedGraph + StartNode + Successors,
{ {
iterate::TriColorDepthFirstSearch::new(graph) iterate::TriColorDepthFirstSearch::new(graph)
.run_from_start(&mut iterate::CycleDetector) .run_from_start(&mut iterate::CycleDetector)

View file

@ -8,7 +8,7 @@ impl<'graph, G: DirectedGraph> DirectedGraph for &'graph G {
} }
} }
impl<'graph, G: WithStartNode> WithStartNode for &'graph G { impl<'graph, G: StartNode> StartNode for &'graph G {
fn start_node(&self) -> Self::Node { fn start_node(&self) -> Self::Node {
(**self).start_node() (**self).start_node()
} }

View file

@ -7,7 +7,7 @@
use crate::fx::FxHashSet; use crate::fx::FxHashSet;
use crate::graph::vec_graph::VecGraph; use crate::graph::vec_graph::VecGraph;
use crate::graph::{DirectedGraph, Successors, WithNumEdges}; use crate::graph::{DirectedGraph, NumEdges, Successors};
use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use std::ops::Range; use std::ops::Range;
@ -97,7 +97,7 @@ impl<N: Idx, S: Idx + Ord> DirectedGraph for Sccs<N, S> {
} }
} }
impl<N: Idx, S: Idx + Ord> WithNumEdges for Sccs<N, S> { impl<N: Idx, S: Idx + Ord> NumEdges for Sccs<N, S> {
fn num_edges(&self) -> usize { fn num_edges(&self) -> usize {
self.scc_data.all_successors.len() self.scc_data.all_successors.len()
} }

View file

@ -42,7 +42,7 @@ impl DirectedGraph for TestGraph {
} }
} }
impl WithStartNode for TestGraph { impl StartNode for TestGraph {
fn start_node(&self) -> usize { fn start_node(&self) -> usize {
self.start_node self.start_node
} }

View file

@ -1,4 +1,4 @@
use crate::graph::{DirectedGraph, Successors, WithNumEdges}; use crate::graph::{DirectedGraph, NumEdges, Successors};
use rustc_index::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
#[cfg(test)] #[cfg(test)]
@ -86,7 +86,7 @@ impl<N: Idx> DirectedGraph for VecGraph<N> {
} }
} }
impl<N: Idx> WithNumEdges for VecGraph<N> { impl<N: Idx> NumEdges for VecGraph<N> {
fn num_edges(&self) -> usize { fn num_edges(&self) -> usize {
self.edge_targets.len() self.edge_targets.len()
} }

View file

@ -148,7 +148,7 @@ impl<'tcx> graph::DirectedGraph for BasicBlocks<'tcx> {
} }
} }
impl<'tcx> graph::WithStartNode for BasicBlocks<'tcx> { impl<'tcx> graph::StartNode for BasicBlocks<'tcx> {
#[inline] #[inline]
fn start_node(&self) -> Self::Node { fn start_node(&self) -> Self::Node {
START_BLOCK START_BLOCK

View file

@ -5,7 +5,7 @@ use std::io::{self, Write};
pub struct GraphvizWriter< pub struct GraphvizWriter<
'a, 'a,
G: graph::DirectedGraph + graph::Successors + graph::WithStartNode, G: graph::DirectedGraph + graph::Successors + graph::StartNode,
NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>, NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
EdgeLabelsFn: 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< impl<
'a, 'a,
G: graph::DirectedGraph + graph::Successors + graph::WithStartNode, G: graph::DirectedGraph + graph::Successors + graph::StartNode,
NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>, NodeContentFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
EdgeLabelsFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>, EdgeLabelsFn: Fn(<G as graph::DirectedGraph>::Node) -> Vec<String>,
> GraphvizWriter<'a, G, NodeContentFn, EdgeLabelsFn> > GraphvizWriter<'a, G, NodeContentFn, EdgeLabelsFn>

View file

@ -1,7 +1,7 @@
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::{self, Dominators}; use rustc_data_structures::graph::dominators::{self, Dominators};
use rustc_data_structures::graph::{self, DirectedGraph, WithStartNode}; use rustc_data_structures::graph::{self, DirectedGraph, StartNode};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::{self, BasicBlock, Terminator, TerminatorKind}; use rustc_middle::mir::{self, BasicBlock, Terminator, TerminatorKind};
@ -200,7 +200,7 @@ impl graph::DirectedGraph for CoverageGraph {
} }
} }
impl graph::WithStartNode for CoverageGraph { impl graph::StartNode for CoverageGraph {
#[inline] #[inline]
fn start_node(&self) -> Self::Node { fn start_node(&self) -> Self::Node {
self.bcb_from_bb(mir::START_BLOCK) self.bcb_from_bb(mir::START_BLOCK)