1
Fork 0

interpret: sanity-check that required_consts captures all consts that can fail

This commit is contained in:
Ralf Jung 2024-03-14 07:28:25 +01:00
parent b2b617a88e
commit bf021ea625
7 changed files with 62 additions and 34 deletions

View file

@ -46,6 +46,12 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
type MemoryKind = !;
const PANIC_ON_ALLOC_FAIL: bool = true;
#[inline(always)]
fn all_required_consts_are_checked(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
// We want to just eval random consts in the program, so `eval_mir_const` can fail.
false
}
#[inline(always)]
fn enforce_alignment(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
false // no reason to enforce alignment

View file

@ -375,6 +375,20 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
const PANIC_ON_ALLOC_FAIL: bool = false; // will be raised as a proper error
#[inline]
fn all_required_consts_are_checked(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
// Generally we expect required_consts to be properly filled, except for promoteds where
// storing these consts shows up negatively in benchmarks. A promoted can only be relevant
// if its parent MIR is relevant, and the consts in the promoted will be in the parent's
// `required_consts`, so we are still sure to catch any const-eval bugs, just a bit less
// directly.
if ecx.frame_idx() == 0 && ecx.frame().body.source.promoted.is_some() {
false
} else {
true
}
}
#[inline(always)]
fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
matches!(ecx.machine.check_alignment, CheckAlignment::Error)