diff --git a/src/error.rs b/src/error.rs index 9952cfd9a7e8..2d723e692352 100644 --- a/src/error.rs +++ b/src/error.rs @@ -30,9 +30,9 @@ pub enum EvalError<'tcx> { Math(Span, ConstMathErr), InvalidChar(u32), OutOfMemory { - allocation_size: u64, - memory_size: u64, - memory_usage: u64, + allocation_size: usize, + memory_size: usize, + memory_usage: usize, }, ExecutionTimeLimitReached, StackFrameLimitReached, diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 34fa9d8de6fd..04d7d9f9d050 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -136,8 +136,7 @@ enum ConstantKind { } impl<'a, 'tcx> EvalContext<'a, 'tcx> { - pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, memory_size: u64, stack_limit: u64) -> Self { - assert_eq!(stack_limit as usize as u64, stack_limit); + pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, memory_size: usize, stack_limit: usize) -> Self { EvalContext { tcx: tcx, mir_map: mir_map, @@ -145,7 +144,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { memory: Memory::new(&tcx.data_layout, memory_size), statics: HashMap::new(), stack: Vec::new(), - stack_limit: stack_limit as usize, + stack_limit: stack_limit, } } @@ -937,9 +936,9 @@ pub fn eval_main<'a, 'tcx: 'a>( tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, node_id: ast::NodeId, - memory_size: u64, + memory_size: usize, step_limit: u64, - stack_limit: u64, + stack_limit: usize, ) { let mir = mir_map.map.get(&node_id).expect("no mir for main function"); let def_id = tcx.map.local_def_id(node_id); diff --git a/src/memory.rs b/src/memory.rs index 2453b1f6e67a..79130b4e24b1 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -67,9 +67,9 @@ pub struct Memory<'a, 'tcx> { /// Actual memory allocations (arbitrary bytes, may contain pointers into other allocations) alloc_map: HashMap, /// Number of virtual bytes allocated - memory_usage: u64, + memory_usage: usize, /// Maximum number of virtual bytes that may be allocated - memory_size: u64, + memory_size: usize, /// Function "allocations". They exist solely so pointers have something to point to, and /// we can figure out what they point to. functions: HashMap>, @@ -82,7 +82,7 @@ pub struct Memory<'a, 'tcx> { const ZST_ALLOC_ID: AllocId = AllocId(0); impl<'a, 'tcx> Memory<'a, 'tcx> { - pub fn new(layout: &'a TargetDataLayout, max_memory: u64) -> Self { + pub fn new(layout: &'a TargetDataLayout, max_memory: usize) -> Self { let mut mem = Memory { alloc_map: HashMap::new(), functions: HashMap::new(), @@ -137,14 +137,14 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { if size == 0 { return Ok(Pointer::zst_ptr()); } - if self.memory_size - self.memory_usage < size as u64 { + if self.memory_size - self.memory_usage < size { return Err(EvalError::OutOfMemory { - allocation_size: size as u64, + allocation_size: size, memory_size: self.memory_size, memory_usage: self.memory_usage, }); } - self.memory_usage += size as u64; + self.memory_usage += size; let alloc = Allocation { bytes: vec![0; size], relocations: BTreeMap::new(), @@ -174,14 +174,14 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { if new_size > size { let amount = new_size - size; - self.memory_usage += amount as u64; + self.memory_usage += amount; let alloc = self.get_mut(ptr.alloc_id)?; alloc.bytes.extend(iter::repeat(0).take(amount)); alloc.undef_mask.grow(amount, false); } else if size > new_size { // it's possible to cause miri to use arbitrary amounts of memory that aren't detectable // through the memory_usage value, by allocating a lot and reallocating to zero - self.memory_usage -= (size - new_size) as u64; + self.memory_usage -= size - new_size; self.clear_relocations(ptr.offset(new_size as isize), size - new_size)?; let alloc = self.get_mut(ptr.alloc_id)?; alloc.bytes.truncate(new_size); @@ -202,7 +202,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { } if let Some(alloc) = self.alloc_map.remove(&ptr.alloc_id) { - self.memory_usage -= alloc.bytes.len() as u64; + self.memory_usage -= alloc.bytes.len(); } else { debug!("deallocated a pointer twice: {}", ptr.alloc_id); // TODO(solson): Report error about erroneous free. This is blocked on properly tracking