@@ -45,7 +45,9 @@ use self::free_regions::RegionRelations;
4545use self :: lexical_region_resolve:: LexicalRegionResolutions ;
4646use self :: outlives:: env:: OutlivesEnvironment ;
4747use self :: region_constraints:: { GenericKind , RegionConstraintData , VarInfos , VerifyBound } ;
48- use self :: region_constraints:: { RegionConstraintCollector , RegionSnapshot } ;
48+ use self :: region_constraints:: {
49+ RegionConstraintCollector , RegionConstraintStorage , RegionSnapshot ,
50+ } ;
4951use self :: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
5052
5153pub mod at;
@@ -161,7 +163,7 @@ pub struct InferCtxtInner<'tcx> {
161163 /// `resolve_regions_and_report_errors` is invoked, this gets set to `None`
162164 /// -- further attempts to perform unification, etc., may fail if new
163165 /// region constraints would've been added.
164- region_constraints : Option < RegionConstraintCollector < ' tcx > > ,
166+ region_constraints : Option < RegionConstraintStorage < ' tcx > > ,
165167
166168 /// A set of constraints that regionck must validate. Each
167169 /// constraint has the form `T:'a`, meaning "some type `T` must
@@ -206,7 +208,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
206208 const_unification_table : ut:: UnificationStorage :: new ( ) ,
207209 int_unification_table : ut:: UnificationStorage :: new ( ) ,
208210 float_unification_table : ut:: UnificationStorage :: new ( ) ,
209- region_constraints : Some ( RegionConstraintCollector :: new ( ) ) ,
211+ region_constraints : Some ( RegionConstraintStorage :: new ( ) ) ,
210212 region_obligations : vec ! [ ] ,
211213 }
212214 }
@@ -243,8 +245,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
243245 ut:: UnificationTable :: with_log ( & mut self . const_unification_table , & mut self . undo_log )
244246 }
245247
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 )
248253 }
249254}
250255
@@ -258,6 +263,14 @@ pub(crate) enum UndoLog<'tcx> {
258263 ConstUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: ConstVid < ' tcx > > > ) ,
259264 IntUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: IntVid > > ) ,
260265 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+ }
261274}
262275
263276impl < ' 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> {
308321 }
309322}
310323
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+
311330pub ( crate ) type UnificationTable < ' a , ' tcx , T > =
312331 ut:: UnificationTable < ut:: InPlace < T , & ' a mut ut:: UnificationStorage < T > , & ' a mut Logs < ' tcx > > > ;
313332
@@ -316,6 +335,7 @@ struct RollbackView<'tcx, 'a> {
316335 const_unification_table : & ' a mut ut:: UnificationStorage < ty:: ConstVid < ' tcx > > ,
317336 int_unification_table : & ' a mut ut:: UnificationStorage < ty:: IntVid > ,
318337 float_unification_table : & ' a mut ut:: UnificationStorage < ty:: FloatVid > ,
338+ region_constraints : & ' a mut RegionConstraintStorage < ' tcx > ,
319339}
320340
321341impl < ' tcx > Rollback < UndoLog < ' tcx > > for RollbackView < ' tcx , ' _ > {
@@ -325,6 +345,10 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> {
325345 UndoLog :: ConstUnificationTable ( undo) => self . const_unification_table . reverse ( undo) ,
326346 UndoLog :: IntUnificationTable ( undo) => self . int_unification_table . reverse ( undo) ,
327347 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+ }
328352 }
329353 }
330354}
@@ -408,6 +432,16 @@ impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
408432}
409433
410434impl < ' 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+
411445 fn assert_open_snapshot ( & self , snapshot : & Snapshot < ' tcx > ) {
412446 // Failures here may indicate a failure to follow a stack discipline.
413447 assert ! ( self . logs. len( ) >= snapshot. undo_len) ;
@@ -1004,7 +1038,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10041038 const_snapshot : _,
10051039 int_snapshot : _,
10061040 float_snapshot : _,
1007- region_constraints_snapshot,
1041+ region_constraints_snapshot : _ ,
10081042 region_obligations_snapshot,
10091043 universe,
10101044 was_in_snapshot,
@@ -1023,6 +1057,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10231057 const_unification_table,
10241058 int_unification_table,
10251059 float_unification_table,
1060+ region_constraints,
10261061 ..
10271062 } = inner;
10281063 inner. undo_log . rollback_to (
@@ -1031,11 +1066,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10311066 const_unification_table,
10321067 int_unification_table,
10331068 float_unification_table,
1069+ region_constraints : region_constraints. as_mut ( ) . unwrap ( ) ,
10341070 } ,
10351071 undo_snapshot,
10361072 ) ;
10371073 inner. projection_cache . rollback_to ( projection_cache_snapshot) ;
1038- inner. unwrap_region_constraints ( ) . rollback_to ( region_constraints_snapshot) ;
10391074 inner. region_obligations . truncate ( region_obligations_snapshot) ;
10401075 }
10411076
@@ -1048,7 +1083,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10481083 const_snapshot : _,
10491084 int_snapshot : _,
10501085 float_snapshot : _,
1051- region_constraints_snapshot,
1086+ region_constraints_snapshot : _ ,
10521087 region_obligations_snapshot : _,
10531088 universe : _,
10541089 was_in_snapshot,
@@ -1062,7 +1097,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10621097 let mut inner = self . inner . borrow_mut ( ) ;
10631098 inner. undo_log . commit ( undo_snapshot) ;
10641099 inner. projection_cache . commit ( projection_cache_snapshot) ;
1065- inner. unwrap_region_constraints ( ) . commit ( region_constraints_snapshot) ;
10661100 }
10671101
10681102 /// Executes `f` and commit the bindings.
@@ -1135,7 +1169,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11351169 self . inner
11361170 . borrow_mut ( )
11371171 . unwrap_region_constraints ( )
1138- . region_constraints_added_in_snapshot ( & snapshot. region_constraints_snapshot )
1172+ . region_constraints_added_in_snapshot ( & snapshot. undo_snapshot )
11391173 }
11401174
11411175 pub fn add_given ( & self , sub : ty:: Region < ' tcx > , sup : ty:: RegionVid ) {
@@ -1466,6 +1500,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14661500 . region_constraints
14671501 . take ( )
14681502 . expect ( "regions already resolved" )
1503+ . with_log ( & mut inner. undo_log )
14691504 . into_infos_and_data ( ) ;
14701505
14711506 let region_rels = & RegionRelations :: new (
@@ -1527,12 +1562,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15271562 /// called. This is used only during NLL processing to "hand off" ownership
15281563 /// of the set of region variables into the NLL region context.
15291564 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
15331567 . region_constraints
15341568 . take ( )
15351569 . expect ( "regions already resolved" )
1570+ . with_log ( & mut inner. undo_log )
15361571 . into_infos_and_data ( ) ;
15371572 assert ! ( data. is_empty( ) ) ;
15381573 var_infos
0 commit comments