Allocation failure in constprop panics right away
This commit is contained in:
parent
3e20129a18
commit
e9d69d9f8e
6 changed files with 12 additions and 3 deletions
|
@ -126,7 +126,7 @@ impl<Tag> Allocation<Tag> {
|
|||
|
||||
/// Try to create an Allocation of `size` bytes, failing if there is not enough memory
|
||||
/// available to the compiler to do so.
|
||||
pub fn uninit(size: Size, align: Align) -> InterpResult<'static, Self> {
|
||||
pub fn uninit(size: Size, align: Align, panic_on_fail: bool) -> InterpResult<'static, Self> {
|
||||
let mut bytes = Vec::new();
|
||||
bytes.try_reserve(size.bytes_usize()).map_err(|_| {
|
||||
// This results in an error that can happen non-deterministically, since the memory
|
||||
|
@ -134,6 +134,9 @@ impl<Tag> Allocation<Tag> {
|
|||
// deterministic. However, we can be non-determinstic here because all uses of const
|
||||
// evaluation (including ConstProp!) will make compilation fail (via hard error
|
||||
// or ICE) upon encountering a `MemoryExhausted` error.
|
||||
if panic_on_fail {
|
||||
panic!("Allocation::uninit called with panic_on_fail had allocation failure")
|
||||
}
|
||||
ty::tls::with(|tcx| {
|
||||
tcx.sess.delay_span_bug(DUMMY_SP, "exhausted memory during interpreation")
|
||||
});
|
||||
|
|
|
@ -60,7 +60,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let ptr_align = tcx.data_layout.pointer_align.abi;
|
||||
|
||||
let vtable_size = ptr_size * u64::try_from(vtable_entries.len()).unwrap();
|
||||
let mut vtable = Allocation::uninit(vtable_size, ptr_align)?;
|
||||
let mut vtable = Allocation::uninit(vtable_size, ptr_align, true)?;
|
||||
|
||||
// No need to do any alignment checks on the memory accesses below, because we know the
|
||||
// allocation is correctly aligned as we created it above. Also we're only offsetting by
|
||||
|
|
|
@ -201,6 +201,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
|
||||
type MemoryExtra = MemoryExtra;
|
||||
|
||||
const PANIC_ON_ALLOC_FAIL: bool = false; // will be raised as a proper error
|
||||
|
||||
fn load_mir(
|
||||
ecx: &InterpCx<'mir, 'tcx, Self>,
|
||||
instance: ty::InstanceDef<'tcx>,
|
||||
|
|
|
@ -122,6 +122,9 @@ pub trait Machine<'mir, 'tcx>: Sized {
|
|||
/// that is added to the memory so that the work is not done twice.
|
||||
const GLOBAL_KIND: Option<Self::MemoryKind>;
|
||||
|
||||
/// Should the machine panic on allocation failures?
|
||||
const PANIC_ON_ALLOC_FAIL: bool;
|
||||
|
||||
/// Whether memory accesses should be alignment-checked.
|
||||
fn enforce_alignment(memory_extra: &Self::MemoryExtra) -> bool;
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
align: Align,
|
||||
kind: MemoryKind<M::MemoryKind>,
|
||||
) -> InterpResult<'static, Pointer<M::PointerTag>> {
|
||||
let alloc = Allocation::uninit(size, align)?;
|
||||
let alloc = Allocation::uninit(size, align, M::PANIC_ON_ALLOC_FAIL)?;
|
||||
Ok(self.allocate_with(alloc, kind))
|
||||
}
|
||||
|
||||
|
|
|
@ -181,6 +181,7 @@ impl<'mir, 'tcx> ConstPropMachine<'mir, 'tcx> {
|
|||
|
||||
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> {
|
||||
compile_time_machine!(<'mir, 'tcx>);
|
||||
const PANIC_ON_ALLOC_FAIL: bool = true; // all allocations are small
|
||||
|
||||
type MemoryKind = !;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue