1010
1111use super :: universal_regions:: UniversalRegions ;
1212use borrow_check:: nll:: region_infer:: values:: ToElementIndex ;
13+ use borrow_check:: nll:: constraint_set:: { ConstraintIndex , ConstraintSet , OutlivesConstraint } ;
1314use rustc:: hir:: def_id:: DefId ;
1415use rustc:: infer:: canonical:: QueryRegionConstraint ;
1516use rustc:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
@@ -25,7 +26,6 @@ use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
2526use rustc:: util:: common:: { self , ErrorReported } ;
2627use rustc_data_structures:: bitvec:: BitVector ;
2728use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
28- use std:: fmt;
2929use std:: rc:: Rc ;
3030use syntax_pos:: Span ;
3131
@@ -65,7 +65,7 @@ pub struct RegionInferenceContext<'tcx> {
6565 dependency_map : Option < IndexVec < RegionVid , Option < ConstraintIndex > > > ,
6666
6767 /// The constraints we have accumulated and used during solving.
68- constraints : IndexVec < ConstraintIndex , OutlivesConstraint > ,
68+ constraints : ConstraintSet ,
6969
7070 /// Type constraints that we check after solving.
7171 type_tests : Vec < TypeTest < ' tcx > > ,
@@ -114,37 +114,6 @@ pub(crate) enum Cause {
114114 UniversalRegion ( RegionVid ) ,
115115}
116116
117- #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
118- pub struct OutlivesConstraint {
119- // NB. The ordering here is not significant for correctness, but
120- // it is for convenience. Before we dump the constraints in the
121- // debugging logs, we sort them, and we'd like the "super region"
122- // to be first, etc. (In particular, span should remain last.)
123- /// The region SUP must outlive SUB...
124- pub sup : RegionVid ,
125-
126- /// Region that must be outlived.
127- pub sub : RegionVid ,
128-
129- /// At this location.
130- pub point : Location ,
131-
132- /// Later on, we thread the constraints onto a linked list
133- /// grouped by their `sub` field. So if you had:
134- ///
135- /// Index | Constraint | Next Field
136- /// ----- | ---------- | ----------
137- /// 0 | `'a: 'b` | Some(2)
138- /// 1 | `'b: 'c` | None
139- /// 2 | `'c: 'b` | None
140- pub next : Option < ConstraintIndex > ,
141-
142- /// Where did this constraint arise?
143- pub span : Span ,
144- }
145-
146- newtype_index ! ( ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" } ) ;
147-
148117/// A "type test" corresponds to an outlives constraint between a type
149118/// and a lifetime, like `T: 'x` or `<T as Foo>::Bar: 'x`. They are
150119/// translated from the `Verify` region constraints in the ordinary
@@ -243,7 +212,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
243212 var_infos : VarInfos ,
244213 universal_regions : UniversalRegions < ' tcx > ,
245214 mir : & Mir < ' tcx > ,
246- outlives_constraints : Vec < OutlivesConstraint > ,
215+ outlives_constraints : ConstraintSet ,
247216 type_tests : Vec < TypeTest < ' tcx > > ,
248217 ) -> Self {
249218 // The `next` field should not yet have been initialized:
@@ -266,7 +235,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
266235 liveness_constraints : RegionValues :: new ( elements, num_region_variables) ,
267236 inferred_values : None ,
268237 dependency_map : None ,
269- constraints : IndexVec :: from_raw ( outlives_constraints) ,
238+ constraints : outlives_constraints,
270239 type_tests,
271240 universal_regions,
272241 } ;
@@ -392,15 +361,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
392361 sub : RegionVid ,
393362 point : Location ,
394363 ) {
395- debug ! ( "add_outlives({:?}: {:?} @ {:?}" , sup, sub, point) ;
396364 assert ! ( self . inferred_values. is_none( ) , "values already inferred" ) ;
397365 self . constraints . push ( OutlivesConstraint {
398366 span,
399367 sup,
400368 sub,
401369 point,
402370 next : None ,
403- } ) ;
371+ } )
404372 }
405373
406374 /// Perform region inference and report errors if we see any
@@ -498,13 +466,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
498466 debug ! ( "propagate_constraints: sub={:?}" , constraint. sub) ;
499467 debug ! ( "propagate_constraints: sup={:?}" , constraint. sup) ;
500468
501- let mut opt_dep_idx = dependency_map[ constraint. sup ] ;
502- while let Some ( dep_idx) = opt_dep_idx {
469+ self . constraints . each_affected_by_dirty ( dependency_map[ constraint. sup ] , |dep_idx| {
503470 if clean_bit_vec. remove ( dep_idx. index ( ) ) {
504471 dirty_list. push ( dep_idx) ;
505472 }
506- opt_dep_idx = self . constraints [ dep_idx] . next ;
507- }
473+ } ) ;
508474 }
509475
510476 debug ! ( "\n " ) ;
@@ -518,16 +484,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
518484 /// These are constraints like Y: X @ P -- so if X changed, we may
519485 /// need to grow Y.
520486 fn build_dependency_map ( & mut self ) -> IndexVec < RegionVid , Option < ConstraintIndex > > {
521- let mut map = IndexVec :: from_elem ( None , & self . definitions ) ;
522-
523- for ( idx, constraint) in self . constraints . iter_enumerated_mut ( ) . rev ( ) {
524- let mut head = & mut map[ constraint. sub ] ;
525- debug_assert ! ( constraint. next. is_none( ) ) ;
526- constraint. next = * head;
527- * head = Some ( idx) ;
528- }
529-
530- map
487+ self . constraints . link ( self . definitions . len ( ) )
531488 }
532489
533490 /// Once regions have been propagated, this method is used to see
@@ -1115,7 +1072,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11151072
11161073 while changed {
11171074 changed = false ;
1118- for constraint in & self . constraints {
1075+ for constraint in self . constraints . iter ( ) {
11191076 if let Some ( n) = result_set[ constraint. sup ] {
11201077 let m = n + 1 ;
11211078 if result_set[ constraint. sub ]
@@ -1146,16 +1103,6 @@ impl<'tcx> RegionDefinition<'tcx> {
11461103 }
11471104}
11481105
1149- impl fmt:: Debug for OutlivesConstraint {
1150- fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
1151- write ! (
1152- formatter,
1153- "({:?}: {:?} @ {:?}) due to {:?}" ,
1154- self . sup, self . sub, self . point, self . span
1155- )
1156- }
1157- }
1158-
11591106pub trait ClosureRegionRequirementsExt < ' gcx , ' tcx > {
11601107 fn apply_requirements (
11611108 & self ,
0 commit comments