@@ -20,6 +20,7 @@ pub use self::VarValue::*;
20
20
use super :: { RegionVariableOrigin , SubregionOrigin , TypeTrace , MiscVariable } ;
21
21
22
22
use rustc_data_structures:: graph:: { self , Direction , NodeIndex } ;
23
+ use rustc_data_structures:: unify:: { self , UnificationTable } ;
23
24
use middle:: free_region:: FreeRegionMap ;
24
25
use middle:: ty:: { self , Ty } ;
25
26
use middle:: ty:: { BoundRegion , FreeRegion , Region , RegionVid } ;
@@ -234,15 +235,16 @@ pub struct RegionVarBindings<'a, 'tcx: 'a> {
234
235
// bound on a variable and so forth, which can never be rolled
235
236
// back.
236
237
undo_log : RefCell < Vec < UndoLogEntry > > ,
238
+ unification_table : RefCell < UnificationTable < ty:: RegionVid > > ,
237
239
238
240
// This contains the results of inference. It begins as an empty
239
241
// option and only acquires a value after inference is complete.
240
242
values : RefCell < Option < Vec < VarValue > > > ,
241
243
}
242
244
243
- #[ derive( Debug ) ]
244
245
pub struct RegionSnapshot {
245
246
length : usize ,
247
+ region_snapshot : unify:: Snapshot < ty:: RegionVid > ,
246
248
skolemization_count : u32 ,
247
249
}
248
250
@@ -260,6 +262,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
260
262
skolemization_count : Cell :: new ( 0 ) ,
261
263
bound_count : Cell :: new ( 0 ) ,
262
264
undo_log : RefCell :: new ( Vec :: new ( ) ) ,
265
+ unification_table : RefCell :: new ( UnificationTable :: new ( ) ) ,
263
266
}
264
267
}
265
268
@@ -273,6 +276,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
273
276
self . undo_log . borrow_mut ( ) . push ( OpenSnapshot ) ;
274
277
RegionSnapshot {
275
278
length : length,
279
+ region_snapshot : self . unification_table . borrow_mut ( ) . snapshot ( ) ,
276
280
skolemization_count : self . skolemization_count . get ( ) ,
277
281
}
278
282
}
@@ -289,6 +293,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
289
293
( * undo_log) [ snapshot. length ] = CommitedSnapshot ;
290
294
}
291
295
self . skolemization_count . set ( snapshot. skolemization_count ) ;
296
+ self . unification_table . borrow_mut ( ) . commit ( snapshot. region_snapshot ) ;
292
297
}
293
298
294
299
pub fn rollback_to ( & self , snapshot : RegionSnapshot ) {
@@ -328,6 +333,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
328
333
let c = undo_log. pop ( ) . unwrap ( ) ;
329
334
assert ! ( c == OpenSnapshot ) ;
330
335
self . skolemization_count . set ( snapshot. skolemization_count ) ;
336
+ self . unification_table . borrow_mut ( )
337
+ . rollback_to ( snapshot. region_snapshot ) ;
331
338
}
332
339
333
340
pub fn num_vars ( & self ) -> u32 {
@@ -340,7 +347,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
340
347
pub fn new_region_var ( & self , origin : RegionVariableOrigin ) -> RegionVid {
341
348
let id = self . num_vars ( ) ;
342
349
self . var_origins . borrow_mut ( ) . push ( origin. clone ( ) ) ;
343
- let vid = RegionVid { index : id } ;
350
+ let vid = self . unification_table . borrow_mut ( ) . new_key ( ( ) ) ;
351
+ assert_eq ! ( vid. index, id) ;
344
352
if self . in_snapshot ( ) {
345
353
self . undo_log . borrow_mut ( ) . push ( AddVar ( vid) ) ;
346
354
}
@@ -460,6 +468,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
460
468
// equating regions.
461
469
self . make_subregion ( origin. clone ( ) , sub, sup) ;
462
470
self . make_subregion ( origin, sup, sub) ;
471
+
472
+ if let ( ty:: ReVar ( sub) , ty:: ReVar ( sup) ) = ( sub, sup) {
473
+ self . unification_table . borrow_mut ( ) . union ( sub, sup) ;
474
+ }
463
475
}
464
476
}
465
477
@@ -568,6 +580,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
568
580
}
569
581
}
570
582
583
+ pub fn opportunistic_resolve_var ( & self , rid : RegionVid ) -> ty:: Region {
584
+ ty:: ReVar ( self . unification_table . borrow_mut ( ) . find ( rid) )
585
+ }
586
+
571
587
fn combine_map ( & self , t : CombineMapType ) -> & RefCell < CombineMap > {
572
588
match t {
573
589
Glb => & self . glbs ,
@@ -1312,6 +1328,13 @@ impl<'tcx> fmt::Debug for RegionAndOrigin<'tcx> {
1312
1328
}
1313
1329
}
1314
1330
1331
+ impl fmt:: Debug for RegionSnapshot {
1332
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1333
+ write ! ( f, "RegionSnapshot(length={},skolemization={})" ,
1334
+ self . length, self . skolemization_count)
1335
+ }
1336
+ }
1337
+
1315
1338
impl < ' tcx > fmt:: Debug for GenericKind < ' tcx > {
1316
1339
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1317
1340
match * self {
0 commit comments