Skip to content

Track dbg! calls #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/bit_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,24 @@ impl BitMachine {
call_stack.push(CallStack::Goto(left));
}
node::Inner::Case(..) | node::Inner::AssertL(..) | node::Inner::AssertR(..) => {
let choice_bit = self.read[self.read.len() - 1].peek_bit(&self.data);
let in_frame = &self.read[self.read.len() - 1];
let choice_bit: bool = in_frame.peek_bit(&self.data);

let (sum_a_b, _c) = ip.arrow().source.as_product().unwrap();
let (a, b) = sum_a_b.as_sum().unwrap();

if tracker.is_track_debug_enabled() {
if let node::Inner::AssertL(_, cmr) = ip.inner() {
let mut bits = in_frame.as_bit_iter(&self.data);
// Skips 1 + max(a.bit_width, b.bit_width) - a.bit_width
bits.nth(a.pad_left(b))
.expect("AssertL: unexpected end of frame");
let value = Value::from_padded_bits(&mut bits, _c)
.expect("AssertL: decode `C` value");
tracker.track_dbg_call(cmr, value);
}
}

match (ip.inner(), choice_bit) {
(node::Inner::Case(_, right), true)
| (node::Inner::AssertR(_, right), true) => {
Expand Down Expand Up @@ -545,6 +558,12 @@ pub trait ExecTracker<J: Jet> {
output_buffer: &[UWORD],
success: bool,
);

/// Track the potential execution of a `dbg!` call with the given `cmr` and `value`.
fn track_dbg_call(&mut self, cmr: &Cmr, value: Value);

/// Check if tracking debug calls is enabled.
fn is_track_debug_enabled(&self) -> bool;
}

/// Tracker of executed left and right branches for each case node.
Expand Down Expand Up @@ -580,6 +599,12 @@ impl<J: Jet> ExecTracker<J> for SetTracker {
}

fn track_jet_call(&mut self, _: &J, _: &[UWORD], _: &[UWORD], _: bool) {}

fn track_dbg_call(&mut self, _: &Cmr, _: Value) {}

fn is_track_debug_enabled(&self) -> bool {
false
}
}

impl<J: Jet> ExecTracker<J> for NoTracker {
Expand All @@ -588,6 +613,13 @@ impl<J: Jet> ExecTracker<J> for NoTracker {
fn track_right(&mut self, _: Ihr) {}

fn track_jet_call(&mut self, _: &J, _: &[UWORD], _: &[UWORD], _: bool) {}

fn track_dbg_call(&mut self, _: &Cmr, _: Value) {}

fn is_track_debug_enabled(&self) -> bool {
// Set flag to test frame decoding in unit tests
cfg!(test)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ideal, but I don't have a better idea

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, I think it's ok. Agree that it looks pretty weird, but the nice thing is that cfg(test) is only ever set within this project, so we don't need to worry about this weirdness somehow being exposed to our dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the "right" way to do it is to add a whole nother Tracker type for use in tests. But I think this is fine for now.

}
}

/// Errors related to simplicity Execution
Expand Down