Make depth_first_search
into a standalone function
Does not necessarily change much, but we never overwrite it, so I see no reason for it to be in the `Successors` trait. (+we already have a similar `is_cyclic`)
This commit is contained in:
parent
3124fa9310
commit
e8d2221e3b
6 changed files with 21 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_data_structures::graph::Successors;
|
use rustc_data_structures::graph;
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdges,
|
self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdges,
|
||||||
|
@ -262,7 +262,7 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
|
||||||
|
|
||||||
// We first handle the cases where the loan doesn't go out of scope, depending on the issuing
|
// We first handle the cases where the loan doesn't go out of scope, depending on the issuing
|
||||||
// region's successors.
|
// region's successors.
|
||||||
for successor in self.regioncx.region_graph().depth_first_search(issuing_region) {
|
for successor in graph::depth_first_search(&self.regioncx.region_graph(), issuing_region) {
|
||||||
// 1. Via applied member constraints
|
// 1. Via applied member constraints
|
||||||
//
|
//
|
||||||
// The issuing region can flow into the choice regions, and they are either:
|
// The issuing region can flow into the choice regions, and they are either:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::constraints::ConstraintSccIndex;
|
use crate::constraints::ConstraintSccIndex;
|
||||||
use crate::RegionInferenceContext;
|
use crate::RegionInferenceContext;
|
||||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||||
|
use rustc_data_structures::graph;
|
||||||
use rustc_data_structures::graph::vec_graph::VecGraph;
|
use rustc_data_structures::graph::vec_graph::VecGraph;
|
||||||
use rustc_data_structures::graph::Successors;
|
|
||||||
use rustc_middle::ty::RegionVid;
|
use rustc_middle::ty::RegionVid;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ impl ReverseSccGraph {
|
||||||
scc0: ConstraintSccIndex,
|
scc0: ConstraintSccIndex,
|
||||||
) -> impl Iterator<Item = RegionVid> + 'a {
|
) -> impl Iterator<Item = RegionVid> + 'a {
|
||||||
let mut duplicates = FxIndexSet::default();
|
let mut duplicates = FxIndexSet::default();
|
||||||
self.graph
|
graph::depth_first_search(&self.graph, scc0)
|
||||||
.depth_first_search(scc0)
|
|
||||||
.flat_map(move |scc1| {
|
.flat_map(move |scc1| {
|
||||||
self.scc_regions
|
self.scc_regions
|
||||||
.get(&scc1)
|
.get(&scc1)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::graph::Successors;
|
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::interval::IntervalSet;
|
use rustc_index::interval::IntervalSet;
|
||||||
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
||||||
|
@ -64,7 +63,10 @@ pub(super) fn trace<'mir, 'tcx>(
|
||||||
// Traverse each issuing region's constraints, and record the loan as flowing into the
|
// Traverse each issuing region's constraints, and record the loan as flowing into the
|
||||||
// outlived region.
|
// outlived region.
|
||||||
for (loan, issuing_region_data) in borrow_set.iter_enumerated() {
|
for (loan, issuing_region_data) in borrow_set.iter_enumerated() {
|
||||||
for succ in region_graph.depth_first_search(issuing_region_data.region) {
|
for succ in rustc_data_structures::graph::depth_first_search(
|
||||||
|
®ion_graph,
|
||||||
|
issuing_region_data.region,
|
||||||
|
) {
|
||||||
// We don't need to mention that a loan flows into its issuing region.
|
// We don't need to mention that a loan flows into its issuing region.
|
||||||
if succ == issuing_region_data.region {
|
if succ == issuing_region_data.region {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -30,10 +30,6 @@ pub trait Successors: DirectedGraph {
|
||||||
Self: 'g;
|
Self: 'g;
|
||||||
|
|
||||||
fn successors(&self, node: Self::Node) -> Self::Successors<'_>;
|
fn successors(&self, node: Self::Node) -> Self::Successors<'_>;
|
||||||
|
|
||||||
fn depth_first_search(&self, from: Self::Node) -> iterate::DepthFirstSearch<'_, Self> {
|
|
||||||
iterate::DepthFirstSearch::new(self).with_start_node(from)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Predecessors: DirectedGraph {
|
pub trait Predecessors: DirectedGraph {
|
||||||
|
@ -57,3 +53,10 @@ where
|
||||||
.run_from_start(&mut iterate::CycleDetector)
|
.run_from_start(&mut iterate::CycleDetector)
|
||||||
.is_some()
|
.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn depth_first_search<G>(graph: &G, from: G::Node) -> iterate::DepthFirstSearch<'_, G>
|
||||||
|
where
|
||||||
|
G: ?Sized + Successors,
|
||||||
|
{
|
||||||
|
iterate::DepthFirstSearch::new(graph).with_start_node(from)
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::graph;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn create_graph() -> VecGraph<usize> {
|
fn create_graph() -> VecGraph<usize> {
|
||||||
|
@ -37,6 +39,6 @@ fn successors() {
|
||||||
#[test]
|
#[test]
|
||||||
fn dfs() {
|
fn dfs() {
|
||||||
let graph = create_graph();
|
let graph = create_graph();
|
||||||
let dfs: Vec<_> = graph.depth_first_search(0).collect();
|
let dfs: Vec<_> = graph::depth_first_search(&graph, 0).collect();
|
||||||
assert_eq!(dfs, vec![0, 1, 3, 4, 2]);
|
assert_eq!(dfs, vec![0, 1, 3, 4, 2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::FnCtxt;
|
use crate::FnCtxt;
|
||||||
use rustc_data_structures::{
|
use rustc_data_structures::{
|
||||||
graph::Successors,
|
graph::{self, iterate::DepthFirstSearch, vec_graph::VecGraph},
|
||||||
graph::{iterate::DepthFirstSearch, vec_graph::VecGraph},
|
|
||||||
unord::{UnordBag, UnordMap, UnordSet},
|
unord::{UnordBag, UnordMap, UnordSet},
|
||||||
};
|
};
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||||
|
@ -300,7 +299,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||||
debug!(
|
debug!(
|
||||||
"calculate_diverging_fallback: root_vid={:?} reaches {:?}",
|
"calculate_diverging_fallback: root_vid={:?} reaches {:?}",
|
||||||
root_vid,
|
root_vid,
|
||||||
coercion_graph.depth_first_search(root_vid).collect::<Vec<_>>()
|
graph::depth_first_search(&coercion_graph, root_vid).collect::<Vec<_>>()
|
||||||
);
|
);
|
||||||
|
|
||||||
// drain the iterator to visit all nodes reachable from this node
|
// drain the iterator to visit all nodes reachable from this node
|
||||||
|
@ -342,8 +341,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||||
for &diverging_vid in &diverging_vids {
|
for &diverging_vid in &diverging_vids {
|
||||||
let diverging_ty = Ty::new_var(self.tcx, diverging_vid);
|
let diverging_ty = Ty::new_var(self.tcx, diverging_vid);
|
||||||
let root_vid = self.root_var(diverging_vid);
|
let root_vid = self.root_var(diverging_vid);
|
||||||
let can_reach_non_diverging = coercion_graph
|
let can_reach_non_diverging = graph::depth_first_search(&coercion_graph, root_vid)
|
||||||
.depth_first_search(root_vid)
|
|
||||||
.any(|n| roots_reachable_from_non_diverging.visited(n));
|
.any(|n| roots_reachable_from_non_diverging.visited(n));
|
||||||
|
|
||||||
let infer_var_infos: UnordBag<_> = self
|
let infer_var_infos: UnordBag<_> = self
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue