add ReverseSccGraph::compute
This commit is contained in:
parent
2d5ffc513f
commit
ad3c35bea5
1 changed files with 27 additions and 18 deletions
|
|
@ -7,6 +7,8 @@ use rustc_middle::ty::RegionVid;
|
|||
|
||||
use crate::RegionInferenceContext;
|
||||
use crate::constraints::ConstraintSccIndex;
|
||||
use crate::region_infer::ConstraintSccs;
|
||||
use crate::universal_regions::UniversalRegions;
|
||||
|
||||
pub(crate) struct ReverseSccGraph {
|
||||
graph: VecGraph<ConstraintSccIndex>,
|
||||
|
|
@ -19,6 +21,29 @@ pub(crate) struct ReverseSccGraph {
|
|||
}
|
||||
|
||||
impl ReverseSccGraph {
|
||||
pub(super) fn compute(
|
||||
constraint_sccs: &ConstraintSccs,
|
||||
universal_regions: &UniversalRegions<'_>,
|
||||
) -> Self {
|
||||
let graph = constraint_sccs.reverse();
|
||||
let mut paired_scc_regions = universal_regions
|
||||
.universal_regions_iter()
|
||||
.map(|region| (constraint_sccs.scc(region), region))
|
||||
.collect::<Vec<_>>();
|
||||
paired_scc_regions.sort();
|
||||
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
|
||||
|
||||
let mut scc_regions = FxIndexMap::default();
|
||||
let mut start = 0;
|
||||
for chunk in paired_scc_regions.chunk_by(|&(scc1, _), &(scc2, _)| scc1 == scc2) {
|
||||
let (scc, _) = chunk[0];
|
||||
|
||||
scc_regions.insert(scc, start..start + chunk.len());
|
||||
start += chunk.len();
|
||||
}
|
||||
ReverseSccGraph { graph, scc_regions, universal_regions }
|
||||
}
|
||||
|
||||
/// Find all universal regions that are required to outlive the given SCC.
|
||||
pub(super) fn upper_bounds(&self, scc0: ConstraintSccIndex) -> impl Iterator<Item = RegionVid> {
|
||||
let mut duplicates = FxIndexSet::default();
|
||||
|
|
@ -40,23 +65,7 @@ impl RegionInferenceContext<'_> {
|
|||
return;
|
||||
}
|
||||
|
||||
let graph = self.constraint_sccs.reverse();
|
||||
let mut paired_scc_regions = self
|
||||
.universal_regions()
|
||||
.universal_regions_iter()
|
||||
.map(|region| (self.constraint_sccs.scc(region), region))
|
||||
.collect::<Vec<_>>();
|
||||
paired_scc_regions.sort();
|
||||
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
|
||||
|
||||
let mut scc_regions = FxIndexMap::default();
|
||||
let mut start = 0;
|
||||
for chunk in paired_scc_regions.chunk_by(|&(scc1, _), &(scc2, _)| scc1 == scc2) {
|
||||
let (scc, _) = chunk[0];
|
||||
scc_regions.insert(scc, start..start + chunk.len());
|
||||
start += chunk.len();
|
||||
}
|
||||
|
||||
self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });
|
||||
self.rev_scc_graph =
|
||||
Some(ReverseSccGraph::compute(&self.constraint_sccs, self.universal_regions()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue