Skip to content

Commit 56a12b2

Browse files
committed
Auto merge of rust-lang#62003 - christianpoveda:master, r=oli-obk
Replace MemoryExtra by Memory in intptrcast methods r? @RalfJung @oli-obk
2 parents dbec74f + e152c38 commit 56a12b2

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/librustc_mir/const_eval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::interpret::{self,
2424
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar,
2525
RawConst, ConstValue,
2626
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpretCx, StackPopCleanup,
27-
Allocation, AllocId, MemoryKind,
27+
Allocation, AllocId, MemoryKind, Memory,
2828
snapshot, RefTracking, intern_const_alloc_recursive,
2929
};
3030

@@ -410,7 +410,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
410410
_id: AllocId,
411411
alloc: Cow<'b, Allocation>,
412412
_kind: Option<MemoryKind<!>>,
413-
_memory_extra: &(),
413+
_memory: &Memory<'mir, 'tcx, Self>,
414414
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
415415
// We do not use a tag so we can just cheaply forward the allocation
416416
(alloc, ())
@@ -419,7 +419,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
419419
#[inline(always)]
420420
fn tag_static_base_pointer(
421421
_id: AllocId,
422-
_memory_extra: &(),
422+
_memory: &Memory<'mir, 'tcx, Self>,
423423
) -> Self::PointerTag {
424424
()
425425
}

src/librustc_mir/interpret/machine.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use rustc::ty::{self, query::TyCtxtAt};
1111

1212
use super::{
1313
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
14-
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer,
15-
InterpErrorInfo, InterpError
14+
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory
1615
};
1716

1817
/// Whether this kind of memory is allowed to leak
@@ -178,7 +177,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
178177
id: AllocId,
179178
alloc: Cow<'b, Allocation>,
180179
kind: Option<MemoryKind<Self::MemoryKinds>>,
181-
memory_extra: &Self::MemoryExtra,
180+
memory: &Memory<'mir, 'tcx, Self>,
182181
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);
183182

184183
/// Return the "base" tag for the given static allocation: the one that is used for direct
@@ -188,7 +187,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
188187
/// for cyclic statics!
189188
fn tag_static_base_pointer(
190189
id: AllocId,
191-
memory_extra: &Self::MemoryExtra,
190+
memory: &Memory<'mir, 'tcx, Self>,
192191
) -> Self::PointerTag;
193192

194193
/// Executes a retagging operation
@@ -212,19 +211,19 @@ pub trait Machine<'mir, 'tcx>: Sized {
212211

213212
fn int_to_ptr(
214213
int: u64,
215-
_extra: &Self::MemoryExtra,
214+
_mem: &Memory<'mir, 'tcx, Self>,
216215
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
217216
if int == 0 {
218-
Err(InterpErrorInfo::from(InterpError::InvalidNullPointerUsage))
217+
err!(InvalidNullPointerUsage)
219218
} else {
220-
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer))
219+
err!(ReadBytesAsPointer)
221220
}
222221
}
223222

224223
fn ptr_to_int(
225224
_ptr: Pointer<Self::PointerTag>,
226-
_extra: &Self::MemoryExtra,
225+
_mem: &Memory<'mir, 'tcx, Self>,
227226
) -> InterpResult<'tcx, u64> {
228-
Err(InterpErrorInfo::from(InterpError::ReadPointerAsBytes))
227+
err!(ReadPointerAsBytes)
229228
}
230229
}

src/librustc_mir/interpret/memory.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
107107

108108
#[inline]
109109
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
110-
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self.extra))
110+
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self))
111111
}
112112

113113
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
@@ -140,7 +140,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
140140
kind: MemoryKind<M::MemoryKinds>,
141141
) -> Pointer<M::PointerTag> {
142142
let id = self.tcx.alloc_map.lock().reserve();
143-
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self.extra);
143+
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self);
144144
self.alloc_map.insert(id, (kind, alloc.into_owned()));
145145
Pointer::from(id).with_tag(tag)
146146
}
@@ -327,7 +327,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
327327
fn get_static_alloc(
328328
id: AllocId,
329329
tcx: TyCtxtAt<'tcx>,
330-
memory_extra: &M::MemoryExtra,
330+
memory: &Memory<'mir, 'tcx, M>,
331331
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
332332
let alloc = tcx.alloc_map.lock().get(id);
333333
let alloc = match alloc {
@@ -374,7 +374,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
374374
id, // always use the ID we got as input, not the "hidden" one.
375375
alloc,
376376
M::STATIC_KIND.map(MemoryKind::Machine),
377-
memory_extra
377+
memory
378378
).0)
379379
}
380380

@@ -387,7 +387,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
387387
// `get_static_alloc` that we can actually use directly without inserting anything anywhere.
388388
// So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`.
389389
let a = self.alloc_map.get_or(id, || {
390-
let alloc = Self::get_static_alloc(id, self.tcx, &self.extra).map_err(Err)?;
390+
let alloc = Self::get_static_alloc(id, self.tcx, &self).map_err(Err)?;
391391
match alloc {
392392
Cow::Borrowed(alloc) => {
393393
// We got a ref, cheaply return that as an "error" so that the
@@ -416,11 +416,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
416416
id: AllocId,
417417
) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> {
418418
let tcx = self.tcx;
419-
let memory_extra = &self.extra;
419+
let alloc = Self::get_static_alloc(id, tcx, &self);
420420
let a = self.alloc_map.get_mut_or(id, || {
421421
// Need to make a copy, even if `get_static_alloc` is able
422422
// to give us a cheap reference.
423-
let alloc = Self::get_static_alloc(id, tcx, memory_extra)?;
423+
let alloc = alloc?;
424424
if alloc.mutability == Mutability::Immutable {
425425
return err!(ModifiedConstantMemory);
426426
}
@@ -843,7 +843,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
843843
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
844844
match scalar {
845845
Scalar::Ptr(ptr) => Ok(ptr),
846-
_ => M::int_to_ptr(scalar.to_usize(self)?, &self.extra)
846+
_ => M::int_to_ptr(scalar.to_usize(self)?, self)
847847
}
848848
}
849849

@@ -854,7 +854,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
854854
) -> InterpResult<'tcx, u128> {
855855
match scalar.to_bits_or_ptr(size, self) {
856856
Ok(bits) => Ok(bits),
857-
Err(ptr) => Ok(M::ptr_to_int(ptr, &self.extra)? as u128)
857+
Err(ptr) => Ok(M::ptr_to_int(ptr, self)? as u128)
858858
}
859859
}
860860
}

0 commit comments

Comments
 (0)