Skip to main content

RuleEffect

Struct RuleEffect 

Source
#[non_exhaustive]
pub struct RuleEffect { pub new_expression: Expression, pub new_top: Vec<Expression>, pub symbols: SymbolTable, pub new_clauses: Vec<CnfClause>, /* private fields */ }
Expand description

Represents the result of applying a rule to an expression within a model.

A RuleEffect encapsulates the changes made to a model during a rule application. It includes a new expression to replace the original one, an optional top-level constraint to be added to the model, and any updates to the model’s symbol table.

This struct allows for representing side-effects of rule applications, ensuring that all modifications, including symbol table expansions and additional constraints, are accounted for and can be applied to the model consistently.

§Fields

  • new_expression: The updated Expression that replaces the original one after applying the rule.
  • new_top: An additional top-level Vec<Expression> constraint that should be added to the model. If no top-level constraint is needed, this field can be set to an empty vector Vec::new().
  • symbols: A SymbolTable containing any new symbol definitions or modifications to be added to the model’s symbol table. If no symbols are modified, this field can be set to an empty symbol table.

§Usage

A RuleEffect can be created using one of the provided constructors:

  • RuleEffect::new: Creates an effect with a new expression, top-level constraint, and symbol modifications.
  • RuleEffect::pure: Creates an effect with only a new expression and no side-effects on the symbol table or constraints.
  • RuleEffect::with_symbols: Creates an effect with a new expression and symbol table modifications, but no top-level constraint.
  • RuleEffect::with_top: Creates an effect with a new expression and a top-level constraint, but no symbol table modifications.
  • RuleEffect::cnf: Creates an effect with a new expression, cnf clauses and symbol modifications, but no top-level constraints.

The apply method allows for applying the changes represented by the RuleEffect to a Model.

§Example

// Need to add an example

§See Also

  • ApplicationResult: Represents the result of applying a rule, which may either be a RuleEffect or an ApplicationError.
  • Model: The structure to which the RuleEffect changes are applied.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§new_expression: Expression§new_top: Vec<Expression>§symbols: SymbolTable§new_clauses: Vec<CnfClause>

Implementations§

Source§

impl RuleEffect

Source

pub fn new( new_expression: Expression, new_top: Vec<Expression>, symbols: SymbolTable, ) -> Self

Source

pub fn pure(new_expression: Expression) -> Self

Represents an effect with no side effects on the model.

Source

pub fn with_symbols(new_expression: Expression, symbols: SymbolTable) -> Self

Represents an effect that also modifies the symbol table.

Source

pub fn with_top(new_expression: Expression, new_top: Vec<Expression>) -> Self

Represents an effect that also adds a top-level constraint to the model.

Source

pub fn cnf( new_expression: Expression, new_clauses: Vec<CnfClause>, symbols: SymbolTable, ) -> Self

Represents an effect that also adds clauses to the model.

Source

pub fn deferred( materialise: impl Fn(&SymbolTable) -> RuleEffect + Send + Sync + 'static, ) -> Self

Defers constructing a concrete effect until the rewriter chooses to apply this rule.

This is intended for rule effects that allocate fresh names or otherwise depend on global model state. Applicability checks can return a deferred effect without consuming those effects; the rewriter calls RuleEffect::materialise only for the selected rule.

Source

pub fn materialise(self, symbols: &SymbolTable) -> Self

Returns the concrete effect for the current symbol table.

This consumes the selected effect: cloning a concrete effect can duplicate its expression, top-level constraints, clauses, and speculative symbol table. Before returning, the symbol snapshot is reduced to the bindings that the effect actually changes.

Source

pub fn with_declaration_updates( self, updates: impl IntoIterator<Item = (DeclarationPtr, DeclarationKind)>, ) -> Self

Adds declaration replacements that are committed only if this effect is selected.

Source

pub fn updated_declaration_names(&self) -> impl Iterator<Item = Name> + '_

Iterates over the names changed by deferred declaration updates.

Source

pub fn apply(self, model: &mut Model)

Applies side-effects (e.g. symbol table updates)

Source

pub fn added_symbols(&self, initial_symbols: &SymbolTable) -> BTreeSet<Name>

Gets symbols added by this effect.

Walks this effect’s own symbols rather than diffing two whole tables. The rewriter asks this once per applied rule, and most effects are pure, so diffing made every rewrite cost a clone and a sort of the entire model symbol table.

Source

pub fn changed_symbols( &self, initial_symbols: &SymbolTable, ) -> Vec<(Name, DeclarationPtr, DeclarationPtr)>

Gets symbols changed by this effect.

Returns a list of tuples of (name, domain before effect, domain after effect), ordered by name.

Walks this effect’s symbols for the same reason as RuleEffect::added_symbols: a symbol can only have changed if this effect carries its new value.

Trait Implementations§

Source§

impl Clone for RuleEffect

Source§

fn clone(&self) -> RuleEffect

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleEffect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

§

fn into_ast(self, _a: &A) -> A

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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 352 bytes