Skip to content

Commit 398da59

Browse files
committed
Merge WithNumNodes into DirectedGraph
1 parent 029cb1b commit 398da59

13 files changed

Lines changed: 33 additions & 52 deletions

File tree

‎compiler/rustc_borrowck/src/constraints/graph.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'s, 'tcx, D>
216216

217217
impl<'s,'tcx,D:ConstraintGraphDirection> graph::DirectedGraphforRegionGraph<'s,'tcx,D>{
218218
typeNode = RegionVid;
219-
}
220219

221-
impl<'s,'tcx,D:ConstraintGraphDirection> graph::WithNumNodesforRegionGraph<'s,'tcx,D>{
222220
fnnum_nodes(&self) -> usize{
223221
self.constraint_graph.first_constraints.len()
224222
}

‎compiler/rustc_data_structures/src/graph/iterate/mod.rs‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
usesuper::{DirectedGraph,WithNumNodes,WithStartNode,WithSuccessors};
1+
usesuper::{DirectedGraph,WithStartNode,WithSuccessors};
22
use rustc_index::bit_set::BitSet;
33
use rustc_index::{IndexSlice,IndexVec};
44
use std::ops::ControlFlow;
55

66
#[cfg(test)]
77
mod tests;
88

9-
pubfnpost_order_from<G:DirectedGraph + WithSuccessors + WithNumNodes>(
9+
pubfnpost_order_from<G:DirectedGraph + WithSuccessors>(
1010
graph:&G,
1111
start_node:G::Node,
1212
) -> Vec<G::Node>{
1313
post_order_from_to(graph, start_node,None)
1414
}
1515

16-
pubfnpost_order_from_to<G:DirectedGraph + WithSuccessors + WithNumNodes>(
16+
pubfnpost_order_from_to<G:DirectedGraph + WithSuccessors>(
1717
graph:&G,
1818
start_node:G::Node,
1919
end_node:Option<G::Node>,
@@ -27,7 +27,7 @@ pub fn post_order_from_to<G: DirectedGraph + WithSuccessors + WithNumNodes>(
2727
result
2828
}
2929

30-
fnpost_order_walk<G:DirectedGraph + WithSuccessors + WithNumNodes>(
30+
fnpost_order_walk<G:DirectedGraph + WithSuccessors>(
3131
graph:&G,
3232
node:G::Node,
3333
result:&mutVec<G::Node>,
@@ -60,7 +60,7 @@ fn post_order_walk<G: DirectedGraph + WithSuccessors + WithNumNodes>(
6060
}
6161
}
6262

63-
pubfnreverse_post_order<G:DirectedGraph + WithSuccessors + WithNumNodes>(
63+
pubfnreverse_post_order<G:DirectedGraph + WithSuccessors>(
6464
graph:&G,
6565
start_node:G::Node,
6666
) -> Vec<G::Node>{
@@ -72,7 +72,7 @@ pub fn reverse_post_order<G: DirectedGraph + WithSuccessors + WithNumNodes>(
7272
/// A "depth-first search" iterator for a directed graph.
7373
pubstructDepthFirstSearch<'graph,G>
7474
where
75-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
75+
G: ?Sized + DirectedGraph + WithSuccessors,
7676
{
7777
graph:&'graphG,
7878
stack:Vec<G::Node>,
@@ -81,7 +81,7 @@ where
8181

8282
impl<'graph,G>DepthFirstSearch<'graph,G>
8383
where
84-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
84+
G: ?Sized + DirectedGraph + WithSuccessors,
8585
{
8686
pubfnnew(graph:&'graphG) -> Self{
8787
Self{ graph,stack:vec![],visited:BitSet::new_empty(graph.num_nodes())}
@@ -127,7 +127,7 @@ where
127127

128128
impl<G> std::fmt::DebugforDepthFirstSearch<'_,G>
129129
where
130-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
130+
G: ?Sized + DirectedGraph + WithSuccessors,
131131
{
132132
fnfmt(&self,fmt:&mut std::fmt::Formatter<'_>) -> std::fmt::Result{
133133
letmut f = fmt.debug_set();
@@ -140,7 +140,7 @@ where
140140

141141
impl<G>IteratorforDepthFirstSearch<'_,G>
142142
where
143-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
143+
G: ?Sized + DirectedGraph + WithSuccessors,
144144
{
145145
typeItem = G::Node;
146146

@@ -201,7 +201,7 @@ struct Event<N> {
201201
/// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms
202202
pubstructTriColorDepthFirstSearch<'graph,G>
203203
where
204-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
204+
G: ?Sized + DirectedGraph + WithSuccessors,
205205
{
206206
graph:&'graphG,
207207
stack:Vec<Event<G::Node>>,
@@ -211,7 +211,7 @@ where
211211

212212
impl<'graph,G>TriColorDepthFirstSearch<'graph,G>
213213
where
214-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
214+
G: ?Sized + DirectedGraph + WithSuccessors,
215215
{
216216
pubfnnew(graph:&'graphG) -> Self{
217217
TriColorDepthFirstSearch{
@@ -278,7 +278,7 @@ where
278278

279279
impl<G>TriColorDepthFirstSearch<'_,G>
280280
where
281-
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors + WithStartNode,
281+
G: ?Sized + DirectedGraph + WithSuccessors + WithStartNode,
282282
{
283283
/// Performs a depth-first search, starting from `G::start_node()`.
284284
///

‎compiler/rustc_data_structures/src/graph/mod.rs‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ mod tests;
1212

1313
pubtraitDirectedGraph{
1414
typeNode:Idx;
15-
}
1615

17-
pubtraitWithNumNodes:DirectedGraph{
1816
fnnum_nodes(&self) -> usize;
1917
}
2018

@@ -28,10 +26,7 @@ where
2826
{
2927
fnsuccessors(&self,node:Self::Node) -> <SelfasGraphSuccessors<'_>>::Iter;
3028

31-
fndepth_first_search(&self,from:Self::Node) -> iterate::DepthFirstSearch<'_,Self>
32-
where
33-
Self:WithNumNodes,
34-
{
29+
fndepth_first_search(&self,from:Self::Node) -> iterate::DepthFirstSearch<'_,Self>{
3530
iterate::DepthFirstSearch::new(self).with_start_node(from)
3631
}
3732
}
@@ -60,20 +55,20 @@ pub trait WithStartNode: DirectedGraph {
6055
}
6156

6257
pubtraitControlFlowGraph:
63-
DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors + WithNumNodes
58+
DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors
6459
{
6560
// convenient trait
6661
}
6762

6863
impl<T>ControlFlowGraphforTwhere
69-
T:DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors + WithNumNodes
64+
T:DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors
7065
{
7166
}
7267

7368
/// Returns `true` if the graph has a cycle that is reachable from the start node.
7469
pubfnis_cyclic<G>(graph:&G) -> bool
7570
where
76-
G: ?Sized + DirectedGraph + WithStartNode + WithSuccessors + WithNumNodes,
71+
G: ?Sized + DirectedGraph + WithStartNode + WithSuccessors,
7772
{
7873
iterate::TriColorDepthFirstSearch::new(graph)
7974
.run_from_start(&mut iterate::CycleDetector)

‎compiler/rustc_data_structures/src/graph/reference.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use super::*;
22

33
impl<'graph,G:DirectedGraph>DirectedGraphfor&'graphG{
44
typeNode = G::Node;
5-
}
65

7-
impl<'graph,G:WithNumNodes>WithNumNodesfor&'graphG{
86
fnnum_nodes(&self) -> usize{
97
(**self).num_nodes()
108
}

‎compiler/rustc_data_structures/src/graph/scc/mod.rs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
usecrate::fx::FxHashSet;
99
usecrate::graph::vec_graph::VecGraph;
10-
usecrate::graph::{DirectedGraph,GraphSuccessors,WithNumEdges,WithNumNodes,WithSuccessors};
10+
usecrate::graph::{DirectedGraph,GraphSuccessors,WithNumEdges,WithSuccessors};
1111
use rustc_index::{Idx,IndexSlice,IndexVec};
1212
use std::ops::Range;
1313

@@ -39,7 +39,7 @@ pub struct SccData<S: Idx> {
3939
}
4040

4141
impl<N:Idx,S:Idx + Ord>Sccs<N,S>{
42-
pubfnnew(graph:&(implDirectedGraph<Node = N> + WithNumNodes + WithSuccessors)) -> Self{
42+
pubfnnew(graph:&(implDirectedGraph<Node = N> + WithSuccessors)) -> Self{
4343
SccsConstruction::construct(graph)
4444
}
4545

@@ -89,17 +89,15 @@ impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
8989
}
9090
}
9191

92-
impl<N:Idx,S:Idx>DirectedGraphforSccs<N,S>{
92+
impl<N:Idx,S:Idx + Ord>DirectedGraphforSccs<N,S>{
9393
typeNode = S;
94-
}
9594

96-
impl<N:Idx,S:Idx + Ord>WithNumNodesforSccs<N,S>{
9795
fnnum_nodes(&self) -> usize{
9896
self.num_sccs()
9997
}
10098
}
10199

102-
impl<N:Idx,S:Idx>WithNumEdgesforSccs<N,S>{
100+
impl<N:Idx,S:Idx + Ord>WithNumEdgesforSccs<N,S>{
103101
fnnum_edges(&self) -> usize{
104102
self.scc_data.all_successors.len()
105103
}
@@ -158,7 +156,7 @@ impl<S: Idx> SccData<S> {
158156
}
159157
}
160158

161-
structSccsConstruction<'c,G:DirectedGraph + WithNumNodes + WithSuccessors,S:Idx>{
159+
structSccsConstruction<'c,G:DirectedGraph + WithSuccessors,S:Idx>{
162160
graph:&'cG,
163161

164162
/// The state of each node; used during walk to record the stack
@@ -218,7 +216,7 @@ enum WalkReturn<S> {
218216

219217
impl<'c,G,S>SccsConstruction<'c,G,S>
220218
where
221-
G:DirectedGraph + WithNumNodes + WithSuccessors,
219+
G:DirectedGraph + WithSuccessors,
222220
S:Idx,
223221
{
224222
/// Identifies SCCs in the graph `G` and computes the resulting

‎compiler/rustc_data_structures/src/graph/tests.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ impl TestGraph {
3636

3737
implDirectedGraphforTestGraph{
3838
typeNode = usize;
39+
40+
fnnum_nodes(&self) -> usize{
41+
self.num_nodes
42+
}
3943
}
4044

4145
implWithStartNodeforTestGraph{
@@ -44,12 +48,6 @@ impl WithStartNode for TestGraph {
4448
}
4549
}
4650

47-
implWithNumNodesforTestGraph{
48-
fnnum_nodes(&self) -> usize{
49-
self.num_nodes
50-
}
51-
}
52-
5351
implWithPredecessorsforTestGraph{
5452
fnpredecessors(&self,node:usize) -> <SelfasGraphPredecessors<'_>>::Iter{
5553
self.predecessors[&node].iter().cloned()

‎compiler/rustc_data_structures/src/graph/vec_graph/mod.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usecrate::graph::{DirectedGraph,GraphSuccessors,WithNumEdges,WithNumNodes,WithSuccessors};
1+
usecrate::graph::{DirectedGraph,GraphSuccessors,WithNumEdges,WithSuccessors};
22
use rustc_index::{Idx,IndexVec};
33

44
#[cfg(test)]
@@ -80,9 +80,7 @@ impl<N: Idx + Ord> VecGraph<N> {
8080

8181
impl<N:Idx>DirectedGraphforVecGraph<N>{
8282
typeNode = N;
83-
}
8483

85-
impl<N:Idx>WithNumNodesforVecGraph<N>{
8684
fnnum_nodes(&self) -> usize{
8785
self.node_starts.len() - 1
8886
}

‎compiler/rustc_middle/src/mir/basic_blocks.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ impl<'tcx> std::ops::Deref for BasicBlocks<'tcx> {
141141

142142
impl<'tcx> graph::DirectedGraphforBasicBlocks<'tcx>{
143143
typeNode = BasicBlock;
144-
}
145144

146-
impl<'tcx> graph::WithNumNodesforBasicBlocks<'tcx>{
147145
#[inline]
148146
fnnum_nodes(&self) -> usize{
149147
self.basic_blocks.len()

‎compiler/rustc_middle/src/mir/generic_graphviz.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::{self, Write};
55

66
pubstructGraphvizWriter<
77
'a,
8-
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode + graph::WithNumNodes,
8+
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode,
99
NodeContentFn:Fn(<Gas graph::DirectedGraph>::Node) -> Vec<String>,
1010
EdgeLabelsFn:Fn(<Gas graph::DirectedGraph>::Node) -> Vec<String>,
1111
>{
@@ -19,7 +19,7 @@ pub struct GraphvizWriter<
1919

2020
impl<
2121
'a,
22-
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode + graph::WithNumNodes,
22+
G: graph::DirectedGraph + graph::WithSuccessors + graph::WithStartNode,
2323
NodeContentFn:Fn(<Gas graph::DirectedGraph>::Node) -> Vec<String>,
2424
EdgeLabelsFn:Fn(<Gas graph::DirectedGraph>::Node) -> Vec<String>,
2525
>GraphvizWriter<'a,G,NodeContentFn,EdgeLabelsFn>

‎compiler/rustc_mir_transform/src/coverage/counters.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt::{self, Debug};
22

33
use rustc_data_structures::captures::Captures;
44
use rustc_data_structures::fx::FxHashMap;
5-
use rustc_data_structures::graph::WithNumNodes;
5+
use rustc_data_structures::graph::DirectedGraph;
66
use rustc_index::IndexVec;
77
use rustc_middle::mir::coverage::{CounterId,CovTerm,Expression,ExpressionId,Op};
88

0 commit comments

Comments
 (0)