diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index e51a7a28b..18b62c697 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -48,8 +48,7 @@ use crate::conflicts::MaterializedTreeValue; use crate::default_index::AsCompositeIndex; use crate::default_index::CompositeIndex; use crate::default_index::IndexPosition; -use crate::graph::GraphEdge; -use crate::graph::GraphNodeResult; +use crate::graph::GraphNode; use crate::matchers::Matcher; use crate::matchers::Visit; use crate::merged_tree::resolve_file_values; @@ -131,8 +130,7 @@ impl RevsetImpl { pub fn iter_graph_impl( &self, skip_transitive_edges: bool, - ) -> impl Iterator>), RevsetEvaluationError>> - { + ) -> impl Iterator, RevsetEvaluationError>> { let index = self.index.clone(); let walk = self.inner.positions(); let mut graph_walk = RevsetGraphWalk::new(walk, skip_transitive_edges); @@ -180,7 +178,7 @@ impl Revset for RevsetImpl { fn iter_graph<'a>( &self, - ) -> Box> + 'a> + ) -> Box, RevsetEvaluationError>> + 'a> where Self: 'a, { diff --git a/lib/src/default_index/revset_graph_iterator.rs b/lib/src/default_index/revset_graph_iterator.rs index fc807cffa..dc0664a3b 100644 --- a/lib/src/default_index/revset_graph_iterator.rs +++ b/lib/src/default_index/revset_graph_iterator.rs @@ -28,6 +28,7 @@ use super::revset_engine::BoxedRevWalk; use crate::backend::CommitId; use crate::graph::GraphEdge; use crate::graph::GraphEdgeType; +use crate::graph::GraphNode; // This can be cheaply allocated and hashed compared to `CommitId`-based type. type IndexGraphEdge = GraphEdge; @@ -308,7 +309,7 @@ impl<'a> RevsetGraphWalk<'a> { } impl RevWalk for RevsetGraphWalk<'_> { - type Item = (CommitId, Vec>); + type Item = GraphNode; fn next(&mut self, index: &CompositeIndex) -> Option { let position = self.next_index_position(index)?; diff --git a/lib/src/graph.rs b/lib/src/graph.rs index af061720b..fcbc95bfd 100644 --- a/lib/src/graph.rs +++ b/lib/src/graph.rs @@ -21,14 +21,15 @@ use std::hash::Hash; use crate::revset::RevsetEvaluationError; +/// Node and edges pair of type `N`. +pub type GraphNode = (N, Vec>); + #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] pub struct GraphEdge { pub target: N, pub edge_type: GraphEdgeType, } -pub type GraphNodeResult = Result<(N, Vec>), E>; - impl GraphEdge { pub fn missing(target: N) -> Self { Self { @@ -74,7 +75,7 @@ fn reachable_targets(edges: &[GraphEdge]) -> impl DoubleEndedIterator { - items: Vec<(N, Vec>)>, + items: Vec>, } impl ReverseGraphIterator @@ -82,7 +83,7 @@ where N: Hash + Eq + Clone, { pub fn new( - input: impl Iterator>), RevsetEvaluationError>>, + input: impl Iterator, RevsetEvaluationError>>, ) -> Result { let mut entries = vec![]; let mut reverse_edges: HashMap>> = HashMap::new(); @@ -107,7 +108,7 @@ where } impl Iterator for ReverseGraphIterator { - type Item = Result<(N, Vec>), RevsetEvaluationError>; + type Item = Result, RevsetEvaluationError>; fn next(&mut self) -> Option { self.items.pop().map(Ok) @@ -155,12 +156,10 @@ impl Default for TopoGroupedGraphNode { } } -type NextNodeResult = Result>)>, E>; - impl TopoGroupedGraphIterator where N: Clone + Hash + Eq, - I: Iterator>), E>>, + I: Iterator, E>>, { /// Wraps the given iterator to group topological branches. The input /// iterator must be topologically ordered. @@ -262,7 +261,7 @@ where self.emittable_ids.push(new_head_id); } - fn next_node(&mut self) -> NextNodeResult { + fn next_node(&mut self) -> Result>, E> { // Based on Kahn's algorithm loop { if let Some(current_id) = self.emittable_ids.last() { @@ -312,9 +311,9 @@ where impl Iterator for TopoGroupedGraphIterator where N: Clone + Hash + Eq, - I: Iterator>), E>>, + I: Iterator, E>>, { - type Item = Result<(N, Vec>), E>; + type Item = Result, E>; fn next(&mut self) -> Option { match self.next_node() { @@ -360,7 +359,7 @@ mod tests { } } - fn format_graph(graph_iter: impl IntoIterator>)>) -> String { + fn format_graph(graph_iter: impl IntoIterator>) -> String { let mut renderer = GraphRowRenderer::new() .output() .with_min_row_height(2) @@ -407,14 +406,12 @@ mod tests { fn topo_grouped(graph_iter: I) -> TopoGroupedGraphIterator where - I: IntoIterator>), E>>, + I: IntoIterator, E>>, { TopoGroupedGraphIterator::new(graph_iter.into_iter()) } - fn infallible( - input: (char, Vec>), - ) -> Result<(char, Vec>), Infallible> { + fn infallible(input: GraphNode) -> Result, Infallible> { Ok(input) } @@ -684,7 +681,7 @@ mod tests { fn sub_graph( chars: impl IntoIterator, root_edges: Vec>, - ) -> Vec<(char, Vec>)> { + ) -> Vec> { let [b, c, d, e, f]: [char; 5] = chars.into_iter().collect_vec().try_into().unwrap(); vec![ (f, vec![direct(c)]), diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 4b3598e99..6ef8aa7b0 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -37,7 +37,7 @@ use crate::dsl_util::AliasExpandError as _; use crate::fileset; use crate::fileset::FilesetDiagnostics; use crate::fileset::FilesetExpression; -use crate::graph::GraphNodeResult; +use crate::graph::GraphNode; use crate::hex_util::to_forward_hex; use crate::id_prefix::IdPrefixContext; use crate::id_prefix::IdPrefixIndex; @@ -2203,7 +2203,7 @@ pub trait Revset: fmt::Debug { fn iter_graph<'a>( &self, - ) -> Box> + 'a> + ) -> Box, RevsetEvaluationError>> + 'a> where Self: 'a;