Skip to content

Commit 0300774

Browse files
committed
Promote EvalSnapshot to newtype
1 parent 7fa42be commit 0300774

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,24 @@ impl<'tcx> LocalValue {
196196
}
197197

198198
/// The virtual machine state during const-evaluation at a given point in time.
199-
type EvalSnapshot<'a, 'mir, 'tcx, M>
200-
= (M, Vec<Frame<'mir, 'tcx>>, Memory<'a, 'mir, 'tcx, M>);
199+
#[derive(Eq, PartialEq, Hash)]
200+
pub(crate) struct EvalSnapshot<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
201+
machine: M,
202+
memory: Memory<'a, 'mir, 'tcx, M>,
203+
stack: Vec<Frame<'mir, 'tcx>>,
204+
}
205+
206+
impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M>
207+
where M: Machine<'mir, 'tcx>,
208+
{
209+
fn new<'b>(machine: &M, memory: &Memory<'a, 'mir, 'tcx, M>, stack: &[Frame<'mir, 'tcx>]) -> Self {
210+
EvalSnapshot {
211+
machine: machine.clone(),
212+
memory: memory.clone(),
213+
stack: stack.into(),
214+
}
215+
}
216+
}
201217

202218
pub(super) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
203219
/// The set of all `EvalSnapshot` *hashes* observed by this detector.
@@ -238,21 +254,20 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M>
238254
pub fn observe_and_analyze(
239255
&mut self,
240256
machine: &M,
241-
stack: &Vec<Frame<'mir, 'tcx>>,
242257
memory: &Memory<'a, 'mir, 'tcx, M>,
258+
stack: &[Frame<'mir, 'tcx>],
243259
) -> EvalResult<'tcx, ()> {
244-
let snapshot = (machine, stack, memory);
245260

246261
let mut fx = FxHasher::default();
247-
snapshot.hash(&mut fx);
262+
(machine, memory, stack).hash(&mut fx);
248263
let hash = fx.finish();
249264

250265
if self.hashes.insert(hash) {
251266
// No collision
252267
return Ok(())
253268
}
254269

255-
if self.snapshots.insert((machine.clone(), stack.clone(), memory.clone())) {
270+
if self.snapshots.insert(EvalSnapshot::new(machine, memory, stack)) {
256271
// Spurious collision or first cycle
257272
return Ok(())
258273
}

src/librustc_mir/interpret/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
7373
"Constant evaluating a complex constant, this might take some time");
7474
}
7575

76-
self.loop_detector.observe_and_analyze(&self.machine, &self.stack, &self.memory)
76+
self.loop_detector.observe_and_analyze(&self.machine, &self.memory, &self.stack[..])
7777
}
7878

7979
pub fn run(&mut self) -> EvalResult<'tcx> {

0 commit comments

Comments
 (0)