@@ -69,6 +69,10 @@ pub struct RegionConstraintCollector<'tcx> {
69
69
/// would wind up with a fresh stream of region variables that
70
70
/// have been equated but appear distinct.
71
71
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 ,
72
76
}
73
77
74
78
pub type VarInfos = IndexVec < RegionVid , RegionVariableInfo > ;
@@ -234,6 +238,7 @@ pub struct RegionVariableInfo {
234
238
pub struct RegionSnapshot {
235
239
length : usize ,
236
240
region_snapshot : ut:: Snapshot < ut:: InPlace < ty:: RegionVid > > ,
241
+ any_unifications : bool ,
237
242
}
238
243
239
244
/// When working with skolemized regions, we often wish to find all of
@@ -280,6 +285,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
280
285
bound_count : 0 ,
281
286
undo_log : Vec :: new ( ) ,
282
287
unification_table : ut:: UnificationTable :: new ( ) ,
288
+ any_unifications : false ,
283
289
}
284
290
}
285
291
@@ -325,6 +331,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
325
331
bound_count : _,
326
332
undo_log : _,
327
333
unification_table,
334
+ any_unifications,
328
335
} = self ;
329
336
330
337
// Clear the tables of (lubs, glbs), so that we will create
@@ -338,7 +345,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
338
345
// un-unified" state. Note that when we unify `a` and `b`, we
339
346
// also insert `a <= b` and a `b <= a` edges, so the
340
347
// `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
+ }
342
352
343
353
mem:: replace ( data, RegionConstraintData :: default ( ) )
344
354
}
@@ -358,6 +368,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
358
368
RegionSnapshot {
359
369
length,
360
370
region_snapshot : self . unification_table . snapshot ( ) ,
371
+ any_unifications : self . any_unifications ,
361
372
}
362
373
}
363
374
@@ -385,6 +396,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
385
396
let c = self . undo_log . pop ( ) . unwrap ( ) ;
386
397
assert ! ( c == OpenSnapshot ) ;
387
398
self . unification_table . rollback_to ( snapshot. region_snapshot ) ;
399
+ self . any_unifications = snapshot. any_unifications ;
388
400
}
389
401
390
402
fn rollback_undo_entry ( & mut self , undo_entry : UndoLogEntry < ' tcx > ) {
@@ -623,6 +635,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
623
635
624
636
if let ( ty:: ReVar ( sub) , ty:: ReVar ( sup) ) = ( * sub, * sup) {
625
637
self . unification_table . union ( sub, sup) ;
638
+ self . any_unifications = true ;
626
639
}
627
640
}
628
641
}
0 commit comments