EGraph

Struct EGraph 

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

The state associated with an egglog program.

Implementations§

Source§

impl EGraph

Source

pub fn new_rule(&mut self, desc: &str, seminaive: bool) -> RuleBuilder<'_>

Add a rewrite rule for this EGraph using a RuleBuilder. If you aren’t sure, use egraph.new_rule("", true).

Source

pub fn free_rule(&mut self, id: RuleId)

Remove a rewrite rule from this EGraph.

Source§

impl EGraph

Source

pub fn with_tracing() -> EGraph

Create a new EGraph with tracing (aka ‘proofs’) enabled.

Execution of queries against a tracing-enabled EGraph will be slower, but will annotate the egraph with annotations that can explain how rows came to appear.

Source

pub fn base_values_mut(&mut self) -> &mut BaseValues

Get a mutable reference to the underlying table of base values for this EGraph.

Source

pub fn container_values_mut(&mut self) -> &mut ContainerValues

Get a mutable reference to the underlying table of containers for this EGraph.

Source

pub fn container_values(&self) -> &ContainerValues

Get a reference to the underlying table of containers for this EGraph.

Source

pub fn get_container_value<C: ContainerValue>(&mut self, val: C) -> Value

Intern the given container value into the EGraph.

Source

pub fn register_container_ty<C: ContainerValue>(&mut self)

Register the given ContainerValue type with this EGraph.

The given container will use the EGraph’s union-find to manage rebuilding and the merging of containers with a common id.

Source

pub fn base_values(&self) -> &BaseValues

Get a reference to the underlying table of base values for this EGraph.

Source

pub fn base_value_constant<T>(&self, x: T) -> QueryEntry
where T: BaseValue,

Create a QueryEntry for a base value.

Source

pub fn register_external_func( &mut self, func: impl ExternalFunction + 'static, ) -> ExternalFunctionId

Source

pub fn free_external_func(&mut self, func: ExternalFunctionId)

Source

pub fn fresh_id(&mut self) -> Value

Generate a fresh id.

Source

pub fn get_canon_repr(&self, val: Value, ty: ColumnTy) -> Value

Get the canonical representation for val based on type.

For ColumnTy::Id, it looks up the union find; otherwise, it returns the value itself.

Source

pub fn add_values( &mut self, values: impl IntoIterator<Item = (FunctionId, Vec<Value>)>, )

Load the given values into the database.

§Panics

This method panics if the values do not match the arity of the function.

NB: this is not an efficient interface for bulk loading. We should add one that allows us to pass through a series of RowBuffers before incrementing the timestamp.

Source

pub fn add_term( &mut self, func: FunctionId, inputs: &[Value], desc: &str, ) -> Value

A term-oriented means of adding data to the database: hand back a “term id” for the given function and keys for the function. Proofs for this term will include desc.

§Panics

This method panics if the values do not match the arity of the function.

Source

pub fn lookup_id(&self, func: FunctionId, key: &[Value]) -> Option<Value>

Lookup the id associated with a function func and the given arguments (key).

Source

pub fn add_values_with_desc( &mut self, desc: &str, values: impl IntoIterator<Item = (FunctionId, Vec<Value>)>, )

Load the given values into the database. If tracing is enabled, the proof rows will be tagged with “desc” as their proof.

§Panics

This method panics if the values do not match the arity of the function.

NB: this is not an efficient interface for bulk loading. We should add one that allows us to pass through a series of RowBuffers before incrementing the timestamp.

Source

pub fn approx_table_size(&self, table: FunctionId) -> usize

Source

pub fn table_size(&self, table: FunctionId) -> usize

Source

pub fn explain_term( &mut self, id: Value, store: &mut ProofStore, ) -> Result<TermProofId>

Generate a proof explaining why a given term is in the database.

§Errors

This method will return an error if tracing is not enabled, or if the row is not in the database.

§Panics

This method may panic if key does not match the arity of the function, or is otherwise malformed.

Source

pub fn explain_terms_equal( &mut self, id1: Value, id2: Value, store: &mut ProofStore, ) -> Result<EqProofId>

Generate a proof explaining why the term corresponding to id1 is equal to that corresponding to id2.

§Errors

This method will return an error if tracing is not enabled, if the row is not in the database, or if the terms themselves are not equal.

Source

pub fn for_each(&self, table: FunctionId, f: impl FnMut(FunctionRow<'_>))

Read the contents of the given function.

The callback f is called with each row and its subsumption status.

Source

pub fn for_each_while( &self, table: FunctionId, f: impl FnMut(FunctionRow<'_>) -> bool, )

Iterate over the rows of a function table, calling f on each row. If f returns false the function returns early and stops reading rows from the table.

Source

pub fn dump_debug_info(&self)

A basic method for dumping the state of the database to log::info!.

For large tables, this is unlikely to give particularly useful output.

Source

pub fn add_table(&mut self, config: FunctionConfig) -> FunctionId

Register a function in this EGraph.

Source

pub fn run_rules(&mut self, rules: &[RuleId]) -> Result<IterationReport>

Run the given rules, returning whether the database changed.

If the given rules are malformed, this method can return an error.

Source

pub fn with_execution_state<R>( &self, f: impl FnOnce(&mut ExecutionState<'_>) -> R, ) -> R

Gives the user a handle to the underlying ExecutionState. Useful for staging updates to the database.

The staged updates are not immediately reflected in the EGraph, so you may want to manually flush the updates using EGraph::flush_updates.

Source

pub fn flush_updates(&mut self) -> bool

Flush the pending update buffers to the EGraph. Returns true if the database is updated.

Source§

impl EGraph

Source

pub fn new_panic(&mut self, message: String) -> ExternalFunctionId

Create a new ExternalFunction that panics with the given message.

Source

pub fn new_panic_lazy( &mut self, message: impl FnOnce() -> String + Send + 'static, ) -> ExternalFunctionId

Trait Implementations§

Source§

impl Clone for EGraph

Source§

fn clone(&self) -> EGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for EGraph

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for EGraph

§

impl !RefUnwindSafe for EGraph

§

impl Send for EGraph

§

impl Sync for EGraph

§

impl Unpin for EGraph

§

impl !UnwindSafe for EGraph

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V