Skip to main content

DeadCodeEliminator

Struct DeadCodeEliminator 

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

The dead code elimination pass for TLExpr trees.

Run with DeadCodeEliminator::run for a full fixed-point iteration, or run_pass for a single traversal.

Implementations§

Source§

impl DeadCodeEliminator

Source

pub fn is_free(&self, var: &str, expr: &TLExpr) -> bool

Returns true if var appears free (as a predicate argument or inside a binder that does not shadow it) anywhere in expr.

Variable occurrences in TLExpr live in two places:

  1. Term::Var(name) inside Pred args
  2. AllDifferent { variables } variable name lists
  3. Any binder (Exists, ForAll, Let, Lambda, LeastFixpoint, etc.) that introduces a new scope — we stop counting the variable as free inside the scope if the binder’s name equals var.
Source§

impl DeadCodeEliminator

Source

pub fn count_nodes(expr: &TLExpr) -> u64

Count the total number of nodes in an expression tree.

Every node (leaf or internal) counts as 1.

Source§

impl DeadCodeEliminator

Source

pub fn new(config: DceConfig) -> Self

Create a new eliminator with the given configuration.

Source

pub fn with_default() -> Self

Create a new eliminator with default configuration.

Source

pub fn run(&self, expr: TLExpr) -> (TLExpr, DceStats)

Run DCE to a fixed point (or until config.max_passes is reached).

Returns the simplified expression and collected DceStats.

Trait Implementations§

Source§

impl Default for DeadCodeEliminator

Source§

fn default() -> Self

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

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> 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, 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.