Skip to content

Commit

Permalink
Use chunk_by when building ReverseSccGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Mar 24, 2024
1 parent 2f090c3 commit 87808e7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
@@ -1,6 +1,5 @@
use crate::constraints::ConstraintSccIndex;
use crate::RegionInferenceContext;
use itertools::Itertools;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::vec_graph::VecGraph;
use rustc_data_structures::graph::WithSuccessors;
Expand Down Expand Up @@ -48,16 +47,16 @@ impl RegionInferenceContext<'_> {
.universal_regions
.universal_regions()
.map(|region| (self.constraint_sccs.scc(region), region))
.collect_vec();
.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 (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) {
let group_size = group.count();
scc_regions.insert(scc, start..start + group_size);
start += group_size;
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 });
Expand Down

0 comments on commit 87808e7

Please sign in to comment.