@@ -9,10 +9,10 @@ use crate::unify_log as ul;
9
9
10
10
use ena:: undo_log:: { Rollback , Snapshots , UndoLogs } ;
11
11
12
- enum UndoLog < K : ut:: UnifyKey , I > {
12
+ pub enum UndoLog < K : ut:: UnifyKey , I = K > {
13
13
Relation ( sv:: UndoLog < ut:: Delegate < K > > ) ,
14
14
UnifyLog ( ul:: Undo < I > ) ,
15
- ModifiedSet ( ms:: Undo ) ,
15
+ ModifiedSet ( ms:: Undo < I > ) ,
16
16
}
17
17
18
18
impl < K : ut:: UnifyKey , I > From < sv:: UndoLog < ut:: Delegate < K > > > for UndoLog < K , I > {
@@ -27,8 +27,8 @@ impl<K: ut::UnifyKey, I> From<ul::Undo<I>> for UndoLog<K, I> {
27
27
}
28
28
}
29
29
30
- impl < K : ut:: UnifyKey , I > From < ms:: Undo > for UndoLog < K , I > {
31
- fn from ( l : ms:: Undo ) -> Self {
30
+ impl < K : ut:: UnifyKey , I > From < ms:: Undo < I > > for UndoLog < K , I > {
31
+ fn from ( l : ms:: Undo < I > ) -> Self {
32
32
UndoLog :: ModifiedSet ( l)
33
33
}
34
34
}
56
56
self . logs . push ( undo. into ( ) )
57
57
}
58
58
}
59
+ fn clear ( & mut self ) {
60
+ self . logs . clear ( ) ;
61
+ self . num_open_snapshots = 0 ;
62
+ }
59
63
fn extend < J > ( & mut self , undos : J )
60
64
where
61
65
Self : Sized ,
67
71
}
68
72
}
69
73
70
- struct RollbackView < ' a , K : ut:: UnifyKey , I : Idx > {
71
- relations : & ' a mut ut:: UnificationStorage < K > ,
72
- unify_log : & ' a mut ul:: UnifyLog < I > ,
73
- modified_set : & ' a mut ms:: ModifiedSet < I > ,
74
- }
75
-
76
- impl < K : ut:: UnifyKey , I : Idx > Rollback < UndoLog < K , I > > for RollbackView < ' _ , K , I > {
74
+ impl < K : ut:: UnifyKey , I : Idx > Rollback < UndoLog < K , I > > for LoggedUnificationTableStorage < K , I > {
77
75
fn reverse ( & mut self , undo : UndoLog < K , I > ) {
78
76
match undo {
79
77
UndoLog :: Relation ( undo) => self . relations . reverse ( undo) ,
@@ -93,12 +91,18 @@ impl<K: ut::UnifyKey, I: Idx> Snapshots<UndoLog<K, I>> for Logs<K, I> {
93
91
unreachable ! ( )
94
92
}
95
93
96
- fn rollback_to ( & mut self , values : & mut impl Rollback < UndoLog < K , I > > , snapshot : Self :: Snapshot ) {
94
+ fn rollback_to < R > ( & mut self , values : impl FnOnce ( ) -> R , snapshot : Self :: Snapshot )
95
+ where
96
+ R : Rollback < UndoLog < K , I > > ,
97
+ {
97
98
debug ! ( "rollback_to({})" , snapshot. undo_len) ;
98
99
self . assert_open_snapshot ( & snapshot) ;
99
100
100
- while self . logs . len ( ) > snapshot. undo_len {
101
- values. reverse ( self . logs . pop ( ) . unwrap ( ) ) ;
101
+ if self . logs . len ( ) > snapshot. undo_len {
102
+ let mut values = values ( ) ;
103
+ while self . logs . len ( ) > snapshot. undo_len {
104
+ values. reverse ( self . logs . pop ( ) . unwrap ( ) ) ;
105
+ }
102
106
}
103
107
104
108
if self . num_open_snapshots == 1 {
@@ -135,14 +139,18 @@ impl<K: ut::UnifyKey, I: Idx> Logs<K, I> {
135
139
}
136
140
}
137
141
138
- pub struct LoggedUnificationTable < K : ut:: UnifyKey , I : Idx = K > {
139
- relations : ut:: UnificationStorage < K > ,
142
+ pub struct LoggedUnificationTableStorage < K : ut:: UnifyKey , I : Idx = K > {
143
+ relations : ut:: UnificationTableStorage < K > ,
140
144
unify_log : ul:: UnifyLog < I > ,
141
145
modified_set : ms:: ModifiedSet < I > ,
142
- undo_log : Logs < K , I > ,
143
146
}
144
147
145
- impl < K , I > LoggedUnificationTable < K , I >
148
+ pub struct LoggedUnificationTable < ' a , K : ut:: UnifyKey , I : Idx , L > {
149
+ storage : & ' a mut LoggedUnificationTableStorage < K , I > ,
150
+ undo_log : L ,
151
+ }
152
+
153
+ impl < K , I > LoggedUnificationTableStorage < K , I >
146
154
where
147
155
K : ut:: UnifyKey + From < I > ,
148
156
I : Idx + From < K > ,
@@ -152,14 +160,34 @@ where
152
160
relations : Default :: default ( ) ,
153
161
unify_log : ul:: UnifyLog :: new ( ) ,
154
162
modified_set : ms:: ModifiedSet :: new ( ) ,
155
- undo_log : Logs :: default ( ) ,
156
163
}
157
164
}
158
165
166
+ pub fn with_log < L > ( & mut self , undo_log : L ) -> LoggedUnificationTable < ' _ , K , I , L > {
167
+ LoggedUnificationTable { storage : self , undo_log }
168
+ }
169
+ }
170
+
171
+ impl < K , I , L > LoggedUnificationTable < ' _ , K , I , L >
172
+ where
173
+ K : ut:: UnifyKey ,
174
+ I : Idx ,
175
+ {
176
+ pub fn len ( & self ) -> usize {
177
+ self . storage . relations . len ( )
178
+ }
179
+ }
180
+
181
+ impl < K , I , L > LoggedUnificationTable < ' _ , K , I , L >
182
+ where
183
+ K : ut:: UnifyKey + From < I > ,
184
+ I : Idx + From < K > ,
185
+ L : UndoLogs < ms:: Undo < I > > + UndoLogs < ul:: Undo < I > > + UndoLogs < sv:: UndoLog < ut:: Delegate < K > > > ,
186
+ {
159
187
fn relations (
160
188
& mut self ,
161
- ) -> ut:: UnificationTable < ut:: InPlace < K , & mut ut:: UnificationStorage < K > , & mut Logs < K , I > > > {
162
- ut:: UnificationTable :: with_log ( & mut self . relations , & mut self . undo_log )
189
+ ) -> ut:: UnificationTable < ut:: InPlace < K , & mut ut:: UnificationStorage < K > , & mut L > > {
190
+ ut:: UnificationTable :: with_log ( & mut self . storage . relations , & mut self . undo_log )
163
191
}
164
192
165
193
pub fn unify ( & mut self , a : I , b : I )
@@ -173,9 +201,9 @@ where
173
201
where
174
202
K :: Value : ut:: UnifyValue < Error = ut:: NoError > ,
175
203
{
176
- if self . unify_log . needs_log ( vid) {
204
+ if self . storage . unify_log . needs_log ( vid) {
177
205
warn ! ( "ModifiedSet {:?} => {:?}" , vid, ty) ;
178
- self . modified_set . set ( & mut self . undo_log , vid) ;
206
+ self . storage . modified_set . set ( & mut self . undo_log , vid) ;
179
207
}
180
208
let vid = vid. into ( ) ;
181
209
let mut relations = self . relations ( ) ;
@@ -195,8 +223,8 @@ where
195
223
value : K :: Value ,
196
224
) -> Result < ( ) , <K :: Value as ut:: UnifyValue >:: Error > {
197
225
let vid = self . find ( vid) . into ( ) ;
198
- if self . unify_log . needs_log ( vid) {
199
- self . modified_set . set ( & mut self . undo_log , vid) ;
226
+ if self . storage . unify_log . needs_log ( vid) {
227
+ self . storage . modified_set . set ( & mut self . undo_log , vid) ;
200
228
}
201
229
self . relations ( ) . unify_var_value ( vid, value)
202
230
}
@@ -212,9 +240,9 @@ where
212
240
relations. unify_var_var ( a, b) ?;
213
241
214
242
if a == relations. find ( a) {
215
- self . unify_log . unify ( & mut self . undo_log , a. into ( ) , b. into ( ) ) ;
243
+ self . storage . unify_log . unify ( & mut self . undo_log , a. into ( ) , b. into ( ) ) ;
216
244
} else {
217
- self . unify_log . unify ( & mut self . undo_log , b. into ( ) , a. into ( ) ) ;
245
+ self . storage . unify_log . unify ( & mut self . undo_log , b. into ( ) , a. into ( ) ) ;
218
246
}
219
247
Ok ( ( ) )
220
248
}
@@ -240,14 +268,11 @@ where
240
268
self . relations ( ) . new_key ( value)
241
269
}
242
270
243
- pub fn len ( & self ) -> usize {
244
- self . relations . len ( )
245
- }
246
-
247
271
pub fn vars_since_snapshot ( & mut self , s : & Snapshot < K , I > ) -> Range < K > {
248
272
K :: from ( I :: new ( s. value_count ) ) ..K :: from ( I :: new ( self . relations ( ) . len ( ) ) )
249
273
}
250
274
275
+ /* FIXME
251
276
pub fn snapshot(&mut self) -> Snapshot<K, I> {
252
277
self.undo_log.num_open_snapshots += 1;
253
278
Snapshot {
@@ -258,44 +283,44 @@ where
258
283
}
259
284
260
285
pub fn rollback_to(&mut self, snapshot: Snapshot<K, I>) {
261
- let Self { relations, unify_log, modified_set, .. } = self ;
286
+ let UnificationTableStorage { relations, unify_log, modified_set, .. } = self.storage ;
262
287
263
- self . undo_log
264
- . rollback_to ( & mut RollbackView { relations, unify_log, modified_set } , snapshot) ;
288
+ self.undo_log.rollback_to(|| RollbackView { relations, unify_log, modified_set }, snapshot);
265
289
266
290
if self.undo_log.num_open_snapshots == 0 {
267
- self . modified_set . clear ( ) ;
291
+ self.storage. modified_set.clear();
268
292
}
269
293
}
270
294
271
295
pub fn commit(&mut self, snapshot: Snapshot<K, I>) {
272
296
self.undo_log.commit(snapshot);
273
297
274
- if self . undo_log . num_open_snapshots == 0 {
275
- self . modified_set . clear ( ) ;
298
+ if self.undo_log.num_open_snapshots() == 0 {
299
+ self.storage. modified_set.clear();
276
300
}
277
301
}
302
+ */
278
303
279
304
pub fn register ( & mut self ) -> ms:: Offset < I > {
280
- self . modified_set . register ( )
305
+ self . storage . modified_set . register ( )
281
306
}
282
307
283
308
pub fn deregister ( & mut self , offset : ms:: Offset < I > ) {
284
- self . modified_set . deregister ( offset) ;
309
+ self . storage . modified_set . deregister ( offset) ;
285
310
}
286
311
287
312
pub fn watch_variable ( & mut self , index : I ) {
288
313
debug_assert ! ( index == self . relations( ) . find( index) . into( ) ) ;
289
- self . unify_log . watch_variable ( index)
314
+ self . storage . unify_log . watch_variable ( index)
290
315
}
291
316
292
317
pub fn unwatch_variable ( & mut self , index : I ) {
293
- self . unify_log . unwatch_variable ( index)
318
+ self . storage . unify_log . unwatch_variable ( index)
294
319
}
295
320
296
321
pub fn drain_modified_set ( & mut self , offset : & ms:: Offset < I > , mut f : impl FnMut ( I ) -> bool ) {
297
- let unify_log = & self . unify_log ;
298
- self . modified_set . drain ( & mut self . undo_log , offset, |vid| {
322
+ let unify_log = & self . storage . unify_log ;
323
+ self . storage . modified_set . drain ( & mut self . undo_log , offset, |vid| {
299
324
for & unified_vid in unify_log. get ( vid) {
300
325
f ( unified_vid) ;
301
326
}
0 commit comments