Auto merge of #62003 - christianpoveda:master, r=oli-obk

Replace MemoryExtra by Memory in intptrcast methods

r? @RalfJung @oli-obk
This commit is contained in:
bors 2019-06-21 06:37:17 +00:00
commit 56a12b2ad0
3 changed files with 20 additions and 21 deletions

View File

@ -24,7 +24,7 @@
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar, PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar,
RawConst, ConstValue, RawConst, ConstValue,
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpretCx, StackPopCleanup, InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpretCx, StackPopCleanup,
Allocation, AllocId, MemoryKind, Allocation, AllocId, MemoryKind, Memory,
snapshot, RefTracking, intern_const_alloc_recursive, snapshot, RefTracking, intern_const_alloc_recursive,
}; };
@ -410,7 +410,7 @@ fn tag_allocation<'b>(
_id: AllocId, _id: AllocId,
alloc: Cow<'b, Allocation>, alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<!>>, _kind: Option<MemoryKind<!>>,
_memory_extra: &(), _memory: &Memory<'mir, 'tcx, Self>,
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) { ) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
// We do not use a tag so we can just cheaply forward the allocation // We do not use a tag so we can just cheaply forward the allocation
(alloc, ()) (alloc, ())
@ -419,7 +419,7 @@ fn tag_allocation<'b>(
#[inline(always)] #[inline(always)]
fn tag_static_base_pointer( fn tag_static_base_pointer(
_id: AllocId, _id: AllocId,
_memory_extra: &(), _memory: &Memory<'mir, 'tcx, Self>,
) -> Self::PointerTag { ) -> Self::PointerTag {
() ()
} }

View File

@ -11,8 +11,7 @@
use super::{ use super::{
Allocation, AllocId, InterpResult, Scalar, AllocationExtra, Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory
InterpErrorInfo, InterpError
}; };
/// Whether this kind of memory is allowed to leak /// Whether this kind of memory is allowed to leak
@ -178,7 +177,7 @@ fn tag_allocation<'b>(
id: AllocId, id: AllocId,
alloc: Cow<'b, Allocation>, alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKinds>>, kind: Option<MemoryKind<Self::MemoryKinds>>,
memory_extra: &Self::MemoryExtra, memory: &Memory<'mir, 'tcx, Self>,
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag); ) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);
/// Return the "base" tag for the given static allocation: the one that is used for direct /// Return the "base" tag for the given static allocation: the one that is used for direct
@ -188,7 +187,7 @@ fn tag_allocation<'b>(
/// for cyclic statics! /// for cyclic statics!
fn tag_static_base_pointer( fn tag_static_base_pointer(
id: AllocId, id: AllocId,
memory_extra: &Self::MemoryExtra, memory: &Memory<'mir, 'tcx, Self>,
) -> Self::PointerTag; ) -> Self::PointerTag;
/// Executes a retagging operation /// Executes a retagging operation
@ -212,19 +211,19 @@ fn stack_pop(
fn int_to_ptr( fn int_to_ptr(
int: u64, int: u64,
_extra: &Self::MemoryExtra, _mem: &Memory<'mir, 'tcx, Self>,
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> { ) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
if int == 0 { if int == 0 {
Err(InterpErrorInfo::from(InterpError::InvalidNullPointerUsage)) err!(InvalidNullPointerUsage)
} else { } else {
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer)) err!(ReadBytesAsPointer)
} }
} }
fn ptr_to_int( fn ptr_to_int(
_ptr: Pointer<Self::PointerTag>, _ptr: Pointer<Self::PointerTag>,
_extra: &Self::MemoryExtra, _mem: &Memory<'mir, 'tcx, Self>,
) -> InterpResult<'tcx, u64> { ) -> InterpResult<'tcx, u64> {
Err(InterpErrorInfo::from(InterpError::ReadPointerAsBytes)) err!(ReadPointerAsBytes)
} }
} }

View File

@ -107,7 +107,7 @@ pub fn new(tcx: TyCtxtAt<'tcx>) -> Self {
#[inline] #[inline]
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> { pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self.extra)) ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self))
} }
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> { pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
@ -140,7 +140,7 @@ pub fn allocate_with(
kind: MemoryKind<M::MemoryKinds>, kind: MemoryKind<M::MemoryKinds>,
) -> Pointer<M::PointerTag> { ) -> Pointer<M::PointerTag> {
let id = self.tcx.alloc_map.lock().reserve(); let id = self.tcx.alloc_map.lock().reserve();
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self.extra); let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self);
self.alloc_map.insert(id, (kind, alloc.into_owned())); self.alloc_map.insert(id, (kind, alloc.into_owned()));
Pointer::from(id).with_tag(tag) Pointer::from(id).with_tag(tag)
} }
@ -327,7 +327,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
fn get_static_alloc( fn get_static_alloc(
id: AllocId, id: AllocId,
tcx: TyCtxtAt<'tcx>, tcx: TyCtxtAt<'tcx>,
memory_extra: &M::MemoryExtra, memory: &Memory<'mir, 'tcx, M>,
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> { ) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
let alloc = tcx.alloc_map.lock().get(id); let alloc = tcx.alloc_map.lock().get(id);
let alloc = match alloc { let alloc = match alloc {
@ -374,7 +374,7 @@ fn get_static_alloc(
id, // always use the ID we got as input, not the "hidden" one. id, // always use the ID we got as input, not the "hidden" one.
alloc, alloc,
M::STATIC_KIND.map(MemoryKind::Machine), M::STATIC_KIND.map(MemoryKind::Machine),
memory_extra memory
).0) ).0)
} }
@ -387,7 +387,7 @@ pub fn get(
// `get_static_alloc` that we can actually use directly without inserting anything anywhere. // `get_static_alloc` that we can actually use directly without inserting anything anywhere.
// So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`. // So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`.
let a = self.alloc_map.get_or(id, || { let a = self.alloc_map.get_or(id, || {
let alloc = Self::get_static_alloc(id, self.tcx, &self.extra).map_err(Err)?; let alloc = Self::get_static_alloc(id, self.tcx, &self).map_err(Err)?;
match alloc { match alloc {
Cow::Borrowed(alloc) => { Cow::Borrowed(alloc) => {
// We got a ref, cheaply return that as an "error" so that the // We got a ref, cheaply return that as an "error" so that the
@ -416,11 +416,11 @@ pub fn get_mut(
id: AllocId, id: AllocId,
) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> { ) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> {
let tcx = self.tcx; let tcx = self.tcx;
let memory_extra = &self.extra; let alloc = Self::get_static_alloc(id, tcx, &self);
let a = self.alloc_map.get_mut_or(id, || { let a = self.alloc_map.get_mut_or(id, || {
// Need to make a copy, even if `get_static_alloc` is able // Need to make a copy, even if `get_static_alloc` is able
// to give us a cheap reference. // to give us a cheap reference.
let alloc = Self::get_static_alloc(id, tcx, memory_extra)?; let alloc = alloc?;
if alloc.mutability == Mutability::Immutable { if alloc.mutability == Mutability::Immutable {
return err!(ModifiedConstantMemory); return err!(ModifiedConstantMemory);
} }
@ -843,7 +843,7 @@ pub fn force_ptr(
) -> InterpResult<'tcx, Pointer<M::PointerTag>> { ) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
match scalar { match scalar {
Scalar::Ptr(ptr) => Ok(ptr), Scalar::Ptr(ptr) => Ok(ptr),
_ => M::int_to_ptr(scalar.to_usize(self)?, &self.extra) _ => M::int_to_ptr(scalar.to_usize(self)?, self)
} }
} }
@ -854,7 +854,7 @@ pub fn force_bits(
) -> InterpResult<'tcx, u128> { ) -> InterpResult<'tcx, u128> {
match scalar.to_bits_or_ptr(size, self) { match scalar.to_bits_or_ptr(size, self) {
Ok(bits) => Ok(bits), Ok(bits) => Ok(bits),
Err(ptr) => Ok(M::ptr_to_int(ptr, &self.extra)? as u128) Err(ptr) => Ok(M::ptr_to_int(ptr, self)? as u128)
} }
} }
} }