Skip to content

Commit e6ff0ba

Browse files
committed
rustc VecGraph: require the index type to implement Ord
1 parent a4a8c24 commit e6ff0ba

File tree

2 files changed

+9
-6
lines changed
  • compiler/rustc_data_structures/src/graph

2 files changed

+9
-6
lines changed

Diff for: compiler/rustc_data_structures/src/graph/scc/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::fx::FxHashSet;
99
use crate::graph::vec_graph::VecGraph;
1010
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
1111
use rustc_index::vec::{Idx, IndexVec};
12+
use std::cmp::Ord;
1213
use std::ops::Range;
1314

1415
#[cfg(test)]
@@ -38,7 +39,7 @@ struct SccData<S: Idx> {
3839
all_successors: Vec<S>,
3940
}
4041

41-
impl<N: Idx, S: Idx> Sccs<N, S> {
42+
impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
4243
pub fn new(graph: &(impl DirectedGraph<Node = N> + WithNumNodes + WithSuccessors)) -> Self {
4344
SccsConstruction::construct(graph)
4445
}
@@ -85,7 +86,7 @@ impl<N: Idx, S: Idx> DirectedGraph for Sccs<N, S> {
8586
type Node = S;
8687
}
8788

88-
impl<N: Idx, S: Idx> WithNumNodes for Sccs<N, S> {
89+
impl<N: Idx, S: Idx + Ord> WithNumNodes for Sccs<N, S> {
8990
fn num_nodes(&self) -> usize {
9091
self.num_sccs()
9192
}
@@ -103,7 +104,7 @@ impl<'graph, N: Idx, S: Idx> GraphSuccessors<'graph> for Sccs<N, S> {
103104
type Iter = std::iter::Cloned<std::slice::Iter<'graph, S>>;
104105
}
105106

106-
impl<N: Idx, S: Idx> WithSuccessors for Sccs<N, S> {
107+
impl<N: Idx, S: Idx + Ord> WithSuccessors for Sccs<N, S> {
107108
fn successors(&self, node: S) -> <Self as GraphSuccessors<'_>>::Iter {
108109
self.successors(node).iter().cloned()
109110
}

Diff for: compiler/rustc_data_structures/src/graph/vec_graph/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::cmp::Ord;
2+
13
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
24
use rustc_index::vec::{Idx, IndexVec};
35

@@ -17,10 +19,10 @@ pub struct VecGraph<N: Idx> {
1719
edge_targets: Vec<N>,
1820
}
1921

20-
impl<N: Idx> VecGraph<N> {
22+
impl<N: Idx + Ord> VecGraph<N> {
2123
pub fn new(num_nodes: usize, mut edge_pairs: Vec<(N, N)>) -> Self {
2224
// Sort the edges by the source -- this is important.
23-
edge_pairs.sort_by_key(|&edge_pairs| (edge_pairs.0.index(), edge_pairs.1.index()));
25+
edge_pairs.sort();
2426

2527
let num_edges = edge_pairs.len();
2628

@@ -100,7 +102,7 @@ impl<'graph, N: Idx> GraphSuccessors<'graph> for VecGraph<N> {
100102
type Iter = std::iter::Cloned<std::slice::Iter<'graph, N>>;
101103
}
102104

103-
impl<N: Idx> WithSuccessors for VecGraph<N> {
105+
impl<N: Idx + Ord> WithSuccessors for VecGraph<N> {
104106
fn successors(&self, node: N) -> <Self as GraphSuccessors<'_>>::Iter {
105107
self.successors(node).iter().cloned()
106108
}

0 commit comments

Comments
 (0)