Rollup merge of #122970 - cuviper:use-chunk_by, r=Mark-Simulacrum

Use `chunk_by` when building `ReverseSccGraph`

With stable `chunk_by` in Rust 1.77, this code doesn't need `Itertools::group_by` anymore.
This commit is contained in:
Matthias Krüger 2024-03-25 17:05:33 +01:00 committed by GitHub
commit 9b4ee1be9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,5 @@
use crate::constraints::ConstraintSccIndex; use crate::constraints::ConstraintSccIndex;
use crate::RegionInferenceContext; use crate::RegionInferenceContext;
use itertools::Itertools;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::vec_graph::VecGraph; use rustc_data_structures::graph::vec_graph::VecGraph;
use rustc_data_structures::graph::WithSuccessors; use rustc_data_structures::graph::WithSuccessors;
@ -48,16 +47,16 @@ pub(super) fn compute_reverse_scc_graph(&mut self) {
.universal_regions .universal_regions
.universal_regions() .universal_regions()
.map(|region| (self.constraint_sccs.scc(region), region)) .map(|region| (self.constraint_sccs.scc(region), region))
.collect_vec(); .collect::<Vec<_>>();
paired_scc_regions.sort(); paired_scc_regions.sort();
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect(); let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
let mut scc_regions = FxIndexMap::default(); let mut scc_regions = FxIndexMap::default();
let mut start = 0; let mut start = 0;
for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) { for chunk in paired_scc_regions.chunk_by(|&(scc1, _), &(scc2, _)| scc1 == scc2) {
let group_size = group.count(); let (scc, _) = chunk[0];
scc_regions.insert(scc, start..start + group_size); scc_regions.insert(scc, start..start + chunk.len());
start += group_size; start += chunk.len();
} }
self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions }); self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });