Skip to content

Commit 37844e5

Browse files
Reimplement CTFE snapshot comparison using a DFS
1 parent fa5ff3a commit 37844e5

File tree

3 files changed

+417
-310
lines changed

3 files changed

+417
-310
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
514514
}
515515
}
516516

517+
// Emit a warning if this is the first time we have triggered the loop detector. This means
518+
// we have been executing for quite some time.
517519
let span = ecx.frame().span;
518-
ecx.machine.loop_detector.observe_and_analyze(
519-
*ecx.tcx,
520-
span,
521-
&ecx.memory,
522-
&ecx.stack[..],
523-
)
520+
if ecx.machine.loop_detector.is_empty() {
521+
// FIXME(#49980): make this warning a lint
522+
ecx.tcx.sess.span_warn(span,
523+
"Constant evaluating a complex constant, this might take some time");
524+
}
525+
526+
ecx.machine.loop_detector.observe_and_analyze(&ecx.stack, &ecx.memory)
524527
}
525528

526529
#[inline(always)]

src/librustc_mir/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
935935

936936
/// A depth-first search over the allocation graph.
937937
///
938-
/// This is based on the DFS in `rustc_data_structures`, which we cannot use directly because
939-
/// `AllocId` does not implement `Idx`.
938+
/// This is based on the DFS iterator in `rustc_data_structures`, which we cannot use directly
939+
/// because `AllocId` does not implement `Idx` (it is not dense).
940940
pub struct DepthFirstSearch<'mem, 'mir, 'tcx, M: Machine<'mir, 'tcx>> {
941941
memory: &'mem Memory<'mir, 'tcx, M>,
942942
visited: FxHashSet<AllocId>,

0 commit comments

Comments
 (0)