Skip to content

Commit d0a746e

Browse files
committed
remove AllocId generalization of Pointer
1 parent bd0bacc commit d0a746e

File tree

5 files changed

+33
-39
lines changed

5 files changed

+33
-39
lines changed

src/librustc_middle/mir/interpret/pointer.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,14 @@ pub trait PointerArithmetic: HasDataLayout {
101101

102102
impl<T: HasDataLayout> PointerArithmetic for T {}
103103

104-
/// `Pointer` is generic over the type that represents a reference to `Allocation`s,
105-
/// thus making it possible for the most convenient representation to be used in
106-
/// each context.
104+
/// Represents a pointer in the Miri engine.
107105
///
108-
/// Defaults to the index based and loosely coupled `AllocId`.
109-
///
110-
/// `Pointer` is also generic over the `Tag` associated with each pointer,
106+
/// `Pointer` is generic over the `Tag` associated with each pointer,
111107
/// which is used to do provenance tracking during execution.
112108
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
113109
#[derive(HashStable)]
114-
pub struct Pointer<Tag = (), Id = AllocId> {
115-
pub alloc_id: Id,
110+
pub struct Pointer<Tag = ()> {
111+
pub alloc_id: AllocId,
116112
pub offset: Size,
117113
pub tag: Tag,
118114
}
@@ -123,7 +119,7 @@ static_assert_size!(Pointer, 16);
123119
// all the Miri types.
124120
// We have to use `Debug` output for the tag, because `()` does not implement
125121
// `Display` so we cannot specialize that.
126-
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> {
122+
impl<Tag: fmt::Debug> fmt::Debug for Pointer<Tag> {
127123
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128124
if f.alternate() {
129125
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> {
133129
}
134130
}
135131
// Specialization for no tag
136-
impl<Id: fmt::Debug> fmt::Debug for Pointer<(), Id> {
132+
impl fmt::Debug for Pointer<()> {
137133
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138134
if f.alternate() {
139135
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())

src/librustc_middle/mir/interpret/value.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> ConstValue<'tcx> {
8989
/// of a simple value or a pointer into another `Allocation`
9090
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
9191
#[derive(HashStable)]
92-
pub enum Scalar<Tag = (), Id = AllocId> {
92+
pub enum Scalar<Tag = ()> {
9393
/// The raw bytes of a simple value.
9494
Raw {
9595
/// The first `size` bytes of `data` are the value.
@@ -101,15 +101,15 @@ pub enum Scalar<Tag = (), Id = AllocId> {
101101
/// A pointer into an `Allocation`. An `Allocation` in the `memory` module has a list of
102102
/// relocations, but a `Scalar` is only large enough to contain one, so we just represent the
103103
/// relocation and its associated offset together as a `Pointer` here.
104-
Ptr(Pointer<Tag, Id>),
104+
Ptr(Pointer<Tag>),
105105
}
106106

107107
#[cfg(target_arch = "x86_64")]
108108
static_assert_size!(Scalar, 24);
109109

110110
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
111111
// all the Miri types.
112-
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> {
112+
impl<Tag: fmt::Debug> fmt::Debug for Scalar<Tag> {
113113
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114114
match self {
115115
Scalar::Ptr(ptr) => write!(f, "{:?}", ptr),
@@ -542,8 +542,8 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
542542
}
543543

544544
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)]
545-
pub enum ScalarMaybeUndef<Tag = (), Id = AllocId> {
546-
Scalar(Scalar<Tag, Id>),
545+
pub enum ScalarMaybeUndef<Tag = ()> {
546+
Scalar(Scalar<Tag>),
547547
Undef,
548548
}
549549

@@ -563,7 +563,7 @@ impl<Tag> From<Pointer<Tag>> for ScalarMaybeUndef<Tag> {
563563

564564
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
565565
// all the Miri types.
566-
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag, Id> {
566+
impl<Tag: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag> {
567567
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
568568
match self {
569569
ScalarMaybeUndef::Undef => write!(f, "<uninitialized>"),

src/librustc_mir/interpret/eval_context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_macros::HashStable;
1111
use rustc_middle::ich::StableHashingContext;
1212
use rustc_middle::mir;
1313
use rustc_middle::mir::interpret::{
14-
sign_extend, truncate, AllocId, FrameInfo, GlobalId, InterpResult, Pointer, Scalar,
14+
sign_extend, truncate, FrameInfo, GlobalId, InterpResult, Pointer, Scalar,
1515
};
1616
use rustc_middle::ty::layout::{self, TyAndLayout};
1717
use rustc_middle::ty::{
@@ -103,16 +103,16 @@ pub enum StackPopCleanup {
103103

104104
/// State of a local variable including a memoized layout
105105
#[derive(Clone, PartialEq, Eq, HashStable)]
106-
pub struct LocalState<'tcx, Tag = (), Id = AllocId> {
107-
pub value: LocalValue<Tag, Id>,
106+
pub struct LocalState<'tcx, Tag = ()> {
107+
pub value: LocalValue<Tag>,
108108
/// Don't modify if `Some`, this is only used to prevent computing the layout twice
109109
#[stable_hasher(ignore)]
110110
pub layout: Cell<Option<TyAndLayout<'tcx>>>,
111111
}
112112

113113
/// Current value of a local variable
114114
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
115-
pub enum LocalValue<Tag = (), Id = AllocId> {
115+
pub enum LocalValue<Tag = ()> {
116116
/// This local is not currently alive, and cannot be used at all.
117117
Dead,
118118
/// This local is alive but not yet initialized. It can be written to
@@ -125,7 +125,7 @@ pub enum LocalValue<Tag = (), Id = AllocId> {
125125
/// This is an optimization over just always having a pointer here;
126126
/// we can thus avoid doing an allocation when the local just stores
127127
/// immediate values *and* never has its address taken.
128-
Live(Operand<Tag, Id>),
128+
Live(Operand<Tag>),
129129
}
130130

131131
impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {

src/librustc_mir/interpret/operand.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_target::abi::{Abi, DiscriminantKind, HasDataLayout, Integer, LayoutOf,
1515
use rustc_target::abi::{VariantIdx, Variants};
1616

1717
use super::{
18-
from_known_layout, sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpCx,
18+
from_known_layout, sign_extend, truncate, ConstValue, GlobalId, InterpCx,
1919
InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUndef,
2020
};
2121

@@ -27,9 +27,9 @@ use super::{
2727
/// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely
2828
/// defined on `Immediate`, and do not have to work with a `Place`.
2929
#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)]
30-
pub enum Immediate<Tag = (), Id = AllocId> {
31-
Scalar(ScalarMaybeUndef<Tag, Id>),
32-
ScalarPair(ScalarMaybeUndef<Tag, Id>, ScalarMaybeUndef<Tag, Id>),
30+
pub enum Immediate<Tag = ()> {
31+
Scalar(ScalarMaybeUndef<Tag>),
32+
ScalarPair(ScalarMaybeUndef<Tag>, ScalarMaybeUndef<Tag>),
3333
}
3434

3535
impl<Tag> From<ScalarMaybeUndef<Tag>> for Immediate<Tag> {
@@ -145,9 +145,9 @@ impl<'tcx, Tag> ::std::ops::Deref for ImmTy<'tcx, Tag> {
145145
/// or still in memory. The latter is an optimization, to delay reading that chunk of
146146
/// memory and to avoid having to store arbitrary-sized data here.
147147
#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)]
148-
pub enum Operand<Tag = (), Id = AllocId> {
149-
Immediate(Immediate<Tag, Id>),
150-
Indirect(MemPlace<Tag, Id>),
148+
pub enum Operand<Tag = ()> {
149+
Immediate(Immediate<Tag>),
150+
Indirect(MemPlace<Tag>),
151151
}
152152

153153
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]

src/librustc_mir/interpret/place.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use super::{
2020

2121
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
2222
/// Information required for the sound usage of a `MemPlace`.
23-
pub enum MemPlaceMeta<Tag = (), Id = AllocId> {
23+
pub enum MemPlaceMeta<Tag = ()> {
2424
/// The unsized payload (e.g. length for slices or vtable pointer for trait objects).
25-
Meta(Scalar<Tag, Id>),
25+
Meta(Scalar<Tag>),
2626
/// `Sized` types or unsized `extern type`
2727
None,
2828
/// 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> {
3232
Poison,
3333
}
3434

35-
impl<Tag, Id> MemPlaceMeta<Tag, Id> {
36-
pub fn unwrap_meta(self) -> Scalar<Tag, Id> {
35+
impl<Tag> MemPlaceMeta<Tag> {
36+
pub fn unwrap_meta(self) -> Scalar<Tag> {
3737
match self {
3838
Self::Meta(s) => s,
3939
Self::None | Self::Poison => {
@@ -47,9 +47,7 @@ impl<Tag, Id> MemPlaceMeta<Tag, Id> {
4747
Self::None | Self::Poison => false,
4848
}
4949
}
50-
}
5150

52-
impl<Tag> MemPlaceMeta<Tag> {
5351
pub fn erase_tag(self) -> MemPlaceMeta<()> {
5452
match self {
5553
Self::Meta(s) => MemPlaceMeta::Meta(s.erase_tag()),
@@ -60,22 +58,22 @@ impl<Tag> MemPlaceMeta<Tag> {
6058
}
6159

6260
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
63-
pub struct MemPlace<Tag = (), Id = AllocId> {
61+
pub struct MemPlace<Tag = ()> {
6462
/// A place may have an integral pointer for ZSTs, and since it might
6563
/// be turned back into a reference before ever being dereferenced.
6664
/// However, it may never be undef.
67-
pub ptr: Scalar<Tag, Id>,
65+
pub ptr: Scalar<Tag>,
6866
pub align: Align,
6967
/// Metadata for unsized places. Interpretation is up to the type.
7068
/// Must not be present for sized types, but can be missing for unsized types
7169
/// (e.g., `extern type`).
72-
pub meta: MemPlaceMeta<Tag, Id>,
70+
pub meta: MemPlaceMeta<Tag>,
7371
}
7472

7573
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
76-
pub enum Place<Tag = (), Id = AllocId> {
74+
pub enum Place<Tag = ()> {
7775
/// A place referring to a value allocated in the `Memory` system.
78-
Ptr(MemPlace<Tag, Id>),
76+
Ptr(MemPlace<Tag>),
7977

8078
/// To support alloc-free locals, we are able to write directly to a local.
8179
/// (Without that optimization, we'd just always be a `MemPlace`.)

0 commit comments

Comments
 (0)