1
1
use std:: marker:: PhantomData ;
2
2
3
3
use 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 } ;
5
5
use rustc_data_structures:: unify as ut;
6
- use rustc_hir as hir;
7
6
use rustc_middle:: ty;
8
7
9
8
use crate :: {
10
- infer:: {
11
- region_constraints:: { self , RegionConstraintStorage } ,
12
- type_variable, RegionObligation ,
13
- } ,
9
+ infer:: { region_constraints, type_variable, InferCtxtInner } ,
14
10
traits,
15
11
} ;
16
12
@@ -19,6 +15,7 @@ pub struct Snapshot<'tcx> {
19
15
_marker : PhantomData < & ' tcx ( ) > ,
20
16
}
21
17
18
+ /// Records the 'undo' data fora single operation that affects some form of inference variable.
22
19
pub ( crate ) enum UndoLog < ' tcx > {
23
20
TypeVariables ( type_variable:: UndoLog < ' tcx > ) ,
24
21
ConstUnificationTable ( sv:: UndoLog < ut:: Delegate < ty:: ConstVid < ' tcx > > > ) ,
@@ -96,26 +93,18 @@ impl<'tcx> From<traits::UndoLog<'tcx>> for UndoLog<'tcx> {
96
93
}
97
94
}
98
95
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 > {
110
97
fn reverse ( & mut self , undo : UndoLog < ' tcx > ) {
111
98
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
+ }
117
106
UndoLog :: RegionUnificationTable ( undo) => {
118
- self . region_constraints . unification_table . reverse ( undo)
107
+ self . region_constraints . as_mut ( ) . unwrap ( ) . unification_table . reverse ( undo)
119
108
}
120
109
UndoLog :: ProjectionCache ( undo) => self . projection_cache . reverse ( undo) ,
121
110
UndoLog :: PushRegionObligation => {
@@ -163,58 +152,52 @@ where
163
152
}
164
153
}
165
154
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 > ) {
181
157
debug ! ( "rollback_to({})" , snapshot. undo_len) ;
182
- self . assert_open_snapshot ( & snapshot) ;
158
+ self . undo_log . assert_open_snapshot ( & snapshot) ;
183
159
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) ;
189
163
}
190
164
191
- if self . num_open_snapshots == 1 {
165
+ if self . undo_log . num_open_snapshots == 1 {
192
166
// The root snapshot. It's safe to clear the undo log because
193
167
// there's no snapshot further out that we might need to roll back
194
168
// to.
195
169
assert ! ( snapshot. undo_len == 0 ) ;
196
- self . logs . clear ( ) ;
170
+ self . undo_log . logs . clear ( ) ;
197
171
}
198
172
199
- self . num_open_snapshots -= 1 ;
173
+ self . undo_log . num_open_snapshots -= 1 ;
200
174
}
201
175
202
- fn commit ( & mut self , snapshot : Self :: Snapshot ) {
176
+ pub fn commit ( & mut self , snapshot : Snapshot < ' tcx > ) {
203
177
debug ! ( "commit({})" , snapshot. undo_len) ;
204
178
205
- if self . num_open_snapshots == 1 {
179
+ if self . undo_log . num_open_snapshots == 1 {
206
180
// The root snapshot. It's safe to clear the undo log because
207
181
// there's no snapshot further out that we might need to roll back
208
182
// to.
209
183
assert ! ( snapshot. undo_len == 0 ) ;
210
- self . logs . clear ( ) ;
184
+ self . undo_log . logs . clear ( ) ;
211
185
}
212
186
213
- self . num_open_snapshots -= 1 ;
187
+ self . undo_log . num_open_snapshots -= 1 ;
214
188
}
215
189
}
216
190
217
191
impl < ' 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
+
218
201
pub ( crate ) fn region_constraints_in_snapshot (
219
202
& self ,
220
203
s : & Snapshot < ' tcx > ,
0 commit comments