pub struct Model { /* private fields */ }Expand description
A model: sets, relations, actions, and facts.
Implementations§
Source§impl Model
impl Model
Sourcepub fn set(&mut self, name: &str) -> Expr
pub fn set(&mut self, name: &str) -> Expr
A top-level set: its own atoms, as many as the command’s scope.
Sourcepub fn changing_set(&mut self, name: &str) -> Expr
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.
Sourcepub fn ints(&mut self) -> Expr
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.
Sourcepub fn abstract_set(&mut self, name: &str) -> Expr
pub fn abstract_set(&mut self, name: &str) -> Expr
A top-level set that is the union of the sets that extend it.
Sourcepub fn subset(&mut self, name: &str, parent: &Expr) -> Expr
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.
Sourcepub fn one_extends(&mut self, name: &str, parent: &Expr) -> Expr
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.
Sourcepub fn changing_subset(&mut self, name: &str, parent: &Expr) -> Expr
pub fn changing_subset(&mut self, name: &str, parent: &Expr) -> Expr
Sourcepub fn changing_relation(&mut self, name: &str, columns: &[&Expr]) -> Expr
pub fn changing_relation(&mut self, name: &str, columns: &[&Expr]) -> Expr
A relation over columns that may change from state to state.
Sourcepub fn changing_field(
&mut self,
name: &str,
domain: &Expr,
range: &Expr,
) -> Expr
pub fn changing_field( &mut self, name: &str, domain: &Expr, range: &Expr, ) -> Expr
A field that may change from state to state.
Sourcepub fn changing_field_with(
&mut self,
name: &str,
domain: &Expr,
multiplicity: Multiplicity,
range: &Expr,
) -> Expr
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.
Sourcepub fn relations(&self) -> Vec<Relation>
pub fn relations(&self) -> Vec<Relation>
Every set and relation of the model, in declaration order, then the relations of orderings.
Sourcepub fn column_tops(&self, r: &Relation) -> Option<Vec<Expr>>
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.
Sourcepub fn column_sets(&self, r: &Relation) -> Option<Vec<Vec<String>>>
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.
Sourcepub fn top_of(&self, set: &Expr) -> Option<Expr>
pub fn top_of(&self, set: &Expr) -> Option<Expr>
The top-level set a set of this model is inside.
Sourcepub fn ordering(&mut self, set: &Expr) -> Ordering
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.
Sourcepub fn enum_ordering(&mut self, set: &Expr) -> Ordering
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).
Sourcepub fn action<const N: usize>(
&mut self,
name: &str,
params: [&Expr; N],
body: impl FnOnce(&mut Step, [Expr; N]),
) -> Action
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.
Sourcepub fn relation_over_unions(
&mut self,
name: &str,
columns: &[Vec<&Expr>],
changing: bool,
) -> Expr
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.
Sourcepub fn set_place(&mut self, expr: &Expr, place: Place)
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.
Sourcepub fn relation(&mut self, name: &str, columns: &[&Expr]) -> Expr
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.
Sourcepub fn field(&mut self, name: &str, domain: &Expr, range: &Expr) -> Expr
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.
Sourcepub fn field_with(
&mut self,
name: &str,
domain: &Expr,
multiplicity: Multiplicity,
range: &Expr,
) -> Expr
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.
Sourcepub fn fact_named(&mut self, name: impl Into<String>, f: Formula)
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).
Sourcepub fn run(&self, f: &Formula) -> Command<'_>
pub fn run(&self, f: &Formula) -> Command<'_>
A command that looks for an instance of the facts and f.
Sourcepub fn check(&self, assertion: &Formula) -> Command<'_>
pub fn check(&self, assertion: &Formula) -> Command<'_>
A command that looks for a counterexample to assertion under the
facts.
Sourcepub fn register_step_label(
&mut self,
name: impl Into<String>,
vars: Vec<Variable>,
ranges: Vec<Expr>,
formula: Formula,
)
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.
Sourcepub fn register_step_spec(&mut self, spec: StepSpec)
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).
Sourcepub fn register_transition_extra(
&mut self,
fact_name: impl Into<String>,
arm: Formula,
)
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.
Sourcepub fn step_specs(&self) -> &[StepSpec]
pub fn step_specs(&self) -> &[StepSpec]
The structured step specifications registered on this model (N11, N14, W14).
Sourcepub fn all_facts_named(&self) -> Vec<(String, Formula)>
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§impl Model
impl Model
Sourcepub fn generate_tests(
&self,
scope: usize,
steps: usize,
budget: Budget,
with_sql: bool,
) -> Result<Vec<TestCase>, Vec<Error>>
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.
Sourcepub 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>>
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.
Sourcepub 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>>
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_tablesis 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 byAFTERtriggers are not emitted as duplicateINSERTstatements.