@@ -43,9 +43,11 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
43
43
/// The maximum number of stack frames allowed
44
44
pub ( crate ) stack_limit : usize ,
45
45
46
- /// The number of terminators to be evaluated before enabling the infinite
47
- /// loop detector.
48
- pub ( crate ) steps_until_detector_enabled : isize ,
46
+ /// When this value is negative, it indicates the number of interpreter
47
+ /// steps *until* the loop detector is enabled. When it is positive, it is
48
+ /// the number of steps after the detector has been enabled modulo the loop
49
+ /// detector period.
50
+ pub ( crate ) steps_since_detector_enabled : isize ,
49
51
50
52
pub ( crate ) loop_detector : InfiniteLoopDetector < ' a , ' mir , ' tcx , M > ,
51
53
}
@@ -148,14 +150,15 @@ type EvalSnapshot<'a, 'mir, 'tcx, M>
148
150
pub ( crate ) struct InfiniteLoopDetector < ' a , ' mir , ' tcx : ' a + ' mir , M : Machine < ' mir , ' tcx > > {
149
151
/// The set of all `EvalSnapshot` *hashes* observed by this detector.
150
152
///
151
- /// When a collision occurs in this table, we store the full snapshot in `snapshots`.
153
+ /// When a collision occurs in this table, we store the full snapshot in
154
+ /// `snapshots`.
152
155
hashes : FxHashSet < u64 > ,
153
156
154
157
/// The set of all `EvalSnapshot`s observed by this detector.
155
158
///
156
- /// An `EvalSnapshot` will only be fully cloned once it has caused a collision in `hashes`. As
157
- /// a result, the detector must observe at least *two* full cycles of an infinite loop before
158
- /// it triggers.
159
+ /// An `EvalSnapshot` will only be fully cloned once it has caused a
160
+ /// collision in `hashes`. As a result, the detector must observe at least
161
+ /// *two* full cycles of an infinite loop before it triggers.
159
162
snapshots : FxHashSet < EvalSnapshot < ' a , ' mir , ' tcx , M > > ,
160
163
}
161
164
@@ -291,7 +294,7 @@ impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf
291
294
}
292
295
}
293
296
294
- const MAX_TERMINATORS : isize = 1_000_000 ;
297
+ const STEPS_UNTIL_DETECTOR_ENABLED : isize = 1_000_000 ;
295
298
296
299
impl < ' a , ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > EvalContext < ' a , ' mir , ' tcx , M > {
297
300
pub fn new (
@@ -310,16 +313,16 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
310
313
stack : Vec :: new ( ) ,
311
314
stack_limit : tcx. sess . const_eval_stack_frame_limit ,
312
315
loop_detector : Default :: default ( ) ,
313
- steps_until_detector_enabled : MAX_TERMINATORS ,
316
+ steps_since_detector_enabled : - STEPS_UNTIL_DETECTOR_ENABLED ,
314
317
}
315
318
}
316
319
317
320
pub ( crate ) fn with_fresh_body < F : FnOnce ( & mut Self ) -> R , R > ( & mut self , f : F ) -> R {
318
321
let stack = mem:: replace ( & mut self . stack , Vec :: new ( ) ) ;
319
- let steps = mem:: replace ( & mut self . steps_until_detector_enabled , MAX_TERMINATORS ) ;
322
+ let steps = mem:: replace ( & mut self . steps_since_detector_enabled , - STEPS_UNTIL_DETECTOR_ENABLED ) ;
320
323
let r = f ( self ) ;
321
324
self . stack = stack;
322
- self . steps_until_detector_enabled = steps;
325
+ self . steps_since_detector_enabled = steps;
323
326
r
324
327
}
325
328
@@ -661,8 +664,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
661
664
}
662
665
663
666
Aggregate ( ref kind, ref operands) => {
664
- self . inc_step_counter_and_detect_loops ( operands. len ( ) ) ?;
665
-
666
667
let ( dest, active_field_index) = match * * kind {
667
668
mir:: AggregateKind :: Adt ( adt_def, variant_index, _, active_field_index) => {
668
669
self . write_discriminant_value ( dest_ty, dest, variant_index) ?;
0 commit comments