1
Fork 0

Rollup merge of #123934 - WaffleLapkin:graph-mini-refactor, r=fmease

`rustc_data_structures::graph` mini refactor

Who doesn't love to breathe dust from the ancient times?
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-04-15 16:56:18 +01:00 committed by GitHub
commit 5580ae9795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 90 additions and 194 deletions

View file

@ -2,7 +2,7 @@ use std::fmt::{self, Debug};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph::WithNumNodes;
use rustc_data_structures::graph::DirectedGraph;
use rustc_index::IndexVec;
use rustc_middle::mir::coverage::{CounterId, CovTerm, Expression, ExpressionId, Op};

View file

@ -1,7 +1,7 @@
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::{self, Dominators};
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
use rustc_data_structures::graph::{self, DirectedGraph, StartNode};
use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec;
use rustc_middle::mir::{self, BasicBlock, Terminator, TerminatorKind};
@ -193,16 +193,14 @@ impl IndexMut<BasicCoverageBlock> for CoverageGraph {
impl graph::DirectedGraph for CoverageGraph {
type Node = BasicCoverageBlock;
}
impl graph::WithNumNodes for CoverageGraph {
#[inline]
fn num_nodes(&self) -> usize {
self.bcbs.len()
}
}
impl graph::WithStartNode for CoverageGraph {
impl graph::StartNode for CoverageGraph {
#[inline]
fn start_node(&self) -> Self::Node {
self.bcb_from_bb(mir::START_BLOCK)
@ -210,28 +208,16 @@ impl graph::WithStartNode for CoverageGraph {
}
}
type BcbSuccessors<'graph> = std::slice::Iter<'graph, BasicCoverageBlock>;
impl<'graph> graph::GraphSuccessors<'graph> for CoverageGraph {
type Item = BasicCoverageBlock;
type Iter = std::iter::Cloned<BcbSuccessors<'graph>>;
}
impl graph::WithSuccessors for CoverageGraph {
impl graph::Successors for CoverageGraph {
#[inline]
fn successors(&self, node: Self::Node) -> <Self as GraphSuccessors<'_>>::Iter {
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.successors[node].iter().cloned()
}
}
impl<'graph> graph::GraphPredecessors<'graph> for CoverageGraph {
type Item = BasicCoverageBlock;
type Iter = std::iter::Copied<std::slice::Iter<'graph, BasicCoverageBlock>>;
}
impl graph::WithPredecessors for CoverageGraph {
impl graph::Predecessors for CoverageGraph {
#[inline]
fn predecessors(&self, node: Self::Node) -> <Self as graph::GraphPredecessors<'_>>::Iter {
fn predecessors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
self.predecessors[node].iter().copied()
}
}

View file

@ -1,4 +1,4 @@
use rustc_data_structures::graph::WithNumNodes;
use rustc_data_structures::graph::DirectedGraph;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir;
use rustc_span::{BytePos, Span};

View file

@ -28,8 +28,7 @@ use super::counters;
use super::graph::{self, BasicCoverageBlock};
use itertools::Itertools;
use rustc_data_structures::graph::WithNumNodes;
use rustc_data_structures::graph::WithSuccessors;
use rustc_data_structures::graph::{DirectedGraph, Successors};
use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::*;
use rustc_middle::ty;