Skip to main content

Report

Struct Report 

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

A record of one PassManager run.

A Report is the observability hook: it lists every pass that ran, in order, with the Outcome each reported, and summarizes the run — how many sweeps it took, whether it reached a fixpoint, and how many passes changed the unit. It is produced by PassManager::run and PassManager::run_to_fixpoint; you read it, you do not build it.

§Examples

use pass_lang::{Outcome, Pass, PassError, PassManager};

struct Halve;
impl Pass<i64> for Halve {
    fn name(&self) -> &'static str { "halve" }
    fn run(&mut self, u: &mut i64) -> Result<Outcome, PassError> {
        if *u <= 1 { return Ok(Outcome::Unchanged); }
        *u /= 2;
        Ok(Outcome::Changed)
    }
}

let mut pm = PassManager::new();
pm.add(Halve);

let mut unit = 8;
let report = pm.run_to_fixpoint(&mut unit, 16).unwrap();

assert_eq!(unit, 1);                 // 8 -> 4 -> 2 -> 1
assert!(report.converged());         // a final sweep changed nothing
assert_eq!(report.iterations(), 4);  // three halving sweeps + one confirming sweep
assert_eq!(report.changes(), 3);     // three sweeps reported Changed

Implementations§

Source§

impl Report

Source

pub fn runs(&self) -> &[PassRun]

Every pass execution, in the order it happened.

§Examples
use pass_lang::{Outcome, Pass, PassError, PassManager};

struct A;
impl Pass<i64> for A {
    fn name(&self) -> &'static str { "a" }
    fn run(&mut self, _: &mut i64) -> Result<Outcome, PassError> { Ok(Outcome::Unchanged) }
}
struct B;
impl Pass<i64> for B {
    fn name(&self) -> &'static str { "b" }
    fn run(&mut self, _: &mut i64) -> Result<Outcome, PassError> { Ok(Outcome::Unchanged) }
}

let mut pm = PassManager::new();
pm.add(A).add(B);
let mut unit = 0;
let report = pm.run(&mut unit).unwrap();

let names: Vec<_> = report.runs().iter().map(|r| r.name()).collect();
assert_eq!(names, ["a", "b"]);
Source

pub fn changes(&self) -> usize

How many pass executions reported Outcome::Changed.

§Examples
use pass_lang::{Outcome, Pass, PassError, PassManager};

struct Inc;
impl Pass<i64> for Inc {
    fn name(&self) -> &'static str { "inc" }
    fn run(&mut self, u: &mut i64) -> Result<Outcome, PassError> {
        *u += 1;
        Ok(Outcome::Changed)
    }
}

let mut pm = PassManager::new();
pm.add(Inc);
let mut unit = 0;
assert_eq!(pm.run(&mut unit).unwrap().changes(), 1);
Source

pub fn iterations(&self) -> usize

The number of full sweeps over the pipeline.

PassManager::run always reports 1. PassManager::run_to_fixpoint reports how many sweeps it actually performed.

Source

pub fn converged(&self) -> bool

Whether the final sweep made no change — the pipeline reached a fixpoint.

For run this is true when the single sweep changed nothing. For run_to_fixpoint it is true when a sweep settled before the iteration bound was hit, and false when the bound was reached with the unit still changing.

Trait Implementations§

Source§

impl Clone for Report

Source§

fn clone(&self) -> Report

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 Report

Source§

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

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

impl Default for Report

Source§

fn default() -> Report

Returns the “default value” for a type. Read more
Source§

impl Eq for Report

Source§

impl PartialEq for Report

Source§

fn eq(&self, other: &Report) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Report

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Report

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.