Make vaious allocation related types generic on the allocation id
This commit is contained in:
parent
015f470daa
commit
2f5c3fde7c
5 changed files with 29 additions and 28 deletions
|
@ -134,8 +134,8 @@ impl<T: layout::HasDataLayout> PointerArithmetic for T {}
|
|||
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub struct Pointer {
|
||||
pub alloc_id: AllocId,
|
||||
pub struct Pointer<Id=AllocId> {
|
||||
pub alloc_id: Id,
|
||||
pub offset: Size,
|
||||
}
|
||||
|
||||
|
@ -543,16 +543,16 @@ impl Allocation {
|
|||
impl<'tcx> ::serialize::UseSpecializedDecodable for &'tcx Allocation {}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub struct Relocations(SortedMap<Size, AllocId>);
|
||||
pub struct Relocations<Id=AllocId>(SortedMap<Size, Id>);
|
||||
|
||||
impl Relocations {
|
||||
pub fn new() -> Relocations {
|
||||
impl<Id> Relocations<Id> {
|
||||
pub fn new() -> Self {
|
||||
Relocations(SortedMap::new())
|
||||
}
|
||||
|
||||
// The caller must guarantee that the given relocations are already sorted
|
||||
// by address and contain no duplicates.
|
||||
pub fn from_presorted(r: Vec<(Size, AllocId)>) -> Relocations {
|
||||
pub fn from_presorted(r: Vec<(Size, Id)>) -> Self {
|
||||
Relocations(SortedMap::from_presorted_elements(r))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -326,7 +326,7 @@ impl From<Pointer> for Scalar {
|
|||
/// size. Like a range of bytes in an `Allocation`, a `Scalar` can either represent the raw bytes
|
||||
/// of a simple value or a pointer into another `Allocation`
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub enum Scalar {
|
||||
pub enum Scalar<Id=AllocId> {
|
||||
/// The raw bytes of a simple value.
|
||||
Bits {
|
||||
/// The first `size` bytes are the value.
|
||||
|
@ -338,12 +338,12 @@ pub enum Scalar {
|
|||
/// A pointer into an `Allocation`. An `Allocation` in the `memory` module has a list of
|
||||
/// relocations, but a `Scalar` is only large enough to contain one, so we just represent the
|
||||
/// relocation and its associated offset together as a `Pointer` here.
|
||||
Ptr(Pointer),
|
||||
Ptr(Pointer<Id>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub enum ScalarMaybeUndef {
|
||||
Scalar(Scalar),
|
||||
pub enum ScalarMaybeUndef<Id=AllocId> {
|
||||
Scalar(Scalar<Id>),
|
||||
Undef,
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
|
||||
use rustc::mir::interpret::{
|
||||
GlobalId, Scalar, FrameInfo,
|
||||
GlobalId, Scalar, FrameInfo, AllocId,
|
||||
EvalResult, EvalErrorKind,
|
||||
ScalarMaybeUndef,
|
||||
truncate, sign_extend,
|
||||
|
@ -98,7 +98,7 @@ pub struct Frame<'mir, 'tcx: 'mir> {
|
|||
/// The locals are stored as `Option<Value>`s.
|
||||
/// `None` represents a local that is currently dead, while a live local
|
||||
/// can either directly contain `Scalar` or refer to some part of an `Allocation`.
|
||||
pub locals: IndexVec<mir::Local, LocalValue>,
|
||||
pub locals: IndexVec<mir::Local, LocalValue<AllocId>>,
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Current position within the function
|
||||
|
@ -178,13 +178,13 @@ impl<'a> HashStable<StableHashingContext<'a>> for StackPopCleanup {
|
|||
|
||||
// State of a local variable
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum LocalValue {
|
||||
pub enum LocalValue<Id=AllocId> {
|
||||
Dead,
|
||||
// Mostly for convenience, we re-use the `Operand` type here.
|
||||
// This is an optimization over just always having a pointer here;
|
||||
// we can thus avoid doing an allocation when the local just stores
|
||||
// immediate values *and* never has its address taken.
|
||||
Live(Operand),
|
||||
Live(Operand<Id>),
|
||||
}
|
||||
|
||||
impl<'tcx> LocalValue {
|
||||
|
|
|
@ -17,9 +17,10 @@ use std::convert::TryInto;
|
|||
use rustc::{mir, ty};
|
||||
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt};
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
||||
use rustc::mir::interpret::{
|
||||
GlobalId, ConstValue, Scalar, EvalResult, Pointer, ScalarMaybeUndef, EvalErrorKind
|
||||
GlobalId, AllocId,
|
||||
ConstValue, Pointer, Scalar, ScalarMaybeUndef,
|
||||
EvalResult, EvalErrorKind
|
||||
};
|
||||
use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
|
||||
|
||||
|
@ -31,9 +32,9 @@ use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
|
|||
/// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely
|
||||
/// defined on `Value`, and do not have to work with a `Place`.
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum Value {
|
||||
Scalar(ScalarMaybeUndef),
|
||||
ScalarPair(ScalarMaybeUndef, ScalarMaybeUndef),
|
||||
pub enum Value<Id=AllocId> {
|
||||
Scalar(ScalarMaybeUndef<Id>),
|
||||
ScalarPair(ScalarMaybeUndef<Id>, ScalarMaybeUndef<Id>),
|
||||
}
|
||||
|
||||
impl<'tcx> Value {
|
||||
|
@ -106,9 +107,9 @@ impl<'tcx> ::std::ops::Deref for ValTy<'tcx> {
|
|||
/// or still in memory. The latter is an optimization, to delay reading that chunk of
|
||||
/// memory and to avoid having to store arbitrary-sized data here.
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum Operand {
|
||||
Immediate(Value),
|
||||
Indirect(MemPlace),
|
||||
pub enum Operand<Id=AllocId> {
|
||||
Immediate(Value<Id>),
|
||||
Indirect(MemPlace<Id>),
|
||||
}
|
||||
|
||||
impl Operand {
|
||||
|
|
|
@ -22,21 +22,21 @@ use rustc_data_structures::indexed_vec::Idx;
|
|||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
|
||||
|
||||
use rustc::mir::interpret::{
|
||||
GlobalId, Scalar, EvalResult, Pointer, ScalarMaybeUndef, PointerArithmetic
|
||||
GlobalId, AllocId, Scalar, EvalResult, Pointer, ScalarMaybeUndef, PointerArithmetic
|
||||
};
|
||||
use super::{EvalContext, Machine, Value, ValTy, Operand, OpTy, MemoryKind};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub struct MemPlace {
|
||||
pub struct MemPlace<Id=AllocId> {
|
||||
/// A place may have an integral pointer for ZSTs, and since it might
|
||||
/// be turned back into a reference before ever being dereferenced.
|
||||
/// However, it may never be undef.
|
||||
pub ptr: Scalar,
|
||||
pub ptr: Scalar<Id>,
|
||||
pub align: Align,
|
||||
/// Metadata for unsized places. Interpretation is up to the type.
|
||||
/// Must not be present for sized types, but can be missing for unsized types
|
||||
/// (e.g. `extern type`).
|
||||
pub extra: Option<Scalar>,
|
||||
pub extra: Option<Scalar<Id>>,
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct ::interpret::MemPlace {
|
||||
|
@ -46,9 +46,9 @@ impl_stable_hash_for!(struct ::interpret::MemPlace {
|
|||
});
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub enum Place {
|
||||
pub enum Place<Id=AllocId> {
|
||||
/// A place referring to a value allocated in the `Memory` system.
|
||||
Ptr(MemPlace),
|
||||
Ptr(MemPlace<Id>),
|
||||
|
||||
/// To support alloc-free locals, we are able to write directly to a local.
|
||||
/// (Without that optimization, we'd just always be a `MemPlace`.)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue