Skip to content
Permalink
Browse files

Machine: make self-like parameters come first

  • Loading branch information...
RalfJung committed Jul 2, 2019
1 parent b43eb42 commit 8ad28cd2cb77758cc0a77555db5c03648fc8cd3f
Showing with 16 additions and 16 deletions.
  1. +4 −4 src/librustc_mir/const_eval.rs
  2. +6 −6 src/librustc_mir/interpret/machine.rs
  3. +6 −6 src/librustc_mir/interpret/memory.rs
@@ -11,7 +11,7 @@ use rustc::hir::def::DefKind;
use rustc::hir::def_id::DefId;
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
use rustc::mir;
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
use rustc::ty::{self, TyCtxt};
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
use rustc::ty::subst::Subst;
use rustc::traits::Reveal;
@@ -398,27 +398,27 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
}

fn find_foreign_static(
_tcx: TyCtxt<'tcx>,
_def_id: DefId,
_tcx: TyCtxtAt<'tcx>,
) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
err!(ReadForeignStatic)
}

#[inline(always)]
fn tag_allocation<'b>(
_memory: &Memory<'mir, 'tcx, Self>,
_id: AllocId,
alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<!>>,
_memory: &Memory<'mir, 'tcx, Self>,
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
// We do not use a tag so we can just cheaply forward the allocation
(alloc, ())
}

#[inline(always)]
fn tag_static_base_pointer(
_id: AllocId,
_memory: &Memory<'mir, 'tcx, Self>,
_id: AllocId,
) -> Self::PointerTag {
()
}
@@ -7,7 +7,7 @@ use std::hash::Hash;

use rustc::hir::def_id::DefId;
use rustc::mir;
use rustc::ty::{self, query::TyCtxtAt};
use rustc::ty::{self, TyCtxt};

use super::{
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
@@ -136,8 +136,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
///
/// This allocation will then be fed to `tag_allocation` to initialize the "extra" state.
fn find_foreign_static(
tcx: TyCtxt<'tcx>,
def_id: DefId,
tcx: TyCtxtAt<'tcx>,
) -> InterpResult<'tcx, Cow<'tcx, Allocation>>;

/// Called for all binary operations on integer(-like) types when one operand is a pointer
@@ -174,10 +174,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// For static allocations, the tag returned must be the same as the one returned by
/// `tag_static_base_pointer`.
fn tag_allocation<'b>(
memory: &Memory<'mir, 'tcx, Self>,
id: AllocId,
alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKinds>>,
memory: &Memory<'mir, 'tcx, Self>,
) -> (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
@@ -186,8 +186,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Be aware that requesting the `Allocation` for that `id` will lead to cycles
/// for cyclic statics!
fn tag_static_base_pointer(
id: AllocId,
memory: &Memory<'mir, 'tcx, Self>,
id: AllocId,
) -> Self::PointerTag;

/// Executes a retagging operation
@@ -210,8 +210,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
) -> InterpResult<'tcx>;

fn int_to_ptr(
int: u64,
_mem: &Memory<'mir, 'tcx, Self>,
int: u64,
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
if int == 0 {
err!(InvalidNullPointerUsage)
@@ -221,8 +221,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
}

fn ptr_to_int(
_ptr: Pointer<Self::PointerTag>,
_mem: &Memory<'mir, 'tcx, Self>,
_ptr: Pointer<Self::PointerTag>,
) -> InterpResult<'tcx, u64> {
err!(ReadPointerAsBytes)
}
@@ -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(&self, ptr.alloc_id))
}

pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
@@ -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(&self, id, Cow::Owned(alloc), Some(kind));
self.alloc_map.insert(id, (kind, alloc.into_owned()));
Pointer::from(id).with_tag(tag)
}
@@ -384,7 +384,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// We got a "lazy" static that has not been computed yet.
if tcx.is_foreign_item(def_id) {
trace!("static_alloc: foreign item {:?}", def_id);
M::find_foreign_static(def_id, tcx)?
M::find_foreign_static(tcx.tcx, def_id)?
} else {
trace!("static_alloc: Need to compute {:?}", def_id);
let instance = Instance::mono(tcx.tcx, def_id);
@@ -414,10 +414,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// We got tcx memory. Let the machine figure out whether and how to
// turn that into memory with the right pointer tag.
Ok(M::tag_allocation(
memory,
id, // always use the ID we got as input, not the "hidden" one.
alloc,
M::STATIC_KIND.map(MemoryKind::Machine),
memory
).0)
}

@@ -890,7 +890,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(&self, scalar.to_usize(self)?)
}
}

@@ -901,7 +901,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(&self, ptr)? as u128)
}
}
}

0 comments on commit 8ad28cd

Please sign in to comment.
You can’t perform that action at this time.