|
8 | 8 |
|
9 | 9 | mod frame; |
10 | 10 | mod limits; |
| 11 | +mod tracker; |
11 | 12 |
|
12 | | -use std::collections::HashSet; |
13 | 13 | use std::error; |
14 | 14 | use std::fmt; |
15 | 15 | use std::sync::Arc; |
16 | 16 |
|
| 17 | +use crate::analysis; |
17 | 18 | use crate::jet::{Jet, JetFailed}; |
18 | 19 | use crate::node::{self, RedeemNode}; |
19 | 20 | use crate::types::Final; |
20 | | -use crate::{analysis, Ihr}; |
21 | 21 | use crate::{Cmr, FailEntropy, Value}; |
22 | 22 | use frame::Frame; |
23 | | -use simplicity_sys::ffi::UWORD; |
24 | 23 |
|
25 | 24 | pub use self::limits::LimitError; |
| 25 | +pub use self::tracker::{ExecTracker, NoTracker, SetTracker}; |
26 | 26 |
|
27 | 27 | /// An iterator over the contents of a read or write frame which yields bits. |
28 | 28 | pub type FrameIter<'a> = crate::BitIter<core::iter::Copied<core::slice::Iter<'a, u8>>>; |
@@ -539,92 +539,6 @@ impl BitMachine { |
539 | 539 | } |
540 | 540 | } |
541 | 541 |
|
542 | | -/// A type that keeps track of Bit Machine execution. |
543 | | -/// |
544 | | -/// The trait is implemented for [`SetTracker`], that tracks which case branches were executed, |
545 | | -/// and it is implemented for [`NoTracker`], which is a dummy tracker that is |
546 | | -/// optimized out by the compiler. |
547 | | -/// |
548 | | -/// The trait enables us to turn tracking on or off depending on a generic parameter. |
549 | | -pub trait ExecTracker<J: Jet> { |
550 | | - /// Track the execution of the left branch of the case node with the given `ihr`. |
551 | | - fn track_left(&mut self, ihr: Ihr); |
552 | | - |
553 | | - /// Track the execution of the right branch of the case node with the given `ihr`. |
554 | | - fn track_right(&mut self, ihr: Ihr); |
555 | | - |
556 | | - /// Track the execution of a `jet` call with the given `input_buffer`, `output_buffer`, and call result `success`. |
557 | | - fn track_jet_call( |
558 | | - &mut self, |
559 | | - jet: &J, |
560 | | - input_buffer: &[UWORD], |
561 | | - output_buffer: &[UWORD], |
562 | | - success: bool, |
563 | | - ); |
564 | | - |
565 | | - /// Track the potential execution of a `dbg!` call with the given `cmr` and `value`. |
566 | | - fn track_dbg_call(&mut self, cmr: &Cmr, value: Value); |
567 | | - |
568 | | - /// Check if tracking debug calls is enabled. |
569 | | - fn is_track_debug_enabled(&self) -> bool; |
570 | | -} |
571 | | - |
572 | | -/// Tracker of executed left and right branches for each case node. |
573 | | -#[derive(Clone, Debug, Default)] |
574 | | -pub struct SetTracker { |
575 | | - left: HashSet<Ihr>, |
576 | | - right: HashSet<Ihr>, |
577 | | -} |
578 | | - |
579 | | -impl SetTracker { |
580 | | - /// Access the set of IHRs of case nodes whose left branch was executed. |
581 | | - pub fn left(&self) -> &HashSet<Ihr> { |
582 | | - &self.left |
583 | | - } |
584 | | - |
585 | | - /// Access the set of IHRs of case nodes whose right branch was executed. |
586 | | - pub fn right(&self) -> &HashSet<Ihr> { |
587 | | - &self.right |
588 | | - } |
589 | | -} |
590 | | - |
591 | | -/// Tracker that does not do anything (noop). |
592 | | -#[derive(Copy, Clone, Debug)] |
593 | | -pub struct NoTracker; |
594 | | - |
595 | | -impl<J: Jet> ExecTracker<J> for SetTracker { |
596 | | - fn track_left(&mut self, ihr: Ihr) { |
597 | | - self.left.insert(ihr); |
598 | | - } |
599 | | - |
600 | | - fn track_right(&mut self, ihr: Ihr) { |
601 | | - self.right.insert(ihr); |
602 | | - } |
603 | | - |
604 | | - fn track_jet_call(&mut self, _: &J, _: &[UWORD], _: &[UWORD], _: bool) {} |
605 | | - |
606 | | - fn track_dbg_call(&mut self, _: &Cmr, _: Value) {} |
607 | | - |
608 | | - fn is_track_debug_enabled(&self) -> bool { |
609 | | - false |
610 | | - } |
611 | | -} |
612 | | - |
613 | | -impl<J: Jet> ExecTracker<J> for NoTracker { |
614 | | - fn track_left(&mut self, _: Ihr) {} |
615 | | - |
616 | | - fn track_right(&mut self, _: Ihr) {} |
617 | | - |
618 | | - fn track_jet_call(&mut self, _: &J, _: &[UWORD], _: &[UWORD], _: bool) {} |
619 | | - |
620 | | - fn track_dbg_call(&mut self, _: &Cmr, _: Value) {} |
621 | | - |
622 | | - fn is_track_debug_enabled(&self) -> bool { |
623 | | - // Set flag to test frame decoding in unit tests |
624 | | - cfg!(test) |
625 | | - } |
626 | | -} |
627 | | - |
628 | 542 | /// Errors related to simplicity Execution |
629 | 543 | #[derive(Debug)] |
630 | 544 | pub enum ExecutionError { |
|
0 commit comments