ExecutionState

Struct ExecutionState 

Source
pub struct ExecutionState<'a> { /* private fields */ }
Expand description

A handle on a database that may be in the process of running a rule.

An ExecutionState grants immutable access to the (much of) the database, and also provides a limited API to mutate database contents.

A few important notes:

§Some tables may be missing

Callers external to this crate cannot construct an ExecutionState directly. Depending on the context, some tables may not be available. In particular, when running crate::Table::merge operations, only a table’s read-side dependencies are available for reading (sim. for writing). This allows tables that do not need access to one another to be merged in parallel.

When executing a rule, ExecutionState has access to all tables.

§Limited Mutability

Callers can only stage insertsions and deletions to tables. These changes are not applied until the next call to merge on the underlying table.

§Predicted Values

ExecutionStates provide a means of synchronizing the results of a pending write across different executions of a rule. This is particularly important in the case where the result of an operation (such as “lookup or insert new id” operatiosn) is a fresh id. A common ExecutionState ensures that future lookups will see the same id (even across calls to ExecutionState::clone).

Implementations§

Source§

impl<'a> ExecutionState<'a>

Source

pub fn stage_insert(&mut self, table: TableId, row: &[Value])

Stage an insertion of the given row into table.

If you are using egglog, consider using egglog_bridge::TableAction.

Source

pub fn stage_remove(&mut self, table: TableId, key: &[Value])

Stage a removal of the given row from table if it is present.

If you are using egglog, consider using egglog_bridge::TableAction.

Source

pub fn call_external_func( &mut self, func: ExternalFunctionId, args: &[Value], ) -> Option<Value>

Call an external function.

Source

pub fn inc_counter(&self, ctr: CounterId) -> usize

Source

pub fn read_counter(&self, ctr: CounterId) -> usize

Source

pub fn get_table(&self, table: TableId) -> &'a WrappedTable

Get an immutable reference to the table with id table. Dangerous: Reading from a table during action execution may break the semi-naive evaluation

Source

pub fn base_values(&self) -> &BaseValues

Source

pub fn container_values(&self) -> &'a ContainerValues

Source

pub fn predict_val( &mut self, table: TableId, key: &[Value], vals: impl ExactSizeIterator<Item = MergeVal>, ) -> Pooled<Vec<Value>>

Get the current value for a given key in table, or otherwise insert the unique next value.

Insertions into tables are not performed immediately, but rules and merge functions sometimes need to get the result of an insertion. For such cases, executions keep a cache of “predicted” values for a given mapping that manage the insertions, etc.

If you are using egglog, consider using egglog_bridge::TableAction.

Source

pub fn predict_col( &mut self, table: TableId, key: &[Value], vals: impl ExactSizeIterator<Item = MergeVal>, col: ColumnId, ) -> Value

A variant of ExecutionState::predict_val that avoids materializing the full row, and instead only returns the value in the given column.

Trait Implementations§

Source§

impl Clone for ExecutionState<'_>

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl<'a> Freeze for ExecutionState<'a>

§

impl<'a> !RefUnwindSafe for ExecutionState<'a>

§

impl<'a> Send for ExecutionState<'a>

§

impl<'a> Sync for ExecutionState<'a>

§

impl<'a> Unpin for ExecutionState<'a>

§

impl<'a> !UnwindSafe for ExecutionState<'a>

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