Skip to content

Commit 8de5353

Browse files
committed
Auto merge of #49947 - oli-obk:turing_complete_const_eval, r=nagisa
Don't abort const eval due to long running evals, just warn one check-box of #49930 r? @nagisa (rust-lang/rfcs#2344 (comment))
2 parents 7360d6d + 907df8c commit 8de5353

File tree

6 files changed

+10
-18
lines changed

6 files changed

+10
-18
lines changed

src/librustc/ich/impls_ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ for ::mir::interpret::EvalError<'gcx> {
551551
InvalidPointerMath |
552552
ReadUndefBytes |
553553
DeadLocal |
554-
ExecutionTimeLimitReached |
555554
StackFrameLimitReached |
556555
OutOfTls |
557556
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
@@ -112,8 +112,6 @@ pub struct Session {
112112

113113
/// The maximum number of stackframes allowed in const eval
114114
pub const_eval_stack_frame_limit: usize,
115-
/// The maximum number miri steps per constant
116-
pub const_eval_step_limit: usize,
117115

118116
/// The metadata::creader module may inject an allocator/panic_runtime
119117
/// dependency if it didn't already find one, and this tracks what was
@@ -1103,7 +1101,6 @@ pub fn build_session_(
11031101
recursion_limit: Once::new(),
11041102
type_length_limit: Once::new(),
11051103
const_eval_stack_frame_limit: 100,
1106-
const_eval_step_limit: 1_000_000,
11071104
next_node_id: OneThread::new(Cell::new(NodeId::new(1))),
11081105
injected_allocator: Once::new(),
11091106
allocator_kind: Once::new(),

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,
198-
steps_remaining: tcx.sess.const_eval_step_limit,
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

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ 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+
// FIXME(#49980): make this warning a lint
15+
self.tcx.sess.span_warn(self.frame().span, "Constant evaluating a complex constant, this might take some time");
16+
self.terminators_remaining = 1_000_000;
1717
}
1818
}
1919

@@ -36,7 +36,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3636
return Ok(true);
3737
}
3838

39-
self.inc_step_counter_and_check_limit(1)?;
39+
self.inc_step_counter_and_check_limit(1);
4040

4141
let terminator = basic_block.terminator();
4242
assert_eq!(old_frames, self.cur_frame());

0 commit comments

Comments
 (0)