Skip to main content

Crate dive_model

Crate dive_model 

Source
Expand description

dive-model: binding a specification to its TLC model configuration.

This is a port of TLC’s tlc2.tool.impl.SpecProcessor (tlaplus 94d0c50), with the parts of Spec and Tool that finish setting up a model. bind takes the lowered specification and the parsed configuration and does what TLC does before it checks the assumptions, in TLC’s order:

  1. Literals (processConstants): a numeral too big for --int=tlc or a decimal stops TLC first.
  2. Names (intern): the run’s name table is filled in TLC’s encounter order, so that strings and model values order and fingerprint as in TLC.
  3. Constants and overrides (processSpec): every root constant must be assigned (C = v) or substituted (C <- D); Op = v and Op <- D replace definitions; [M] entries replace definitions of module M. Errors carry TLC’s codes (Ec).
  4. Constant definitions (processConstantDefns): every zero-arity definition TLC’s level bound (level) finds constant is evaluated at start-up, module by module, and its value is used from then on. Print output appears here, as in TLC.
  5. Roles (processConfig): invariants, the behavior specification (INIT/NEXT or SPECIFICATION, split into initial predicates, the next-state relation and temporal formulas), properties (split into invariants, implied initial predicates, implied actions and temporal properties), constraints, VIEW.
  6. Actions (Tool.getActions): the next-state relation split into TLC’s actions, with their labels, as dive_eval::next actions.

The result is a Model: an dive_eval::Evaluator with everything bound, and every role as a Pred (an expression and the scope TLC evaluates it in). Features dive does not check yet (liveness, SYMMETRY, operators it does not implement) are listed in Model::unsupported; the checker refuses such a model by name. Anything this stage cannot do exactly is an ErrorKind::Unsupported error.

§Java overrides and loaded modules

Which Java implementation TLC uses for a standard operator depends on the modules loaded: Integers’ methods replace Naturals’ when both are loaded. The IR records the active override of every definition, computed from the loaded modules (dive_ir::std_op). TLC’s -dumpTrace json loads _JsonTrace, and with it Integers, without extending the root module; dive_sema::Options::extra_root_extendees reproduces that for oracle comparison (see DUMP_TRACE_JSON_MODULES).

§Example

use std::sync::Arc;
use dive_model::{bind, BindOptions};

let src = "---- MODULE M ----\nEXTENDS Naturals, TLC\nCONSTANT N\nVARIABLE x\n\
           Max == Print(N, N * 2)\nInit == x = 0\nNext == x < Max /\\ x' = x + 1\n\
           Inv == x <= Max\n====\n";
let analysis = dive_sema::analyze_source("M.tla", src, &dive_sema::Options::default());
let ir = Arc::new(dive_ir::lower(&analysis).unwrap());
let cfg = dive_config::parse("CONSTANT N = 3\nINIT Init\nNEXT Next\nINVARIANT Inv\n")
    .into_config()
    .unwrap();
let model = bind(ir, &cfg, &BindOptions::tlc()).unwrap();
// `Max` is evaluated once, at start-up, as TLC does.
assert_eq!(model.output, [dive_model::Message::Print("3  6".to_owned())]);
assert_eq!(model.invariants[0].name, "Inv");
assert_eq!(model.actions.len(), 1);
assert!(model.actions[0].label().starts_with("<Next line 7, col 9 to line 7, col"));

Re-exports§

pub use symmetry::SymmetryLiveness;
pub use symmetry::SymmetryLivenessResolution;

Modules§

intern
The run’s name table, fed in TLC’s encounter order.
level
TLC’s level bound (SymbolNodeValueLookupProvider.getLevelBound and getLevelBoundAppl, tlaplus 94d0c50).
symmetry
Pure symmetry declaration preparation, bounded closure and safety keys.

Structs§

BindError
An error binding the model.
BindOptions
How the binding stage runs.
Failure
A failed binding: the error, and what TLC printed before it.
Init
An initial predicate (getInitStateSpec).
Model
A specification bound to its configuration.
Named
A role with the name TLC reports it under.
Pred
A predicate or expression TLC evaluates for a role, with the context it is evaluated in: TLC’s tlc2.tool.Action (pred, con).
Recipe
Immutable inputs for reconstructing a model’s startup runtime.
Settings
The -deadlock and CHECK_DEADLOCK outcome and other run settings.
Unsupported
A feature of the model that dive does not check yet. The checker refuses the model as unsupported, naming it.

Enums§

ControlledBindError
A controlled binding failed, preserving startup output and run ownership.
Ec
TLC’s message codes (tlc2.output.EC) the binding stage reports.
ErrorKind
What kind of failure a BindError is.
Message
Something TLC prints while it processes the model, in order.
UnsupportedKind
Why the model cannot yet receive a complete checking verdict.

Constants§

DUMP_TRACE_JSON_MODULES
The modules TLC’s -dumpTrace json <file> loads in addition to the specification’s own (TLC.java adds the _JsonTrace post-condition, and ParameterizedSpecObj makes SANY load _JsonTrace as if the root module extended it). Pass it as dive_sema::Options::extra_root_extendees to reproduce the conformance harness’s TLC runs, which use -dumpTrace json: it changes which Java overrides are active (Integers replaces Naturals’ arithmetic) and the encounter order of names. TLC as users run it, and so --compat=tlc, does not load them. Oracle reproduction only, until the goldens are regenerated without -dumpTrace (issue #35).
HANOI_BITS_CLASS_SHA256
SHA-256 of the supported local Bits.class from the pinned Examples Hanoi model.
TLC_CDOT
TLC’s action composition counts its intermediate states as generated; the parallel engine’s per-source counts double as successor ordinals. Sequential BFS reason for TLC composition intermediate-state accounting. DFID and simulation ignore those intermediate states, as their TLC functors do.

Functions§

bind
Binds ir to cfg as TLC does (see the crate documentation).
bind_controlled
Binds a fresh model with typed cooperative evaluator control.
bind_deferring_constants
Binds ir to cfg for Core: as bind, except that the pure constant-level definitions used only as values by the roles the core compiles are not evaluated at start-up. They are listed in Model::deferred_constants, for the core to evaluate when it compiles its plan; the model’s own evaluator evaluates them lazily wherever it needs them, with the same values. The root module’s pure ASSUMEs are listed in Model::deferred_assumptions: the core evaluates them when it compiles its plan, and Model::check_assumptions_except checks the others. With genuine temporal properties, the definitions those properties, the specification’s fairness and the configured properties reach are evaluated at start-up as bind evaluates them, for the dive-eval evaluator that checks them; the core keeps the others.
local_java_class_digests
SHA-256 identities of adjacent local Java classes, sorted by module name.
transformed_randomness
Names an unsupported random interaction with VIEW or SYMMETRY, without evaluating source, binding constants or invoking a host callback.