@@ -11,7 +11,7 @@ use syntax::ast::Mutability;
11
11
use syntax:: source_map:: Span ;
12
12
13
13
use super :: eval_context:: { LocalValue , StackPopCleanup } ;
14
- use super :: { Frame , Memory , Machine , Operand , MemPlace , Place , PlaceExtra , Value } ;
14
+ use super :: { Frame , Memory , Machine , Operand , MemPlace , Place , Value } ;
15
15
16
16
trait SnapshotContext < ' a > {
17
17
type To ;
@@ -24,6 +24,20 @@ trait Snapshot<'a, Ctx: SnapshotContext<'a>> {
24
24
fn snapshot ( & self , ctx : & ' a Ctx ) -> Self :: Item ;
25
25
}
26
26
27
+ impl < ' a , Ctx , T > Snapshot < ' a , Ctx > for Option < T >
28
+ where Ctx : SnapshotContext < ' a > ,
29
+ T : Snapshot < ' a , Ctx >
30
+ {
31
+ type Item = Option < <T as Snapshot < ' a , Ctx > >:: Item > ;
32
+
33
+ fn snapshot ( & self , ctx : & ' a Ctx ) -> Self :: Item {
34
+ match self {
35
+ Some ( x) => Some ( x. snapshot ( ctx) ) ,
36
+ None => None ,
37
+ }
38
+ }
39
+ }
40
+
27
41
#[ derive( Eq , PartialEq ) ]
28
42
struct AllocIdSnapshot < ' a > ( Option < AllocationSnapshot < ' a > > ) ;
29
43
@@ -124,22 +138,6 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for Place
124
138
}
125
139
}
126
140
127
- type PlaceExtraSnapshot < ' a > = PlaceExtra < AllocIdSnapshot < ' a > > ;
128
-
129
- impl < ' a , Ctx > Snapshot < ' a , Ctx > for PlaceExtra
130
- where Ctx : SnapshotContext < ' a , To =Allocation , From =AllocId > ,
131
- {
132
- type Item = PlaceExtraSnapshot < ' a > ;
133
-
134
- fn snapshot ( & self , ctx : & ' a Ctx ) -> Self :: Item {
135
- match self {
136
- PlaceExtra :: Vtable ( p) => PlaceExtra :: Vtable ( p. snapshot ( ctx) ) ,
137
- PlaceExtra :: Length ( l) => PlaceExtra :: Length ( * l) ,
138
- PlaceExtra :: None => PlaceExtra :: None ,
139
- }
140
- }
141
- }
142
-
143
141
type ValueSnapshot < ' a > = Value < AllocIdSnapshot < ' a > > ;
144
142
145
143
impl < ' a , Ctx > Snapshot < ' a , Ctx > for Value
@@ -203,7 +201,7 @@ struct AllocationSnapshot<'a> {
203
201
relocations : RelocationsSnapshot < ' a > ,
204
202
undef_mask : & ' a UndefMask ,
205
203
align : & ' a Align ,
206
- runtime_mutability : & ' a Mutability ,
204
+ mutability : & ' a Mutability ,
207
205
}
208
206
209
207
impl < ' a , Ctx > Snapshot < ' a , Ctx > for & ' a Allocation
@@ -212,20 +210,20 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
212
210
type Item = AllocationSnapshot < ' a > ;
213
211
214
212
fn snapshot ( & self , ctx : & ' a Ctx ) -> Self :: Item {
215
- let Allocation { bytes, relocations, undef_mask, align, runtime_mutability } = self ;
213
+ let Allocation { bytes, relocations, undef_mask, align, mutability } = self ;
216
214
217
215
AllocationSnapshot {
218
216
bytes,
219
217
undef_mask,
220
218
align,
221
- runtime_mutability ,
219
+ mutability ,
222
220
relocations : relocations. snapshot ( ctx) ,
223
221
}
224
222
}
225
223
}
226
224
227
225
#[ derive( Eq , PartialEq ) ]
228
- struct FrameSnapshot < ' a , ' tcx > {
226
+ struct FrameSnapshot < ' a , ' tcx : ' a > {
229
227
instance : & ' a ty:: Instance < ' tcx > ,
230
228
span : & ' a Span ,
231
229
return_to_block : & ' a StackPopCleanup ,
@@ -269,6 +267,15 @@ struct MemorySnapshot<'a, 'mir: 'a, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx> + 'a
269
267
data : & ' a M :: MemoryData ,
270
268
}
271
269
270
+ impl < ' a , ' mir , ' tcx , M > Memory < ' a , ' mir , ' tcx , M >
271
+ where M : Machine < ' mir , ' tcx > ,
272
+ {
273
+ fn snapshot < ' b : ' a > ( & ' b self ) -> MemorySnapshot < ' b , ' mir , ' tcx , M > {
274
+ let Memory { data, .. } = self ;
275
+ MemorySnapshot { data }
276
+ }
277
+ }
278
+
272
279
impl < ' a , ' b , ' mir , ' tcx , M > SnapshotContext < ' b > for Memory < ' a , ' mir , ' tcx , M >
273
280
where M : Machine < ' mir , ' tcx > ,
274
281
{
@@ -280,7 +287,6 @@ impl<'a, 'b, 'mir, 'tcx, M> SnapshotContext<'b> for Memory<'a, 'mir, 'tcx, M>
280
287
}
281
288
282
289
/// The virtual machine state during const-evaluation at a given point in time.
283
- #[ derive( Eq , PartialEq ) ]
284
290
pub struct EvalSnapshot < ' a , ' mir , ' tcx : ' a + ' mir , M : Machine < ' mir , ' tcx > > {
285
291
machine : M ,
286
292
memory : Memory < ' a , ' mir , ' tcx , M > ,
@@ -297,6 +303,11 @@ impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M>
297
303
stack : stack. into ( ) ,
298
304
}
299
305
}
306
+
307
+ fn snapshot < ' b : ' a > ( & ' b self ) -> ( & ' b M , MemorySnapshot < ' b , ' mir , ' tcx , M > , Vec < FrameSnapshot < ' a , ' tcx > > ) {
308
+ let EvalSnapshot { machine, memory, stack } = self ;
309
+ ( & machine, memory. snapshot ( ) , stack. iter ( ) . map ( |frame| frame. snapshot ( memory) ) . collect ( ) )
310
+ }
300
311
}
301
312
302
313
impl < ' a , ' mir , ' tcx , M > Hash for EvalSnapshot < ' a , ' mir , ' tcx , M >
@@ -319,3 +330,15 @@ impl<'a, 'b, 'mir, 'tcx, M> HashStable<StableHashingContext<'b>> for EvalSnapsho
319
330
( machine, & memory. data , stack) . hash_stable ( hcx, hasher) ;
320
331
}
321
332
}
333
+
334
+ impl < ' a , ' mir , ' tcx , M > Eq for EvalSnapshot < ' a , ' mir , ' tcx , M >
335
+ where M : Machine < ' mir , ' tcx > ,
336
+ { }
337
+
338
+ impl < ' a , ' mir , ' tcx , M > PartialEq for EvalSnapshot < ' a , ' mir , ' tcx , M >
339
+ where M : Machine < ' mir , ' tcx > ,
340
+ {
341
+ fn eq ( & self , other : & Self ) -> bool {
342
+ self . snapshot ( ) == other. snapshot ( )
343
+ }
344
+ }
0 commit comments