@@ -11,7 +11,7 @@ use syntax::ast::Mutability;
1111use syntax:: source_map:: Span ;
1212
1313use 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 } ;
1515
1616trait SnapshotContext < ' a > {
1717 type To ;
@@ -24,6 +24,20 @@ trait Snapshot<'a, Ctx: SnapshotContext<'a>> {
2424 fn snapshot ( & self , ctx : & ' a Ctx ) -> Self :: Item ;
2525}
2626
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+
2741#[ derive( Eq , PartialEq ) ]
2842struct AllocIdSnapshot < ' a > ( Option < AllocationSnapshot < ' a > > ) ;
2943
@@ -124,22 +138,6 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for Place
124138 }
125139}
126140
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-
143141type ValueSnapshot < ' a > = Value < AllocIdSnapshot < ' a > > ;
144142
145143impl < ' a , Ctx > Snapshot < ' a , Ctx > for Value
@@ -203,7 +201,7 @@ struct AllocationSnapshot<'a> {
203201 relocations : RelocationsSnapshot < ' a > ,
204202 undef_mask : & ' a UndefMask ,
205203 align : & ' a Align ,
206- runtime_mutability : & ' a Mutability ,
204+ mutability : & ' a Mutability ,
207205}
208206
209207impl < ' a , Ctx > Snapshot < ' a , Ctx > for & ' a Allocation
@@ -212,20 +210,20 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
212210 type Item = AllocationSnapshot < ' a > ;
213211
214212 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 ;
216214
217215 AllocationSnapshot {
218216 bytes,
219217 undef_mask,
220218 align,
221- runtime_mutability ,
219+ mutability ,
222220 relocations : relocations. snapshot ( ctx) ,
223221 }
224222 }
225223}
226224
227225#[ derive( Eq , PartialEq ) ]
228- struct FrameSnapshot < ' a , ' tcx > {
226+ struct FrameSnapshot < ' a , ' tcx : ' a > {
229227 instance : & ' a ty:: Instance < ' tcx > ,
230228 span : & ' a Span ,
231229 return_to_block : & ' a StackPopCleanup ,
@@ -269,6 +267,15 @@ struct MemorySnapshot<'a, 'mir: 'a, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx> + 'a
269267 data : & ' a M :: MemoryData ,
270268}
271269
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+
272279impl < ' a , ' b , ' mir , ' tcx , M > SnapshotContext < ' b > for Memory < ' a , ' mir , ' tcx , M >
273280 where M : Machine < ' mir , ' tcx > ,
274281{
@@ -280,7 +287,6 @@ impl<'a, 'b, 'mir, 'tcx, M> SnapshotContext<'b> for Memory<'a, 'mir, 'tcx, M>
280287}
281288
282289/// The virtual machine state during const-evaluation at a given point in time.
283- #[ derive( Eq , PartialEq ) ]
284290pub struct EvalSnapshot < ' a , ' mir , ' tcx : ' a + ' mir , M : Machine < ' mir , ' tcx > > {
285291 machine : M ,
286292 memory : Memory < ' a , ' mir , ' tcx , M > ,
@@ -297,6 +303,11 @@ impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M>
297303 stack : stack. into ( ) ,
298304 }
299305 }
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+ }
300311}
301312
302313impl < ' 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
319330 ( machine, & memory. data , stack) . hash_stable ( hcx, hasher) ;
320331 }
321332}
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