Skip to content

Commit 2f5c3fd

Browse files
committed
Make vaious allocation related types generic on the allocation id
1 parent 015f470 commit 2f5c3fd

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl<T: layout::HasDataLayout> PointerArithmetic for T {}
134134

135135

136136
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
137-
pub struct Pointer {
138-
pub alloc_id: AllocId,
137+
pub struct Pointer<Id=AllocId> {
138+
pub alloc_id: Id,
139139
pub offset: Size,
140140
}
141141

@@ -543,16 +543,16 @@ impl Allocation {
543543
impl<'tcx> ::serialize::UseSpecializedDecodable for &'tcx Allocation {}
544544

545545
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
546-
pub struct Relocations(SortedMap<Size, AllocId>);
546+
pub struct Relocations<Id=AllocId>(SortedMap<Size, Id>);
547547

548-
impl Relocations {
549-
pub fn new() -> Relocations {
548+
impl<Id> Relocations<Id> {
549+
pub fn new() -> Self {
550550
Relocations(SortedMap::new())
551551
}
552552

553553
// The caller must guarantee that the given relocations are already sorted
554554
// by address and contain no duplicates.
555-
pub fn from_presorted(r: Vec<(Size, AllocId)>) -> Relocations {
555+
pub fn from_presorted(r: Vec<(Size, Id)>) -> Self {
556556
Relocations(SortedMap::from_presorted_elements(r))
557557
}
558558
}

src/librustc/mir/interpret/value.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl From<Pointer> for Scalar {
326326
/// size. Like a range of bytes in an `Allocation`, a `Scalar` can either represent the raw bytes
327327
/// of a simple value or a pointer into another `Allocation`
328328
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
329-
pub enum Scalar {
329+
pub enum Scalar<Id=AllocId> {
330330
/// The raw bytes of a simple value.
331331
Bits {
332332
/// The first `size` bytes are the value.
@@ -338,12 +338,12 @@ pub enum Scalar {
338338
/// A pointer into an `Allocation`. An `Allocation` in the `memory` module has a list of
339339
/// relocations, but a `Scalar` is only large enough to contain one, so we just represent the
340340
/// relocation and its associated offset together as a `Pointer` here.
341-
Ptr(Pointer),
341+
Ptr(Pointer<Id>),
342342
}
343343

344344
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
345-
pub enum ScalarMaybeUndef {
346-
Scalar(Scalar),
345+
pub enum ScalarMaybeUndef<Id=AllocId> {
346+
Scalar(Scalar<Id>),
347347
Undef,
348348
}
349349

src/librustc_mir/interpret/eval_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_data_structures::fx::FxHashSet;
2626
use rustc_data_structures::indexed_vec::IndexVec;
2727
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
2828
use rustc::mir::interpret::{
29-
GlobalId, Scalar, FrameInfo,
29+
GlobalId, Scalar, FrameInfo, AllocId,
3030
EvalResult, EvalErrorKind,
3131
ScalarMaybeUndef,
3232
truncate, sign_extend,
@@ -98,7 +98,7 @@ pub struct Frame<'mir, 'tcx: 'mir> {
9898
/// The locals are stored as `Option<Value>`s.
9999
/// `None` represents a local that is currently dead, while a live local
100100
/// can either directly contain `Scalar` or refer to some part of an `Allocation`.
101-
pub locals: IndexVec<mir::Local, LocalValue>,
101+
pub locals: IndexVec<mir::Local, LocalValue<AllocId>>,
102102

103103
////////////////////////////////////////////////////////////////////////////////
104104
// Current position within the function
@@ -178,13 +178,13 @@ impl<'a> HashStable<StableHashingContext<'a>> for StackPopCleanup {
178178

179179
// State of a local variable
180180
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
181-
pub enum LocalValue {
181+
pub enum LocalValue<Id=AllocId> {
182182
Dead,
183183
// Mostly for convenience, we re-use the `Operand` type here.
184184
// This is an optimization over just always having a pointer here;
185185
// we can thus avoid doing an allocation when the local just stores
186186
// immediate values *and* never has its address taken.
187-
Live(Operand),
187+
Live(Operand<Id>),
188188
}
189189

190190
impl<'tcx> LocalValue {

src/librustc_mir/interpret/operand.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use std::convert::TryInto;
1717
use rustc::{mir, ty};
1818
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt};
1919
use rustc_data_structures::indexed_vec::Idx;
20-
2120
use rustc::mir::interpret::{
22-
GlobalId, ConstValue, Scalar, EvalResult, Pointer, ScalarMaybeUndef, EvalErrorKind
21+
GlobalId, AllocId,
22+
ConstValue, Pointer, Scalar, ScalarMaybeUndef,
23+
EvalResult, EvalErrorKind
2324
};
2425
use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
2526

@@ -31,9 +32,9 @@ use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
3132
/// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely
3233
/// defined on `Value`, and do not have to work with a `Place`.
3334
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
34-
pub enum Value {
35-
Scalar(ScalarMaybeUndef),
36-
ScalarPair(ScalarMaybeUndef, ScalarMaybeUndef),
35+
pub enum Value<Id=AllocId> {
36+
Scalar(ScalarMaybeUndef<Id>),
37+
ScalarPair(ScalarMaybeUndef<Id>, ScalarMaybeUndef<Id>),
3738
}
3839

3940
impl<'tcx> Value {
@@ -106,9 +107,9 @@ impl<'tcx> ::std::ops::Deref for ValTy<'tcx> {
106107
/// or still in memory. The latter is an optimization, to delay reading that chunk of
107108
/// memory and to avoid having to store arbitrary-sized data here.
108109
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
109-
pub enum Operand {
110-
Immediate(Value),
111-
Indirect(MemPlace),
110+
pub enum Operand<Id=AllocId> {
111+
Immediate(Value<Id>),
112+
Indirect(MemPlace<Id>),
112113
}
113114

114115
impl Operand {

src/librustc_mir/interpret/place.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ use rustc_data_structures::indexed_vec::Idx;
2222
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
2323

2424
use rustc::mir::interpret::{
25-
GlobalId, Scalar, EvalResult, Pointer, ScalarMaybeUndef, PointerArithmetic
25+
GlobalId, AllocId, Scalar, EvalResult, Pointer, ScalarMaybeUndef, PointerArithmetic
2626
};
2727
use super::{EvalContext, Machine, Value, ValTy, Operand, OpTy, MemoryKind};
2828

2929
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
30-
pub struct MemPlace {
30+
pub struct MemPlace<Id=AllocId> {
3131
/// A place may have an integral pointer for ZSTs, and since it might
3232
/// be turned back into a reference before ever being dereferenced.
3333
/// However, it may never be undef.
34-
pub ptr: Scalar,
34+
pub ptr: Scalar<Id>,
3535
pub align: Align,
3636
/// Metadata for unsized places. Interpretation is up to the type.
3737
/// Must not be present for sized types, but can be missing for unsized types
3838
/// (e.g. `extern type`).
39-
pub extra: Option<Scalar>,
39+
pub extra: Option<Scalar<Id>>,
4040
}
4141

4242
impl_stable_hash_for!(struct ::interpret::MemPlace {
@@ -46,9 +46,9 @@ impl_stable_hash_for!(struct ::interpret::MemPlace {
4646
});
4747

4848
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
49-
pub enum Place {
49+
pub enum Place<Id=AllocId> {
5050
/// A place referring to a value allocated in the `Memory` system.
51-
Ptr(MemPlace),
51+
Ptr(MemPlace<Id>),
5252

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

0 commit comments

Comments
 (0)