Skip to main content

Trace

Struct Trace 

Source
pub struct Trace { /* private fields */ }
Expand description

Records a run’s events and writes them out as a trace.

Give it to Run::with_observer, then write the run with to_jsonl:

use bitwright::engine::{Engine, Run, Trace};
use bitwright::{Context, ParseOptions, Width};

let engine = Engine::standard();
let mut cx = Context::new();
let e = cx.parse("((x ^ 0x5a) + 3 - 3) ^ 0x5a", &ParseOptions::width(Width::W32))?;
let mut trace = Trace::new(&engine);
let out = engine.run(&mut cx, &[e], Run::default().with_observer(&mut trace))?;
let text = trace.to_jsonl(&mut cx, &[e], &out)?;
assert!(text.lines().any(|l| l.contains(r#""ev":"applied","pass":"linear""#)));

§Format

One JSON object per line, in this order (format 1):

  • a header: {"trace":"bitwright","format":1,"version":…,"strategy":…,"max_rounds":…, "phases":[{"name":"fact_fold"},{"name":"local","groups":[…]},…]};
  • each rule and host rewrite the events name, numbered from 0 in order of appearance: {"rule":0,"name":"core.arith::add_xor_and","id":"…","kind":"identity","proven":true, "doc":…,"examples":[["…","…"]],"source":…,"ledger":…} (source, the rule as written, and ledger, the evidence its proof ledger records, when known: always for the built-in rules, and for others from with_source), {"rewrite":0,"name":…};
  • each node the events, results and assumptions name, with every node below it, operands first: {"node":12,"op":"add","w":32,"args":[5,9],"text":"x + y"}. op is const (with value), sym (with name), a unary or binary operator’s name, cmp (with pred, its spelling: <u), zext, sext, extract (with lo), concat, select, fp (with fp_op and format) or ext (with output). Node numbers are the context’s own, so a node keeps its number across the whole trace: equal numbers are equal expressions. Only the nodes named directly carry text, the expression as the printer writes it, and, with with_facts, facts ({"zero":"0x…","one":"0x…","u":["0x…","0x…"], "stride":1,"s":["0x…","0x…"]}: the known zero and one bits, the unsigned interval and its stride, the signed interval as bit patterns) and, under assumptions where they differ, assumed (the same, with relies);
  • each constraint of the run’s assumptions (with_assumptions): {"assume":0,"expr":40};
  • the events, in order: {"ev":"root","index":0,"root":20} (with "again":true for a root worked on again), {"ev":"stage","stage":"cases","before":…,"after":…}, {"ev":"phase_begin","round":0,"phase":1,"root":…}, {"ev":"candidate","rule":3,"node":…}, {"ev":"no_match","rule":3,"node":…} (also degraded and no_change), {"ev":"guard_false","rule":3,"node":…,"pred":"disjoint","args":[5,9]} (args null where an operand is no parameter), {"ev":"applied","rule":3,"before":…,"after":…} (or "pass":"linear", or "rewrite":0), {"ev":"relied","on":[0,2]} (with "later":true when constraints from 63 on may be among them), {"ev":"explain","pass":"invert", "node":…,"why":{"kind":"invert",…}}, {"ev":"not_smaller","pass":"linear","node":…, "candidate":…,"added":4,"freed":3,"shared":false} (candidate null when it was not built), {"ev":"folded","node":…,"after":…}, {"ev":"vetoed",…}, {"ev":"rejected",…,"reason":"verify"}, {"ev":"phase_end","round":0,"phase":1, "root":…,"spent":{"node_visits":16,…}} (the nonzero work only; with "stopped":"node_visits" when a limit stopped it);
  • each root’s result: {"result":0,"input":20,"expr":31,"changed":true,"end":"completed", "relies_on":[]} (end is also budget_terminated, with stopped, or declined, with cap);
  • the run’s counters: {"stats":{…}}, every field of Stats by name.

The why of an explain event is the pass’s Explanation as an object with its kind; like the type, its fields may change in any release. A reader should skip events, fields and kinds it does not know. The same run of the same engine on the same input writes the same trace.

Implementations§

Source§

impl Trace

Source

pub const FORMAT: u32 = 1

The trace format this version writes.

Source

pub fn new(engine: &Engine) -> Trace

An empty trace of runs of engine (its strategy goes in the header), which knows the built-in rules’ text and proof ledger.

Source

pub fn with_explanations(self, yes: bool) -> Trace

Asks the engine for the passes’ reasoning too (Detail::Explain), recorded as explain events.

Source

pub fn with_facts(self, yes: bool) -> Trace

Writes the facts of every node named directly: known bits and intervals, and under the assumptions given to with_assumptions where they differ.

Source

pub fn with_source(self, source: &str, ledger: Option<&Ledger>) -> Trace

The source of a rule program the engine links, with the ledger that vouches for it: the trace gives the text and evidence of its rules (those of the groups it declares).

Source

pub fn with_assumptions( &mut self, cx: &mut Context, a: &Assumptions, ) -> Result<(), Error>

Records the run’s assumptions, written as assume lines (and used for the facts under them). Call it with the assumptions the run is given.

Source

pub fn len(&self) -> usize

The number of events recorded.

Source

pub fn is_empty(&self) -> bool

Whether no event was recorded.

Source

pub fn to_jsonl( &self, cx: &mut Context, roots: &[Expr], outcome: &Outcome, ) -> Result<String, Error>

The run as a trace: the header, the rules and nodes the events name, the assumptions, the events, the result of each root (roots[i] is answered by outcome.roots[i]) and the counters. See Trace for the format. Fails when an expression is not of cx.

Trait Implementations§

Source§

impl Clone for Trace

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Trace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Observer for Trace

Source§

fn event(&mut self, event: Event<'_>)

Called for every event, in order.
Source§

fn detail(&self) -> Detail

How much the engine builds for this observer: Detail::Events unless it asks for more.

Auto Trait Implementations§

§

impl Forget for Trace

§

impl Freeze for Trace

§

impl Move for Trace

§

impl RefUnwindSafe for Trace

§

impl Send for Trace

§

impl Sync for Trace

§

impl Unpin for Trace

§

impl UnsafeUnpin for Trace

§

impl UnwindSafe for Trace

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.