Skip to content

Commit 4360fd7

Browse files
authored
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`
2 parents 14c424a + 0be1ec1 commit 4360fd7

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use rustc_middle::ty::RegionVid;
77

88
use crate::RegionInferenceContext;
99
use crate::constraints::ConstraintSccIndex;
10+
use crate::region_infer::ConstraintSccs;
11+
use crate::universal_regions::UniversalRegions;
1012

1113
pub(crate) struct ReverseSccGraph {
1214
graph: VecGraph<ConstraintSccIndex>,
@@ -19,6 +21,29 @@ pub(crate) struct ReverseSccGraph {
1921
}
2022

2123
impl ReverseSccGraph {
24+
pub(super) fn compute(
25+
constraint_sccs: &ConstraintSccs,
26+
universal_regions: &UniversalRegions<'_>,
27+
) -> Self {
28+
let graph = constraint_sccs.reverse();
29+
let mut paired_scc_regions = universal_regions
30+
.universal_regions_iter()
31+
.map(|region| (constraint_sccs.scc(region), region))
32+
.collect::<Vec<_>>();
33+
paired_scc_regions.sort();
34+
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
35+
36+
let mut scc_regions = FxIndexMap::default();
37+
let mut start = 0;
38+
for chunk in paired_scc_regions.chunk_by(|&(scc1, _), &(scc2, _)| scc1 == scc2) {
39+
let (scc, _) = chunk[0];
40+
41+
scc_regions.insert(scc, start..start + chunk.len());
42+
start += chunk.len();
43+
}
44+
ReverseSccGraph { graph, scc_regions, universal_regions }
45+
}
46+
2247
/// Find all universal regions that are required to outlive the given SCC.
2348
pub(super) fn upper_bounds(&self, scc0: ConstraintSccIndex) -> impl Iterator<Item = RegionVid> {
2449
let mut duplicates = FxIndexSet::default();
@@ -40,23 +65,7 @@ impl RegionInferenceContext<'_> {
4065
return;
4166
}
4267

43-
let graph = self.constraint_sccs.reverse();
44-
let mut paired_scc_regions = self
45-
.universal_regions()
46-
.universal_regions_iter()
47-
.map(|region| (self.constraint_sccs.scc(region), region))
48-
.collect::<Vec<_>>();
49-
paired_scc_regions.sort();
50-
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
51-
52-
let mut scc_regions = FxIndexMap::default();
53-
let mut start = 0;
54-
for chunk in paired_scc_regions.chunk_by(|&(scc1, _), &(scc2, _)| scc1 == scc2) {
55-
let (scc, _) = chunk[0];
56-
scc_regions.insert(scc, start..start + chunk.len());
57-
start += chunk.len();
58-
}
59-
60-
self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });
68+
self.rev_scc_graph =
69+
Some(ReverseSccGraph::compute(&self.constraint_sccs, self.universal_regions()));
6170
}
6271
}

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'tcx>>;
4141

4242
pub(crate) struct CreateResult<'tcx> {
4343
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
44-
pub(crate) region_bound_pairs: RegionBoundPairs<'tcx>,
45-
pub(crate) known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
44+
pub(crate) region_bound_pairs: Frozen<RegionBoundPairs<'tcx>>,
45+
pub(crate) known_type_outlives_obligations: Frozen<Vec<ty::PolyTypeOutlivesPredicate<'tcx>>>,
4646
pub(crate) normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>,
4747
}
4848

@@ -333,8 +333,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
333333
outlives: self.outlives.freeze(),
334334
inverse_outlives: self.inverse_outlives.freeze(),
335335
}),
336-
known_type_outlives_obligations,
337-
region_bound_pairs: self.region_bound_pairs,
336+
known_type_outlives_obligations: Frozen::freeze(known_type_outlives_obligations),
337+
region_bound_pairs: Frozen::freeze(self.region_bound_pairs),
338338
normalized_inputs_and_output,
339339
}
340340
}

compiler/rustc_borrowck/src/type_check/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ pub(crate) fn type_check<'a, 'tcx>(
151151
body,
152152
promoted,
153153
user_type_annotations: &body.user_type_annotations,
154-
region_bound_pairs,
155-
known_type_outlives_obligations,
154+
region_bound_pairs: &region_bound_pairs,
155+
known_type_outlives_obligations: &known_type_outlives_obligations,
156156
reported_errors: Default::default(),
157157
universal_regions: &universal_region_relations.universal_regions,
158158
location_table,
@@ -216,8 +216,8 @@ struct TypeChecker<'a, 'tcx> {
216216
/// User type annotations are shared between the main MIR and the MIR of
217217
/// all of the promoted items.
218218
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
219-
region_bound_pairs: RegionBoundPairs<'tcx>,
220-
known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
219+
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
220+
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
221221
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
222222
universal_regions: &'a UniversalRegions<'tcx>,
223223
location_table: &'a PoloniusLocationTable,
@@ -412,9 +412,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
412412
constraint_conversion::ConstraintConversion::new(
413413
self.infcx,
414414
self.universal_regions,
415-
&self.region_bound_pairs,
415+
self.region_bound_pairs,
416416
self.infcx.param_env,
417-
&self.known_type_outlives_obligations,
417+
self.known_type_outlives_obligations,
418418
locations,
419419
locations.span(self.body),
420420
category,
@@ -2506,9 +2506,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25062506
constraint_conversion::ConstraintConversion::new(
25072507
self.infcx,
25082508
self.universal_regions,
2509-
&self.region_bound_pairs,
2509+
self.region_bound_pairs,
25102510
self.infcx.param_env,
2511-
&self.known_type_outlives_obligations,
2511+
self.known_type_outlives_obligations,
25122512
locations,
25132513
self.body.span, // irrelevant; will be overridden.
25142514
ConstraintCategory::Boring, // same as above.

0 commit comments

Comments
 (0)