Auto merge of #82338 - RalfJung:interp-error-allocs, r=oli-obk
all InterpError allocate now, so adjust alloc-error-check Cc https://github.com/rust-lang/rust/pull/82116#discussion_r578310770 r? `@oli-obk`
This commit is contained in:
commit
89d32eb1ea
@ -543,12 +543,12 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
|
||||
/// error which will report the first range of bytes which is uninitialized.
|
||||
fn check_init(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
|
||||
self.is_init(ptr, size).or_else(|idx_range| {
|
||||
throw_ub!(InvalidUninitBytes(Some(Box::new(UninitBytesAccess {
|
||||
throw_ub!(InvalidUninitBytes(Some(UninitBytesAccess {
|
||||
access_ptr: ptr.erase_tag(),
|
||||
access_size: size,
|
||||
uninit_ptr: Pointer::new(ptr.alloc_id, idx_range.start),
|
||||
uninit_size: idx_range.end - idx_range.start, // `Size` subtraction
|
||||
}))))
|
||||
})))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ use rustc_macros::HashStable;
|
||||
use rustc_session::CtfeBacktrace;
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_target::abi::{Align, Size};
|
||||
use std::{any::Any, backtrace::Backtrace, fmt, mem};
|
||||
use std::{any::Any, backtrace::Backtrace, fmt};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||
pub enum ErrorHandled {
|
||||
@ -263,7 +263,7 @@ pub enum UndefinedBehaviorInfo<'tcx> {
|
||||
/// Using a string that is not valid UTF-8,
|
||||
InvalidStr(std::str::Utf8Error),
|
||||
/// Using uninitialized data where it is not allowed.
|
||||
InvalidUninitBytes(Option<Box<UninitBytesAccess>>),
|
||||
InvalidUninitBytes(Option<UninitBytesAccess>),
|
||||
/// Working with a local that is not currently live.
|
||||
DeadLocal,
|
||||
/// Data size is not equal to target size.
|
||||
@ -445,7 +445,7 @@ impl dyn MachineStopType {
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
static_assert_size!(InterpError<'_>, 40);
|
||||
static_assert_size!(InterpError<'_>, 72);
|
||||
|
||||
pub enum InterpError<'tcx> {
|
||||
/// The program caused undefined behavior.
|
||||
@ -486,19 +486,14 @@ impl fmt::Debug for InterpError<'_> {
|
||||
}
|
||||
|
||||
impl InterpError<'_> {
|
||||
/// Some errors allocate to be created as they contain free-form strings.
|
||||
/// And sometimes we want to be sure that did not happen as it is a
|
||||
/// waste of resources.
|
||||
pub fn allocates(&self) -> bool {
|
||||
/// Some errors to string formatting even if the error is never printed.
|
||||
/// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors,
|
||||
/// so this method lets us detect them and `bug!` on unexpected errors.
|
||||
pub fn formatted_string(&self) -> bool {
|
||||
match self {
|
||||
// Zero-sized boxes do not allocate.
|
||||
InterpError::MachineStop(b) => mem::size_of_val::<dyn MachineStopType>(&**b) > 0,
|
||||
InterpError::Unsupported(UnsupportedOpInfo::Unsupported(_))
|
||||
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure(_))
|
||||
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_))
|
||||
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some(_))) => {
|
||||
true
|
||||
}
|
||||
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -352,14 +352,6 @@ where
|
||||
error
|
||||
),
|
||||
);
|
||||
// Some errors shouldn't come up because creating them causes
|
||||
// an allocation, which we should avoid. When that happens,
|
||||
// dedicated error variants should be introduced instead.
|
||||
assert!(
|
||||
!error.kind().allocates(),
|
||||
"interning encountered allocating error: {}",
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -466,8 +466,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||
// an allocation, which we should avoid. When that happens,
|
||||
// dedicated error variants should be introduced instead.
|
||||
assert!(
|
||||
!error.kind().allocates(),
|
||||
"const-prop encountered allocating error: {}",
|
||||
!error.kind().formatted_string(),
|
||||
"const-prop encountered formatting error: {}",
|
||||
error
|
||||
);
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user