10
10
11
11
use super :: universal_regions:: UniversalRegions ;
12
12
use borrow_check:: nll:: region_infer:: values:: ToElementIndex ;
13
+ use borrow_check:: nll:: constraint_set:: { ConstraintIndex , ConstraintSet , OutlivesConstraint } ;
13
14
use rustc:: hir:: def_id:: DefId ;
14
15
use rustc:: infer:: canonical:: QueryRegionConstraint ;
15
16
use rustc:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
@@ -25,7 +26,6 @@ use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
25
26
use rustc:: util:: common:: { self , ErrorReported } ;
26
27
use rustc_data_structures:: bitvec:: BitVector ;
27
28
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
28
- use std:: fmt;
29
29
use std:: rc:: Rc ;
30
30
use syntax_pos:: Span ;
31
31
@@ -65,7 +65,7 @@ pub struct RegionInferenceContext<'tcx> {
65
65
dependency_map : Option < IndexVec < RegionVid , Option < ConstraintIndex > > > ,
66
66
67
67
/// The constraints we have accumulated and used during solving.
68
- constraints : IndexVec < ConstraintIndex , OutlivesConstraint > ,
68
+ constraints : ConstraintSet ,
69
69
70
70
/// Type constraints that we check after solving.
71
71
type_tests : Vec < TypeTest < ' tcx > > ,
@@ -114,37 +114,6 @@ pub(crate) enum Cause {
114
114
UniversalRegion ( RegionVid ) ,
115
115
}
116
116
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
-
148
117
/// A "type test" corresponds to an outlives constraint between a type
149
118
/// and a lifetime, like `T: 'x` or `<T as Foo>::Bar: 'x`. They are
150
119
/// translated from the `Verify` region constraints in the ordinary
@@ -243,7 +212,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
243
212
var_infos : VarInfos ,
244
213
universal_regions : UniversalRegions < ' tcx > ,
245
214
mir : & Mir < ' tcx > ,
246
- outlives_constraints : Vec < OutlivesConstraint > ,
215
+ outlives_constraints : ConstraintSet ,
247
216
type_tests : Vec < TypeTest < ' tcx > > ,
248
217
) -> Self {
249
218
// The `next` field should not yet have been initialized:
@@ -266,7 +235,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
266
235
liveness_constraints : RegionValues :: new ( elements, num_region_variables) ,
267
236
inferred_values : None ,
268
237
dependency_map : None ,
269
- constraints : IndexVec :: from_raw ( outlives_constraints) ,
238
+ constraints : outlives_constraints,
270
239
type_tests,
271
240
universal_regions,
272
241
} ;
@@ -392,15 +361,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
392
361
sub : RegionVid ,
393
362
point : Location ,
394
363
) {
395
- debug ! ( "add_outlives({:?}: {:?} @ {:?}" , sup, sub, point) ;
396
364
assert ! ( self . inferred_values. is_none( ) , "values already inferred" ) ;
397
365
self . constraints . push ( OutlivesConstraint {
398
366
span,
399
367
sup,
400
368
sub,
401
369
point,
402
370
next : None ,
403
- } ) ;
371
+ } )
404
372
}
405
373
406
374
/// Perform region inference and report errors if we see any
@@ -498,13 +466,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
498
466
debug ! ( "propagate_constraints: sub={:?}" , constraint. sub) ;
499
467
debug ! ( "propagate_constraints: sup={:?}" , constraint. sup) ;
500
468
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| {
503
470
if clean_bit_vec. remove ( dep_idx. index ( ) ) {
504
471
dirty_list. push ( dep_idx) ;
505
472
}
506
- opt_dep_idx = self . constraints [ dep_idx] . next ;
507
- }
473
+ } ) ;
508
474
}
509
475
510
476
debug ! ( "\n " ) ;
@@ -518,16 +484,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
518
484
/// These are constraints like Y: X @ P -- so if X changed, we may
519
485
/// need to grow Y.
520
486
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 ( ) )
531
488
}
532
489
533
490
/// Once regions have been propagated, this method is used to see
@@ -1115,7 +1072,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1115
1072
1116
1073
while changed {
1117
1074
changed = false ;
1118
- for constraint in & self . constraints {
1075
+ for constraint in self . constraints . iter ( ) {
1119
1076
if let Some ( n) = result_set[ constraint. sup ] {
1120
1077
let m = n + 1 ;
1121
1078
if result_set[ constraint. sub ]
@@ -1146,16 +1103,6 @@ impl<'tcx> RegionDefinition<'tcx> {
1146
1103
}
1147
1104
}
1148
1105
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
-
1159
1106
pub trait ClosureRegionRequirementsExt < ' gcx , ' tcx > {
1160
1107
fn apply_requirements (
1161
1108
& self ,
0 commit comments