@@ -69,6 +69,10 @@ pub struct RegionConstraintCollector<'tcx> {
6969 /// would wind up with a fresh stream of region variables that
7070 /// have been equated but appear distinct.
7171 unification_table : ut:: UnificationTable < ut:: InPlace < ty:: RegionVid > > ,
72+
73+ /// a flag set to true when we perform any unifications; this is used
74+ /// to micro-optimize `take_and_reset_data`
75+ any_unifications : bool ,
7276}
7377
7478pub type VarInfos = IndexVec < RegionVid , RegionVariableInfo > ;
@@ -234,6 +238,7 @@ pub struct RegionVariableInfo {
234238pub struct RegionSnapshot {
235239 length : usize ,
236240 region_snapshot : ut:: Snapshot < ut:: InPlace < ty:: RegionVid > > ,
241+ any_unifications : bool ,
237242}
238243
239244/// When working with skolemized regions, we often wish to find all of
@@ -280,6 +285,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
280285 bound_count : 0 ,
281286 undo_log : Vec :: new ( ) ,
282287 unification_table : ut:: UnificationTable :: new ( ) ,
288+ any_unifications : false ,
283289 }
284290 }
285291
@@ -325,6 +331,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
325331 bound_count : _,
326332 undo_log : _,
327333 unification_table,
334+ any_unifications,
328335 } = self ;
329336
330337 // Clear the tables of (lubs, glbs), so that we will create
@@ -338,7 +345,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
338345 // un-unified" state. Note that when we unify `a` and `b`, we
339346 // also insert `a <= b` and a `b <= a` edges, so the
340347 // `RegionConstraintData` contains the relationship here.
341- unification_table. reset_unifications ( |vid| unify_key:: RegionVidKey { min_vid : vid } ) ;
348+ if * any_unifications {
349+ unification_table. reset_unifications ( |vid| unify_key:: RegionVidKey { min_vid : vid } ) ;
350+ * any_unifications = false ;
351+ }
342352
343353 mem:: replace ( data, RegionConstraintData :: default ( ) )
344354 }
@@ -358,6 +368,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
358368 RegionSnapshot {
359369 length,
360370 region_snapshot : self . unification_table . snapshot ( ) ,
371+ any_unifications : self . any_unifications ,
361372 }
362373 }
363374
@@ -385,6 +396,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
385396 let c = self . undo_log . pop ( ) . unwrap ( ) ;
386397 assert ! ( c == OpenSnapshot ) ;
387398 self . unification_table . rollback_to ( snapshot. region_snapshot ) ;
399+ self . any_unifications = snapshot. any_unifications ;
388400 }
389401
390402 fn rollback_undo_entry ( & mut self , undo_entry : UndoLogEntry < ' tcx > ) {
@@ -623,6 +635,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
623635
624636 if let ( ty:: ReVar ( sub) , ty:: ReVar ( sup) ) = ( * sub, * sup) {
625637 self . unification_table . union ( sub, sup) ;
638+ self . any_unifications = true ;
626639 }
627640 }
628641 }
0 commit comments