Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't abort const eval due to long running evals, just warn #49947

Merged
merged 2 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ for ::mir::interpret::EvalError<'gcx> {
InvalidPointerMath |
ReadUndefBytes |
DeadLocal |
ExecutionTimeLimitReached |
StackFrameLimitReached |
OutOfTls |
TlsOutOfBounds |
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub enum EvalErrorKind<'tcx> {
Intrinsic(String),
OverflowingMath,
InvalidChar(u128),
ExecutionTimeLimitReached,
StackFrameLimitReached,
OutOfTls,
TlsOutOfBounds,
Expand Down Expand Up @@ -188,8 +187,6 @@ impl<'tcx> Error for EvalError<'tcx> {
"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 =>
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ impl<'a, 'tcx> Lift<'tcx> for interpret::EvalError<'a> {
Intrinsic(ref s) => Intrinsic(s.clone()),
OverflowingMath => OverflowingMath,
InvalidChar(c) => InvalidChar(c),
ExecutionTimeLimitReached => ExecutionTimeLimitReached,
StackFrameLimitReached => StackFrameLimitReached,
OutOfTls => OutOfTls,
TlsOutOfBounds => TlsOutOfBounds,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
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,
}
}

Expand Down Expand Up @@ -538,7 +538,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
}

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) => {
Expand Down
13 changes: 6 additions & 7 deletions src/librustc_mir/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use rustc::mir::interpret::EvalResult;
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fill an issue that raises a question of making this a lint-warning and link the issue with a comment here?

self.terminators_remaining = 1_000_000;
}
}

Expand All @@ -36,7 +35,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
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());
Expand Down