1
1
//! See `README.md`.
2
2
3
3
use self :: CombineMapType :: * ;
4
- use self :: UndoLog :: * ;
5
4
6
- use super :: {
7
- InferCtxtUndoLogs , MiscVariable , RegionVariableOrigin , Rollback , Snapshot , SubregionOrigin ,
8
- } ;
5
+ use super :: { InferCtxtUndoLogs , MiscVariable , RegionVariableOrigin , SubregionOrigin } ;
9
6
10
- use rustc_data_structures:: fx:: FxHashMap ;
7
+ use rustc_data_structures:: fx:: FxIndexMap ;
11
8
use rustc_data_structures:: intern:: Interned ;
12
9
use rustc_data_structures:: sync:: Lrc ;
13
10
use rustc_data_structures:: undo_log:: UndoLogs ;
@@ -20,7 +17,6 @@ use rustc_middle::ty::{ReBound, ReVar};
20
17
use rustc_middle:: ty:: { Region , RegionVid } ;
21
18
use rustc_span:: Span ;
22
19
23
- use std:: collections:: BTreeMap ;
24
20
use std:: ops:: Range ;
25
21
use std:: { cmp, fmt, mem} ;
26
22
@@ -90,7 +86,7 @@ pub type VarInfos = IndexVec<RegionVid, RegionVariableInfo>;
90
86
pub struct RegionConstraintData < ' tcx > {
91
87
/// Constraints of the form `A <= B`, where either `A` or `B` can
92
88
/// be a region variable (or neither, as it happens).
93
- pub constraints : BTreeMap < Constraint < ' tcx > , SubregionOrigin < ' tcx > > ,
89
+ pub constraints : Vec < ( Constraint < ' tcx > , SubregionOrigin < ' tcx > ) > ,
94
90
95
91
/// Constraints of the form `R0 member of [R1, ..., Rn]`, meaning that
96
92
/// `R0` must be equal to one of the regions `R1..Rn`. These occur
@@ -267,28 +263,13 @@ pub(crate) struct TwoRegions<'tcx> {
267
263
b : Region < ' tcx > ,
268
264
}
269
265
270
- #[ derive( Copy , Clone , PartialEq ) ]
271
- pub ( crate ) enum UndoLog < ' tcx > {
272
- /// We added `RegionVid`.
273
- AddVar ( RegionVid ) ,
274
-
275
- /// We added the given `constraint`.
276
- AddConstraint ( Constraint < ' tcx > ) ,
277
-
278
- /// We added the given `verify`.
279
- AddVerify ( usize ) ,
280
-
281
- /// We added a GLB/LUB "combination variable".
282
- AddCombination ( CombineMapType , TwoRegions < ' tcx > ) ,
283
- }
284
-
285
266
#[ derive( Copy , Clone , PartialEq ) ]
286
267
pub ( crate ) enum CombineMapType {
287
268
Lub ,
288
269
Glb ,
289
270
}
290
271
291
- type CombineMap < ' tcx > = FxHashMap < TwoRegions < ' tcx > , RegionVid > ;
272
+ type CombineMap < ' tcx > = FxIndexMap < TwoRegions < ' tcx > , RegionVid > ;
292
273
293
274
#[ derive( Debug , Clone , Copy ) ]
294
275
pub struct RegionVariableInfo {
@@ -298,6 +279,11 @@ pub struct RegionVariableInfo {
298
279
299
280
pub struct RegionSnapshot {
300
281
any_unifications : bool ,
282
+ vars_len : usize ,
283
+ constraints_len : usize ,
284
+ verifys_len : usize ,
285
+ glbs_len : usize ,
286
+ lubs_len : usize ,
301
287
}
302
288
303
289
impl < ' tcx > RegionConstraintStorage < ' tcx > {
@@ -312,28 +298,6 @@ impl<'tcx> RegionConstraintStorage<'tcx> {
312
298
) -> RegionConstraintCollector < ' a , ' tcx > {
313
299
RegionConstraintCollector { storage : self , undo_log }
314
300
}
315
-
316
- fn rollback_undo_entry ( & mut self , undo_entry : UndoLog < ' tcx > ) {
317
- match undo_entry {
318
- AddVar ( vid) => {
319
- self . var_infos . pop ( ) . unwrap ( ) ;
320
- assert_eq ! ( self . var_infos. len( ) , vid. index( ) ) ;
321
- }
322
- AddConstraint ( ref constraint) => {
323
- self . data . constraints . remove ( constraint) ;
324
- }
325
- AddVerify ( index) => {
326
- self . data . verifys . pop ( ) ;
327
- assert_eq ! ( self . data. verifys. len( ) , index) ;
328
- }
329
- AddCombination ( Glb , ref regions) => {
330
- self . glbs . remove ( regions) ;
331
- }
332
- AddCombination ( Lub , ref regions) => {
333
- self . lubs . remove ( regions) ;
334
- }
335
- }
336
- }
337
301
}
338
302
339
303
impl < ' tcx > RegionConstraintCollector < ' _ , ' tcx > {
@@ -407,12 +371,32 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
407
371
408
372
pub ( super ) fn start_snapshot ( & mut self ) -> RegionSnapshot {
409
373
debug ! ( "RegionConstraintCollector: start_snapshot" ) ;
410
- RegionSnapshot { any_unifications : self . any_unifications }
374
+ RegionSnapshot {
375
+ any_unifications : self . any_unifications ,
376
+ vars_len : self . var_infos . len ( ) ,
377
+ constraints_len : self . data . constraints . len ( ) ,
378
+ verifys_len : self . data . verifys . len ( ) ,
379
+ glbs_len : self . glbs . len ( ) ,
380
+ lubs_len : self . lubs . len ( ) ,
381
+ }
411
382
}
412
383
413
384
pub ( super ) fn rollback_to ( & mut self , snapshot : RegionSnapshot ) {
414
385
debug ! ( "RegionConstraintCollector: rollback_to({:?})" , snapshot) ;
415
- self . any_unifications = snapshot. any_unifications ;
386
+ let RegionSnapshot {
387
+ any_unifications,
388
+ vars_len,
389
+ constraints_len,
390
+ verifys_len,
391
+ glbs_len,
392
+ lubs_len,
393
+ } = snapshot;
394
+ self . any_unifications = any_unifications;
395
+ self . var_infos . truncate ( vars_len) ;
396
+ self . data . constraints . truncate ( constraints_len) ;
397
+ self . data . verifys . truncate ( verifys_len) ;
398
+ self . glbs . truncate ( glbs_len) ;
399
+ self . lubs . truncate ( lubs_len) ;
416
400
}
417
401
418
402
pub ( super ) fn new_region_var (
@@ -424,7 +408,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
424
408
425
409
let u_vid = self . unification_table_mut ( ) . new_key ( UnifiedRegion :: new ( None ) ) ;
426
410
assert_eq ! ( vid, u_vid. vid) ;
427
- self . undo_log . push ( AddVar ( vid) ) ;
428
411
debug ! ( "created new region variable {:?} in {:?} with origin {:?}" , vid, universe, origin) ;
429
412
vid
430
413
}
@@ -442,15 +425,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
442
425
fn add_constraint ( & mut self , constraint : Constraint < ' tcx > , origin : SubregionOrigin < ' tcx > ) {
443
426
// cannot add constraints once regions are resolved
444
427
debug ! ( "RegionConstraintCollector: add_constraint({:?})" , constraint) ;
445
-
446
- // never overwrite an existing (constraint, origin) - only insert one if it isn't
447
- // present in the map yet. This prevents origins from outside the snapshot being
448
- // replaced with "less informative" origins e.g., during calls to `can_eq`
449
- let undo_log = & mut self . undo_log ;
450
- self . storage . data . constraints . entry ( constraint) . or_insert_with ( || {
451
- undo_log. push ( AddConstraint ( constraint) ) ;
452
- origin
453
- } ) ;
428
+ self . storage . data . constraints . push ( ( constraint, origin) ) ;
454
429
}
455
430
456
431
fn add_verify ( & mut self , verify : Verify < ' tcx > ) {
@@ -464,9 +439,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
464
439
return ;
465
440
}
466
441
467
- let index = self . data . verifys . len ( ) ;
468
442
self . data . verifys . push ( verify) ;
469
- self . undo_log . push ( AddVerify ( index) ) ;
470
443
}
471
444
472
445
pub ( super ) fn make_eqregion (
@@ -638,6 +611,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
638
611
b : Region < ' tcx > ,
639
612
origin : SubregionOrigin < ' tcx > ,
640
613
) -> Region < ' tcx > {
614
+ //assert!(!UndoLogs::<super::UndoLog<'_>>::in_snapshot(&self.undo_log));
641
615
let vars = TwoRegions { a, b } ;
642
616
if let Some ( & c) = self . combine_map ( t) . get ( & vars) {
643
617
return ty:: Region :: new_var ( tcx, c) ;
@@ -647,7 +621,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
647
621
let c_universe = cmp:: max ( a_universe, b_universe) ;
648
622
let c = self . new_region_var ( c_universe, MiscVariable ( origin. span ( ) ) ) ;
649
623
self . combine_map ( t) . insert ( vars, c) ;
650
- self . undo_log . push ( AddCombination ( t, vars) ) ;
651
624
let new_r = ty:: Region :: new_var ( tcx, c) ;
652
625
for old_r in [ a, b] {
653
626
match t {
@@ -686,10 +659,16 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
686
659
}
687
660
688
661
/// See `InferCtxt::region_constraints_added_in_snapshot`.
689
- pub fn region_constraints_added_in_snapshot ( & self , mark : & Snapshot < ' tcx > ) -> bool {
690
- self . undo_log
691
- . region_constraints_in_snapshot ( mark)
692
- . any ( |& elt| matches ! ( elt, AddConstraint ( _) ) )
662
+ pub fn region_constraints_added_in_snapshot ( & self , snapshot : & RegionSnapshot ) -> bool {
663
+ self . data . constraints . len ( ) != snapshot. constraints_len
664
+ }
665
+
666
+ fn region_constraints_in_snapshot (
667
+ & self ,
668
+ snapshot : & RegionSnapshot ,
669
+ ) -> impl Iterator < Item = & Constraint < ' tcx > > {
670
+ assert_eq ! ( snapshot. verifys_len, self . data. verifys. len( ) ) ;
671
+ self . data . constraints [ snapshot. constraints_len ..] . iter ( ) . map ( |( constraint, _) | constraint)
693
672
}
694
673
695
674
#[ inline]
@@ -774,9 +753,3 @@ impl<'tcx> RegionConstraintData<'tcx> {
774
753
constraints. is_empty ( ) && member_constraints. is_empty ( ) && verifys. is_empty ( )
775
754
}
776
755
}
777
-
778
- impl < ' tcx > Rollback < UndoLog < ' tcx > > for RegionConstraintStorage < ' tcx > {
779
- fn reverse ( & mut self , undo : UndoLog < ' tcx > ) {
780
- self . rollback_undo_entry ( undo)
781
- }
782
- }
0 commit comments