forked from noir-lang/noir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracer): Record function calls and returns
This commit also records function calls and returns from functions, without passing the actual arguments and values in either direction. That would be a follow-up. Details: * `get_variables` is now public in `tooling/debugger/src/context.rs`; it is needed to extract the stack frame from the debugger; * drive-by: `trace_metadata.json` is also stored, because the frontend expects that too; * `tail_diff_vecs` is a generic utility function to extract the difference between two vectors; it has good documentation, so details within; * a local structure `StackFrame` is introduced, because the `StackFrame` in the debugger does not own its data; here, we need to remember the previous stack trace (a vector of `StackFrame`'s) in order to discover function calls or returns, so we need to own the data; * a `stack_trace` field is added to `TracingContext`; see previous point; * the new `fn get_stack_trace` performs the conversion mentioned; * the old contents of `update_record` are the basis for `tail_diff_vecs`; the new contents use that function to perform the same operation as before; in addition, the core logic of the PR is here: return events are registered for dropped stack frames and call events are registered for new stack frames; * all tracing tests are updated, to reflect the new traces that are generated. To test: ``` cargo test trace ```
- Loading branch information
Showing
7 changed files
with
122 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// Produce the "tail difference" of two vectors. | ||
/// | ||
/// Here, this means that the common prefix of the two vectors is computed. The length of that | ||
/// prefix is returned, together with the suffix of the first vector that follows the common | ||
/// prefix, as well as the suffix of the second vector that follows the common prefix. | ||
/// | ||
/// Example: | ||
/// ``` | ||
/// use noir_tracer::tail_diff_vecs::tail_diff_vecs; | ||
/// let a = 1; | ||
/// let b = 2; | ||
/// let c = 3; | ||
/// let d = 4; | ||
/// let e = 5; | ||
/// let f = 6; | ||
/// | ||
/// assert_eq!(tail_diff_vecs(&vec!(a, b, c), &vec!(a, b, e, f)), (2, vec!(&c), vec!(&e, &f))); | ||
// | ||
/// assert_eq!(tail_diff_vecs(&vec!(a, b, c), &vec!(e, f)), (0, vec!(&a, &b, &c), vec!(&e, &f))); | ||
/// | ||
/// assert_eq!(tail_diff_vecs(&vec!(a, b, c), &vec!(a, b)), (2, vec!(&c), vec!())); | ||
/// | ||
/// assert_eq!(tail_diff_vecs(&vec!(a, b, c, d), &vec!(a, b, e)), (2, vec!(&c, &d), vec!(&e))); | ||
/// | ||
/// // Corner cases: | ||
/// assert_eq!(tail_diff_vecs(&vec!(a, b), &vec!(a, b, c)), (2, vec!(), vec!(&c))); | ||
/// assert_eq!(tail_diff_vecs::<usize>(&vec!(), &vec!()), (0, vec!(), vec!())); | ||
/// ``` | ||
pub fn tail_diff_vecs<'a, T>(xs: &'a Vec<T>, ys: &'a Vec<T>) -> (usize, Vec<&'a T>, Vec<&'a T>) | ||
where | ||
T: PartialEq + Clone, | ||
{ | ||
let min_len = std::cmp::min(xs.len(), ys.len()); | ||
let first_nomatch = xs.iter().zip(ys.iter()).position(|(x, y)| x != y).unwrap_or(min_len); | ||
|
||
let xs_tail: Vec<&T> = xs[first_nomatch..].iter().collect(); | ||
let ys_tail: Vec<&T> = ys[first_nomatch..].iter().collect(); | ||
|
||
(first_nomatch, xs_tail, ys_tail) | ||
} |