1
- use std:: { marker:: PhantomData , ops:: Range } ;
2
-
3
1
use rustc_index:: vec:: Idx ;
4
2
5
3
use crate :: modified_set as ms;
6
4
use crate :: snapshot_vec as sv;
7
5
use crate :: unify as ut;
8
6
use crate :: unify_log as ul;
9
7
10
- use ena:: undo_log:: { Rollback , Snapshots , UndoLogs } ;
8
+ use ena:: undo_log:: { Rollback , UndoLogs } ;
11
9
12
10
pub enum UndoLog < K : ut:: UnifyKey , I = K > {
13
11
Relation ( sv:: UndoLog < ut:: Delegate < K > > ) ,
@@ -33,44 +31,6 @@ impl<K: ut::UnifyKey, I> From<ms::Undo<I>> for UndoLog<K, I> {
33
31
}
34
32
}
35
33
36
- struct Logs < K : ut:: UnifyKey , I > {
37
- logs : Vec < UndoLog < K , I > > ,
38
- num_open_snapshots : usize ,
39
- }
40
-
41
- impl < K : ut:: UnifyKey , I > Default for Logs < K , I > {
42
- fn default ( ) -> Self {
43
- Self { logs : Default :: default ( ) , num_open_snapshots : Default :: default ( ) }
44
- }
45
- }
46
-
47
- impl < T , K : ut:: UnifyKey , I > UndoLogs < T > for Logs < K , I >
48
- where
49
- UndoLog < K , I > : From < T > ,
50
- {
51
- fn num_open_snapshots ( & self ) -> usize {
52
- self . num_open_snapshots
53
- }
54
- fn push ( & mut self , undo : T ) {
55
- if self . in_snapshot ( ) {
56
- self . logs . push ( undo. into ( ) )
57
- }
58
- }
59
- fn clear ( & mut self ) {
60
- self . logs . clear ( ) ;
61
- self . num_open_snapshots = 0 ;
62
- }
63
- fn extend < J > ( & mut self , undos : J )
64
- where
65
- Self : Sized ,
66
- J : IntoIterator < Item = T > ,
67
- {
68
- if self . in_snapshot ( ) {
69
- self . logs . extend ( undos. into_iter ( ) . map ( UndoLog :: from) )
70
- }
71
- }
72
- }
73
-
74
34
impl < K : ut:: UnifyKey , I : Idx > Rollback < UndoLog < K , I > > for LoggedUnificationTableStorage < K , I > {
75
35
fn reverse ( & mut self , undo : UndoLog < K , I > ) {
76
36
match undo {
@@ -81,64 +41,6 @@ impl<K: ut::UnifyKey, I: Idx> Rollback<UndoLog<K, I>> for LoggedUnificationTable
81
41
}
82
42
}
83
43
84
- impl < K : ut:: UnifyKey , I : Idx > Snapshots < UndoLog < K , I > > for Logs < K , I > {
85
- type Snapshot = Snapshot < K , I > ;
86
- fn actions_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> & [ UndoLog < K , I > ] {
87
- & self . logs [ snapshot. undo_len ..]
88
- }
89
-
90
- fn start_snapshot ( & mut self ) -> Self :: Snapshot {
91
- unreachable ! ( )
92
- }
93
-
94
- fn rollback_to < R > ( & mut self , values : impl FnOnce ( ) -> R , snapshot : Self :: Snapshot )
95
- where
96
- R : Rollback < UndoLog < K , I > > ,
97
- {
98
- debug ! ( "rollback_to({})" , snapshot. undo_len) ;
99
- self . assert_open_snapshot ( & snapshot) ;
100
-
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
- }
106
- }
107
-
108
- if self . num_open_snapshots == 1 {
109
- // The root snapshot. It's safe to clear the undo log because
110
- // there's no snapshot further out that we might need to roll back
111
- // to.
112
- assert ! ( snapshot. undo_len == 0 ) ;
113
- self . logs . clear ( ) ;
114
- }
115
-
116
- self . num_open_snapshots -= 1 ;
117
- }
118
-
119
- fn commit ( & mut self , snapshot : Self :: Snapshot ) {
120
- debug ! ( "commit({})" , snapshot. undo_len) ;
121
-
122
- if self . num_open_snapshots == 1 {
123
- // The root snapshot. It's safe to clear the undo log because
124
- // there's no snapshot further out that we might need to roll back
125
- // to.
126
- assert ! ( snapshot. undo_len == 0 ) ;
127
- self . logs . clear ( ) ;
128
- }
129
-
130
- self . num_open_snapshots -= 1 ;
131
- }
132
- }
133
-
134
- impl < K : ut:: UnifyKey , I : Idx > Logs < K , I > {
135
- fn assert_open_snapshot ( & self , snapshot : & Snapshot < K , I > ) {
136
- // Failures here may indicate a failure to follow a stack discipline.
137
- assert ! ( self . logs. len( ) >= snapshot. undo_len) ;
138
- assert ! ( self . num_open_snapshots > 0 ) ;
139
- }
140
- }
141
-
142
44
pub struct LoggedUnificationTableStorage < K : ut:: UnifyKey , I : Idx = K > {
143
45
relations : ut:: UnificationTableStorage < K > ,
144
46
unify_log : ul:: UnifyLog < I > ,
@@ -268,39 +170,10 @@ where
268
170
self . relations ( ) . new_key ( value)
269
171
}
270
172
271
- pub fn vars_since_snapshot ( & mut self , s : & Snapshot < K , I > ) -> Range < K > {
272
- K :: from ( I :: new ( s . value_count ) ) .. K :: from ( I :: new ( self . relations ( ) . len ( ) ) )
173
+ pub fn clear_modified_set ( & mut self ) {
174
+ self . storage . modified_set . clear ( ) ;
273
175
}
274
176
275
- /* FIXME
276
- pub fn snapshot(&mut self) -> Snapshot<K, I> {
277
- self.undo_log.num_open_snapshots += 1;
278
- Snapshot {
279
- undo_len: self.undo_log.logs.len(),
280
- value_count: self.relations().len(),
281
- _marker: PhantomData,
282
- }
283
- }
284
-
285
- pub fn rollback_to(&mut self, snapshot: Snapshot<K, I>) {
286
- let UnificationTableStorage { relations, unify_log, modified_set, .. } = self.storage;
287
-
288
- self.undo_log.rollback_to(|| RollbackView { relations, unify_log, modified_set }, snapshot);
289
-
290
- if self.undo_log.num_open_snapshots == 0 {
291
- self.storage.modified_set.clear();
292
- }
293
- }
294
-
295
- pub fn commit(&mut self, snapshot: Snapshot<K, I>) {
296
- self.undo_log.commit(snapshot);
297
-
298
- if self.undo_log.num_open_snapshots() == 0 {
299
- self.storage.modified_set.clear();
300
- }
301
- }
302
- */
303
-
304
177
pub fn register ( & mut self ) -> ms:: Offset < I > {
305
178
self . storage . modified_set . register ( )
306
179
}
@@ -329,9 +202,3 @@ where
329
202
} )
330
203
}
331
204
}
332
-
333
- pub struct Snapshot < K : ut:: UnifyKey , I : Idx = K > {
334
- undo_len : usize ,
335
- value_count : usize ,
336
- _marker : PhantomData < ( K , I ) > ,
337
- }
0 commit comments