about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-03-21 13:53:00 +0100
committerRalf Jung <post@ralfj.de>2024-04-23 23:02:54 +0200
commit173d1bd36be1925c0cb0b0bf55740c26db4ac476 (patch)
treea4ecdef1b76bd546deb5d3346ad378310c62868b /compiler/rustc_const_eval/src
parentbf021ea6258bcd886fae523e8448f3697dd041fe (diff)
downloadrust-173d1bd36be1925c0cb0b0bf55740c26db4ac476.tar.gz
rust-173d1bd36be1925c0cb0b0bf55740c26db4ac476.zip
properly fill a promoted's required_consts
then we can also make all_required_consts_are_checked a constant instead of a function
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/dummy_machine.rs7
-rw-r--r--compiler/rustc_const_eval/src/const_eval/machine.rs14
-rw-r--r--compiler/rustc_const_eval/src/interpret/eval_context.rs4
-rw-r--r--compiler/rustc_const_eval/src/interpret/machine.rs2
4 files changed, 4 insertions, 23 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs b/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs
index de8de021b09..7b6828c6e18 100644
--- a/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs
+++ b/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs
@@ -46,11 +46,8 @@ 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
-    }
+    // We want to just eval random consts in the program, so `eval_mir_const` can fail.
+    const ALL_CONSTS_ARE_PRECHECKED: bool = false;
 
     #[inline(always)]
     fn enforce_alignment(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs
index 2d06460f353..dd835279df3 100644
--- a/compiler/rustc_const_eval/src/const_eval/machine.rs
+++ b/compiler/rustc_const_eval/src/const_eval/machine.rs
@@ -375,20 +375,6 @@ 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)
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs
index 8f7c2580ad4..126d64329f8 100644
--- a/compiler/rustc_const_eval/src/interpret/eval_context.rs
+++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs
@@ -1179,9 +1179,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
         M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
             let const_val = val.eval(*ecx.tcx, ecx.param_env, span).map_err(|err| {
-                if M::all_required_consts_are_checked(self)
-                    && !matches!(err, ErrorHandled::TooGeneric(..))
-                {
+                if M::ALL_CONSTS_ARE_PRECHECKED && !matches!(err, ErrorHandled::TooGeneric(..)) {
                     // Looks like the const is not captued by `required_consts`, that's bad.
                     bug!("interpret const eval failure of {val:?} which is not in required_consts");
                 }
diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs
index e8ecbe089c3..8bc569bed54 100644
--- a/compiler/rustc_const_eval/src/interpret/machine.rs
+++ b/compiler/rustc_const_eval/src/interpret/machine.rs
@@ -142,7 +142,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
 
     /// Determines whether `eval_mir_constant` can never fail because all required consts have
     /// already been checked before.
-    fn all_required_consts_are_checked(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
+    const ALL_CONSTS_ARE_PRECHECKED: bool = true;
 
     /// Whether memory accesses should be alignment-checked.
     fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;