Skip to main content

dive_value/
lib.rs

1//! `dive-value`: TLA+ values with TLC's canonical ordering, equality, printing and
2//! fingerprints; model values; lazy and enumerable sets.
3//!
4//! The crate has no dependencies on other dive crates. The design records behind it
5//! are in the repository's [decision records](https://github.com/Chelis-Lang/dive/tree/main/docs/decisions).
6//!
7//! # Overview
8//!
9//! - [`Value`]: an immutable, 16-byte, `Send + Sync` value; compound values are shared
10//!   behind `Arc`s, so cloning is cheap.
11//! - [`Ctx`]: the semantics of a run: [`IntMode`] (TLC's 32-bit integers or
12//!   arbitrary precision) and [`ValueOrder`] (TLC's intern order or dive's canonical
13//!   order). Defaults are dive's; [`Ctx::tlc`] is `--compat=tlc`.
14//! - [`Interner`]: the run's table of names (strings, model values, record fields).
15//! - [`tlc`]: TLC's checked equality, comparison and membership, with TLC's errors.
16//! - [`mod@print`]: TLC's value printing and pretty-printer.
17//! - [`fp64`]: TLC's FP64 fingerprints.
18//! - [`json`]: TLC's JSON form of values.
19//! - [`codec`]: compact, deterministic byte encodings of values for state storage.
20//!
21//! ```
22//! use dive_value::{Ctx, Interner, Value, print::print_value, tlc};
23//!
24//! let ctx = Ctx::tlc();
25//! let names = Interner::new();
26//! let s = Value::set(
27//!     vec![Value::string(&names, "b"), Value::string(&names, "a")],
28//!     ctx,
29//! )?;
30//! // TLC orders strings by intern order: "b" was interned first.
31//! assert_eq!(print_value(&s, ctx)?, r#"{"b", "a"}"#);
32//!
33//! // TLC refuses to compare an integer with a string.
34//! let err = tlc::equals(&Value::from(1), &Value::string(&names, "a"), ctx).unwrap_err();
35//! assert_eq!(err.message(), "Attempted to check equality of integer 1 with non-integer:\n\"a\"");
36//! # Ok::<(), dive_value::ValueError>(())
37//! ```
38#![forbid(unsafe_code)]
39
40mod atom;
41pub mod codec;
42mod construction;
43pub use construction::ConstructionError;
44mod ctx;
45mod depth;
46mod enumerate;
47mod error;
48pub mod fp64;
49mod function_domain;
50mod int;
51pub mod json;
52mod names;
53pub mod ops;
54mod order;
55mod pprint;
56pub mod print;
57mod receiver;
58mod stream;
59pub mod tlc;
60mod value;
61
62pub use atom::{Atom, Interner};
63pub use ctx::{Ctx, IntMode, ValueOrder};
64pub use depth::{MAX_DEPTH, checked_operation_depth};
65pub use enumerate::MAX_ENUMERATION;
66pub use error::{ErrorKind, Result, ValueError};
67pub use int::Int;
68pub use names::NameError;
69pub use receiver::{ReceiverDomain, ReceiverFailure, ReceiverMethod};
70pub use stream::{ConcreteSubsetStream, SubsetCommit, SubsetScratch};
71pub use value::{
72    DeferredKind, DeferredSet, DomainLookup, Fcn, FcnKind, Set, SetKind, Value,
73    quiet_operation_active,
74};
75
76/// An owned incremental stream of set elements, with no complete output buffer.
77/// See [`Set::concrete_element_stream`] for construction and a bounded example.
78pub type SetElementStream = Box<dyn Iterator<Item = Value> + Send>;