Use RPITIT for Successors and Predecessors traits

Now with RPITIT instead of GAT!
This commit is contained in:
Maybe Waffle 2024-04-15 13:33:08 +00:00
parent e8d2221e3b
commit 435db9b9bd
8 changed files with 14 additions and 46 deletions

View File

@ -223,9 +223,7 @@ fn num_nodes(&self) -> usize {
}
impl<'s, 'tcx, D: ConstraintGraphDirection> graph::Successors for RegionGraph<'s, 'tcx, D> {
type Successors<'g> = Successors<'s, 'tcx, D> where Self: 'g;
fn successors(&self, node: Self::Node) -> Self::Successors<'_> {
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.outgoing_regions(node)
}
}

View File

@ -25,19 +25,11 @@ pub trait StartNode: DirectedGraph {
}
pub trait Successors: DirectedGraph {
type Successors<'g>: Iterator<Item = Self::Node>
where
Self: 'g;
fn successors(&self, node: Self::Node) -> Self::Successors<'_>;
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node>;
}
pub trait Predecessors: DirectedGraph {
type Predecessors<'g>: Iterator<Item = Self::Node>
where
Self: 'g;
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>;
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node>;
}
/// Alias for [`DirectedGraph`] + [`StartNode`] + [`Predecessors`] + [`Successors`].

View File

@ -15,17 +15,13 @@ fn start_node(&self) -> Self::Node {
}
impl<'graph, G: Successors> Successors for &'graph G {
type Successors<'g> = G::Successors<'g> where 'graph: 'g;
fn successors(&self, node: Self::Node) -> Self::Successors<'_> {
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
(**self).successors(node)
}
}
impl<'graph, G: Predecessors> Predecessors for &'graph G {
type Predecessors<'g> = G::Predecessors<'g> where 'graph: 'g;
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_> {
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
(**self).predecessors(node)
}
}

View File

@ -104,9 +104,7 @@ fn num_edges(&self) -> usize {
}
impl<N: Idx, S: Idx + Ord> Successors for Sccs<N, S> {
type Successors<'g> = std::iter::Cloned<std::slice::Iter<'g, S>>;
fn successors(&self, node: S) -> Self::Successors<'_> {
fn successors(&self, node: S) -> impl Iterator<Item = Self::Node> {
self.successors(node).iter().cloned()
}
}

View File

@ -1,7 +1,5 @@
use crate::fx::FxHashMap;
use std::cmp::max;
use std::iter;
use std::slice;
use super::*;
@ -49,17 +47,13 @@ fn start_node(&self) -> usize {
}
impl Predecessors for TestGraph {
type Predecessors<'g> = iter::Cloned<slice::Iter<'g, usize>>;
fn predecessors(&self, node: usize) -> Self::Predecessors<'_> {
fn predecessors(&self, node: usize) -> impl Iterator<Item = Self::Node> {
self.predecessors[&node].iter().cloned()
}
}
impl Successors for TestGraph {
type Successors<'g> = iter::Cloned<slice::Iter<'g, usize>>;
fn successors(&self, node: usize) -> Self::Successors<'_> {
fn successors(&self, node: usize) -> impl Iterator<Item = Self::Node> {
self.successors[&node].iter().cloned()
}
}

View File

@ -93,9 +93,7 @@ fn num_edges(&self) -> usize {
}
impl<N: Idx + Ord> Successors for VecGraph<N> {
type Successors<'g> = std::iter::Cloned<std::slice::Iter<'g, N>>;
fn successors(&self, node: N) -> Self::Successors<'_> {
fn successors(&self, node: N) -> impl Iterator<Item = Self::Node> {
self.successors(node).iter().cloned()
}
}

View File

@ -1,5 +1,5 @@
use crate::mir::traversal::Postorder;
use crate::mir::{BasicBlock, BasicBlockData, Successors, Terminator, TerminatorKind, START_BLOCK};
use crate::mir::{BasicBlock, BasicBlockData, Terminator, TerminatorKind, START_BLOCK};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph;
@ -156,19 +156,15 @@ fn start_node(&self) -> Self::Node {
}
impl<'tcx> graph::Successors for BasicBlocks<'tcx> {
type Successors<'b> = Successors<'b> where 'tcx: 'b;
#[inline]
fn successors(&self, node: Self::Node) -> Self::Successors<'_> {
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.basic_blocks[node].terminator().successors()
}
}
impl<'tcx> graph::Predecessors for BasicBlocks<'tcx> {
type Predecessors<'b> = std::iter::Copied<std::slice::Iter<'b, BasicBlock>> where 'tcx: 'b;
#[inline]
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_> {
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.predecessors()[node].iter().copied()
}
}

View File

@ -209,19 +209,15 @@ fn start_node(&self) -> Self::Node {
}
impl graph::Successors for CoverageGraph {
type Successors<'g> = std::iter::Cloned<std::slice::Iter<'g, BasicCoverageBlock>>;
#[inline]
fn successors(&self, node: Self::Node) -> Self::Successors<'_> {
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.successors[node].iter().cloned()
}
}
impl graph::Predecessors for CoverageGraph {
type Predecessors<'g> = std::iter::Copied<std::slice::Iter<'g, BasicCoverageBlock>>;
#[inline]
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_> {
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.predecessors[node].iter().copied()
}
}