Skip to content

Commit

Permalink
Revert "Auto merge of rust-lang#62003 - christianpoveda:master, r=oli…
Browse files Browse the repository at this point in the history
…-obk"

This reverts commit 56a12b2, reversing
changes made to dbec74f.
  • Loading branch information
RalfJung committed Jul 1, 2019
1 parent 0af8e87 commit 269866b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::interpret::{self,
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar,
RawConst, ConstValue,
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpretCx, StackPopCleanup,
Allocation, AllocId, MemoryKind, Memory,
Allocation, AllocId, MemoryKind,
snapshot, RefTracking, intern_const_alloc_recursive,
};

Expand Down Expand Up @@ -409,7 +409,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
_id: AllocId,
alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<!>>,
_memory: &Memory<'mir, 'tcx, Self>,
_memory_extra: &(),
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
// We do not use a tag so we can just cheaply forward the allocation
(alloc, ())
Expand All @@ -418,7 +418,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
#[inline(always)]
fn tag_static_base_pointer(
_id: AllocId,
_memory: &Memory<'mir, 'tcx, Self>,
_memory_extra: &(),
) -> Self::PointerTag {
()
}
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use rustc::ty::{self, query::TyCtxtAt};

use super::{
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer,
InterpErrorInfo, InterpError
};

/// Whether this kind of memory is allowed to leak
Expand Down Expand Up @@ -177,7 +178,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
id: AllocId,
alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKinds>>,
memory: &Memory<'mir, 'tcx, Self>,
memory_extra: &Self::MemoryExtra,
) -> (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
Expand All @@ -187,7 +188,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// for cyclic statics!
fn tag_static_base_pointer(
id: AllocId,
memory: &Memory<'mir, 'tcx, Self>,
memory_extra: &Self::MemoryExtra,
) -> Self::PointerTag;

/// Executes a retagging operation
Expand All @@ -211,19 +212,19 @@ pub trait Machine<'mir, 'tcx>: Sized {

fn int_to_ptr(
int: u64,
_mem: &Memory<'mir, 'tcx, Self>,
_extra: &Self::MemoryExtra,
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
if int == 0 {
err!(InvalidNullPointerUsage)
Err(InterpErrorInfo::from(InterpError::InvalidNullPointerUsage))
} else {
err!(ReadBytesAsPointer)
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer))
}
}

fn ptr_to_int(
_ptr: Pointer<Self::PointerTag>,
_mem: &Memory<'mir, 'tcx, Self>,
_extra: &Self::MemoryExtra,
) -> InterpResult<'tcx, u64> {
err!(ReadPointerAsBytes)
Err(InterpErrorInfo::from(InterpError::ReadPointerAsBytes))
}
}
18 changes: 9 additions & 9 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {

#[inline]
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self))
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self.extra))
}

pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
kind: MemoryKind<M::MemoryKinds>,
) -> Pointer<M::PointerTag> {
let id = self.tcx.alloc_map.lock().reserve();
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self);
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self.extra);
self.alloc_map.insert(id, (kind, alloc.into_owned()));
Pointer::from(id).with_tag(tag)
}
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
fn get_static_alloc(
id: AllocId,
tcx: TyCtxtAt<'tcx>,
memory: &Memory<'mir, 'tcx, M>,
memory_extra: &M::MemoryExtra,
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
let alloc = tcx.alloc_map.lock().get(id);
let alloc = match alloc {
Expand Down Expand Up @@ -414,7 +414,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
id, // always use the ID we got as input, not the "hidden" one.
alloc,
M::STATIC_KIND.map(MemoryKind::Machine),
memory
memory_extra
).0)
}

Expand All @@ -427,7 +427,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// `get_static_alloc` that we can actually use directly without inserting anything anywhere.
// So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`.
let a = self.alloc_map.get_or(id, || {
let alloc = Self::get_static_alloc(id, self.tcx, &self).map_err(Err)?;
let alloc = Self::get_static_alloc(id, self.tcx, &self.extra).map_err(Err)?;
match alloc {
Cow::Borrowed(alloc) => {
// We got a ref, cheaply return that as an "error" so that the
Expand Down Expand Up @@ -456,11 +456,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
id: AllocId,
) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> {
let tcx = self.tcx;
let alloc = Self::get_static_alloc(id, tcx, &self);
let memory_extra = &self.extra;
let a = self.alloc_map.get_mut_or(id, || {
// Need to make a copy, even if `get_static_alloc` is able
// to give us a cheap reference.
let alloc = alloc?;
let alloc = Self::get_static_alloc(id, tcx, memory_extra)?;
if alloc.mutability == Mutability::Immutable {
return err!(ModifiedConstantMemory);
}
Expand Down Expand Up @@ -887,7 +887,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
match scalar {
Scalar::Ptr(ptr) => Ok(ptr),
_ => M::int_to_ptr(scalar.to_usize(self)?, self)
_ => M::int_to_ptr(scalar.to_usize(self)?, &self.extra)
}
}

Expand All @@ -898,7 +898,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
) -> InterpResult<'tcx, u128> {
match scalar.to_bits_or_ptr(size, self) {
Ok(bits) => Ok(bits),
Err(ptr) => Ok(M::ptr_to_int(ptr, self)? as u128)
Err(ptr) => Ok(M::ptr_to_int(ptr, &self.extra)? as u128)
}
}
}

0 comments on commit 269866b

Please sign in to comment.