pub struct EGraph { /* private fields */ }Expand description
The state associated with an egglog program.
Implementations§
Source§impl EGraph
impl EGraph
Sourcepub fn base_values_mut(&mut self) -> &mut BaseValues
pub fn base_values_mut(&mut self) -> &mut BaseValues
Get a mutable reference to the underlying table of base values for this
EGraph.
Sourcepub fn container_values_mut(&mut self) -> &mut ContainerValues
pub fn container_values_mut(&mut self) -> &mut ContainerValues
Get a mutable reference to the underlying table of containers for this
EGraph.
Sourcepub fn container_values(&self) -> &ContainerValues
pub fn container_values(&self) -> &ContainerValues
Get a reference to the underlying table of containers for this EGraph.
Sourcepub fn get_container_value<C: ContainerValue>(&mut self, val: C) -> Value
pub fn get_container_value<C: ContainerValue>(&mut self, val: C) -> Value
Intern the given container value into the EGraph.
Sourcepub fn register_container_ty<C: ContainerValue>(&mut self)
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.
Sourcepub fn base_values(&self) -> &BaseValues
pub fn base_values(&self) -> &BaseValues
Get a reference to the underlying table of base values for this EGraph.
Sourcepub fn base_value_constant<T>(&self, x: T) -> QueryEntrywhere
T: BaseValue,
pub fn base_value_constant<T>(&self, x: T) -> QueryEntrywhere
T: BaseValue,
Create a QueryEntry for a base value.
Sourcepub fn register_external_func(
&mut self,
func: Box<dyn ExternalFunction + 'static>,
) -> ExternalFunctionId
pub fn register_external_func( &mut self, func: Box<dyn ExternalFunction + 'static>, ) -> ExternalFunctionId
Register a low-level external function. The callback receives a
raw &mut ExecutionState.
§Seminaive-safety trust boundary
Like EGraph::with_execution_state, this is a raw escape —
the registered function has unrestricted access and is not
tracked by the per-context validity system. Prefer building
primitives via the higher-level egglog::Primitive /
egglog::EGraph::add_primitive API, which enforces #772’s
seminaive-safety contract.
pub fn free_external_func(&mut self, func: ExternalFunctionId)
Sourcepub fn get_canon_repr(&self, val: Value, ty: ColumnTy) -> Value
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.
Sourcepub fn add_values(
&mut self,
values: impl IntoIterator<Item = (FunctionId, Vec<Value>)>,
)
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.
Sourcepub fn add_term(&mut self, func: FunctionId, inputs: &[Value]) -> Value
pub fn add_term(&mut self, func: FunctionId, inputs: &[Value]) -> 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.
§Panics
This method panics if the values do not match the arity of the function.
Sourcepub fn lookup_id(&self, func: FunctionId, key: &[Value]) -> Option<Value>
pub fn lookup_id(&self, func: FunctionId, key: &[Value]) -> Option<Value>
Lookup the id associated with a function func and the given arguments
(key).
pub fn approx_table_size(&self, table: FunctionId) -> usize
pub fn table_size(&self, table: FunctionId) -> usize
Sourcepub fn clear_table(&mut self, func: FunctionId)
pub fn clear_table(&mut self, func: FunctionId)
Remove every row from the given function’s backing table.
This is the bulk counterpart to staging a remove for every key in the
table: the underlying Database::clear_table drops the row buffer in
O(1)-in-row-count time and bumps the table’s major generation, which
lazily invalidates any cached subsets or indexes a later reader might
consult. Any rows staged for this table by an in-flight
MutationBuffer are dropped along with the table contents.
Callers that have staged inserts/removes for other tables that they
want flushed first should call EGraph::flush_updates before
clearing.
Sourcepub fn for_each(&self, table: FunctionId, f: impl FnMut(ScanEntry<'_>))
pub fn for_each(&self, table: FunctionId, f: impl FnMut(ScanEntry<'_>))
Read the contents of the given function.
The callback f is called with each row and its subsumption status.
Sourcepub fn for_each_while(
&self,
table: FunctionId,
f: impl FnMut(ScanEntry<'_>) -> bool,
)
pub fn for_each_while( &self, table: FunctionId, f: impl FnMut(ScanEntry<'_>) -> 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.
Sourcepub fn dump_debug_info(&self)
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.
Sourcepub fn add_table(&mut self, config: FunctionConfig) -> FunctionId
pub fn add_table(&mut self, config: FunctionConfig) -> FunctionId
Register a function in this EGraph.
Sourcepub fn action_registry(&self) -> &Arc<RwLock<ActionRegistry>>
pub fn action_registry(&self) -> &Arc<RwLock<ActionRegistry>>
A handle to the live ActionRegistry for this EGraph.
The handle is shared (Arc<RwLock<_>>); cloning the outer
Arc does not duplicate the underlying registry. Used by the
egglog crate’s primitive machinery to thread the registry into
state wrappers at invoke time.
Sourcepub fn run_rules(&mut self, rules: &[RuleId]) -> Result<IterationReport>
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.
Sourcepub fn with_execution_state<R>(
&self,
f: impl FnOnce(&mut ExecutionState<'_>) -> R,
) -> R
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.
§Seminaive-safety trust boundary
This method hands out a raw &mut ExecutionState, which bypasses
the egglog crate’s Read / Write capability wrappers
(PureState, WriteState, ReadState, FullState) that
enforce #772’s seminaive-safety model. Treat it as top-level
/ global-action context: appropriate for one-shot database
manipulation from outside any rule, not for use inside
primitive implementations.
Sourcepub fn with_execution_state_tracked<R>(
&self,
f: impl FnOnce(&mut ExecutionState<'_>) -> R,
) -> (R, bool)
pub fn with_execution_state_tracked<R>( &self, f: impl FnOnce(&mut ExecutionState<'_>) -> R, ) -> (R, bool)
Like EGraph::with_execution_state, but also reports whether f
staged any mutation. A read-only closure leaves the flag false, so
callers can skip a EGraph::flush_updates that would otherwise be a
no-op merge plus a spurious timestamp bump.
Sourcepub fn flush_updates(&mut self) -> bool
pub fn flush_updates(&mut self) -> bool
Flush the pending update buffers to the EGraph.
Returns true if the database is updated.
pub fn set_report_level(&mut self, level: ReportLevel)
Source§impl EGraph
impl EGraph
Sourcepub fn new_panic(&mut self, message: String) -> ExternalFunctionId
pub fn new_panic(&mut self, message: String) -> ExternalFunctionId
Create a new ExternalFunction that panics with the given message.
pub fn new_panic_lazy( &mut self, message: impl FnOnce() -> String + Send + 'static, ) -> ExternalFunctionId
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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