Skip to content

Commit 269866b

Browse files
committed
Revert "Auto merge of #62003 - christianpoveda:master, r=oli-obk"
This reverts commit 56a12b2, reversing changes made to dbec74f.
1 parent 0af8e87 commit 269866b

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

Diff for: src/librustc_mir/const_eval.rs

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

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

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

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

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

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

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

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

212213
fn int_to_ptr(
213214
int: u64,
214-
_mem: &Memory<'mir, 'tcx, Self>,
215+
_extra: &Self::MemoryExtra,
215216
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
216217
if int == 0 {
217-
err!(InvalidNullPointerUsage)
218+
Err(InterpErrorInfo::from(InterpError::InvalidNullPointerUsage))
218219
} else {
219-
err!(ReadBytesAsPointer)
220+
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer))
220221
}
221222
}
222223

223224
fn ptr_to_int(
224225
_ptr: Pointer<Self::PointerTag>,
225-
_mem: &Memory<'mir, 'tcx, Self>,
226+
_extra: &Self::MemoryExtra,
226227
) -> InterpResult<'tcx, u64> {
227-
err!(ReadPointerAsBytes)
228+
Err(InterpErrorInfo::from(InterpError::ReadPointerAsBytes))
228229
}
229230
}

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

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

118118
#[inline]
119119
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
120-
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self))
120+
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self.extra))
121121
}
122122

123123
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
@@ -150,7 +150,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
150150
kind: MemoryKind<M::MemoryKinds>,
151151
) -> Pointer<M::PointerTag> {
152152
let id = self.tcx.alloc_map.lock().reserve();
153-
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self);
153+
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self.extra);
154154
self.alloc_map.insert(id, (kind, alloc.into_owned()));
155155
Pointer::from(id).with_tag(tag)
156156
}
@@ -367,7 +367,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
367367
fn get_static_alloc(
368368
id: AllocId,
369369
tcx: TyCtxtAt<'tcx>,
370-
memory: &Memory<'mir, 'tcx, M>,
370+
memory_extra: &M::MemoryExtra,
371371
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
372372
let alloc = tcx.alloc_map.lock().get(id);
373373
let alloc = match alloc {
@@ -414,7 +414,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
414414
id, // always use the ID we got as input, not the "hidden" one.
415415
alloc,
416416
M::STATIC_KIND.map(MemoryKind::Machine),
417-
memory
417+
memory_extra
418418
).0)
419419
}
420420

@@ -427,7 +427,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
427427
// `get_static_alloc` that we can actually use directly without inserting anything anywhere.
428428
// So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`.
429429
let a = self.alloc_map.get_or(id, || {
430-
let alloc = Self::get_static_alloc(id, self.tcx, &self).map_err(Err)?;
430+
let alloc = Self::get_static_alloc(id, self.tcx, &self.extra).map_err(Err)?;
431431
match alloc {
432432
Cow::Borrowed(alloc) => {
433433
// We got a ref, cheaply return that as an "error" so that the
@@ -456,11 +456,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
456456
id: AllocId,
457457
) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> {
458458
let tcx = self.tcx;
459-
let alloc = Self::get_static_alloc(id, tcx, &self);
459+
let memory_extra = &self.extra;
460460
let a = self.alloc_map.get_mut_or(id, || {
461461
// Need to make a copy, even if `get_static_alloc` is able
462462
// to give us a cheap reference.
463-
let alloc = alloc?;
463+
let alloc = Self::get_static_alloc(id, tcx, memory_extra)?;
464464
if alloc.mutability == Mutability::Immutable {
465465
return err!(ModifiedConstantMemory);
466466
}
@@ -887,7 +887,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
887887
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
888888
match scalar {
889889
Scalar::Ptr(ptr) => Ok(ptr),
890-
_ => M::int_to_ptr(scalar.to_usize(self)?, self)
890+
_ => M::int_to_ptr(scalar.to_usize(self)?, &self.extra)
891891
}
892892
}
893893

@@ -898,7 +898,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
898898
) -> InterpResult<'tcx, u128> {
899899
match scalar.to_bits_or_ptr(size, self) {
900900
Ok(bits) => Ok(bits),
901-
Err(ptr) => Ok(M::ptr_to_int(ptr, self)? as u128)
901+
Err(ptr) => Ok(M::ptr_to_int(ptr, &self.extra)? as u128)
902902
}
903903
}
904904
}

0 commit comments

Comments
 (0)