Skip to main content

LetInliner

Struct LetInliner 

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

The let-inlining pass.

Iterates to a fixed point (or until config.max_passes is reached), replacing eligible Let bindings with direct substitution of the bound value into the body.

Implementations§

Source§

impl LetInliner

Source

pub fn new(config: InlineConfig) -> Self

Construct a new inliner with the given configuration.

Source

pub fn with_default() -> Self

Construct a new inliner with the default configuration.

Source

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

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

Returns the rewritten expression and collected InlineStats.

Source

pub fn count_free_occurrences(var: &str, expr: &TLExpr) -> usize

Count how many times var appears free in expr.

Source

pub fn substitute(var: &str, replacement: &TLExpr, body: TLExpr) -> TLExpr

Substitute all free occurrences of var with replacement in body.

Source

pub fn is_constant_binding(expr: &TLExpr) -> bool

Returns true if expr is a constant literal (Constant(_)).

Source

pub fn is_var_binding(expr: &TLExpr) -> bool

Returns true if expr is a zero-argument predicate (variable alias).

Source

pub fn is_simple_binding(expr: &TLExpr) -> bool

Returns true if expr is a “simple” binding worth inlining regardless of use count: either a constant or a variable alias.

Source

pub fn expr_depth(expr: &TLExpr) -> usize

Compute the depth (height) of an expression tree.

Trait Implementations§

Source§

impl Default for LetInliner

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.