Skip to content

Commit 0d5fc9b

Browse files
committed
Merge {With,Graph}{Successors,Predecessors} into {Successors,Predecessors}
Now with GAT!
1 parent 398da59 commit 0d5fc9b

15 files changed

Lines changed: 78 additions & 133 deletions

File tree

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,10 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph
222222
}
223223
}
224224

225-
impl<'s,'tcx,D:ConstraintGraphDirection> graph::WithSuccessorsforRegionGraph<'s,'tcx,D>{
226-
fnsuccessors(&self,node:Self::Node) -> <Selfas graph::GraphSuccessors<'_>>::Iter{
225+
impl<'s,'tcx,D:ConstraintGraphDirection> graph::SuccessorsforRegionGraph<'s,'tcx,D>{
226+
typeSuccessors<'g> = Successors<'s,'tcx,D>whereSelf:'g;
227+
228+
fnsuccessors(&self,node:Self::Node) -> Self::Successors<'_>{
227229
self.outgoing_regions(node)
228230
}
229231
}
230-
231-
impl<'s,'tcx,D:ConstraintGraphDirection> graph::GraphSuccessors<'_>
232-
forRegionGraph<'s,'tcx,D>
233-
{
234-
typeItem = RegionVid;
235-
typeIter = Successors<'s,'tcx,D>;
236-
}

‎compiler/rustc_borrowck/src/dataflow.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::fx::FxIndexMap;
2-
use rustc_data_structures::graph::WithSuccessors;
2+
use rustc_data_structures::graph::Successors;
33
use rustc_index::bit_set::BitSet;
44
use rustc_middle::mir::{
55
self,BasicBlock,Body,CallReturnPlaces,Location,Place,TerminatorEdges,

‎compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::constraints::ConstraintSccIndex;
22
usecrate::RegionInferenceContext;
33
use rustc_data_structures::fx::{FxIndexMap,FxIndexSet};
44
use rustc_data_structures::graph::vec_graph::VecGraph;
5-
use rustc_data_structures::graph::WithSuccessors;
5+
use rustc_data_structures::graph::Successors;
66
use rustc_middle::ty::RegionVid;
77
use std::ops::Range;
88

‎compiler/rustc_borrowck/src/type_check/liveness/trace.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::fx::{FxIndexMap,FxIndexSet};
2-
use rustc_data_structures::graph::WithSuccessors;
2+
use rustc_data_structures::graph::Successors;
33
use rustc_index::bit_set::BitSet;
44
use rustc_index::interval::IntervalSet;
55
use rustc_infer::infer::canonical::QueryRegionConstraints;

‎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,WithStartNode,WithSuccessors};
1+
usesuper::{DirectedGraph,Successors,WithStartNode};
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>(
9+
pubfnpost_order_from<G:DirectedGraph + Successors>(
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>(
16+
pubfnpost_order_from_to<G:DirectedGraph + Successors>(
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>(
2727
result
2828
}
2929

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

63-
pubfnreverse_post_order<G:DirectedGraph + WithSuccessors>(
63+
pubfnreverse_post_order<G:DirectedGraph + Successors>(
6464
graph:&G,
6565
start_node:G::Node,
6666
) -> Vec<G::Node>{
@@ -72,7 +72,7 @@ pub fn reverse_post_order<G: DirectedGraph + WithSuccessors>(
7272
/// A "depth-first search" iterator for a directed graph.
7373
pubstructDepthFirstSearch<'graph,G>
7474
where
75-
G: ?Sized + DirectedGraph + WithSuccessors,
75+
G: ?Sized + DirectedGraph + Successors,
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 + WithSuccessors,
84+
G: ?Sized + DirectedGraph + Successors,
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 + WithSuccessors,
130+
G: ?Sized + DirectedGraph + Successors,
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 + WithSuccessors,
143+
G: ?Sized + DirectedGraph + Successors,
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 + WithSuccessors,
204+
G: ?Sized + DirectedGraph + Successors,
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 + WithSuccessors,
214+
G: ?Sized + DirectedGraph + Successors,
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 + WithSuccessors + WithStartNode,
281+
G: ?Sized + DirectedGraph + Successors + WithStartNode,
282282
{
283283
/// Performs a depth-first search, starting from `G::start_node()`.
284284
///

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,40 @@ pub trait WithNumEdges: DirectedGraph {
2020
fnnum_edges(&self) -> usize;
2121
}
2222

23-
pubtraitWithSuccessors:DirectedGraph
24-
where
25-
Self:for<'graph>GraphSuccessors<'graph,Item = <SelfasDirectedGraph>::Node>,
26-
{
27-
fnsuccessors(&self,node:Self::Node) -> <SelfasGraphSuccessors<'_>>::Iter;
23+
pubtraitSuccessors:DirectedGraph{
24+
typeSuccessors<'g>:Iterator<Item = Self::Node>
25+
where
26+
Self:'g;
27+
28+
fnsuccessors(&self,node:Self::Node) -> Self::Successors<'_>;
2829

2930
fndepth_first_search(&self,from:Self::Node) -> iterate::DepthFirstSearch<'_,Self>{
3031
iterate::DepthFirstSearch::new(self).with_start_node(from)
3132
}
3233
}
3334

34-
#[allow(unused_lifetimes)]
35-
pubtraitGraphSuccessors<'graph>{
36-
typeItem;
37-
typeIter:Iterator<Item = Self::Item>;
38-
}
35+
pubtraitPredecessors:DirectedGraph{
36+
typePredecessors<'g>:Iterator<Item = Self::Node>
37+
where
38+
Self:'g;
3939

40-
pubtraitWithPredecessors:DirectedGraph
41-
where
42-
Self:for<'graph>GraphPredecessors<'graph,Item = <SelfasDirectedGraph>::Node>,
43-
{
44-
fnpredecessors(&self,node:Self::Node) -> <SelfasGraphPredecessors<'_>>::Iter;
45-
}
46-
47-
#[allow(unused_lifetimes)]
48-
pubtraitGraphPredecessors<'graph>{
49-
typeItem;
50-
typeIter:Iterator<Item = Self::Item>;
40+
fnpredecessors(&self,node:Self::Node) -> Self::Predecessors<'_>;
5141
}
5242

5343
pubtraitWithStartNode:DirectedGraph{
5444
fnstart_node(&self) -> Self::Node;
5545
}
5646

57-
pubtraitControlFlowGraph:
58-
DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors
59-
{
47+
pubtraitControlFlowGraph:DirectedGraph + WithStartNode + Predecessors + Successors{
6048
// convenient trait
6149
}
6250

63-
impl<T>ControlFlowGraphforTwhere
64-
T:DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors
65-
{
66-
}
51+
impl<T>ControlFlowGraphforTwhereT:DirectedGraph + WithStartNode + Predecessors + Successors{}
6752

6853
/// Returns `true` if the graph has a cycle that is reachable from the start node.
6954
pubfnis_cyclic<G>(graph:&G) -> bool
7055
where
71-
G: ?Sized + DirectedGraph + WithStartNode + WithSuccessors,
56+
G: ?Sized + DirectedGraph + WithStartNode + Successors,
7257
{
7358
iterate::TriColorDepthFirstSearch::new(graph)
7459
.run_from_start(&mut iterate::CycleDetector)

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@ impl<'graph, G: WithStartNode> WithStartNode for &'graph G {
1414
}
1515
}
1616

17-
impl<'graph,G:WithSuccessors>WithSuccessorsfor&'graphG{
18-
fnsuccessors(&self,node:Self::Node) -> <SelfasGraphSuccessors<'_>>::Iter{
17+
impl<'graph,G:Successors>Successorsfor&'graphG{
18+
typeSuccessors<'g> = G::Successors<'g>where'graph:'g;
19+
20+
fnsuccessors(&self,node:Self::Node) -> Self::Successors<'_>{
1921
(**self).successors(node)
2022
}
2123
}
2224

23-
impl<'graph,G:WithPredecessors>WithPredecessorsfor&'graphG{
24-
fnpredecessors(&self,node:Self::Node) -> <SelfasGraphPredecessors<'_>>::Iter{
25+
impl<'graph,G:Predecessors>Predecessorsfor&'graphG{
26+
typePredecessors<'g> = G::Predecessors<'g>where'graph:'g;
27+
28+
fnpredecessors(&self,node:Self::Node) -> Self::Predecessors<'_>{
2529
(**self).predecessors(node)
2630
}
2731
}
28-
29-
impl<'iter,'graph,G:WithPredecessors>GraphPredecessors<'iter>for&'graphG{
30-
typeItem = G::Node;
31-
typeIter = <GasGraphPredecessors<'iter>>::Iter;
32-
}
33-
34-
impl<'iter,'graph,G:WithSuccessors>GraphSuccessors<'iter>for&'graphG{
35-
typeItem = G::Node;
36-
typeIter = <GasGraphSuccessors<'iter>>::Iter;
37-
}

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

Lines changed: 7 additions & 11 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,WithSuccessors};
10+
usecrate::graph::{DirectedGraph,Successors,WithNumEdges};
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> + WithSuccessors)) -> Self{
42+
pubfnnew(graph:&(implDirectedGraph<Node = N> + Successors)) -> Self{
4343
SccsConstruction::construct(graph)
4444
}
4545

@@ -103,14 +103,10 @@ impl<N: Idx, S: Idx + Ord> WithNumEdges for Sccs<N, S> {
103103
}
104104
}
105105

106-
impl<'graph,N:Idx,S:Idx>GraphSuccessors<'graph>forSccs<N,S>{
107-
typeItem = S;
106+
impl<N:Idx,S:Idx + Ord>SuccessorsforSccs<N,S>{
107+
typeSuccessors<'g> = std::iter::Cloned<std::slice::Iter<'g,S>>;
108108

109-
typeIter = std::iter::Cloned<std::slice::Iter<'graph,S>>;
110-
}
111-
112-
impl<N:Idx,S:Idx + Ord>WithSuccessorsforSccs<N,S>{
113-
fnsuccessors(&self,node:S) -> <SelfasGraphSuccessors<'_>>::Iter{
109+
fnsuccessors(&self,node:S) -> Self::Successors<'_>{
114110
self.successors(node).iter().cloned()
115111
}
116112
}
@@ -156,7 +152,7 @@ impl<S: Idx> SccData<S> {
156152
}
157153
}
158154

159-
structSccsConstruction<'c,G:DirectedGraph + WithSuccessors,S:Idx>{
155+
structSccsConstruction<'c,G:DirectedGraph + Successors,S:Idx>{
160156
graph:&'cG,
161157

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

217213
impl<'c,G,S>SccsConstruction<'c,G,S>
218214
where
219-
G:DirectedGraph + WithSuccessors,
215+
G:DirectedGraph + Successors,
220216
S:Idx,
221217
{
222218
/// Identifies SCCs in the graph `G` and computes the resulting

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,18 @@ impl WithStartNode for TestGraph {
4848
}
4949
}
5050

51-
implWithPredecessorsforTestGraph{
52-
fnpredecessors(&self,node:usize) -> <SelfasGraphPredecessors<'_>>::Iter{
51+
implPredecessorsforTestGraph{
52+
typePredecessors<'g> = iter::Cloned<slice::Iter<'g,usize>>;
53+
54+
fnpredecessors(&self,node:usize) -> Self::Predecessors<'_>{
5355
self.predecessors[&node].iter().cloned()
5456
}
5557
}
5658

57-
implWithSuccessorsforTestGraph{
58-
fnsuccessors(&self,node:usize) -> <SelfasGraphSuccessors<'_>>::Iter{
59+
implSuccessorsforTestGraph{
60+
typeSuccessors<'g> = iter::Cloned<slice::Iter<'g,usize>>;
61+
62+
fnsuccessors(&self,node:usize) -> Self::Successors<'_>{
5963
self.successors[&node].iter().cloned()
6064
}
6165
}
62-
63-
impl<'graph>GraphPredecessors<'graph>forTestGraph{
64-
typeItem = usize;
65-
typeIter = iter::Cloned<slice::Iter<'graph,usize>>;
66-
}
67-
68-
impl<'graph>GraphSuccessors<'graph>forTestGraph{
69-
typeItem = usize;
70-
typeIter = iter::Cloned<slice::Iter<'graph,usize>>;
71-
}

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

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

44
#[cfg(test)]
@@ -92,14 +92,10 @@ impl<N: Idx> WithNumEdges for VecGraph<N> {
9292
}
9393
}
9494

95-
impl<'graph,N:Idx>GraphSuccessors<'graph>forVecGraph<N>{
96-
typeItem = N;
95+
impl<N:Idx + Ord>SuccessorsforVecGraph<N>{
96+
typeSuccessors<'g> = std::iter::Cloned<std::slice::Iter<'g,N>>;
9797

98-
typeIter = std::iter::Cloned<std::slice::Iter<'graph,N>>;
99-
}
100-
101-
impl<N:Idx + Ord>WithSuccessorsforVecGraph<N>{
102-
fnsuccessors(&self,node:N) -> <SelfasGraphSuccessors<'_>>::Iter{
98+
fnsuccessors(&self,node:N) -> Self::Successors<'_>{
10399
self.successors(node).iter().cloned()
104100
}
105101
}

0 commit comments

Comments
 (0)