@@ -43,9 +43,11 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
4343 /// The maximum number of stack frames allowed
4444 pub ( crate ) stack_limit : usize ,
4545
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 ,
4951
5052 pub ( crate ) loop_detector : InfiniteLoopDetector < ' a , ' mir , ' tcx , M > ,
5153}
@@ -148,14 +150,15 @@ type EvalSnapshot<'a, 'mir, 'tcx, M>
148150pub ( crate ) struct InfiniteLoopDetector < ' a , ' mir , ' tcx : ' a + ' mir , M : Machine < ' mir , ' tcx > > {
149151 /// The set of all `EvalSnapshot` *hashes* observed by this detector.
150152 ///
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`.
152155 hashes : FxHashSet < u64 > ,
153156
154157 /// The set of all `EvalSnapshot`s observed by this detector.
155158 ///
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.
159162 snapshots : FxHashSet < EvalSnapshot < ' a , ' mir , ' tcx , M > > ,
160163}
161164
@@ -291,7 +294,7 @@ impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf
291294 }
292295}
293296
294- const MAX_TERMINATORS : isize = 1_000_000 ;
297+ const STEPS_UNTIL_DETECTOR_ENABLED : isize = 1_000_000 ;
295298
296299impl < ' a , ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > EvalContext < ' a , ' mir , ' tcx , M > {
297300 pub fn new (
@@ -310,16 +313,16 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
310313 stack : Vec :: new ( ) ,
311314 stack_limit : tcx. sess . const_eval_stack_frame_limit ,
312315 loop_detector : Default :: default ( ) ,
313- steps_until_detector_enabled : MAX_TERMINATORS ,
316+ steps_since_detector_enabled : - STEPS_UNTIL_DETECTOR_ENABLED ,
314317 }
315318 }
316319
317320 pub ( crate ) fn with_fresh_body < F : FnOnce ( & mut Self ) -> R , R > ( & mut self , f : F ) -> R {
318321 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 ) ;
320323 let r = f ( self ) ;
321324 self . stack = stack;
322- self . steps_until_detector_enabled = steps;
325+ self . steps_since_detector_enabled = steps;
323326 r
324327 }
325328
@@ -661,8 +664,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
661664 }
662665
663666 Aggregate ( ref kind, ref operands) => {
664- self . inc_step_counter_and_detect_loops ( operands. len ( ) ) ?;
665-
666667 let ( dest, active_field_index) = match * * kind {
667668 mir:: AggregateKind :: Adt ( adt_def, variant_index, _, active_field_index) => {
668669 self . write_discriminant_value ( dest_ty, dest, variant_index) ?;
0 commit comments