@@ -22,7 +22,7 @@ use rustc_data_structures::unify as ut;
2222use ty:: { self , Ty , TyCtxt } ;
2323use ty:: { Region , RegionVid } ;
2424use ty:: ReStatic ;
25- use ty:: { BrFresh , ReLateBound , ReSkolemized , ReVar } ;
25+ use ty:: { BrFresh , ReLateBound , ReVar } ;
2626
2727use std:: collections:: BTreeMap ;
2828use std:: { cmp, fmt, mem, u32} ;
@@ -45,9 +45,6 @@ pub struct RegionConstraintCollector<'tcx> {
4545 /// exist). This prevents us from making many such regions.
4646 glbs : CombineMap < ' tcx > ,
4747
48- /// Number of skolemized variables currently active.
49- skolemization_count : ty:: UniverseIndex ,
50-
5148 /// Global counter used during the GLB algorithm to create unique
5249 /// names for fresh bound regions
5350 bound_count : u32 ,
@@ -237,7 +234,6 @@ pub struct RegionVariableInfo {
237234pub struct RegionSnapshot {
238235 length : usize ,
239236 region_snapshot : ut:: Snapshot < ut:: InPlace < ty:: RegionVid > > ,
240- skolemization_count : ty:: UniverseIndex ,
241237}
242238
243239/// When working with skolemized regions, we often wish to find all of
@@ -281,7 +277,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
281277 data : RegionConstraintData :: default ( ) ,
282278 lubs : FxHashMap ( ) ,
283279 glbs : FxHashMap ( ) ,
284- skolemization_count : ty:: UniverseIndex :: ROOT ,
285280 bound_count : 0 ,
286281 undo_log : Vec :: new ( ) ,
287282 unification_table : ut:: UnificationTable :: new ( ) ,
@@ -327,14 +322,11 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
327322 data,
328323 lubs,
329324 glbs,
330- skolemization_count,
331325 bound_count : _,
332326 undo_log : _,
333327 unification_table,
334328 } = self ;
335329
336- assert_eq ! ( * skolemization_count, ty:: UniverseIndex :: ROOT ) ;
337-
338330 // Clear the tables of (lubs, glbs), so that we will create
339331 // fresh regions if we do a LUB operation. As it happens,
340332 // LUB/GLB are not performed by the MIR type-checker, which is
@@ -369,20 +361,13 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
369361 RegionSnapshot {
370362 length,
371363 region_snapshot : self . unification_table . snapshot ( ) ,
372- skolemization_count : self . skolemization_count ,
373364 }
374365 }
375366
376367 pub fn commit ( & mut self , snapshot : RegionSnapshot ) {
377368 debug ! ( "RegionConstraintCollector: commit({})" , snapshot. length) ;
378369 assert ! ( self . undo_log. len( ) > snapshot. length) ;
379370 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- ) ;
386371
387372 if snapshot. length == 0 {
388373 self . undo_log . truncate ( 0 ) ;
@@ -402,7 +387,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
402387 }
403388 let c = self . undo_log . pop ( ) . unwrap ( ) ;
404389 assert ! ( c == OpenSnapshot ) ;
405- self . skolemization_count = snapshot. skolemization_count ;
406390 self . unification_table . rollback_to ( snapshot. region_snapshot ) ;
407391 }
408392
@@ -469,48 +453,13 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
469453 self . var_infos [ vid] . origin
470454 }
471455
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-
507456 /// Removes all the edges to/from the skolemized regions that are
508457 /// in `skols`. This is used after a higher-ranked operation
509458 /// completes to remove all trace of the skolemized regions
510459 /// created in that time.
511460 pub fn pop_skolemized (
512461 & mut self ,
513- _tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
462+ skolemization_count : ty :: UniverseIndex ,
514463 skols : & FxHashSet < ty:: Region < ' tcx > > ,
515464 snapshot : & RegionSnapshot ,
516465 ) {
@@ -519,24 +468,16 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
519468 assert ! ( self . in_snapshot( ) ) ;
520469 assert ! ( self . undo_log[ snapshot. length] == OpenSnapshot ) ;
521470 assert ! (
522- self . skolemization_count. as_usize( ) >= skols. len( ) ,
471+ skolemization_count. as_usize( ) >= skols. len( ) ,
523472 "popping more skolemized variables than actually exist, \
524473 sc now = {:?}, skols.len = {:?}",
525- self . skolemization_count,
474+ skolemization_count,
526475 skols. len( )
527476 ) ;
528477
529- let last_to_pop = self . skolemization_count . subuniverse ( ) ;
478+ let last_to_pop = skolemization_count. subuniverse ( ) ;
530479 let first_to_pop = ty:: UniverseIndex :: from ( last_to_pop. as_u32 ( ) - skols. len ( ) as u32 ) ;
531480
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- ) ;
540481 debug_assert ! {
541482 skols. iter( )
542483 . all( |& k| match * k {
@@ -547,8 +488,8 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
547488 false
548489 } ) ,
549490 "invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}" ,
550- snapshot . skolemization_count ,
551- self . skolemization_count ,
491+ first_to_pop ,
492+ last_to_pop ,
552493 skols
553494 }
554495
@@ -565,7 +506,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
565506 self . rollback_undo_entry ( undo_entry) ;
566507 }
567508
568- self . skolemization_count = snapshot. skolemization_count ;
569509 return ;
570510
571511 fn kill_constraint < ' tcx > (
@@ -900,12 +840,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
900840
901841impl fmt:: Debug for RegionSnapshot {
902842 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)
909844 }
910845}
911846
0 commit comments