diff --git a/src/librustc_middle/mir/interpret/pointer.rs b/src/librustc_middle/mir/interpret/pointer.rs index 7119cc58087f804d646278583ecdef8d4105f557..848c7fe61d4d7411cfd0f6113703ce8a7bf19b88 100644 --- a/src/librustc_middle/mir/interpret/pointer.rs +++ b/src/librustc_middle/mir/interpret/pointer.rs @@ -101,18 +101,14 @@ fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> { impl PointerArithmetic for T {} -/// `Pointer` is generic over the type that represents a reference to `Allocation`s, -/// thus making it possible for the most convenient representation to be used in -/// each context. +/// Represents a pointer in the Miri engine. /// -/// Defaults to the index based and loosely coupled `AllocId`. -/// -/// `Pointer` is also generic over the `Tag` associated with each pointer, +/// `Pointer` is generic over the `Tag` associated with each pointer, /// which is used to do provenance tracking during execution. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] #[derive(HashStable)] -pub struct Pointer { - pub alloc_id: Id, +pub struct Pointer { + pub alloc_id: AllocId, pub offset: Size, pub tag: Tag, } @@ -123,7 +119,7 @@ pub struct Pointer { // all the Miri types. // We have to use `Debug` output for the tag, because `()` does not implement // `Display` so we cannot specialize that. -impl fmt::Debug for Pointer { +impl fmt::Debug for Pointer { default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag) @@ -133,7 +129,7 @@ impl fmt::Debug for Pointer { } } // Specialization for no tag -impl fmt::Debug for Pointer<(), Id> { +impl fmt::Debug for Pointer<()> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes()) diff --git a/src/librustc_middle/mir/interpret/value.rs b/src/librustc_middle/mir/interpret/value.rs index 0df8a9aa9b04001a42705d3d02661c91b129e87e..ed779d52fb50c96a69c3ccda663ae91fa31ea904 100644 --- a/src/librustc_middle/mir/interpret/value.rs +++ b/src/librustc_middle/mir/interpret/value.rs @@ -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` #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] #[derive(HashStable)] -pub enum Scalar { +pub enum Scalar { /// The raw bytes of a simple value. Raw { /// The first `size` bytes of `data` are the value. @@ -101,7 +101,7 @@ 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), } #[cfg(target_arch = "x86_64")] @@ -109,7 +109,7 @@ pub enum Scalar { // We want the `Debug` output to be readable as it is used by `derive(Debug)` for // all the Miri types. -impl fmt::Debug for Scalar { +impl fmt::Debug for Scalar { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Scalar::Ptr(ptr) => write!(f, "{:?}", ptr), @@ -542,8 +542,8 @@ fn from(ptr: Pointer) -> Self { } #[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)] -pub enum ScalarMaybeUndef { - Scalar(Scalar), +pub enum ScalarMaybeUndef { + Scalar(Scalar), Undef, } @@ -563,7 +563,7 @@ fn from(s: Pointer) -> Self { // We want the `Debug` output to be readable as it is used by `derive(Debug)` for // all the Miri types. -impl fmt::Debug for ScalarMaybeUndef { +impl fmt::Debug for ScalarMaybeUndef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ScalarMaybeUndef::Undef => write!(f, ""), diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 82e1984e4623d69abdbd6b9368eff1dd031d7255..f668bafe0803f02a939b8217f444ffd737afef56 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -11,7 +11,7 @@ use rustc_middle::ich::StableHashingContext; use rustc_middle::mir; 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::{ @@ -103,8 +103,8 @@ pub enum StackPopCleanup { /// State of a local variable including a memoized layout #[derive(Clone, PartialEq, Eq, HashStable)] -pub struct LocalState<'tcx, Tag = (), Id = AllocId> { - pub value: LocalValue, +pub struct LocalState<'tcx, Tag = ()> { + pub value: LocalValue, /// Don't modify if `Some`, this is only used to prevent computing the layout twice #[stable_hasher(ignore)] pub layout: Cell>>, @@ -112,7 +112,7 @@ pub struct LocalState<'tcx, Tag = (), Id = AllocId> { /// Current value of a local variable #[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these -pub enum LocalValue { +pub enum LocalValue { /// This local is not currently alive, and cannot be used at all. Dead, /// This local is alive but not yet initialized. It can be written to @@ -125,7 +125,7 @@ pub enum LocalValue { /// 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), } impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> { diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index b924f20ce7cc83afc855023fd9bf6f2b5e23a9b8..a7107de6c71842a1a720a320aee66f600ecff11e 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -15,7 +15,7 @@ use rustc_target::abi::{VariantIdx, Variants}; 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, }; @@ -27,9 +27,9 @@ /// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely /// defined on `Immediate`, and do not have to work with a `Place`. #[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)] -pub enum Immediate { - Scalar(ScalarMaybeUndef), - ScalarPair(ScalarMaybeUndef, ScalarMaybeUndef), +pub enum Immediate { + Scalar(ScalarMaybeUndef), + ScalarPair(ScalarMaybeUndef, ScalarMaybeUndef), } impl From> for Immediate { @@ -145,9 +145,9 @@ fn deref(&self) -> &Immediate { /// 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, PartialEq, Eq, HashStable, Hash)] -pub enum Operand { - Immediate(Immediate), - Indirect(MemPlace), +pub enum Operand { + Immediate(Immediate), + Indirect(MemPlace), } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index ba17a0b482afc79e7c74179f817c0f22401fee8c..fee9ca0c02e39d3170f4b0eaa1f33fc97c908900 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -20,9 +20,9 @@ #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] /// Information required for the sound usage of a `MemPlace`. -pub enum MemPlaceMeta { +pub enum MemPlaceMeta { /// The unsized payload (e.g. length for slices or vtable pointer for trait objects). - Meta(Scalar), + Meta(Scalar), /// `Sized` types or unsized `extern type` None, /// The address of this place may not be taken. This protects the `MemPlace` from coming from @@ -32,8 +32,8 @@ pub enum MemPlaceMeta { Poison, } -impl MemPlaceMeta { - pub fn unwrap_meta(self) -> Scalar { +impl MemPlaceMeta { + pub fn unwrap_meta(self) -> Scalar { match self { Self::Meta(s) => s, Self::None | Self::Poison => { @@ -47,9 +47,7 @@ fn has_meta(self) -> bool { Self::None | Self::Poison => false, } } -} -impl MemPlaceMeta { pub fn erase_tag(self) -> MemPlaceMeta<()> { match self { Self::Meta(s) => MemPlaceMeta::Meta(s.erase_tag()), @@ -60,22 +58,22 @@ pub fn erase_tag(self) -> MemPlaceMeta<()> { } #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] -pub struct MemPlace { +pub struct MemPlace { /// 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, 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 meta: MemPlaceMeta, + pub meta: MemPlaceMeta, } #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] -pub enum Place { +pub enum Place { /// A place referring to a value allocated in the `Memory` system. - Ptr(MemPlace), + Ptr(MemPlace), /// To support alloc-free locals, we are able to write directly to a local. /// (Without that optimization, we'd just always be a `MemPlace`.)