@@ -13,7 +13,7 @@ use rustc_data_structures::sync::Lrc;
13
13
use rustc_data_structures:: undo_log:: UndoLogs ;
14
14
use rustc_data_structures:: unify as ut;
15
15
use rustc_index:: vec:: IndexVec ;
16
- use rustc_middle:: infer:: unify_key:: { RegionVidKey , UnifiedRegion } ;
16
+ use rustc_middle:: infer:: unify_key:: { RegionVidKey , UnifiedRegion , UniverseError } ;
17
17
use rustc_middle:: ty:: ReStatic ;
18
18
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
19
19
use rustc_middle:: ty:: { ReLateBound , ReVar } ;
@@ -375,6 +375,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
375
375
/// Not legal during a snapshot.
376
376
pub fn into_infos_and_data ( self ) -> ( VarInfos , RegionConstraintData < ' tcx > ) {
377
377
assert ! ( !UndoLogs :: <super :: UndoLog <' _>>:: in_snapshot( & self . undo_log) ) ;
378
+ // TODO update universes of var_infos
378
379
( mem:: take ( & mut self . storage . var_infos ) , mem:: take ( & mut self . storage . data ) )
379
380
}
380
381
@@ -397,11 +398,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
397
398
// should think carefully about whether it needs to be cleared
398
399
// or updated in some way.
399
400
let RegionConstraintStorage {
400
- var_infos : _ ,
401
+ var_infos,
401
402
data,
402
403
lubs,
403
404
glbs,
404
- unification_table : _ ,
405
+ unification_table,
405
406
any_unifications,
406
407
} = self . storage ;
407
408
@@ -420,7 +421,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
420
421
// `RegionConstraintData` contains the relationship here.
421
422
if * any_unifications {
422
423
* any_unifications = false ;
423
- self . unification_table_mut ( ) . reset_unifications ( |_| UnifiedRegion ( None ) ) ;
424
+ let mut ut = ut:: UnificationTable :: with_log ( unification_table, & mut self . undo_log ) ;
425
+ ut. reset_unifications ( |key| UnifiedRegion {
426
+ universe : var_infos[ key. vid ] . universe ,
427
+ value : None ,
428
+ } ) ;
424
429
}
425
430
426
431
data
@@ -447,7 +452,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
447
452
) -> RegionVid {
448
453
let vid = self . var_infos . push ( RegionVariableInfo { origin, universe } ) ;
449
454
450
- let u_vid = self . unification_table_mut ( ) . new_key ( UnifiedRegion ( None ) ) ;
455
+ let u_vid = self . unification_table_mut ( ) . new_key ( UnifiedRegion { universe , value : None } ) ;
451
456
assert_eq ! ( vid, u_vid. vid) ;
452
457
self . undo_log . push ( AddVar ( vid) ) ;
453
458
debug ! ( "created new region variable {:?} in {:?} with origin {:?}" , vid, universe, origin) ;
@@ -456,7 +461,13 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
456
461
457
462
/// Returns the universe for the given variable.
458
463
pub ( super ) fn var_universe ( & self , vid : RegionVid ) -> ty:: UniverseIndex {
459
- self . var_infos [ vid] . universe
464
+ // WARN UB ahead!
465
+ unsafe {
466
+ ( & mut * ( self as * const Self as * mut Self ) )
467
+ . unification_table_mut ( )
468
+ . probe_value ( vid)
469
+ . universe
470
+ }
460
471
}
461
472
462
473
/// Returns the origin for the given variable.
@@ -516,13 +527,20 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
516
527
match ( sub, sup) {
517
528
( Region ( Interned ( ReVar ( sub) , _) ) , Region ( Interned ( ReVar ( sup) , _) ) ) => {
518
529
debug ! ( "make_eqregion: unifying {:?} with {:?}" , sub, sup) ;
519
- self . unification_table_mut ( ) . union ( * sub, * sup) ;
530
+ self . unification_table_mut ( )
531
+ . unify_var_var ( * sub, * sup)
532
+ . unwrap_or_else ( |UniverseError | { } ) ;
520
533
self . any_unifications = true ;
521
534
}
522
535
( Region ( Interned ( ReVar ( vid) , _) ) , value)
523
536
| ( value, Region ( Interned ( ReVar ( vid) , _) ) ) => {
524
537
debug ! ( "make_eqregion: unifying {:?} with {:?}" , vid, value) ;
525
- self . unification_table_mut ( ) . union_value ( * vid, UnifiedRegion ( Some ( value) ) ) ;
538
+ self . unification_table_mut ( )
539
+ . unify_var_value (
540
+ * vid,
541
+ UnifiedRegion { universe : ty:: UniverseIndex :: MAX , value : Some ( value) } ,
542
+ )
543
+ . unwrap_or_else ( |UniverseError | { } ) ;
526
544
self . any_unifications = true ;
527
545
}
528
546
( _, _) => { }
@@ -642,7 +660,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
642
660
) -> ty:: Region < ' tcx > {
643
661
let mut ut = self . unification_table_mut ( ) ; // FIXME(rust-lang/ena#42): unnecessary mut
644
662
let root_vid = ut. find ( vid) . vid ;
645
- ut. probe_value ( root_vid) . 0 . unwrap_or_else ( || tcx. mk_re_var ( root_vid) )
663
+ ut. probe_value ( root_vid) . value . unwrap_or_else ( || tcx. mk_re_var ( root_vid) )
646
664
}
647
665
648
666
fn combine_map ( & mut self , t : CombineMapType ) -> & mut CombineMap < ' tcx > {
0 commit comments