@@ -27,10 +27,13 @@ use rustc::ty::subst::Subst;
27
27
use rustc:: hir:: def_id:: DefId ;
28
28
use rustc:: mir;
29
29
30
+ use rustc_data_structures:: fx:: FxHasher ;
31
+
30
32
use syntax:: ast:: Mutability ;
31
33
use syntax:: codemap:: Span ;
32
34
33
35
use std:: collections:: { HashMap , BTreeMap } ;
36
+ use std:: hash:: { Hash , Hasher } ;
34
37
35
38
pub use rustc:: mir:: interpret:: * ;
36
39
pub use rustc_mir:: interpret:: * ;
@@ -296,7 +299,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
296
299
}
297
300
}
298
301
299
- #[ derive( Default ) ]
302
+ #[ derive( Clone , Default , PartialEq , Eq ) ]
300
303
pub struct Evaluator < ' tcx > {
301
304
/// Environment variables set by `setenv`
302
305
/// Miri does not expose env vars from the host to the emulated program
@@ -306,15 +309,34 @@ pub struct Evaluator<'tcx> {
306
309
pub ( crate ) suspended : HashMap < DynamicLifetime , Vec < ValidationQuery < ' tcx > > > ,
307
310
}
308
311
312
+ impl < ' tcx > Hash for Evaluator < ' tcx > {
313
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
314
+ let Evaluator {
315
+ env_vars,
316
+ suspended : _,
317
+ } = self ;
318
+
319
+ env_vars. iter ( )
320
+ . map ( |( env, ptr) | {
321
+ let mut h = FxHasher :: default ( ) ;
322
+ env. hash ( & mut h) ;
323
+ ptr. hash ( & mut h) ;
324
+ h. finish ( )
325
+ } )
326
+ . fold ( 0u64 , |acc, hash| acc. wrapping_add ( hash) )
327
+ . hash ( state) ;
328
+ }
329
+ }
330
+
309
331
pub type TlsKey = u128 ;
310
332
311
- #[ derive( Copy , Clone , Debug ) ]
333
+ #[ derive( Copy , Clone , Debug , Hash , PartialEq , Eq ) ]
312
334
pub struct TlsEntry < ' tcx > {
313
335
data : Scalar , // Will eventually become a map from thread IDs to `Scalar`s, if we ever support more than one thread.
314
336
dtor : Option < ty:: Instance < ' tcx > > ,
315
337
}
316
338
317
- #[ derive( Default ) ]
339
+ #[ derive( Clone , Default , PartialEq , Eq ) ]
318
340
pub struct MemoryData < ' tcx > {
319
341
/// The Key to use for the next thread-local allocation.
320
342
next_thread_local : TlsKey ,
@@ -331,6 +353,19 @@ pub struct MemoryData<'tcx> {
331
353
statics : HashMap < GlobalId < ' tcx > , AllocId > ,
332
354
}
333
355
356
+ impl < ' tcx > Hash for MemoryData < ' tcx > {
357
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
358
+ let MemoryData {
359
+ next_thread_local : _,
360
+ thread_local,
361
+ locks : _,
362
+ statics : _,
363
+ } = self ;
364
+
365
+ thread_local. hash ( state) ;
366
+ }
367
+ }
368
+
334
369
impl < ' mir , ' tcx : ' mir > Machine < ' mir , ' tcx > for Evaluator < ' tcx > {
335
370
type MemoryData = MemoryData < ' tcx > ;
336
371
type MemoryKinds = memory:: MemoryKind ;
0 commit comments