Skip to content

Commit

Permalink
Rollup merge of rust-lang#61625 - RalfJung:eval-interp, r=oli-obk
Browse files Browse the repository at this point in the history
Rename remaining "Eval" to "Interp"

Renaming done by sed.

r? @oli-obk

Fixes rust-lang#54395.
  • Loading branch information
Centril authored Jun 7, 2019
2 parents 80bf0ab + 3aca71f commit 86f392c
Show file tree
Hide file tree
Showing 21 changed files with 273 additions and 270 deletions.
46 changes: 23 additions & 23 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The virtual memory representation of the MIR interpreter.

use super::{
Pointer, EvalResult, AllocId, ScalarMaybeUndef, write_target_uint, read_target_uint, Scalar,
Pointer, InterpResult, AllocId, ScalarMaybeUndef, write_target_uint, read_target_uint, Scalar,
};

use crate::ty::layout::{Size, Align};
Expand Down Expand Up @@ -82,7 +82,7 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Clone {
_alloc: &Allocation<Tag, Self>,
_ptr: Pointer<Tag>,
_size: Size,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
Ok(())
}

Expand All @@ -92,7 +92,7 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Clone {
_alloc: &mut Allocation<Tag, Self>,
_ptr: Pointer<Tag>,
_size: Size,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
Ok(())
}

Expand All @@ -103,7 +103,7 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Clone {
_alloc: &mut Allocation<Tag, Self>,
_ptr: Pointer<Tag>,
_size: Size,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
Ok(())
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
&self,
ptr: Pointer<Tag>,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
let allocation_size = self.bytes.len() as u64;
ptr.check_in_alloc(Size::from_bytes(allocation_size), msg)
}
Expand All @@ -169,7 +169,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
ptr: Pointer<Tag>,
size: Size,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
// if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
self.check_bounds_ptr(ptr.offset(size, cx)?, msg)
}
Expand All @@ -191,7 +191,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
size: Size,
check_defined_and_ptr: bool,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx, &[u8]>
) -> InterpResult<'tcx, &[u8]>
{
self.check_bounds(cx, ptr, size, msg)?;

Expand All @@ -217,7 +217,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
) -> EvalResult<'tcx, &[u8]>
) -> InterpResult<'tcx, &[u8]>
{
self.get_bytes_internal(cx, ptr, size, true, CheckInAllocMsg::MemoryAccessTest)
}
Expand All @@ -230,7 +230,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
) -> EvalResult<'tcx, &[u8]>
) -> InterpResult<'tcx, &[u8]>
{
self.get_bytes_internal(cx, ptr, size, false, CheckInAllocMsg::MemoryAccessTest)
}
Expand All @@ -242,7 +242,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
) -> EvalResult<'tcx, &mut [u8]>
) -> InterpResult<'tcx, &mut [u8]>
{
assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
self.check_bounds(cx, ptr, size, CheckInAllocMsg::MemoryAccessTest)?;
Expand All @@ -267,7 +267,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
&self,
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
) -> EvalResult<'tcx, &[u8]>
) -> InterpResult<'tcx, &[u8]>
{
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
let offset = ptr.offset.bytes() as usize;
Expand All @@ -292,7 +292,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
ptr: Pointer<Tag>,
size: Size,
allow_ptr_and_undef: bool,
) -> EvalResult<'tcx>
) -> InterpResult<'tcx>
{
// Check bounds and relocations on the edges
self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
Expand All @@ -312,7 +312,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
src: &[u8],
) -> EvalResult<'tcx>
) -> InterpResult<'tcx>
{
let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64))?;
bytes.clone_from_slice(src);
Expand All @@ -326,7 +326,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
ptr: Pointer<Tag>,
val: u8,
count: Size
) -> EvalResult<'tcx>
) -> InterpResult<'tcx>
{
let bytes = self.get_bytes_mut(cx, ptr, count)?;
for b in bytes {
Expand All @@ -348,7 +348,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size
) -> EvalResult<'tcx, ScalarMaybeUndef<Tag>>
) -> InterpResult<'tcx, ScalarMaybeUndef<Tag>>
{
// get_bytes_unchecked tests relocation edges
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
&self,
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
) -> EvalResult<'tcx, ScalarMaybeUndef<Tag>>
) -> InterpResult<'tcx, ScalarMaybeUndef<Tag>>
{
self.read_scalar(cx, ptr, cx.data_layout().pointer_size)
}
Expand All @@ -402,7 +402,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
ptr: Pointer<Tag>,
val: ScalarMaybeUndef<Tag>,
type_size: Size,
) -> EvalResult<'tcx>
) -> InterpResult<'tcx>
{
let val = match val {
ScalarMaybeUndef::Scalar(scalar) => scalar,
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
val: ScalarMaybeUndef<Tag>
) -> EvalResult<'tcx>
) -> InterpResult<'tcx>
{
let ptr_size = cx.data_layout().pointer_size;
self.write_scalar(cx, ptr.into(), val, ptr_size)
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
if self.relocations(cx, ptr, size).is_empty() {
Ok(())
} else {
Expand All @@ -487,7 +487,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
// Find the start and end of the given range and its outermost relocations.
let (first, last) = {
// Find all relocations overlapping the given range.
Expand Down Expand Up @@ -525,7 +525,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
cx: &impl HasDataLayout,
ptr: Pointer<Tag>,
size: Size,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
self.check_relocations(cx, ptr, Size::ZERO)?;
self.check_relocations(cx, ptr.offset(size, cx)?, Size::ZERO)?;
Ok(())
Expand All @@ -538,7 +538,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
/// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
/// error which will report the first byte which is undefined.
#[inline]
fn check_defined(&self, ptr: Pointer<Tag>, size: Size) -> EvalResult<'tcx> {
fn check_defined(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
self.undef_mask.is_range_defined(
ptr.offset,
ptr.offset + size,
Expand All @@ -550,7 +550,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
ptr: Pointer<Tag>,
size: Size,
new_state: bool,
) -> EvalResult<'tcx> {
) -> InterpResult<'tcx> {
if size.bytes() == 0 {
return Ok(());
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ pub fn struct_error<'a, 'gcx, 'tcx>(
/// a `InterpError`. In `librustc_mir::interpret`, we have the `err!`
/// macro for this
#[derive(Debug, Clone)]
pub struct EvalError<'tcx> {
pub struct InterpErrorInfo<'tcx> {
pub kind: InterpError<'tcx, u64>,
backtrace: Option<Box<Backtrace>>,
}

impl<'tcx> EvalError<'tcx> {
impl<'tcx> InterpErrorInfo<'tcx> {
pub fn print_backtrace(&mut self) {
if let Some(ref mut backtrace) = self.backtrace {
print_backtrace(&mut *backtrace);
Expand All @@ -203,7 +203,7 @@ fn print_backtrace(backtrace: &mut Backtrace) {
eprintln!("\n\nAn error occurred in miri:\n{:?}", backtrace);
}

impl<'tcx> From<InterpError<'tcx, u64>> for EvalError<'tcx> {
impl<'tcx> From<InterpError<'tcx, u64>> for InterpErrorInfo<'tcx> {
fn from(kind: InterpError<'tcx, u64>) -> Self {
let backtrace = match env::var("RUST_CTFE_BACKTRACE") {
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
Expand All @@ -220,7 +220,7 @@ impl<'tcx> From<InterpError<'tcx, u64>> for EvalError<'tcx> {
},
_ => None,
};
EvalError {
InterpErrorInfo {
kind,
backtrace,
}
Expand Down Expand Up @@ -320,7 +320,7 @@ pub enum InterpError<'tcx, O> {
InfiniteLoop,
}

pub type EvalResult<'tcx, T = ()> = Result<T, EvalError<'tcx>>;
pub type InterpResult<'tcx, T = ()> = Result<T, InterpErrorInfo<'tcx>>;

impl<'tcx, O> InterpError<'tcx, O> {
pub fn description(&self) -> &str {
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<'tcx, O> InterpError<'tcx, O> {
}
}

impl<'tcx> fmt::Display for EvalError<'tcx> {
impl<'tcx> fmt::Display for InterpErrorInfo<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.kind)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod allocation;
mod pointer;

pub use self::error::{
EvalError, EvalResult, InterpError, AssertMessage, ConstEvalErr, struct_error,
InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error,
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled,
};

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ty::layout::{self, HasDataLayout, Size};
use rustc_macros::HashStable;

use super::{
AllocId, EvalResult, CheckInAllocMsg
AllocId, InterpResult, CheckInAllocMsg
};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -52,13 +52,13 @@ pub trait PointerArithmetic: layout::HasDataLayout {
}

#[inline]
fn offset<'tcx>(&self, val: u64, i: u64) -> EvalResult<'tcx, u64> {
fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> {
let (res, over) = self.overflowing_offset(val, i);
if over { err!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
}

#[inline]
fn signed_offset<'tcx>(&self, val: u64, i: i64) -> EvalResult<'tcx, u64> {
fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> {
let (res, over) = self.overflowing_signed_offset(val, i128::from(i));
if over { err!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
}
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'tcx, Tag> Pointer<Tag> {
}

#[inline]
pub fn offset(self, i: Size, cx: &impl HasDataLayout) -> EvalResult<'tcx, Self> {
pub fn offset(self, i: Size, cx: &impl HasDataLayout) -> InterpResult<'tcx, Self> {
Ok(Pointer::new_with_tag(
self.alloc_id,
Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?),
Expand All @@ -145,7 +145,7 @@ impl<'tcx, Tag> Pointer<Tag> {
}

#[inline]
pub fn signed_offset(self, i: i64, cx: &impl HasDataLayout) -> EvalResult<'tcx, Self> {
pub fn signed_offset(self, i: i64, cx: &impl HasDataLayout) -> InterpResult<'tcx, Self> {
Ok(Pointer::new_with_tag(
self.alloc_id,
Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?),
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<'tcx, Tag> Pointer<Tag> {
self,
allocation_size: Size,
msg: CheckInAllocMsg,
) -> EvalResult<'tcx, ()> {
) -> InterpResult<'tcx, ()> {
if self.offset > allocation_size {
err!(PointerOutOfBounds {
ptr: self.erase_tag(),
Expand Down
Loading

0 comments on commit 86f392c

Please sign in to comment.