11use std:: marker:: PhantomData ;
22
33use rustc_data_structures:: snapshot_vec as sv;
4- use rustc_data_structures:: undo_log:: { Rollback , Snapshots , UndoLogs } ;
4+ use rustc_data_structures:: undo_log:: { Rollback , UndoLogs } ;
55use rustc_data_structures:: unify as ut;
6- use rustc_hir as hir;
76use rustc_middle:: ty;
87
98use crate :: {
10- infer:: {
11- region_constraints:: { self , RegionConstraintStorage } ,
12- type_variable, RegionObligation ,
13- } ,
9+ infer:: { region_constraints, type_variable, InferCtxtInner } ,
1410 traits,
1511} ;
1612
@@ -19,6 +15,7 @@ pub struct Snapshot<'tcx> {
1915 _marker : PhantomData < & ' tcx ( ) > ,
2016}
2117
18+ /// Records the 'undo' data fora single operation that affects some form of inference variable.
2219pub ( crate ) enum UndoLog < ' tcx > {
2320 TypeVariables ( type_variable:: UndoLog < ' tcx > ) ,
2421 ConstUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: ConstVid < ' tcx > > > ) ,
@@ -96,26 +93,18 @@ impl<'tcx> From<traits::UndoLog<'tcx>> for UndoLog<'tcx> {
9693 }
9794}
9895
99- pub ( super ) struct RollbackView < ' tcx , ' a > {
100- pub ( super ) type_variables : & ' a mut type_variable:: TypeVariableStorage < ' tcx > ,
101- pub ( super ) const_unification_table : & ' a mut ut:: UnificationTableStorage < ty:: ConstVid < ' tcx > > ,
102- pub ( super ) int_unification_table : & ' a mut ut:: UnificationTableStorage < ty:: IntVid > ,
103- pub ( super ) float_unification_table : & ' a mut ut:: UnificationTableStorage < ty:: FloatVid > ,
104- pub ( super ) region_constraints : & ' a mut RegionConstraintStorage < ' tcx > ,
105- pub ( super ) projection_cache : & ' a mut traits:: ProjectionCacheStorage < ' tcx > ,
106- pub ( super ) region_obligations : & ' a mut Vec < ( hir:: HirId , RegionObligation < ' tcx > ) > ,
107- }
108-
109- impl < ' tcx > Rollback < UndoLog < ' tcx > > for RollbackView < ' tcx , ' _ > {
96+ impl < ' tcx > Rollback < UndoLog < ' tcx > > for InferCtxtInner < ' tcx > {
11097 fn reverse ( & mut self , undo : UndoLog < ' tcx > ) {
11198 match undo {
112- UndoLog :: TypeVariables ( undo) => self . type_variables . reverse ( undo) ,
113- UndoLog :: ConstUnificationTable ( undo) => self . const_unification_table . reverse ( undo) ,
114- UndoLog :: IntUnificationTable ( undo) => self . int_unification_table . reverse ( undo) ,
115- UndoLog :: FloatUnificationTable ( undo) => self . float_unification_table . reverse ( undo) ,
116- UndoLog :: RegionConstraintCollector ( undo) => self . region_constraints . reverse ( undo) ,
99+ UndoLog :: TypeVariables ( undo) => self . type_variable_storage . reverse ( undo) ,
100+ UndoLog :: ConstUnificationTable ( undo) => self . const_unification_storage . reverse ( undo) ,
101+ UndoLog :: IntUnificationTable ( undo) => self . int_unification_storage . reverse ( undo) ,
102+ UndoLog :: FloatUnificationTable ( undo) => self . float_unification_storage . reverse ( undo) ,
103+ UndoLog :: RegionConstraintCollector ( undo) => {
104+ self . region_constraints . as_mut ( ) . unwrap ( ) . reverse ( undo)
105+ }
117106 UndoLog :: RegionUnificationTable ( undo) => {
118- self . region_constraints . unification_table . reverse ( undo)
107+ self . region_constraints . as_mut ( ) . unwrap ( ) . unification_table . reverse ( undo)
119108 }
120109 UndoLog :: ProjectionCache ( undo) => self . projection_cache . reverse ( undo) ,
121110 UndoLog :: PushRegionObligation => {
@@ -163,58 +152,52 @@ where
163152 }
164153}
165154
166- impl < ' tcx > Snapshots < UndoLog < ' tcx > > for InferCtxtUndoLogs < ' tcx > {
167- type Snapshot = Snapshot < ' tcx > ;
168- fn actions_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> & [ UndoLog < ' tcx > ] {
169- & self . logs [ snapshot. undo_len ..]
170- }
171-
172- fn start_snapshot ( & mut self ) -> Self :: Snapshot {
173- self . num_open_snapshots += 1 ;
174- Snapshot { undo_len : self . logs . len ( ) , _marker : PhantomData }
175- }
176-
177- fn rollback_to < R > ( & mut self , values : impl FnOnce ( ) -> R , snapshot : Self :: Snapshot )
178- where
179- R : Rollback < UndoLog < ' tcx > > ,
180- {
155+ impl < ' tcx > InferCtxtInner < ' tcx > {
156+ pub fn rollback_to ( & mut self , snapshot : Snapshot < ' tcx > ) {
181157 debug ! ( "rollback_to({})" , snapshot. undo_len) ;
182- self . assert_open_snapshot ( & snapshot) ;
158+ self . undo_log . assert_open_snapshot ( & snapshot) ;
183159
184- if self . logs . len ( ) > snapshot. undo_len {
185- let mut values = values ( ) ;
186- while self . logs . len ( ) > snapshot. undo_len {
187- values. reverse ( self . logs . pop ( ) . unwrap ( ) ) ;
188- }
160+ while self . undo_log . logs . len ( ) > snapshot. undo_len {
161+ let undo = self . undo_log . logs . pop ( ) . unwrap ( ) ;
162+ self . reverse ( undo) ;
189163 }
190164
191- if self . num_open_snapshots == 1 {
165+ if self . undo_log . num_open_snapshots == 1 {
192166 // The root snapshot. It's safe to clear the undo log because
193167 // there's no snapshot further out that we might need to roll back
194168 // to.
195169 assert ! ( snapshot. undo_len == 0 ) ;
196- self . logs . clear ( ) ;
170+ self . undo_log . logs . clear ( ) ;
197171 }
198172
199- self . num_open_snapshots -= 1 ;
173+ self . undo_log . num_open_snapshots -= 1 ;
200174 }
201175
202- fn commit ( & mut self , snapshot : Self :: Snapshot ) {
176+ pub fn commit ( & mut self , snapshot : Snapshot < ' tcx > ) {
203177 debug ! ( "commit({})" , snapshot. undo_len) ;
204178
205- if self . num_open_snapshots == 1 {
179+ if self . undo_log . num_open_snapshots == 1 {
206180 // The root snapshot. It's safe to clear the undo log because
207181 // there's no snapshot further out that we might need to roll back
208182 // to.
209183 assert ! ( snapshot. undo_len == 0 ) ;
210- self . logs . clear ( ) ;
184+ self . undo_log . logs . clear ( ) ;
211185 }
212186
213- self . num_open_snapshots -= 1 ;
187+ self . undo_log . num_open_snapshots -= 1 ;
214188 }
215189}
216190
217191impl < ' tcx > InferCtxtUndoLogs < ' tcx > {
192+ pub fn actions_since_snapshot ( & self , snapshot : & Snapshot < ' tcx > ) -> & [ UndoLog < ' tcx > ] {
193+ & self . logs [ snapshot. undo_len ..]
194+ }
195+
196+ pub fn start_snapshot ( & mut self ) -> Snapshot < ' tcx > {
197+ self . num_open_snapshots += 1 ;
198+ Snapshot { undo_len : self . logs . len ( ) , _marker : PhantomData }
199+ }
200+
218201 pub ( crate ) fn region_constraints_in_snapshot (
219202 & self ,
220203 s : & Snapshot < ' tcx > ,
0 commit comments