@@ -22,7 +22,7 @@ use rustc_data_structures::unify as ut;
22
22
use ty:: { self , Ty , TyCtxt } ;
23
23
use ty:: { Region , RegionVid } ;
24
24
use ty:: ReStatic ;
25
- use ty:: { BrFresh , ReLateBound , ReSkolemized , ReVar } ;
25
+ use ty:: { BrFresh , ReLateBound , ReVar } ;
26
26
27
27
use std:: collections:: BTreeMap ;
28
28
use std:: { cmp, fmt, mem, u32} ;
@@ -45,9 +45,6 @@ pub struct RegionConstraintCollector<'tcx> {
45
45
/// exist). This prevents us from making many such regions.
46
46
glbs : CombineMap < ' tcx > ,
47
47
48
- /// Number of skolemized variables currently active.
49
- skolemization_count : ty:: UniverseIndex ,
50
-
51
48
/// Global counter used during the GLB algorithm to create unique
52
49
/// names for fresh bound regions
53
50
bound_count : u32 ,
@@ -237,7 +234,6 @@ pub struct RegionVariableInfo {
237
234
pub struct RegionSnapshot {
238
235
length : usize ,
239
236
region_snapshot : ut:: Snapshot < ut:: InPlace < ty:: RegionVid > > ,
240
- skolemization_count : ty:: UniverseIndex ,
241
237
}
242
238
243
239
/// When working with skolemized regions, we often wish to find all of
@@ -281,7 +277,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
281
277
data : RegionConstraintData :: default ( ) ,
282
278
lubs : FxHashMap ( ) ,
283
279
glbs : FxHashMap ( ) ,
284
- skolemization_count : ty:: UniverseIndex :: ROOT ,
285
280
bound_count : 0 ,
286
281
undo_log : Vec :: new ( ) ,
287
282
unification_table : ut:: UnificationTable :: new ( ) ,
@@ -327,14 +322,11 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
327
322
data,
328
323
lubs,
329
324
glbs,
330
- skolemization_count,
331
325
bound_count : _,
332
326
undo_log : _,
333
327
unification_table,
334
328
} = self ;
335
329
336
- assert_eq ! ( * skolemization_count, ty:: UniverseIndex :: ROOT ) ;
337
-
338
330
// Clear the tables of (lubs, glbs), so that we will create
339
331
// fresh regions if we do a LUB operation. As it happens,
340
332
// LUB/GLB are not performed by the MIR type-checker, which is
@@ -369,20 +361,13 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
369
361
RegionSnapshot {
370
362
length,
371
363
region_snapshot : self . unification_table . snapshot ( ) ,
372
- skolemization_count : self . skolemization_count ,
373
364
}
374
365
}
375
366
376
367
pub fn commit ( & mut self , snapshot : RegionSnapshot ) {
377
368
debug ! ( "RegionConstraintCollector: commit({})" , snapshot. length) ;
378
369
assert ! ( self . undo_log. len( ) > snapshot. length) ;
379
370
assert ! ( self . undo_log[ snapshot. length] == OpenSnapshot ) ;
380
- assert ! (
381
- self . skolemization_count == snapshot. skolemization_count,
382
- "failed to pop skolemized regions: {:?} now vs {:?} at start" ,
383
- self . skolemization_count,
384
- snapshot. skolemization_count
385
- ) ;
386
371
387
372
if snapshot. length == 0 {
388
373
self . undo_log . truncate ( 0 ) ;
@@ -402,7 +387,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
402
387
}
403
388
let c = self . undo_log . pop ( ) . unwrap ( ) ;
404
389
assert ! ( c == OpenSnapshot ) ;
405
- self . skolemization_count = snapshot. skolemization_count ;
406
390
self . unification_table . rollback_to ( snapshot. region_snapshot ) ;
407
391
}
408
392
@@ -469,48 +453,13 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
469
453
self . var_infos [ vid] . origin
470
454
}
471
455
472
- /// Creates a new skolemized region. Skolemized regions are fresh
473
- /// regions used when performing higher-ranked computations. They
474
- /// must be used in a very particular way and are never supposed
475
- /// to "escape" out into error messages or the code at large.
476
- ///
477
- /// The idea is to always create a snapshot. Skolemized regions
478
- /// can be created in the context of this snapshot, but before the
479
- /// snapshot is committed or rolled back, they must be popped
480
- /// (using `pop_skolemized_regions`), so that their numbers can be
481
- /// recycled. Normally you don't have to think about this: you use
482
- /// the APIs in `higher_ranked/mod.rs`, such as
483
- /// `skolemize_late_bound_regions` and `plug_leaks`, which will
484
- /// guide you on this path (ensure that the `SkolemizationMap` is
485
- /// consumed and you are good). For more info on how skolemization
486
- /// for HRTBs works, see the [rustc guide].
487
- ///
488
- /// [rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/trait-hrtb.html
489
- ///
490
- /// The `snapshot` argument to this function is not really used;
491
- /// it's just there to make it explicit which snapshot bounds the
492
- /// skolemized region that results. It should always be the top-most snapshot.
493
- pub fn push_skolemized (
494
- & mut self ,
495
- tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
496
- br : ty:: BoundRegion ,
497
- snapshot : & RegionSnapshot ,
498
- ) -> Region < ' tcx > {
499
- assert ! ( self . in_snapshot( ) ) ;
500
- assert ! ( self . undo_log[ snapshot. length] == OpenSnapshot ) ;
501
-
502
- let universe = self . skolemization_count . subuniverse ( ) ;
503
- self . skolemization_count = universe;
504
- tcx. mk_region ( ReSkolemized ( universe, br) )
505
- }
506
-
507
456
/// Removes all the edges to/from the skolemized regions that are
508
457
/// in `skols`. This is used after a higher-ranked operation
509
458
/// completes to remove all trace of the skolemized regions
510
459
/// created in that time.
511
460
pub fn pop_skolemized (
512
461
& mut self ,
513
- _tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
462
+ skolemization_count : ty :: UniverseIndex ,
514
463
skols : & FxHashSet < ty:: Region < ' tcx > > ,
515
464
snapshot : & RegionSnapshot ,
516
465
) {
@@ -519,24 +468,16 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
519
468
assert ! ( self . in_snapshot( ) ) ;
520
469
assert ! ( self . undo_log[ snapshot. length] == OpenSnapshot ) ;
521
470
assert ! (
522
- self . skolemization_count. as_usize( ) >= skols. len( ) ,
471
+ skolemization_count. as_usize( ) >= skols. len( ) ,
523
472
"popping more skolemized variables than actually exist, \
524
473
sc now = {:?}, skols.len = {:?}",
525
- self . skolemization_count,
474
+ skolemization_count,
526
475
skols. len( )
527
476
) ;
528
477
529
- let last_to_pop = self . skolemization_count . subuniverse ( ) ;
478
+ let last_to_pop = skolemization_count. subuniverse ( ) ;
530
479
let first_to_pop = ty:: UniverseIndex :: from ( last_to_pop. as_u32 ( ) - skols. len ( ) as u32 ) ;
531
480
532
- assert ! (
533
- first_to_pop >= snapshot. skolemization_count,
534
- "popping more regions than snapshot contains, \
535
- sc now = {:?}, sc then = {:?}, skols.len = {:?}",
536
- self . skolemization_count,
537
- snapshot. skolemization_count,
538
- skols. len( )
539
- ) ;
540
481
debug_assert ! {
541
482
skols. iter( )
542
483
. all( |& k| match * k {
@@ -547,8 +488,8 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
547
488
false
548
489
} ) ,
549
490
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}" ,
550
- snapshot . skolemization_count ,
551
- self . skolemization_count ,
491
+ first_to_pop ,
492
+ last_to_pop ,
552
493
skols
553
494
}
554
495
@@ -565,7 +506,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
565
506
self . rollback_undo_entry ( undo_entry) ;
566
507
}
567
508
568
- self . skolemization_count = snapshot. skolemization_count ;
569
509
return ;
570
510
571
511
fn kill_constraint < ' tcx > (
@@ -900,12 +840,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
900
840
901
841
impl fmt:: Debug for RegionSnapshot {
902
842
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
903
- write ! (
904
- f,
905
- "RegionSnapshot(length={},skolemization={:?})" ,
906
- self . length,
907
- self . skolemization_count
908
- )
843
+ write ! ( f, "RegionSnapshot(length={})" , self . length)
909
844
}
910
845
}
911
846
0 commit comments