@@ -3,6 +3,7 @@ use rustc::ty::layout::HasTyCtxt;
3
3
use rustc:: ty:: { self , Ty } ;
4
4
use std:: borrow:: { Borrow , Cow } ;
5
5
use std:: collections:: hash_map:: Entry ;
6
+ use std:: convert:: TryFrom ;
6
7
use std:: hash:: Hash ;
7
8
8
9
use rustc_data_structures:: fx:: FxHashMap ;
@@ -85,9 +86,6 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
85
86
}
86
87
}
87
88
88
- /// Number of steps until the detector even starts doing anything.
89
- /// Also, a warning is shown to the user when this number is reached.
90
- const STEPS_UNTIL_DETECTOR_ENABLED : isize = 1_000_000 ;
91
89
/// The number of steps between loop detector snapshots.
92
90
/// Should be a power of two for performance reasons.
93
91
const DETECTOR_SNAPSHOT_PERIOD : isize = 256 ;
@@ -100,6 +98,8 @@ pub struct CompileTimeInterpreter<'mir, 'tcx> {
100
98
/// detector period.
101
99
pub ( super ) steps_since_detector_enabled : isize ,
102
100
101
+ pub ( super ) is_detector_enabled : bool ,
102
+
103
103
/// Extra state to detect loops.
104
104
pub ( super ) loop_detector : snapshot:: InfiniteLoopDetector < ' mir , ' tcx > ,
105
105
}
@@ -111,10 +111,14 @@ pub struct MemoryExtra {
111
111
}
112
112
113
113
impl < ' mir , ' tcx > CompileTimeInterpreter < ' mir , ' tcx > {
114
- pub ( super ) fn new ( ) -> Self {
114
+ pub ( super ) fn new ( const_eval_limit : usize ) -> Self {
115
+ let steps_until_detector_enabled =
116
+ isize:: try_from ( const_eval_limit) . unwrap_or ( std:: isize:: MAX ) ;
117
+
115
118
CompileTimeInterpreter {
116
119
loop_detector : Default :: default ( ) ,
117
- steps_since_detector_enabled : -STEPS_UNTIL_DETECTOR_ENABLED ,
120
+ steps_since_detector_enabled : -steps_until_detector_enabled,
121
+ is_detector_enabled : const_eval_limit != 0 ,
118
122
}
119
123
}
120
124
}
@@ -343,6 +347,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
343
347
}
344
348
345
349
fn before_terminator ( ecx : & mut InterpCx < ' mir , ' tcx , Self > ) -> InterpResult < ' tcx > {
350
+ if !ecx. machine . is_detector_enabled {
351
+ return Ok ( ( ) ) ;
352
+ }
353
+
346
354
{
347
355
let steps = & mut ecx. machine . steps_since_detector_enabled ;
348
356
0 commit comments