pub struct Heap { /* private fields */ }Expand description
A worker’s view of the value regions: the shared persistent store and its own arena.
Implementations§
Source§impl Heap
impl Heap
Sourcepub fn new(store: Arc<Store>, heap_arena: bool, full_hash: bool) -> Self
pub fn new(store: Arc<Store>, heap_arena: bool, full_hash: bool) -> Self
A heap over store with a fresh arena.
Sourcepub fn rollback(&mut self, mark: Mark)
pub fn rollback(&mut self, mark: Mark)
Frees every transient allocated after mark. No handle allocated
after the mark may be used afterwards, including one held in a frame
slot or a thunk cache; such a use is detected as stale.
Sourcepub fn poisoned(&self) -> bool
pub fn poisoned(&self) -> bool
Whether an invalid handle read was detected: an internal error.
Persistent handles are coordinates within one Store. Callers must
keep them with their issuing Store; equal coordinates from another Store cannot
be distinguished from a locally issued handle by this check.
Sourcepub fn view(&self, h: Handle) -> View<'_>
pub fn view(&self, h: Handle) -> View<'_>
The view of a compound handle. A stale or scalar handle gives an empty set view and poisons the heap.
Sourcepub fn proved_concrete(&self, h: Handle) -> bool
pub fn proved_concrete(&self, h: Handle) -> bool
Whether a value is proved materialized by a cached fact, without a
walk: a boolean, an inline integer, a string or model value whose name
this heap’s Store issued, an eager big integer, or a persistent
eager node carrying flags::CONCRETE (an eager Set, IntFcn or
Fcn whose every descendant is materialized, as
compare::materialized defines it). false proves nothing: snapshot
restore, owned exchange and candidate decoding clear the bit, and
Heap::materialized_within then decides.
Sourcepub fn materialized_within(
&self,
roots: &[Handle],
nodes: usize,
name_bytes: Option<usize>,
) -> bool
pub fn materialized_within( &self, roots: &[Handle], nodes: usize, name_bytes: Option<usize>, ) -> bool
Whether every root is materialized as compare::materialized
defines it (no lazy, symbolic or unnormalized node and no unknown name
at any depth), decided by an iterative walk over at most nodes
handles. Transient and empty handles decline. false proves nothing:
an exhausted allowance or a failed scratch allocation also declines,
and so does a heap that is poisoned when the walk ends.
Without name_bytes, a node carrying flags::CONCRETE is trusted
and not entered. With name_bytes: Some(n) every node is entered,
and the text bytes of every string and model-value occurrence count
against n.
Sourcepub fn is_lazy(&self, h: Handle) -> bool
pub fn is_lazy(&self, h: Handle) -> bool
Whether a value must be closed by the evaluator before it is hashed, compared or interned (§11.3).
Sourcepub fn hash(&self, h: Handle) -> u64
pub fn hash(&self, h: Handle) -> u64
The value hash of a closed value. Finite symbolic sets must be normalized first. A lazy value poisons the heap.
Sourcepub fn deep_hash(&self, h: Handle) -> u64
pub fn deep_hash(&self, h: Handle) -> u64
The hash recomputed from the leaves, ignoring cached child hashes
(the -delta-hash ablation).
Sourcepub fn cmp(&self, a: Handle, b: Handle) -> Ordering
pub fn cmp(&self, a: Handle, b: Handle) -> Ordering
The canonical total order (the default profile’s value order): model values by name, booleans,
integers, strings by text, finite sets by size then elements,
functions by size, domain then values, then symbolic sets
structurally. Consistent with
Heap::eq on normalized handles.
Sourcepub fn set_from(&mut self, elems: &mut Vec<Handle>) -> Handle
pub fn set_from(&mut self, elems: &mut Vec<Handle>) -> Handle
A set from normalized elements in any order, with duplicates.
Sourcepub fn set_sorted(&mut self, elems: &[Handle]) -> Handle
pub fn set_sorted(&mut self, elems: &[Handle]) -> Handle
A set from sorted, distinct, closed elements. A lazy element poisons the heap (§11.3).
Sourcepub fn int_fcn(&mut self, lo: i64, vals: &[Handle]) -> Handle
pub fn int_fcn(&mut self, lo: i64, vals: &[Handle]) -> Handle
A function over lo..lo+n-1 from normalized values.
Sourcepub fn tuple_literal(&mut self, vals: &[Handle]) -> Handle
pub fn tuple_literal(&mut self, vals: &[Handle]) -> Handle
A tuple literal <<v1, ...>>: the tuple Heap::tuple builds, with
the view bit flags::TUPLE (as Heap::record).
Sourcepub fn fcn_sorted(&mut self, keys: &[Handle], vals: &[Handle]) -> Handle
pub fn fcn_sorted(&mut self, keys: &[Handle], vals: &[Handle]) -> Handle
A function from sorted, distinct, closed keys and their values (which may be lazy), in canonical form.
Sourcepub fn fcn_from_pairs(&mut self, pairs: &mut [(Handle, Handle)]) -> Handle
pub fn fcn_from_pairs(&mut self, pairs: &mut [(Handle, Handle)]) -> Handle
A function from (key, value) pairs with distinct keys, any order.
Sourcepub fn record(&mut self, keys: &[Handle], vals: &[Handle]) -> Handle
pub fn record(&mut self, keys: &[Handle], vals: &[Handle]) -> Handle
A record literal [f1 |-> v1, ...] from sorted, distinct string keys:
the function Heap::fcn_sorted builds, with flags::RECORD. The
bit is a view bit: equality, hashing, order and Heap::intern
ignore it, and Heap::intern_view keeps it.
Sourcepub fn set_enum(&mut self, elems: &[Handle]) -> Handle
pub fn set_enum(&mut self, elems: &[Handle]) -> Handle
A set enumeration {e1, ...} as TLC builds it before normalizing:
the normalized, closed elements in construction order, duplicates kept, as a
Kind::SetEnum view with flags::UNNORM. It is normalized,
hashed and interned as the set of its elements; only membership and
error paths that the contract names read its order.
Sourcepub fn fcn_with(&mut self, f: Handle, i: usize, new: Handle) -> Handle
pub fn fcn_with(&mut self, f: Handle, i: usize, new: Handle) -> Handle
The same function with the entry at index i replaced, hashing in
O(1) from the stored sum.
Sourcepub fn symbolic(&mut self, kind: Kind, lo: i64, data: &[Handle]) -> Handle
pub fn symbolic(&mut self, kind: Kind, lo: i64, data: &[Handle]) -> Handle
A symbolic set node. Its hash is structural, not extensional: a finite symbolic set is normalized before it is hashed as a value.
Sourcepub fn lambda(
&mut self,
closure: u32,
domain: Handle,
captures: &[Handle],
) -> Handle
pub fn lambda( &mut self, closure: u32, domain: Handle, captures: &[Handle], ) -> Handle
[x \in domain |-> e], unmaterialized: the evaluator’s closure
closure over captures (§11.2). Lazy.
Sourcepub fn set_pred(
&mut self,
closure: u32,
base: Handle,
captures: &[Handle],
) -> Handle
pub fn set_pred( &mut self, closure: u32, base: Handle, captures: &[Handle], ) -> Handle
{x \in base : P}, unenumerated: the evaluator’s closure closure
over captures (§11.2). Lazy.
Sourcepub fn union(&mut self, a: Handle, b: Handle) -> Handle
pub fn union(&mut self, a: Handle, b: Handle) -> Handle
a \cup b, kept symbolic (TLC’s SetCupValue): membership is
either side’s, and it is enumerated only when normalized.
Sourcepub fn closure(&self, h: Handle) -> Option<Closure<'_>>
pub fn closure(&self, h: Handle) -> Option<Closure<'_>>
The closure of a Lambda or SetPred node.
Sourcepub fn rebuild(&mut self, h: Handle, data: &[Handle]) -> Handle
pub fn rebuild(&mut self, h: Handle, data: &[Handle]) -> Handle
The same kind as h with new contents, in canonical form and
rehashed: a set is re-sorted, a function keeps its keys and takes new
values. The evaluator closes a lazy value bottom-up with it
(§11.5 rule 4). For a Fcn, data is the keys then the values, as
in its view.
Sourcepub fn is_finite(&self, h: Handle) -> bool
pub fn is_finite(&self, h: Handle) -> bool
Whether a set is finite (symbolic sets over finite components).
Sourcepub fn norm(&mut self, h: Handle) -> Result<Handle, Error>
pub fn norm(&mut self, h: Handle) -> Result<Handle, Error>
Normalizes a value: a finite symbolic set becomes an enumerated set. Other values are returned unchanged.
§Errors
The set is too large to materialize.
Sourcepub fn materialize(&mut self, h: Handle) -> Result<Handle, Error>
pub fn materialize(&mut self, h: Handle) -> Result<Handle, Error>
The elements of a finite set in canonical order, as a new enumerated set.
§Errors
An infinite or too-large set.
Sourcepub fn materialize_cached(&mut self, h: Handle) -> Result<Handle, Error>
pub fn materialize_cached(&mut self, h: Handle) -> Result<Handle, Error>
As Heap::materialize, but a persistent set’s enumeration is
interned and kept, so that it is built once per worker. Used only by
membership under -symbolic-member: interning every enumeration
would fill the store with values no state holds.
§Errors
Sourcepub fn enumerate_constant(&mut self, h: Handle) -> Result<Handle, Error>
pub fn enumerate_constant(&mut self, h: Handle) -> Result<Handle, Error>
Heap::norm of a constant quantifier domain (a plan constant)
that is enumerated once per evaluation of its quantifier. A
persistent finite symbolic set of at most MAX_CONSTANT_DOMAIN
elements (and MAX_CONSTANT_DOMAIN_WORDS new store words) is
materialized once per heap and kept, when its
enumeration is already in canonical persistent form (interning it
exactly and canonically give the same handle; a read-only canonical
form check runs first, so most rejected domains intern nothing). Its
elements are then
persistent, equal and identical to the ones a fresh enumeration
builds. Any other set is normalized as Heap::norm does.
§Errors
As Heap::norm.
Sourcepub fn set_speculative(&mut self, enabled: bool) -> bool
pub fn set_speculative(&mut self, enabled: bool) -> bool
Selects speculative candidate evaluation, returning the previous mode.
In this mode evaluator memo sites and materialization caches do not
promote results. Explicit intern calls retain their persistent contract.
Sourcepub const fn is_speculative(&self) -> bool
pub const fn is_speculative(&self) -> bool
Whether candidate evaluation is keeping identities local to this Arena.
Sourcepub fn state_identity(&mut self, h: Handle) -> Result<Handle, Error>
pub fn state_identity(&mut self, h: Handle) -> Result<Handle, Error>
Interns for an ordinary run, or closes locally during candidate expansion.
§Errors
Sourcepub fn close_identity_local(&mut self, h: Handle) -> Result<Handle, Error>
pub fn close_identity_local(&mut self, h: Handle) -> Result<Handle, Error>
Closes a mathematical identity in the local Arena without Store promotion.
This performs the same demanded normalization as Self::intern, but
returns values valid only until the owning Arena is rolled back or reset.
No persistent-handle certificate or interning cache is populated.
§Errors
An unclosed lazy value, failed normalization, or a too-deep candidate.
Sourcepub fn close_identity_row_local(
&mut self,
roots: &[Handle],
) -> Result<Vec<Handle>, Error>
pub fn close_identity_row_local( &mut self, roots: &[Handle], ) -> Result<Vec<Handle>, Error>
Closes related roots with one bounded, operation-local sharing map.
No result or source mapping survives this call. Original values retain their symbolic representations; returned roots are Arena-local.
§Errors
As Self::close_identity_local, or root-row workspace exhaustion.
Sourcepub fn intern(&mut self, h: Handle) -> Result<Handle, Error>
pub fn intern(&mut self, h: Handle) -> Result<Handle, Error>
Interns a value into the persistent store, deep-closing it: children first, finite symbolic sets materialized.
§Errors
A set too large to materialize.
Sourcepub fn intern_const(&mut self, h: Handle) -> Result<Handle, Error>
pub fn intern_const(&mut self, h: Handle) -> Result<Handle, Error>
Interns a constant, preserving available function literal classes
recursively and keeping symbolic sets symbolic. This is a value used
for evaluation, not its canonical identity (0121 in the ADRs).
A lazy constant (for example [x \in Nat |-> x + 1]) stays lazy: it
is interned structurally, never compared by handle (§11.1).
§Errors
As Heap::intern.
Sourcepub fn intern_exact(&mut self, h: Handle) -> Result<Handle, Error>
pub fn intern_exact(&mut self, h: Handle) -> Result<Handle, Error>
Interns a closed value exactly as it is: every node keeps its kind
and view bits (a symbolic set stays symbolic, a record literal stays
one), so the persistent handle reads like h everywhere, and two
handles it returns are equal exactly when the representations are.
Step-predicate memo sites use it for their keys and results;
graph capture uses it to retain original
target representations independently of canonical state identities.
§Errors
h is lazy (holds a closure only the evaluator can force).
Sourcepub fn intern_view(&mut self, h: Handle) -> Result<(Handle, Handle), Error>
pub fn intern_view(&mut self, h: Handle) -> Result<(Handle, Handle), Error>
Interns a state value with its lazy view (§8): the identity handle
(as Heap::intern) and, when the value is a symbolic set or carries
a view bit (flags::VIEW) at the top level, that representation
interned apart from identities; otherwise Handle::EMPTY. Nested
view bits are not kept. The engine keeps the view in a side table
only where the plan asks for it; hashing and equality use the identity.
§Errors
As Heap::intern.
Sourcepub fn work_interrupted(&self) -> bool
pub fn work_interrupted(&self) -> bool
Whether this machine reached its caller-owned cooperative stop.
Sourcepub fn string(&self, text: &str) -> Result<Handle, Error>
pub fn string(&self, text: &str) -> Result<Handle, Error>
The string id of text.
§Errors
The string table is full, or the text is new while
Heap::set_existing_strings_only holds (unsupported).
Sourcepub fn set_existing_strings_only(&mut self, enabled: bool) -> bool
pub fn set_existing_strings_only(&mut self, enabled: bool) -> bool
Makes Heap::string refuse any text the shared table does not
already hold, returning the previous mode. An isolated optional
machine uses it so that skipping its work elsewhere cannot change
later string tokens (string order under --compat=tlc).
let previous = heap.set_existing_strings_only(true);
heap.set_existing_strings_only(previous);Source§impl Heap
impl Heap
Sourcepub fn set_int_mode(&mut self, mode: IntMode)
pub fn set_int_mode(&mut self, mode: IntMode)
Sets the integer semantics (from the run’s profile).
Sourcepub fn int_from_i64(&mut self, v: i64) -> Handle
pub fn int_from_i64(&mut self, v: i64) -> Handle
An integer, inline when it fits 61 bits.
Sourcepub fn int_from_big(&mut self, v: &BigInt) -> Handle
pub fn int_from_big(&mut self, v: &BigInt) -> Handle
An integer, inline when it fits 61 bits.
Sourcepub fn int_cmp(&self, a: Handle, b: Handle) -> Option<Ordering>
pub fn int_cmp(&self, a: Handle, b: Handle) -> Option<Ordering>
The numeric order of two integers of any size; None unless both are
integers.