66// it is not used by the general miri engine, just by CTFE.
77
88use std:: hash:: { Hash , Hasher } ;
9- use std:: mem;
109
11- use rustc:: ich:: { StableHashingContext , StableHashingContextProvider } ;
10+ use rustc:: ich:: StableHashingContextProvider ;
1211use rustc:: mir;
1312use rustc:: mir:: interpret:: {
1413 AllocId , Pointer , Scalar ,
@@ -20,7 +19,7 @@ use rustc::ty::{self, TyCtxt};
2019use rustc:: ty:: layout:: Align ;
2120use rustc_data_structures:: fx:: FxHashSet ;
2221use rustc_data_structures:: indexed_vec:: IndexVec ;
23- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher , StableHasherResult } ;
22+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
2423use syntax:: ast:: Mutability ;
2524use syntax:: source_map:: Span ;
2625
@@ -217,23 +216,10 @@ impl_snapshot_for!(struct MemPlace {
217216 align -> * align, // just copy alignment verbatim
218217} ) ;
219218
220- // Can't use the macro here because that does not support named enum fields.
221- impl < ' a > HashStable < StableHashingContext < ' a > > for Place {
222- fn hash_stable < W : StableHasherResult > (
223- & self , hcx : & mut StableHashingContext < ' a > ,
224- hasher : & mut StableHasher < W > )
225- {
226- mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
227- match self {
228- Place :: Ptr ( mem_place) => mem_place. hash_stable ( hcx, hasher) ,
229-
230- Place :: Local { frame, local } => {
231- frame. hash_stable ( hcx, hasher) ;
232- local. hash_stable ( hcx, hasher) ;
233- } ,
234- }
235- }
236- }
219+ impl_stable_hash_for ! ( enum :: interpret:: Place {
220+ Ptr ( mem_place) ,
221+ Local { frame, local } ,
222+ } ) ;
237223impl < ' a , Ctx > Snapshot < ' a , Ctx > for Place
238224 where Ctx : SnapshotContext < ' a > ,
239225{
@@ -317,20 +303,10 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
317303 }
318304}
319305
320- // Can't use the macro here because that does not support named enum fields.
321- impl < ' a > HashStable < StableHashingContext < ' a > > for StackPopCleanup {
322- fn hash_stable < W : StableHasherResult > (
323- & self ,
324- hcx : & mut StableHashingContext < ' a > ,
325- hasher : & mut StableHasher < W > )
326- {
327- mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
328- match self {
329- StackPopCleanup :: Goto ( ref block) => block. hash_stable ( hcx, hasher) ,
330- StackPopCleanup :: None { cleanup } => cleanup. hash_stable ( hcx, hasher) ,
331- }
332- }
333- }
306+ impl_stable_hash_for ! ( enum :: interpret:: eval_context:: StackPopCleanup {
307+ Goto ( block) ,
308+ None { cleanup } ,
309+ } ) ;
334310
335311#[ derive( Eq , PartialEq ) ]
336312struct FrameSnapshot < ' a , ' tcx : ' a > {
@@ -343,28 +319,17 @@ struct FrameSnapshot<'a, 'tcx: 'a> {
343319 stmt : usize ,
344320}
345321
346- // Not using the macro because that does not support types depending on two lifetimes
347- impl < ' a , ' mir , ' tcx : ' mir > HashStable < StableHashingContext < ' a > > for Frame < ' mir , ' tcx > {
348- fn hash_stable < W : StableHasherResult > (
349- & self ,
350- hcx : & mut StableHashingContext < ' a > ,
351- hasher : & mut StableHasher < W > ) {
352-
353- let Frame {
354- mir,
355- instance,
356- span,
357- return_to_block,
358- return_place,
359- locals,
360- block,
361- stmt,
362- } = self ;
322+ impl_stable_hash_for ! ( impl <' tcx, ' mir: ' tcx> for struct Frame <' mir, ' tcx> {
323+ mir,
324+ instance,
325+ span,
326+ return_to_block,
327+ return_place -> ( return_place. as_ref( ) . map( |r| & * * r) ) ,
328+ locals,
329+ block,
330+ stmt,
331+ } ) ;
363332
364- ( mir, instance, span, return_to_block) . hash_stable ( hcx, hasher) ;
365- ( return_place. as_ref ( ) . map ( |r| & * * r) , locals, block, stmt) . hash_stable ( hcx, hasher) ;
366- }
367- }
368333impl < ' a , ' mir , ' tcx , Ctx > Snapshot < ' a , Ctx > for & ' a Frame < ' mir , ' tcx >
369334 where Ctx : SnapshotContext < ' a > ,
370335{
@@ -443,21 +408,11 @@ impl<'a, 'mir, 'tcx> Hash for EvalSnapshot<'a, 'mir, 'tcx>
443408 }
444409}
445410
446- // Not using the macro because we need special handling for `memory`, which the macro
447- // does not support at the same time as the extra bounds on the type.
448- impl < ' a , ' b , ' mir , ' tcx > HashStable < StableHashingContext < ' b > >
449- for EvalSnapshot < ' a , ' mir , ' tcx >
450- {
451- fn hash_stable < W : StableHasherResult > (
452- & self ,
453- hcx : & mut StableHashingContext < ' b > ,
454- hasher : & mut StableHasher < W > )
455- {
456- // Not hashing memory: Avoid hashing memory all the time during execution
457- let EvalSnapshot { memory : _, stack } = self ;
458- stack. hash_stable ( hcx, hasher) ;
459- }
460- }
411+ impl_stable_hash_for ! ( impl <' tcx, ' b, ' mir> for struct EvalSnapshot <' b, ' mir, ' tcx> {
412+ // Not hashing memory: Avoid hashing memory all the time during execution
413+ memory -> _,
414+ stack,
415+ } ) ;
461416
462417impl < ' a , ' mir , ' tcx > Eq for EvalSnapshot < ' a , ' mir , ' tcx >
463418{ }
0 commit comments