@@ -45,7 +45,9 @@ use self::free_regions::RegionRelations;
45
45
use self :: lexical_region_resolve:: LexicalRegionResolutions ;
46
46
use self :: outlives:: env:: OutlivesEnvironment ;
47
47
use self :: region_constraints:: { GenericKind , RegionConstraintData , VarInfos , VerifyBound } ;
48
- use self :: region_constraints:: { RegionConstraintCollector , RegionSnapshot } ;
48
+ use self :: region_constraints:: {
49
+ RegionConstraintCollector , RegionConstraintStorage , RegionSnapshot ,
50
+ } ;
49
51
use self :: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
50
52
51
53
pub mod at;
@@ -161,7 +163,7 @@ pub struct InferCtxtInner<'tcx> {
161
163
/// `resolve_regions_and_report_errors` is invoked, this gets set to `None`
162
164
/// -- further attempts to perform unification, etc., may fail if new
163
165
/// region constraints would've been added.
164
- region_constraints : Option < RegionConstraintCollector < ' tcx > > ,
166
+ region_constraints : Option < RegionConstraintStorage < ' tcx > > ,
165
167
166
168
/// A set of constraints that regionck must validate. Each
167
169
/// constraint has the form `T:'a`, meaning "some type `T` must
@@ -206,7 +208,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
206
208
const_unification_table : ut:: UnificationStorage :: new ( ) ,
207
209
int_unification_table : ut:: UnificationStorage :: new ( ) ,
208
210
float_unification_table : ut:: UnificationStorage :: new ( ) ,
209
- region_constraints : Some ( RegionConstraintCollector :: new ( ) ) ,
211
+ region_constraints : Some ( RegionConstraintStorage :: new ( ) ) ,
210
212
region_obligations : vec ! [ ] ,
211
213
}
212
214
}
@@ -243,8 +245,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
243
245
ut:: UnificationTable :: with_log ( & mut self . const_unification_table , & mut self . undo_log )
244
246
}
245
247
246
- pub fn unwrap_region_constraints ( & mut self ) -> & mut RegionConstraintCollector < ' tcx > {
247
- self . region_constraints . as_mut ( ) . expect ( "region constraints already solved" )
248
+ pub fn unwrap_region_constraints ( & mut self ) -> RegionConstraintCollector < ' tcx , ' _ > {
249
+ self . region_constraints
250
+ . as_mut ( )
251
+ . expect ( "region constraints already solved" )
252
+ . with_log ( & mut self . undo_log )
248
253
}
249
254
}
250
255
@@ -258,6 +263,14 @@ pub(crate) enum UndoLog<'tcx> {
258
263
ConstUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: ConstVid < ' tcx > > > ) ,
259
264
IntUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: IntVid > > ) ,
260
265
FloatUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: FloatVid > > ) ,
266
+ RegionConstraintCollector ( region_constraints:: UndoLog < ' tcx > ) ,
267
+ RegionUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: RegionVid > > ) ,
268
+ }
269
+
270
+ impl < ' tcx > From < region_constraints:: UndoLog < ' tcx > > for UndoLog < ' tcx > {
271
+ fn from ( l : region_constraints:: UndoLog < ' tcx > ) -> Self {
272
+ UndoLog :: RegionConstraintCollector ( l)
273
+ }
261
274
}
262
275
263
276
impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < type_variable:: TyVidEqKey < ' tcx > > > > for UndoLog < ' tcx > {
@@ -308,6 +321,12 @@ impl<'tcx> From<sv::UndoLog<ut::Delegate<ty::FloatVid>>> for UndoLog<'tcx> {
308
321
}
309
322
}
310
323
324
+ impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < ty:: RegionVid > > > for UndoLog < ' tcx > {
325
+ fn from ( l : sv:: UndoLog < ut:: Delegate < ty:: RegionVid > > ) -> Self {
326
+ Self :: RegionUnificationTable ( l)
327
+ }
328
+ }
329
+
311
330
pub ( crate ) type UnificationTable < ' a , ' tcx , T > =
312
331
ut:: UnificationTable < ut:: InPlace < T , & ' a mut ut:: UnificationStorage < T > , & ' a mut Logs < ' tcx > > > ;
313
332
@@ -316,6 +335,7 @@ struct RollbackView<'tcx, 'a> {
316
335
const_unification_table : & ' a mut ut:: UnificationStorage < ty:: ConstVid < ' tcx > > ,
317
336
int_unification_table : & ' a mut ut:: UnificationStorage < ty:: IntVid > ,
318
337
float_unification_table : & ' a mut ut:: UnificationStorage < ty:: FloatVid > ,
338
+ region_constraints : & ' a mut RegionConstraintStorage < ' tcx > ,
319
339
}
320
340
321
341
impl < ' tcx > Rollback < UndoLog < ' tcx > > for RollbackView < ' tcx , ' _ > {
@@ -325,6 +345,10 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> {
325
345
UndoLog :: ConstUnificationTable ( undo) => self . const_unification_table . reverse ( undo) ,
326
346
UndoLog :: IntUnificationTable ( undo) => self . int_unification_table . reverse ( undo) ,
327
347
UndoLog :: FloatUnificationTable ( undo) => self . float_unification_table . reverse ( undo) ,
348
+ UndoLog :: RegionConstraintCollector ( undo) => self . region_constraints . reverse ( undo) ,
349
+ UndoLog :: RegionUnificationTable ( undo) => {
350
+ self . region_constraints . unification_table . reverse ( undo)
351
+ }
328
352
}
329
353
}
330
354
}
@@ -408,6 +432,16 @@ impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
408
432
}
409
433
410
434
impl < ' tcx > Logs < ' tcx > {
435
+ pub ( crate ) fn region_constraints (
436
+ & self ,
437
+ after : usize ,
438
+ ) -> impl Iterator < Item = & ' _ region_constraints:: UndoLog < ' tcx > > + Clone {
439
+ self . logs [ after..] . iter ( ) . filter_map ( |log| match log {
440
+ UndoLog :: RegionConstraintCollector ( log) => Some ( log) ,
441
+ _ => None ,
442
+ } )
443
+ }
444
+
411
445
fn assert_open_snapshot ( & self , snapshot : & Snapshot < ' tcx > ) {
412
446
// Failures here may indicate a failure to follow a stack discipline.
413
447
assert ! ( self . logs. len( ) >= snapshot. undo_len) ;
@@ -1004,7 +1038,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1004
1038
const_snapshot : _,
1005
1039
int_snapshot : _,
1006
1040
float_snapshot : _,
1007
- region_constraints_snapshot,
1041
+ region_constraints_snapshot : _ ,
1008
1042
region_obligations_snapshot,
1009
1043
universe,
1010
1044
was_in_snapshot,
@@ -1023,6 +1057,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1023
1057
const_unification_table,
1024
1058
int_unification_table,
1025
1059
float_unification_table,
1060
+ region_constraints,
1026
1061
..
1027
1062
} = inner;
1028
1063
inner. undo_log . rollback_to (
@@ -1031,11 +1066,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1031
1066
const_unification_table,
1032
1067
int_unification_table,
1033
1068
float_unification_table,
1069
+ region_constraints : region_constraints. as_mut ( ) . unwrap ( ) ,
1034
1070
} ,
1035
1071
undo_snapshot,
1036
1072
) ;
1037
1073
inner. projection_cache . rollback_to ( projection_cache_snapshot) ;
1038
- inner. unwrap_region_constraints ( ) . rollback_to ( region_constraints_snapshot) ;
1039
1074
inner. region_obligations . truncate ( region_obligations_snapshot) ;
1040
1075
}
1041
1076
@@ -1048,7 +1083,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1048
1083
const_snapshot : _,
1049
1084
int_snapshot : _,
1050
1085
float_snapshot : _,
1051
- region_constraints_snapshot,
1086
+ region_constraints_snapshot : _ ,
1052
1087
region_obligations_snapshot : _,
1053
1088
universe : _,
1054
1089
was_in_snapshot,
@@ -1062,7 +1097,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1062
1097
let mut inner = self . inner . borrow_mut ( ) ;
1063
1098
inner. undo_log . commit ( undo_snapshot) ;
1064
1099
inner. projection_cache . commit ( projection_cache_snapshot) ;
1065
- inner. unwrap_region_constraints ( ) . commit ( region_constraints_snapshot) ;
1066
1100
}
1067
1101
1068
1102
/// Executes `f` and commit the bindings.
@@ -1135,7 +1169,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1135
1169
self . inner
1136
1170
. borrow_mut ( )
1137
1171
. unwrap_region_constraints ( )
1138
- . region_constraints_added_in_snapshot ( & snapshot. region_constraints_snapshot )
1172
+ . region_constraints_added_in_snapshot ( & snapshot. undo_snapshot )
1139
1173
}
1140
1174
1141
1175
pub fn add_given ( & self , sub : ty:: Region < ' tcx > , sup : ty:: RegionVid ) {
@@ -1466,6 +1500,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1466
1500
. region_constraints
1467
1501
. take ( )
1468
1502
. expect ( "regions already resolved" )
1503
+ . with_log ( & mut inner. undo_log )
1469
1504
. into_infos_and_data ( ) ;
1470
1505
1471
1506
let region_rels = & RegionRelations :: new (
@@ -1527,12 +1562,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1527
1562
/// called. This is used only during NLL processing to "hand off" ownership
1528
1563
/// of the set of region variables into the NLL region context.
1529
1564
pub fn take_region_var_origins ( & self ) -> VarInfos {
1530
- let ( var_infos, data) = self
1531
- . inner
1532
- . borrow_mut ( )
1565
+ let mut inner = self . inner . borrow_mut ( ) ;
1566
+ let ( var_infos, data) = inner
1533
1567
. region_constraints
1534
1568
. take ( )
1535
1569
. expect ( "regions already resolved" )
1570
+ . with_log ( & mut inner. undo_log )
1536
1571
. into_infos_and_data ( ) ;
1537
1572
assert ! ( data. is_empty( ) ) ;
1538
1573
var_infos
0 commit comments