Skip to content

Commit 054ed8e

Browse files
committed
Introduce Machine::POST_MONO_CHECKS.
1 parent e5fedce commit 054ed8e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
749749
self.stack_mut().push(frame);
750750

751751
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
752-
for ct in &body.required_consts {
753-
let span = ct.span;
754-
let ct = self.subst_from_current_frame_and_normalize_erasing_regions(ct.literal)?;
755-
self.eval_mir_constant(&ct, Some(span), None)?;
752+
if M::POST_MONO_CHECKS {
753+
for ct in &body.required_consts {
754+
let span = ct.span;
755+
let ct = self.subst_from_current_frame_and_normalize_erasing_regions(ct.literal)?;
756+
self.eval_mir_constant(&ct, Some(span), None)?;
757+
}
756758
}
757759

758760
// done

compiler/rustc_const_eval/src/interpret/machine.rs

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
130130
/// Should the machine panic on allocation failures?
131131
const PANIC_ON_ALLOC_FAIL: bool;
132132

133+
/// Should post-monomorphization checks be run when a stack frame is pushed?
134+
const POST_MONO_CHECKS: bool = true;
135+
133136
/// Whether memory accesses should be alignment-checked.
134137
fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> CheckAlignment;
135138

compiler/rustc_mir_transform/src/const_prop.rs

+3
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ impl ConstPropMachine<'_, '_> {
143143

144144
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> {
145145
compile_time_machine!(<'mir, 'tcx>);
146+
146147
const PANIC_ON_ALLOC_FAIL: bool = true; // all allocations are small (see `MAX_ALLOC_LIMIT`)
147148

149+
const POST_MONO_CHECKS: bool = false; // this MIR is still generic!
150+
148151
type MemoryKind = !;
149152

150153
#[inline(always)]

0 commit comments

Comments
 (0)