提交 03007740 编写于 作者: B Bruno Dutra

Promote EvalSnapshot to newtype

上级 7fa42bee
......@@ -196,8 +196,24 @@ pub fn access_mut(&mut self) -> EvalResult<'tcx, &mut Operand> {
}
/// The virtual machine state during const-evaluation at a given point in time.
type EvalSnapshot<'a, 'mir, 'tcx, M>
= (M, Vec<Frame<'mir, 'tcx>>, Memory<'a, 'mir, 'tcx, M>);
#[derive(Eq, PartialEq, Hash)]
pub(crate) struct EvalSnapshot<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
machine: M,
memory: Memory<'a, 'mir, 'tcx, M>,
stack: Vec<Frame<'mir, 'tcx>>,
}
impl<'a, 'mir, 'tcx, M> EvalSnapshot<'a, 'mir, 'tcx, M>
where M: Machine<'mir, 'tcx>,
{
fn new<'b>(machine: &M, memory: &Memory<'a, 'mir, 'tcx, M>, stack: &[Frame<'mir, 'tcx>]) -> Self {
EvalSnapshot {
machine: machine.clone(),
memory: memory.clone(),
stack: stack.into(),
}
}
}
pub(super) struct InfiniteLoopDetector<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
/// The set of all `EvalSnapshot` *hashes* observed by this detector.
......@@ -238,13 +254,12 @@ pub fn is_empty(&self) -> bool {
pub fn observe_and_analyze(
&mut self,
machine: &M,
stack: &Vec<Frame<'mir, 'tcx>>,
memory: &Memory<'a, 'mir, 'tcx, M>,
stack: &[Frame<'mir, 'tcx>],
) -> EvalResult<'tcx, ()> {
let snapshot = (machine, stack, memory);
let mut fx = FxHasher::default();
snapshot.hash(&mut fx);
(machine, memory, stack).hash(&mut fx);
let hash = fx.finish();
if self.hashes.insert(hash) {
......@@ -252,7 +267,7 @@ pub fn observe_and_analyze(
return Ok(())
}
if self.snapshots.insert((machine.clone(), stack.clone(), memory.clone())) {
if self.snapshots.insert(EvalSnapshot::new(machine, memory, stack)) {
// Spurious collision or first cycle
return Ok(())
}
......
......@@ -73,7 +73,7 @@ pub fn inc_step_counter_and_detect_loops(&mut self) -> EvalResult<'tcx, ()> {
"Constant evaluating a complex constant, this might take some time");
}
self.loop_detector.observe_and_analyze(&self.machine, &self.stack, &self.memory)
self.loop_detector.observe_and_analyze(&self.machine, &self.memory, &self.stack[..])
}
pub fn run(&mut self) -> EvalResult<'tcx> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册