Rollup merge of #140604 - lcnr:revealing-use-prep, r=compiler-errors
yet another small borrowck cleanup
The last borrowck changes from #139587 which can be reviewed entirely separately.
r? `@compiler-errors`
diff --git a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
index b2ed8a3..8e04791 100644
--- a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
+++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
@@ -7,6 +7,8 @@
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 @@ pub(super) fn compute_reverse_scc_graph(&mut self) {
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()));
}
}
diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
index 536a277..92732ab 100644
--- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
+++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
@@ -41,8 +41,8 @@ pub(crate) struct UniversalRegionRelations<'tcx> {
pub(crate) struct CreateResult<'tcx> {
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
- pub(crate) region_bound_pairs: RegionBoundPairs<'tcx>,
- pub(crate) known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
+ pub(crate) region_bound_pairs: Frozen<RegionBoundPairs<'tcx>>,
+ pub(crate) known_type_outlives_obligations: Frozen<Vec<ty::PolyTypeOutlivesPredicate<'tcx>>>,
pub(crate) normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>,
}
@@ -333,8 +333,8 @@ pub(crate) fn create(mut self) -> CreateResult<'tcx> {
outlives: self.outlives.freeze(),
inverse_outlives: self.inverse_outlives.freeze(),
}),
- known_type_outlives_obligations,
- region_bound_pairs: self.region_bound_pairs,
+ known_type_outlives_obligations: Frozen::freeze(known_type_outlives_obligations),
+ region_bound_pairs: Frozen::freeze(self.region_bound_pairs),
normalized_inputs_and_output,
}
}
diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs
index 99a5442..8c51225 100644
--- a/compiler/rustc_borrowck/src/type_check/mod.rs
+++ b/compiler/rustc_borrowck/src/type_check/mod.rs
@@ -151,8 +151,8 @@ pub(crate) fn type_check<'a, 'tcx>(
body,
promoted,
user_type_annotations: &body.user_type_annotations,
- region_bound_pairs,
- known_type_outlives_obligations,
+ region_bound_pairs: ®ion_bound_pairs,
+ known_type_outlives_obligations: &known_type_outlives_obligations,
reported_errors: Default::default(),
universal_regions: &universal_region_relations.universal_regions,
location_table,
@@ -216,8 +216,8 @@ struct TypeChecker<'a, 'tcx> {
/// User type annotations are shared between the main MIR and the MIR of
/// all of the promoted items.
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
- region_bound_pairs: RegionBoundPairs<'tcx>,
- known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
+ region_bound_pairs: &'a RegionBoundPairs<'tcx>,
+ known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
universal_regions: &'a UniversalRegions<'tcx>,
location_table: &'a PoloniusLocationTable,
@@ -412,9 +412,9 @@ fn push_region_constraints(
constraint_conversion::ConstraintConversion::new(
self.infcx,
self.universal_regions,
- &self.region_bound_pairs,
+ self.region_bound_pairs,
self.infcx.param_env,
- &self.known_type_outlives_obligations,
+ self.known_type_outlives_obligations,
locations,
locations.span(self.body),
category,
@@ -2506,9 +2506,9 @@ fn prove_closure_bounds(
constraint_conversion::ConstraintConversion::new(
self.infcx,
self.universal_regions,
- &self.region_bound_pairs,
+ self.region_bound_pairs,
self.infcx.param_env,
- &self.known_type_outlives_obligations,
+ self.known_type_outlives_obligations,
locations,
self.body.span, // irrelevant; will be overridden.
ConstraintCategory::Boring, // same as above.