Skip to content

Commit eb03b8b

Browse files
committed
encapsulate access to SCC constraint graph
1 parent 5ef7a99 commit eb03b8b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
262262

263263
impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
264264
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
265+
let sccs = regioncx.constraint_sccs();
266+
let num_sccs = sccs.num_sccs();
267+
265268
// Compute the list of SCCs that are live at all points, as it will be used for all the
266269
// loan scopes we'll compute.
267270
// FIXME: they're surely already available somewhere.
@@ -279,13 +282,12 @@ impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
279282
);
280283
live_at_all_points
281284
})
282-
.map(|r| regioncx.constraint_sccs.scc(r))
285+
.map(|r| sccs.scc(r))
283286
.collect();
284287

285288
// Pre-compute the set of live SCCs per point
286289
let liveness = &regioncx.liveness_constraints;
287-
let sccs = &regioncx.constraint_sccs;
288-
let mut live_sccs_per_point = SparseBitMatrix::new(sccs.num_sccs());
290+
let mut live_sccs_per_point = SparseBitMatrix::new(num_sccs);
289291

290292
for region in liveness.rows() {
291293
let scc = sccs.scc(region);
@@ -306,7 +308,7 @@ impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
306308
loans_out_of_scope_at_location: FxIndexMap::default(),
307309
sccs_live_at_all_points,
308310
live_sccs_per_point,
309-
reachability: BitSet::new_empty(regioncx.constraint_sccs.num_sccs()),
311+
reachability: BitSet::new_empty(num_sccs),
310312
reachability_stack: vec![],
311313
}
312314
}
@@ -327,7 +329,7 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
327329
// regions via member constraints. (The `OutOfScopePrecomputer` wouldn't be called on a
328330
// region that outlives free regions via outlives constraints.)
329331

330-
let sccs = &self.regioncx.constraint_sccs;
332+
let sccs = self.regioncx.constraint_sccs();
331333
let member_constraints = &self.regioncx.member_constraints;
332334

333335
let issuing_region_scc = sccs.scc(issuing_region);

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct RegionInferenceContext<'tcx> {
7171
/// The SCC computed from `constraints` and the constraint
7272
/// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
7373
/// compute the values of each region.
74-
pub(crate) constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
74+
constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
7575

7676
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
7777
/// `B: A`. This is used to compute the universal regions that are required
@@ -2279,6 +2279,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22792279
}
22802280
None
22812281
}
2282+
2283+
/// Access to the SCC constraint graph.
2284+
pub(crate) fn constraint_sccs(&self) -> &Sccs<RegionVid, ConstraintSccIndex> {
2285+
self.constraint_sccs.as_ref()
2286+
}
22822287
}
22832288

22842289
impl<'tcx> RegionDefinition<'tcx> {

0 commit comments

Comments
 (0)