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`
This commit is contained in:
commit
4360fd7f34
3 changed files with 39 additions and 30 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()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'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 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, '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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
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 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue