Skip to content

Commit 2cc625d

Browse files
committed
Don't abort const eval due to long running evals, just warn
1 parent 2b9e857 commit 2cc625d

File tree

6 files changed

+9
-18
lines changed

6 files changed

+9
-18
lines changed

src/librustc/ich/impls_ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ for ::mir::interpret::EvalError<'gcx> {
533533
InvalidPointerMath |
534534
ReadUndefBytes |
535535
DeadLocal |
536-
ExecutionTimeLimitReached |
537536
StackFrameLimitReached |
538537
OutOfTls |
539538
TlsOutOfBounds |

src/librustc/mir/interpret/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ pub enum EvalErrorKind<'tcx> {
6565
Intrinsic(String),
6666
OverflowingMath,
6767
InvalidChar(u128),
68-
ExecutionTimeLimitReached,
6968
StackFrameLimitReached,
7069
OutOfTls,
7170
TlsOutOfBounds,
@@ -188,8 +187,6 @@ impl<'tcx> Error for EvalError<'tcx> {
188187
"mir not found",
189188
InvalidChar(..) =>
190189
"tried to interpret an invalid 32-bit value as a char",
191-
ExecutionTimeLimitReached =>
192-
"the expression was too complex to be evaluated or resulted in an infinite loop",
193190
StackFrameLimitReached =>
194191
"reached the configured maximum number of stack frames",
195192
OutOfTls =>

src/librustc/session/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ pub struct Session {
108108

109109
/// The maximum number of stackframes allowed in const eval
110110
pub const_eval_stack_frame_limit: Cell<usize>,
111-
/// The maximum number miri steps per constant
112-
pub const_eval_step_limit: Cell<usize>,
113111

114112
/// The metadata::creader module may inject an allocator/panic_runtime
115113
/// dependency if it didn't already find one, and this tracks what was
@@ -1146,7 +1144,6 @@ pub fn build_session_(
11461144
recursion_limit: Cell::new(64),
11471145
type_length_limit: Cell::new(1048576),
11481146
const_eval_stack_frame_limit: Cell::new(100),
1149-
const_eval_step_limit: Cell::new(1_000_000),
11501147
next_node_id: Cell::new(NodeId::new(1)),
11511148
injected_allocator: Cell::new(None),
11521149
allocator_kind: Cell::new(None),

src/librustc/ty/structural_impls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ impl<'a, 'tcx> Lift<'tcx> for interpret::EvalError<'a> {
509509
Intrinsic(ref s) => Intrinsic(s.clone()),
510510
OverflowingMath => OverflowingMath,
511511
InvalidChar(c) => InvalidChar(c),
512-
ExecutionTimeLimitReached => ExecutionTimeLimitReached,
513512
StackFrameLimitReached => StackFrameLimitReached,
514513
OutOfTls => OutOfTls,
515514
TlsOutOfBounds => TlsOutOfBounds,

src/librustc_mir/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
4545
/// The maximum number of terminators that may be evaluated.
4646
/// This prevents infinite loops and huge computations from freezing up const eval.
4747
/// Remove once halting problem is solved.
48-
pub(crate) steps_remaining: usize,
48+
pub(crate) terminators_remaining: usize,
4949
}
5050

5151
/// A stack frame.
@@ -195,7 +195,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
195195
memory: Memory::new(tcx, memory_data),
196196
stack: Vec::new(),
197197
stack_limit: tcx.sess.const_eval_stack_frame_limit.get(),
198-
steps_remaining: tcx.sess.const_eval_step_limit.get(),
198+
terminators_remaining: 1_000_000,
199199
}
200200
}
201201

@@ -538,7 +538,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
538538
}
539539

540540
Aggregate(ref kind, ref operands) => {
541-
self.inc_step_counter_and_check_limit(operands.len())?;
541+
self.inc_step_counter_and_check_limit(operands.len());
542542

543543
let (dest, active_field_index) = match **kind {
544544
mir::AggregateKind::Adt(adt_def, variant_index, _, active_field_index) => {

src/librustc_mir/interpret/step.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ use rustc::mir::interpret::EvalResult;
88
use super::{EvalContext, Machine};
99

1010
impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
11-
pub fn inc_step_counter_and_check_limit(&mut self, n: usize) -> EvalResult<'tcx> {
12-
self.steps_remaining = self.steps_remaining.saturating_sub(n);
13-
if self.steps_remaining > 0 {
14-
Ok(())
15-
} else {
16-
err!(ExecutionTimeLimitReached)
11+
pub fn inc_step_counter_and_check_limit(&mut self, n: usize) {
12+
self.terminators_remaining = self.terminators_remaining.saturating_sub(n);
13+
if self.terminators_remaining == 0 {
14+
self.tcx.sess.span_warn(self.frame().span, "Constant evaluating a complex constant, this might take some time");
15+
self.terminators_remaining = 1_000_000;
1716
}
1817
}
1918

@@ -36,7 +35,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3635
return Ok(true);
3736
}
3837

39-
self.inc_step_counter_and_check_limit(1)?;
38+
self.inc_step_counter_and_check_limit(1);
4039

4140
let terminator = basic_block.terminator();
4241
assert_eq!(old_frames, self.cur_frame());

0 commit comments

Comments
 (0)