Skip to content

Commit 752a1a4

Browse files
committed
Updated tag methods for consistency
1 parent 9cc28d4 commit 752a1a4

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Diff for: src/librustc_mir/const_eval.rs

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

@@ -404,7 +404,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
404404
_id: AllocId,
405405
alloc: Cow<'b, Allocation>,
406406
_kind: Option<MemoryKind<!>>,
407-
_memory_extra: &(),
407+
_memory: &Memory<'mir, 'tcx, Self>,
408408
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
409409
// We do not use a tag so we can just cheaply forward the allocation
410410
(alloc, ())
@@ -413,7 +413,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
413413
#[inline(always)]
414414
fn tag_static_base_pointer(
415415
_id: AllocId,
416-
_memory_extra: &(),
416+
_memory: &Memory<'mir, 'tcx, Self>,
417417
) -> Self::PointerTag {
418418
()
419419
}

Diff for: src/librustc_mir/interpret/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
177177
id: AllocId,
178178
alloc: Cow<'b, Allocation>,
179179
kind: Option<MemoryKind<Self::MemoryKinds>>,
180-
memory_extra: &Self::MemoryExtra,
180+
memory: &Memory<'mir, 'tcx, Self>,
181181
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);
182182

183183
/// Return the "base" tag for the given static allocation: the one that is used for direct
@@ -187,7 +187,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
187187
/// for cyclic statics!
188188
fn tag_static_base_pointer(
189189
id: AllocId,
190-
memory_extra: &Self::MemoryExtra,
190+
memory: &Memory<'mir, 'tcx, Self>,
191191
) -> Self::PointerTag;
192192

193193
/// Executes a retagging operation

Diff for: src/librustc_mir/interpret/memory.rs

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

106106
#[inline]
107107
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
108-
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self.extra))
108+
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self))
109109
}
110110

111111
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
@@ -138,7 +138,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
138138
kind: MemoryKind<M::MemoryKinds>,
139139
) -> Pointer<M::PointerTag> {
140140
let id = self.tcx.alloc_map.lock().reserve();
141-
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self.extra);
141+
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self);
142142
self.alloc_map.insert(id, (kind, alloc.into_owned()));
143143
Pointer::from(id).with_tag(tag)
144144
}
@@ -325,7 +325,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
325325
fn get_static_alloc(
326326
id: AllocId,
327327
tcx: TyCtxtAt<'tcx>,
328-
memory_extra: &M::MemoryExtra,
328+
memory: &Memory<'mir, 'tcx, M>,
329329
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
330330
let alloc = tcx.alloc_map.lock().get(id);
331331
let alloc = match alloc {
@@ -372,7 +372,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
372372
id, // always use the ID we got as input, not the "hidden" one.
373373
alloc,
374374
M::STATIC_KIND.map(MemoryKind::Machine),
375-
memory_extra
375+
memory
376376
).0)
377377
}
378378

@@ -385,7 +385,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
385385
// `get_static_alloc` that we can actually use directly without inserting anything anywhere.
386386
// So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`.
387387
let a = self.alloc_map.get_or(id, || {
388-
let alloc = Self::get_static_alloc(id, self.tcx, &self.extra).map_err(Err)?;
388+
let alloc = Self::get_static_alloc(id, self.tcx, &self).map_err(Err)?;
389389
match alloc {
390390
Cow::Borrowed(alloc) => {
391391
// We got a ref, cheaply return that as an "error" so that the
@@ -414,11 +414,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
414414
id: AllocId,
415415
) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> {
416416
let tcx = self.tcx;
417-
let memory_extra = &self.extra;
417+
let alloc = Self::get_static_alloc(id, tcx, &self);
418418
let a = self.alloc_map.get_mut_or(id, || {
419419
// Need to make a copy, even if `get_static_alloc` is able
420420
// to give us a cheap reference.
421-
let alloc = Self::get_static_alloc(id, tcx, memory_extra)?;
421+
let alloc = alloc?;
422422
if alloc.mutability == Mutability::Immutable {
423423
return err!(ModifiedConstantMemory);
424424
}

0 commit comments

Comments
 (0)