@@ -12,7 +12,6 @@ pub use self::error::{EvalError, EvalResult, EvalErrorKind, AssertMessage};
12
12
13
13
pub use self :: value:: { PrimVal , PrimValKind , Value , Pointer , ConstValue } ;
14
14
15
- use std:: collections:: BTreeMap ;
16
15
use std:: fmt;
17
16
use mir;
18
17
use hir:: def_id:: DefId ;
@@ -21,9 +20,11 @@ use ty::layout::{self, Align, HasDataLayout, Size};
21
20
use middle:: region;
22
21
use std:: iter;
23
22
use std:: io;
23
+ use std:: ops:: { Deref , DerefMut } ;
24
24
use std:: hash:: Hash ;
25
25
use syntax:: ast:: Mutability ;
26
26
use rustc_serialize:: { Encoder , Decoder , Decodable , Encodable } ;
27
+ use rustc_data_structures:: sorted_map:: SortedMap ;
27
28
use rustc_data_structures:: fx:: FxHashMap ;
28
29
use byteorder:: { WriteBytesExt , ReadBytesExt , LittleEndian , BigEndian } ;
29
30
@@ -341,7 +342,7 @@ pub struct Allocation {
341
342
pub bytes : Vec < u8 > ,
342
343
/// Maps from byte addresses to allocations.
343
344
/// Only the first byte of a pointer is inserted into the map.
344
- pub relocations : BTreeMap < Size , AllocId > ,
345
+ pub relocations : Relocations ,
345
346
/// Denotes undefined memory. Reading from undefined memory is forbidden in miri
346
347
pub undef_mask : UndefMask ,
347
348
/// The alignment of the allocation to detect unaligned reads.
@@ -358,7 +359,7 @@ impl Allocation {
358
359
undef_mask. grow ( Size :: from_bytes ( slice. len ( ) as u64 ) , true ) ;
359
360
Self {
360
361
bytes : slice. to_owned ( ) ,
361
- relocations : BTreeMap :: new ( ) ,
362
+ relocations : Relocations :: new ( ) ,
362
363
undef_mask,
363
364
align,
364
365
runtime_mutability : Mutability :: Immutable ,
@@ -373,7 +374,7 @@ impl Allocation {
373
374
assert_eq ! ( size. bytes( ) as usize as u64 , size. bytes( ) ) ;
374
375
Allocation {
375
376
bytes : vec ! [ 0 ; size. bytes( ) as usize ] ,
376
- relocations : BTreeMap :: new ( ) ,
377
+ relocations : Relocations :: new ( ) ,
377
378
undef_mask : UndefMask :: new ( size) ,
378
379
align,
379
380
runtime_mutability : Mutability :: Immutable ,
@@ -383,6 +384,35 @@ impl Allocation {
383
384
384
385
impl < ' tcx > :: serialize:: UseSpecializedDecodable for & ' tcx Allocation { }
385
386
387
+ #[ derive( Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
388
+ pub struct Relocations ( SortedMap < Size , AllocId > ) ;
389
+
390
+ impl Relocations {
391
+ pub fn new ( ) -> Relocations {
392
+ Relocations ( SortedMap :: new ( ) )
393
+ }
394
+
395
+ // The caller must guarantee that the given relocations are already sorted
396
+ // by address and contain no duplicates.
397
+ pub fn from_presorted ( r : Vec < ( Size , AllocId ) > ) -> Relocations {
398
+ Relocations ( SortedMap :: from_presorted_elements ( r) )
399
+ }
400
+ }
401
+
402
+ impl Deref for Relocations {
403
+ type Target = SortedMap < Size , AllocId > ;
404
+
405
+ fn deref ( & self ) -> & Self :: Target {
406
+ & self . 0
407
+ }
408
+ }
409
+
410
+ impl DerefMut for Relocations {
411
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
412
+ & mut self . 0
413
+ }
414
+ }
415
+
386
416
////////////////////////////////////////////////////////////////////////////////
387
417
// Methods to access integers in the target endianness
388
418
////////////////////////////////////////////////////////////////////////////////
0 commit comments