提交 d0a746ec 编写于 作者: R Ralf Jung

remove AllocId generalization of Pointer

上级 bd0bacc6
...@@ -101,18 +101,14 @@ fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> { ...@@ -101,18 +101,14 @@ fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> {
impl<T: HasDataLayout> PointerArithmetic for T {} impl<T: HasDataLayout> PointerArithmetic for T {}
/// `Pointer` is generic over the type that represents a reference to `Allocation`s, /// Represents a pointer in the Miri engine.
/// thus making it possible for the most convenient representation to be used in
/// each context.
/// ///
/// Defaults to the index based and loosely coupled `AllocId`. /// `Pointer` is generic over the `Tag` associated with each pointer,
///
/// `Pointer` is also generic over the `Tag` associated with each pointer,
/// which is used to do provenance tracking during execution. /// which is used to do provenance tracking during execution.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
#[derive(HashStable)] #[derive(HashStable)]
pub struct Pointer<Tag = (), Id = AllocId> { pub struct Pointer<Tag = ()> {
pub alloc_id: Id, pub alloc_id: AllocId,
pub offset: Size, pub offset: Size,
pub tag: Tag, pub tag: Tag,
} }
...@@ -123,7 +119,7 @@ pub struct Pointer<Tag = (), Id = AllocId> { ...@@ -123,7 +119,7 @@ pub struct Pointer<Tag = (), Id = AllocId> {
// all the Miri types. // all the Miri types.
// We have to use `Debug` output for the tag, because `()` does not implement // We have to use `Debug` output for the tag, because `()` does not implement
// `Display` so we cannot specialize that. // `Display` so we cannot specialize that.
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> { impl<Tag: fmt::Debug> fmt::Debug for Pointer<Tag> {
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() { if f.alternate() {
write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag) write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
...@@ -133,7 +129,7 @@ impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> { ...@@ -133,7 +129,7 @@ impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> {
} }
} }
// Specialization for no tag // Specialization for no tag
impl<Id: fmt::Debug> fmt::Debug for Pointer<(), Id> { impl fmt::Debug for Pointer<()> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() { if f.alternate() {
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes()) write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())
......
...@@ -89,7 +89,7 @@ pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self { ...@@ -89,7 +89,7 @@ pub fn from_machine_usize(i: u64, cx: &impl HasDataLayout) -> Self {
/// of a simple value or a pointer into another `Allocation` /// of a simple value or a pointer into another `Allocation`
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
#[derive(HashStable)] #[derive(HashStable)]
pub enum Scalar<Tag = (), Id = AllocId> { pub enum Scalar<Tag = ()> {
/// The raw bytes of a simple value. /// The raw bytes of a simple value.
Raw { Raw {
/// The first `size` bytes of `data` are the value. /// The first `size` bytes of `data` are the value.
...@@ -101,7 +101,7 @@ pub enum Scalar<Tag = (), Id = AllocId> { ...@@ -101,7 +101,7 @@ pub enum Scalar<Tag = (), Id = AllocId> {
/// A pointer into an `Allocation`. An `Allocation` in the `memory` module has a list of /// 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 /// 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. /// relocation and its associated offset together as a `Pointer` here.
Ptr(Pointer<Tag, Id>), Ptr(Pointer<Tag>),
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
...@@ -109,7 +109,7 @@ pub enum Scalar<Tag = (), Id = AllocId> { ...@@ -109,7 +109,7 @@ pub enum Scalar<Tag = (), Id = AllocId> {
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for // We want the `Debug` output to be readable as it is used by `derive(Debug)` for
// all the Miri types. // all the Miri types.
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> { impl<Tag: fmt::Debug> fmt::Debug for Scalar<Tag> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Scalar::Ptr(ptr) => write!(f, "{:?}", ptr), Scalar::Ptr(ptr) => write!(f, "{:?}", ptr),
...@@ -542,8 +542,8 @@ fn from(ptr: Pointer<Tag>) -> Self { ...@@ -542,8 +542,8 @@ fn from(ptr: Pointer<Tag>) -> Self {
} }
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)] #[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)]
pub enum ScalarMaybeUndef<Tag = (), Id = AllocId> { pub enum ScalarMaybeUndef<Tag = ()> {
Scalar(Scalar<Tag, Id>), Scalar(Scalar<Tag>),
Undef, Undef,
} }
...@@ -563,7 +563,7 @@ fn from(s: Pointer<Tag>) -> Self { ...@@ -563,7 +563,7 @@ fn from(s: Pointer<Tag>) -> Self {
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for // We want the `Debug` output to be readable as it is used by `derive(Debug)` for
// all the Miri types. // all the Miri types.
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag, Id> { impl<Tag: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
ScalarMaybeUndef::Undef => write!(f, "<uninitialized>"), ScalarMaybeUndef::Undef => write!(f, "<uninitialized>"),
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
use rustc_middle::ich::StableHashingContext; use rustc_middle::ich::StableHashingContext;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::mir::interpret::{ use rustc_middle::mir::interpret::{
sign_extend, truncate, AllocId, FrameInfo, GlobalId, InterpResult, Pointer, Scalar, sign_extend, truncate, FrameInfo, GlobalId, InterpResult, Pointer, Scalar,
}; };
use rustc_middle::ty::layout::{self, TyAndLayout}; use rustc_middle::ty::layout::{self, TyAndLayout};
use rustc_middle::ty::{ use rustc_middle::ty::{
...@@ -103,8 +103,8 @@ pub enum StackPopCleanup { ...@@ -103,8 +103,8 @@ pub enum StackPopCleanup {
/// State of a local variable including a memoized layout /// State of a local variable including a memoized layout
#[derive(Clone, PartialEq, Eq, HashStable)] #[derive(Clone, PartialEq, Eq, HashStable)]
pub struct LocalState<'tcx, Tag = (), Id = AllocId> { pub struct LocalState<'tcx, Tag = ()> {
pub value: LocalValue<Tag, Id>, pub value: LocalValue<Tag>,
/// Don't modify if `Some`, this is only used to prevent computing the layout twice /// Don't modify if `Some`, this is only used to prevent computing the layout twice
#[stable_hasher(ignore)] #[stable_hasher(ignore)]
pub layout: Cell<Option<TyAndLayout<'tcx>>>, pub layout: Cell<Option<TyAndLayout<'tcx>>>,
...@@ -112,7 +112,7 @@ pub struct LocalState<'tcx, Tag = (), Id = AllocId> { ...@@ -112,7 +112,7 @@ pub struct LocalState<'tcx, Tag = (), Id = AllocId> {
/// Current value of a local variable /// Current value of a local variable
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these #[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
pub enum LocalValue<Tag = (), Id = AllocId> { pub enum LocalValue<Tag = ()> {
/// This local is not currently alive, and cannot be used at all. /// This local is not currently alive, and cannot be used at all.
Dead, Dead,
/// This local is alive but not yet initialized. It can be written to /// This local is alive but not yet initialized. It can be written to
...@@ -125,7 +125,7 @@ pub enum LocalValue<Tag = (), Id = AllocId> { ...@@ -125,7 +125,7 @@ pub enum LocalValue<Tag = (), Id = AllocId> {
/// This is an optimization over just always having a pointer here; /// This is an optimization over just always having a pointer here;
/// we can thus avoid doing an allocation when the local just stores /// we can thus avoid doing an allocation when the local just stores
/// immediate values *and* never has its address taken. /// immediate values *and* never has its address taken.
Live(Operand<Tag, Id>), Live(Operand<Tag>),
} }
impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> { impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
use rustc_target::abi::{VariantIdx, Variants}; use rustc_target::abi::{VariantIdx, Variants};
use super::{ use super::{
from_known_layout, sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpCx, from_known_layout, sign_extend, truncate, ConstValue, GlobalId, InterpCx,
InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUndef, InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUndef,
}; };
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
/// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely /// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely
/// defined on `Immediate`, and do not have to work with a `Place`. /// defined on `Immediate`, and do not have to work with a `Place`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)]
pub enum Immediate<Tag = (), Id = AllocId> { pub enum Immediate<Tag = ()> {
Scalar(ScalarMaybeUndef<Tag, Id>), Scalar(ScalarMaybeUndef<Tag>),
ScalarPair(ScalarMaybeUndef<Tag, Id>, ScalarMaybeUndef<Tag, Id>), ScalarPair(ScalarMaybeUndef<Tag>, ScalarMaybeUndef<Tag>),
} }
impl<Tag> From<ScalarMaybeUndef<Tag>> for Immediate<Tag> { impl<Tag> From<ScalarMaybeUndef<Tag>> for Immediate<Tag> {
...@@ -145,9 +145,9 @@ fn deref(&self) -> &Immediate<Tag> { ...@@ -145,9 +145,9 @@ fn deref(&self) -> &Immediate<Tag> {
/// or still in memory. The latter is an optimization, to delay reading that chunk of /// 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. /// memory and to avoid having to store arbitrary-sized data here.
#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)]
pub enum Operand<Tag = (), Id = AllocId> { pub enum Operand<Tag = ()> {
Immediate(Immediate<Tag, Id>), Immediate(Immediate<Tag>),
Indirect(MemPlace<Tag, Id>), Indirect(MemPlace<Tag>),
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
/// Information required for the sound usage of a `MemPlace`. /// Information required for the sound usage of a `MemPlace`.
pub enum MemPlaceMeta<Tag = (), Id = AllocId> { pub enum MemPlaceMeta<Tag = ()> {
/// The unsized payload (e.g. length for slices or vtable pointer for trait objects). /// The unsized payload (e.g. length for slices or vtable pointer for trait objects).
Meta(Scalar<Tag, Id>), Meta(Scalar<Tag>),
/// `Sized` types or unsized `extern type` /// `Sized` types or unsized `extern type`
None, None,
/// The address of this place may not be taken. This protects the `MemPlace` from coming from /// The address of this place may not be taken. This protects the `MemPlace` from coming from
...@@ -32,8 +32,8 @@ pub enum MemPlaceMeta<Tag = (), Id = AllocId> { ...@@ -32,8 +32,8 @@ pub enum MemPlaceMeta<Tag = (), Id = AllocId> {
Poison, Poison,
} }
impl<Tag, Id> MemPlaceMeta<Tag, Id> { impl<Tag> MemPlaceMeta<Tag> {
pub fn unwrap_meta(self) -> Scalar<Tag, Id> { pub fn unwrap_meta(self) -> Scalar<Tag> {
match self { match self {
Self::Meta(s) => s, Self::Meta(s) => s,
Self::None | Self::Poison => { Self::None | Self::Poison => {
...@@ -47,9 +47,7 @@ fn has_meta(self) -> bool { ...@@ -47,9 +47,7 @@ fn has_meta(self) -> bool {
Self::None | Self::Poison => false, Self::None | Self::Poison => false,
} }
} }
}
impl<Tag> MemPlaceMeta<Tag> {
pub fn erase_tag(self) -> MemPlaceMeta<()> { pub fn erase_tag(self) -> MemPlaceMeta<()> {
match self { match self {
Self::Meta(s) => MemPlaceMeta::Meta(s.erase_tag()), Self::Meta(s) => MemPlaceMeta::Meta(s.erase_tag()),
...@@ -60,22 +58,22 @@ pub fn erase_tag(self) -> MemPlaceMeta<()> { ...@@ -60,22 +58,22 @@ pub fn erase_tag(self) -> MemPlaceMeta<()> {
} }
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
pub struct MemPlace<Tag = (), Id = AllocId> { pub struct MemPlace<Tag = ()> {
/// A place may have an integral pointer for ZSTs, and since it might /// A place may have an integral pointer for ZSTs, and since it might
/// be turned back into a reference before ever being dereferenced. /// be turned back into a reference before ever being dereferenced.
/// However, it may never be undef. /// However, it may never be undef.
pub ptr: Scalar<Tag, Id>, pub ptr: Scalar<Tag>,
pub align: Align, pub align: Align,
/// Metadata for unsized places. Interpretation is up to the type. /// Metadata for unsized places. Interpretation is up to the type.
/// Must not be present for sized types, but can be missing for unsized types /// Must not be present for sized types, but can be missing for unsized types
/// (e.g., `extern type`). /// (e.g., `extern type`).
pub meta: MemPlaceMeta<Tag, Id>, pub meta: MemPlaceMeta<Tag>,
} }
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
pub enum Place<Tag = (), Id = AllocId> { pub enum Place<Tag = ()> {
/// A place referring to a value allocated in the `Memory` system. /// A place referring to a value allocated in the `Memory` system.
Ptr(MemPlace<Tag, Id>), Ptr(MemPlace<Tag>),
/// To support alloc-free locals, we are able to write directly to a local. /// To support alloc-free locals, we are able to write directly to a local.
/// (Without that optimization, we'd just always be a `MemPlace`.) /// (Without that optimization, we'd just always be a `MemPlace`.)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册