@@ -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,8 +20,10 @@ use ty::layout::{self, Align, HasDataLayout};
21
20
use middle:: region;
22
21
use std:: iter;
23
22
use std:: io;
23
+ use std:: ops:: { Deref , DerefMut } ;
24
24
use syntax:: ast:: Mutability ;
25
25
use rustc_serialize:: { Encoder , Decoder , Decodable , Encodable } ;
26
+ use rustc_data_structures:: sorted_map:: SortedMap ;
26
27
use byteorder:: { WriteBytesExt , ReadBytesExt , LittleEndian , BigEndian } ;
27
28
28
29
#[ derive( Clone , Debug , PartialEq , RustcEncodable , RustcDecodable ) ]
@@ -244,7 +245,7 @@ pub struct Allocation {
244
245
pub bytes : Vec < u8 > ,
245
246
/// Maps from byte addresses to allocations.
246
247
/// Only the first byte of a pointer is inserted into the map.
247
- pub relocations : BTreeMap < u64 , AllocId > ,
248
+ pub relocations : Relocations ,
248
249
/// Denotes undefined memory. Reading from undefined memory is forbidden in miri
249
250
pub undef_mask : UndefMask ,
250
251
/// The alignment of the allocation to detect unaligned reads.
@@ -261,7 +262,7 @@ impl Allocation {
261
262
undef_mask. grow ( slice. len ( ) as u64 , true ) ;
262
263
Self {
263
264
bytes : slice. to_owned ( ) ,
264
- relocations : BTreeMap :: new ( ) ,
265
+ relocations : Relocations :: new ( ) ,
265
266
undef_mask,
266
267
align,
267
268
runtime_mutability : Mutability :: Immutable ,
@@ -276,7 +277,7 @@ impl Allocation {
276
277
assert_eq ! ( size as usize as u64 , size) ;
277
278
Allocation {
278
279
bytes : vec ! [ 0 ; size as usize ] ,
279
- relocations : BTreeMap :: new ( ) ,
280
+ relocations : Relocations :: new ( ) ,
280
281
undef_mask : UndefMask :: new ( size) ,
281
282
align,
282
283
runtime_mutability : Mutability :: Immutable ,
@@ -286,6 +287,35 @@ impl Allocation {
286
287
287
288
impl < ' tcx > :: serialize:: UseSpecializedDecodable for & ' tcx Allocation { }
288
289
290
+ #[ derive( Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
291
+ pub struct Relocations ( SortedMap < u64 , AllocId > ) ;
292
+
293
+ impl Relocations {
294
+ pub fn new ( ) -> Relocations {
295
+ Relocations ( SortedMap :: new ( ) )
296
+ }
297
+
298
+ // The caller must guarantee that the given relocations are already sorted
299
+ // by address and contain no duplicates.
300
+ pub fn from_presorted ( r : Vec < ( u64 , AllocId ) > ) -> Relocations {
301
+ Relocations ( SortedMap :: from_presorted_elements ( r) )
302
+ }
303
+ }
304
+
305
+ impl Deref for Relocations {
306
+ type Target = SortedMap < u64 , AllocId > ;
307
+
308
+ fn deref ( & self ) -> & Self :: Target {
309
+ & self . 0
310
+ }
311
+ }
312
+
313
+ impl DerefMut for Relocations {
314
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
315
+ & mut self . 0
316
+ }
317
+ }
318
+
289
319
////////////////////////////////////////////////////////////////////////////////
290
320
// Methods to access integers in the target endianness
291
321
////////////////////////////////////////////////////////////////////////////////
0 commit comments