Skip to main content

Model

Struct Model 

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

A model: sets, relations, actions, and facts.

Implementations§

Source§

impl Model

Source

pub fn new() -> Model

An empty model.

Source

pub fn set(&mut self, name: &str) -> Expr

A top-level set: its own atoms, as many as the command’s scope.

Source

pub fn changing_set(&mut self, name: &str) -> Expr

A top-level set whose members may change from state to state; its atoms are fixed by the scope as any top-level set’s are.

Source

pub fn ints(&mut self) -> Expr

Int, the top-level set of integer atoms: in each command, exactly one atom for each integer of its bitwidth, named by the integer, from the least (LOGIC.md 12.9 and 16.1). The same set every time it is asked for.

Source

pub fn abstract_set(&mut self, name: &str) -> Expr

A top-level set that is the union of the sets that extend it.

Source

pub fn one(&mut self, name: &str) -> Expr

A top-level set of exactly one atom.

Source

pub fn subset(&mut self, name: &str, parent: &Expr) -> Expr

A subset of parent.

§Panics

If parent is not a set of this model: a mistake in the Rust that builds the model, found the first time it runs.

Source

pub fn one_extends(&mut self, name: &str, parent: &Expr) -> Expr

An extension of parent with exactly one atom: Alloy’s one sig X extends P. Its parent’s scope makes room for it (LOGIC.md 12.9).

§Panics

As Model::subset.

Source

pub fn extends(&mut self, name: &str, parent: &Expr) -> Expr

A subset of parent, disjoint from the parent’s other extensions.

§Panics

As Model::subset.

Source

pub fn changing_subset(&mut self, name: &str, parent: &Expr) -> Expr

A subset of parent that may change from state to state.

§Panics

As Model::subset.

Source

pub fn changing_relation(&mut self, name: &str, columns: &[&Expr]) -> Expr

A relation over columns that may change from state to state.

Source

pub fn changing_field( &mut self, name: &str, domain: &Expr, range: &Expr, ) -> Expr

A field that may change from state to state.

Source

pub fn changing_field_with( &mut self, name: &str, domain: &Expr, multiplicity: Multiplicity, range: &Expr, ) -> Expr

A field with a multiplicity that may change from state to state; the multiplicity holds in every state.

Source

pub fn relations(&self) -> Vec<Relation>

Every set and relation of the model, in declaration order, then the relations of orderings.

Source

pub fn column_tops(&self, r: &Relation) -> Option<Vec<Expr>>

The top-level sets a relation’s columns range over: a set’s own top- level set, a relation’s columns’ (LOGIC.md 12.9). None for a relation that is not this model’s.

Source

pub fn column_sets(&self, r: &Relation) -> Option<Vec<Vec<String>>>

The top-level sets each of a relation’s columns ranges over, by name and in declaration order, a union having several.

Source

pub fn top_of(&self, set: &Expr) -> Option<Expr>

The top-level set a set of this model is inside.

Source

pub fn ordering(&mut self, set: &Expr) -> Ordering

An ordering of a set (LOGIC.md 12.9). On a top-level set, its scope becomes exact, and first and next follow its atoms in order. On a set that extends or is in another, or a subset of a union made by relation_over_unions with one column, first and next are a total order of it that the solver finds, and its size is fixed as LOGIC.md 12.9 says. An ordering on a set that changes over time is model.not_a_set.

§Panics

If set is neither a set of this model nor such a subset of a union.

Source

pub fn enum_ordering(&mut self, set: &Expr) -> Ordering

An ordering for an enum set whose one extensions are fixed in declaration order (BoundsComputer.java, isEnum, B27).

Source

pub fn action<const N: usize>( &mut self, name: &str, params: [&Expr; N], body: impl FnOnce(&mut Step, [Expr; N]), ) -> Action

An action: a named step with parameters, one per set in params (LOGIC.md 13.5). body gets the step and the parameters, and says when the action can happen and what it changes. Every changing relation it does not change stays as it was.

Source

pub fn relation_over_unions( &mut self, name: &str, columns: &[Vec<&Expr>], changing: bool, ) -> Expr

A relation whose columns each range over a union of sets: Alloy’s f: set A + B (LOGIC.md 15.1).

§Panics

If a column names a set that is not this model’s, or is empty.

Source

pub fn set_place(&mut self, expr: &Expr, place: Place)

Records the source place of a set or relation declared on this model, so any bounds error on it points to that place rather than Elinvar’s internal source.

Source

pub fn relation(&mut self, name: &str, columns: &[&Expr]) -> Expr

A relation over the given columns, each a set of this model.

§Panics

If a column is not a set of this model.

Source

pub fn field(&mut self, name: &str, domain: &Expr, range: &Expr) -> Expr

A field from domain to range: each x of the domain is related to any number of the range.

Source

pub fn field_with( &mut self, name: &str, domain: &Expr, multiplicity: Multiplicity, range: &Expr, ) -> Expr

A field with a multiplicity: each x of the domain is related to one, lone, or some of the range.

Source

pub fn fact(&mut self, f: Formula)

A fact: true in every instance.

Source

pub fn fact_named(&mut self, name: impl Into<String>, f: Formula)

A named fact: true in every instance, identified by name in unsat-core explanations (Command::explain_holds).

Source

pub fn univ(&self) -> Expr

The union of the top-level sets (LOGIC.md 12.9).

Source

pub fn iden(&self) -> Expr

iden restricted to the builder’s univ.

Source

pub fn run(&self, f: &Formula) -> Command<'_>

A command that looks for an instance of the facts and f.

Source

pub fn check(&self, assertion: &Formula) -> Command<'_>

A command that looks for a counterexample to assertion under the facts.

Source

pub fn register_step_label( &mut self, name: impl Into<String>, vars: Vec<Variable>, ranges: Vec<Expr>, formula: Formula, )

Registers a named step predicate for labelling trace steps in stories without adding a frame or transition fact to the model.

Source

pub fn register_step_spec(&mut self, spec: StepSpec)

Registers a structured step decomposition (guards + effect) for per-guard unsat cores (N14), test generation (N11), and model diagrams (W14).

Source

pub fn register_transition_extra( &mut self, fact_name: impl Into<String>, arm: Formula, )

Records a non-decomposed arm (such as nothing) of transition fact fact_name, so rebuilding the transition fact during guard refinement preserves it.

Source

pub fn step_specs(&self) -> &[StepSpec]

The structured step specifications registered on this model (N11, N14, W14).

Source

pub fn all_facts_named(&self) -> Vec<(String, Formula)>

Every fact of the model paired with its rule label (for accepts and diagnostic reporting, N12).

Source

pub fn set_summaries(&self) -> Vec<(String, Option<String>, bool)>

The sets declared on this model (name, parent name if any, changing).

Source

pub fn relation_summaries(&self) -> Vec<(String, Vec<String>, bool)>

The fields/relations declared on this model (name, column set names, changing).

Source§

impl Model

Source

pub fn generate_tests( &self, scope: usize, steps: usize, budget: Budget, with_sql: bool, ) -> Result<Vec<TestCase>, Vec<Error>>

Generates step reachability tests and per-guard refusal tests from the model’s registered StepSpecs (N11).

  • For each step: finds the shortest trace in which it fires, or flags it as TestKind::DeadStep.
  • For each guard condition of each step: finds the shortest trace to a state/attempt where that guard alone refuses the step, or flags it as TestKind::UnreachableGuard.
Source

pub fn generate_tests_with( &self, scope: usize, steps: usize, budget: Budget, with_sql: bool, sample_values: &BTreeMap<String, Vec<String>>, on_case: impl FnMut(&TestCase), ) -> Result<Vec<TestCase>, Vec<Error>>

Streaming, sample-aware variant of Self::generate_tests (B16, N21): invokes on_case immediately as each test finishes, uses sample_values ("table.col" -> valid sample strings) when rendering SQL, and executes the refused step in a relaxed-guard trace so every SQL refusal script includes the concrete statement under test.

Source

pub fn generate_tests_for_tables( &self, scope: usize, steps: usize, budget: Budget, with_sql: bool, sample_values: &BTreeMap<String, Vec<String>>, only_tables: &[String], trigger_targets: &BTreeMap<String, Vec<String>>, on_case: impl FnMut(&TestCase), ) -> Result<Vec<TestCase>, Vec<Error>>

Table-filtered, trigger-aware variant of Self::generate_tests_with (B24, B25, B40):

  • When only_tables is non-empty, only generates cases for steps (insert_<t>, update_<t>, delete_<t>) belonging to those tables, while keeping all other imported tables and rules active in the model.
  • Uses trigger_targets (source_table -> [target_table]) when rendering SQL so rows written automatically by AFTER triggers are not emitted as duplicate INSERT statements.

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Self

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 Model

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Model

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Forget for Model

§

impl Freeze for Model

§

impl Move for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model
where RawVecInner: Send, Arc<Declared>: Send, Arc<FormulaNode>: Send, Arc<ExprNode>: Send, NodeRef<Owned, String, Vec<Formula>, LeafOrInternal>: Send, BoxRaw<(String, Vec<Formula>)>: Send, &'static str: Send,

§

impl Sync for Model
where RawVecInner: Sync, Arc<Declared>: Sync, Arc<FormulaNode>: Sync, Arc<ExprNode>: Sync, NodeRef<Owned, String, Vec<Formula>, LeafOrInternal>: Sync, BoxRaw<(String, Vec<Formula>)>: Sync,

§

impl Unpin for Model
where *const u8 is !null: Unpin, Arc<Declared>: Unpin, Arc<FormulaNode>: Unpin, Arc<ExprNode>: Unpin, *const LeafNode<String, Vec<Formula>> is !null: Unpin, Box<(String, Vec<Formula>)>: Unpin, &'static str: Unpin,

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model
where RawVecInner: UnwindSafe, Arc<Declared>: UnwindSafe, Arc<FormulaNode>: UnwindSafe, Arc<ExprNode>: UnwindSafe, BTreeMap<String, Vec<Formula>>: UnwindSafe, &'static str: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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