]> git.lizzy.rs Git - rust.git/commitdiff
Don't abort const eval due to long running evals, just warn
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Fri, 13 Apr 2018 15:56:45 +0000 (17:56 +0200)
committerOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Fri, 13 Apr 2018 15:56:45 +0000 (17:56 +0200)
src/librustc/ich/impls_ty.rs
src/librustc/mir/interpret/error.rs
src/librustc/session/mod.rs
src/librustc/ty/structural_impls.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/step.rs

index 41cfac2674be66b4dc358a30515923f777923758..5ba6a7246cff47fd7f47e010468ca9a682cb2542 100644 (file)
@@ -550,7 +550,6 @@ fn hash_stable<W: StableHasherResult>(&self,
             InvalidPointerMath |
             ReadUndefBytes |
             DeadLocal |
-            ExecutionTimeLimitReached |
             StackFrameLimitReached |
             OutOfTls |
             TlsOutOfBounds |
index 9e69990f22c0d0c20af457727493daf481e919be..b919f4d15a840a479678aafc968ffafc4cb05bfe 100644 (file)
@@ -65,7 +65,6 @@ pub enum EvalErrorKind<'tcx> {
     Intrinsic(String),
     OverflowingMath,
     InvalidChar(u128),
-    ExecutionTimeLimitReached,
     StackFrameLimitReached,
     OutOfTls,
     TlsOutOfBounds,
@@ -188,8 +187,6 @@ fn description(&self) -> &str {
                 "mir not found",
             InvalidChar(..) =>
                 "tried to interpret an invalid 32-bit value as a char",
-            ExecutionTimeLimitReached =>
-                "the expression was too complex to be evaluated or resulted in an infinite loop",
             StackFrameLimitReached =>
                 "reached the configured maximum number of stack frames",
             OutOfTls =>
index 8f2043fdfc643bb15220e7f70509f635fee56f10..32de006459d32ca1837ad9ed54c93ae5f93b3269 100644 (file)
@@ -112,8 +112,6 @@ pub struct Session {
 
     /// The maximum number of stackframes allowed in const eval
     pub const_eval_stack_frame_limit: usize,
-    /// The maximum number miri steps per constant
-    pub const_eval_step_limit: usize,
 
     /// The metadata::creader module may inject an allocator/panic_runtime
     /// dependency if it didn't already find one, and this tracks what was
@@ -1103,7 +1101,6 @@ pub fn build_session_(
         recursion_limit: Once::new(),
         type_length_limit: Once::new(),
         const_eval_stack_frame_limit: 100,
-        const_eval_step_limit: 1_000_000,
         next_node_id: OneThread::new(Cell::new(NodeId::new(1))),
         injected_allocator: Once::new(),
         allocator_kind: Once::new(),
index 8cf662ccaea9254f9421c5ee4d37a504b828662f..7b4b7082bb6ceae41fb22c35d27e09fbe64aac2f 100644 (file)
@@ -509,7 +509,6 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
             Intrinsic(ref s) => Intrinsic(s.clone()),
             OverflowingMath => OverflowingMath,
             InvalidChar(c) => InvalidChar(c),
-            ExecutionTimeLimitReached => ExecutionTimeLimitReached,
             StackFrameLimitReached => StackFrameLimitReached,
             OutOfTls => OutOfTls,
             TlsOutOfBounds => TlsOutOfBounds,
index 58ea8d48e97114fb23ac49b6243d8b78fe527aa3..7eced104bcac4f34d41ed7cb51e39f89d7acf87e 100644 (file)
@@ -45,7 +45,7 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
     /// The maximum number of terminators that may be evaluated.
     /// This prevents infinite loops and huge computations from freezing up const eval.
     /// Remove once halting problem is solved.
-    pub(crate) steps_remaining: usize,
+    pub(crate) terminators_remaining: usize,
 }
 
 /// A stack frame.
@@ -195,7 +195,7 @@ pub fn new(
             memory: Memory::new(tcx, memory_data),
             stack: Vec::new(),
             stack_limit: tcx.sess.const_eval_stack_frame_limit,
-            steps_remaining: tcx.sess.const_eval_step_limit,
+            terminators_remaining: 1_000_000,
         }
     }
 
@@ -538,7 +538,7 @@ pub(super) fn eval_rvalue_into_place(
             }
 
             Aggregate(ref kind, ref operands) => {
-                self.inc_step_counter_and_check_limit(operands.len())?;
+                self.inc_step_counter_and_check_limit(operands.len());
 
                 let (dest, active_field_index) = match **kind {
                     mir::AggregateKind::Adt(adt_def, variant_index, _, active_field_index) => {
index a22572ec687c3cf05a90177aa0b41d96cb585143..f891d2b8ccb1d6f9afbb4fc7f4a9f1fe25cf6b61 100644 (file)
@@ -8,12 +8,11 @@
 use super::{EvalContext, Machine};
 
 impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
-    pub fn inc_step_counter_and_check_limit(&mut self, n: usize) -> EvalResult<'tcx> {
-        self.steps_remaining = self.steps_remaining.saturating_sub(n);
-        if self.steps_remaining > 0 {
-            Ok(())
-        } else {
-            err!(ExecutionTimeLimitReached)
+    pub fn inc_step_counter_and_check_limit(&mut self, n: usize) {
+        self.terminators_remaining = self.terminators_remaining.saturating_sub(n);
+        if self.terminators_remaining == 0 {
+            self.tcx.sess.span_warn(self.frame().span, "Constant evaluating a complex constant, this might take some time");
+            self.terminators_remaining = 1_000_000;
         }
     }
 
@@ -36,7 +35,7 @@ pub fn step(&mut self) -> EvalResult<'tcx, bool> {
             return Ok(true);
         }
 
-        self.inc_step_counter_and_check_limit(1)?;
+        self.inc_step_counter_and_check_limit(1);
 
         let terminator = basic_block.terminator();
         assert_eq!(old_frames, self.cur_frame());