Rename WithNumEdges
=> NumEdges
and WithStartNode
=> StartNode
This commit is contained in:
parent
0d5fc9bf58
commit
f5144938bd
@ -1,4 +1,4 @@
|
||||
use super::{DirectedGraph, Successors, WithStartNode};
|
||||
use super::{DirectedGraph, StartNode, Successors};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use std::ops::ControlFlow;
|
||||
@ -278,7 +278,7 @@ where
|
||||
|
||||
impl<G> TriColorDepthFirstSearch<'_, G>
|
||||
where
|
||||
G: ?Sized + DirectedGraph + Successors + WithStartNode,
|
||||
G: ?Sized + DirectedGraph + Successors + StartNode,
|
||||
{
|
||||
/// Performs a depth-first search, starting from `G::start_node()`.
|
||||
///
|
||||
|
@ -16,10 +16,14 @@ pub trait DirectedGraph {
|
||||
fn num_nodes(&self) -> usize;
|
||||
}
|
||||
|
||||
pub trait WithNumEdges: DirectedGraph {
|
||||
pub trait NumEdges: DirectedGraph {
|
||||
fn num_edges(&self) -> usize;
|
||||
}
|
||||
|
||||
pub trait StartNode: DirectedGraph {
|
||||
fn start_node(&self) -> Self::Node;
|
||||
}
|
||||
|
||||
pub trait Successors: DirectedGraph {
|
||||
type Successors<'g>: Iterator<Item = Self::Node>
|
||||
where
|
||||
@ -40,20 +44,16 @@ pub trait Predecessors: DirectedGraph {
|
||||
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>;
|
||||
}
|
||||
|
||||
pub trait WithStartNode: DirectedGraph {
|
||||
fn start_node(&self) -> Self::Node;
|
||||
}
|
||||
|
||||
pub trait ControlFlowGraph: DirectedGraph + WithStartNode + Predecessors + Successors {
|
||||
pub trait ControlFlowGraph: DirectedGraph + StartNode + Predecessors + Successors {
|
||||
// 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.
|
||||
pub fn is_cyclic<G>(graph: &G) -> bool
|
||||
where
|
||||
G: ?Sized + DirectedGraph + WithStartNode + Successors,
|
||||
G: ?Sized + DirectedGraph + StartNode + Successors,
|
||||
{
|
||||
iterate::TriColorDepthFirstSearch::new(graph)
|
||||
.run_from_start(&mut iterate::CycleDetector)
|
||||
|
@ -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 {
|
||||
(**self).start_node()
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
use crate::fx::FxHashSet;
|
||||
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 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 {
|
||||
self.scc_data.all_successors.len()
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl DirectedGraph for TestGraph {
|
||||
}
|
||||
}
|
||||
|
||||
impl WithStartNode for TestGraph {
|
||||
impl StartNode for TestGraph {
|
||||
fn start_node(&self) -> usize {
|
||||
self.start_node
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::graph::{DirectedGraph, Successors, WithNumEdges};
|
||||
use crate::graph::{DirectedGraph, NumEdges, Successors};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
|
||||
#[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 {
|
||||
self.edge_targets.len()
|
||||
}
|
||||
|
@ -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]
|
||||
fn start_node(&self) -> Self::Node {
|
||||
START_BLOCK
|
||||
|
@ -5,7 +5,7 @@ use std::io::{self, Write};
|
||||
|
||||
pub struct GraphvizWriter<
|
||||
'a,
|
||||
G: graph::DirectedGraph + graph::Successors + graph::WithStartNode,
|
||||
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::Successors + graph::WithStartNode,
|
||||
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>
|
||||
|
@ -1,7 +1,7 @@
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
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::IndexVec;
|
||||
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]
|
||||
fn start_node(&self) -> Self::Node {
|
||||
self.bcb_from_bb(mir::START_BLOCK)
|
||||
|
Loading…
x
Reference in New Issue
Block a user