@@ -12,7 +12,6 @@ use super::universal_regions::UniversalRegions;
12
12
use borrow_check:: nll:: constraints:: {
13
13
ConstraintIndex , ConstraintSccIndex , ConstraintSet , OutlivesConstraint ,
14
14
} ;
15
- use borrow_check:: nll:: constraints:: graph:: ConstraintGraph ;
16
15
use borrow_check:: nll:: region_infer:: values:: ToElementIndex ;
17
16
use borrow_check:: nll:: type_check:: Locations ;
18
17
use rustc:: hir:: def_id:: DefId ;
@@ -27,6 +26,7 @@ use rustc::mir::{
27
26
} ;
28
27
use rustc:: ty:: { self , RegionVid , Ty , TyCtxt , TypeFoldable } ;
29
28
use rustc:: util:: common;
29
+ use rustc_data_structures:: bitvec:: SparseBitSet ;
30
30
use rustc_data_structures:: graph:: scc:: Sccs ;
31
31
use rustc_data_structures:: indexed_set:: { IdxSet , IdxSetBuf } ;
32
32
use rustc_data_structures:: indexed_vec:: IndexVec ;
@@ -38,7 +38,7 @@ mod dump_mir;
38
38
mod error_reporting;
39
39
mod graphviz;
40
40
mod values;
41
- use self :: values:: { RegionValueElements , RegionValues } ;
41
+ crate use self :: values:: { RegionElement , RegionElementIndex , RegionValueElements , RegionValues } ;
42
42
43
43
use super :: ToRegionVid ;
44
44
@@ -61,13 +61,8 @@ pub struct RegionInferenceContext<'tcx> {
61
61
/// The outlives constraints computed by the type-check.
62
62
constraints : Rc < ConstraintSet > ,
63
63
64
- /// The constraint-set, but in graph form, making it easy to traverse
65
- /// the constraints adjacent to a particular region. Used to construct
66
- /// the SCC (see `constraint_sccs`) and for error reporting.
67
- constraint_graph : Rc < ConstraintGraph > ,
68
-
69
- /// The SCC computed from `constraints` and
70
- /// `constraint_graph`. Used to compute the values of each region.
64
+ /// The SCC computed from `constraints` and the constraint graph. Used to compute the values
65
+ /// of each region.
71
66
constraint_sccs : Rc < Sccs < RegionVid , ConstraintSccIndex > > ,
72
67
73
68
/// The final inferred values of the region variables; we compute
@@ -207,15 +202,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
207
202
pub ( crate ) fn new (
208
203
var_infos : VarInfos ,
209
204
universal_regions : UniversalRegions < ' tcx > ,
210
- mir : & Mir < ' tcx > ,
205
+ _mir : & Mir < ' tcx > ,
211
206
outlives_constraints : ConstraintSet ,
212
207
type_tests : Vec < TypeTest < ' tcx > > ,
208
+ liveness_constraints : RegionValues < RegionVid > ,
209
+ elements : & Rc < RegionValueElements > ,
213
210
) -> Self {
214
211
let universal_regions = Rc :: new ( universal_regions) ;
215
- let num_region_variables = var_infos. len ( ) ;
216
- let num_universal_regions = universal_regions. len ( ) ;
217
-
218
- let elements = & Rc :: new ( RegionValueElements :: new ( mir, num_universal_regions) ) ;
219
212
220
213
// Create a RegionDefinition for each inference variable.
221
214
let definitions: IndexVec < _ , _ > = var_infos
@@ -227,15 +220,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
227
220
let constraint_graph = Rc :: new ( constraints. graph ( definitions. len ( ) ) ) ;
228
221
let constraint_sccs = Rc :: new ( constraints. compute_sccs ( & constraint_graph) ) ;
229
222
230
- let scc_values = RegionValues :: new ( elements, constraint_sccs. num_sccs ( ) ) ;
223
+ let mut scc_values = RegionValues :: new ( elements) ;
224
+
225
+ for ( region, location_set) in liveness_constraints. iter_enumerated ( ) {
226
+ let scc = constraint_sccs. scc ( region) ;
227
+ scc_values. merge_into ( scc, location_set) ;
228
+ }
231
229
232
230
let mut result = Self {
233
231
definitions,
234
232
elements : elements. clone ( ) ,
235
- liveness_constraints : RegionValues :: new ( elements , num_region_variables ) ,
233
+ liveness_constraints,
236
234
constraints,
237
235
constraint_sccs,
238
- constraint_graph,
239
236
scc_values,
240
237
type_tests,
241
238
universal_regions,
@@ -304,6 +301,26 @@ impl<'tcx> RegionInferenceContext<'tcx> {
304
301
self . definitions . indices ( )
305
302
}
306
303
304
+ /// Iterates through each row and the accompanying bit set.
305
+ pub fn liveness_constraints < ' a > (
306
+ & ' a self
307
+ ) -> impl Iterator < Item = ( RegionVid , & ' a SparseBitSet < RegionElementIndex > ) > + ' a {
308
+ self . liveness_constraints . iter_enumerated ( )
309
+ }
310
+
311
+ /// Number of liveness constaints in region inference context.
312
+ pub fn number_of_liveness_constraints ( & self ) -> usize {
313
+ self . liveness_constraints . len ( )
314
+ }
315
+
316
+ /// Returns all the elements contained in a given region's value.
317
+ crate fn elements_contained_in < ' a > (
318
+ & ' a self ,
319
+ r : RegionVid ,
320
+ ) -> impl Iterator < Item = RegionElement > + ' a {
321
+ self . liveness_constraints . elements_contained_in ( r)
322
+ }
323
+
307
324
/// Given a universal region in scope on the MIR, returns the
308
325
/// corresponding index.
309
326
///
@@ -414,7 +431,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
414
431
constraints
415
432
} ) ;
416
433
417
- // To propagate constriants , we walk the DAG induced by the
434
+ // To propagate constraints , we walk the DAG induced by the
418
435
// SCC. For each SCC, we visit its successors and compute
419
436
// their values, then we union all those values to get our
420
437
// own.
0 commit comments