Skip to main content

Heap

Struct Heap 

Source
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

Source

pub fn new(store: Arc<Store>, heap_arena: bool, full_hash: bool) -> Self

A heap over store with a fresh arena.

Source

pub fn store(&self) -> &Arc<Store> ⓘ

The store.

Source

pub fn arena(&self) -> &Arena

The arena.

Source

pub fn reset(&mut self)

Frees the transients of the current expansion.

Source

pub fn mark(&self) -> Mark

The current transient allocation point.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn kind(&self, h: Handle) -> Option<Kind>

The kind of a compound, None for a scalar.

Source

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.

Source

pub fn deep_hash(&self, h: Handle) -> u64

The hash recomputed from the leaves, ignoring cached child hashes (the -delta-hash ablation).

Source

pub fn eq(&self, a: Handle, b: Handle) -> bool

Value equality of two normalized handles.

Source

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.

Source

pub fn set_from(&mut self, elems: &mut Vec<Handle>) -> Handle

A set from normalized elements in any order, with duplicates.

Source

pub fn set_sorted(&mut self, elems: &[Handle]) -> Handle

A set from sorted, distinct, closed elements. A lazy element poisons the heap (§11.3).

Source

pub fn empty_set(&mut self) -> Handle

The empty set.

Source

pub fn int_fcn(&mut self, lo: i64, vals: &[Handle]) -> Handle

A function over lo..lo+n-1 from normalized values.

Source

pub fn tuple(&mut self, vals: &[Handle]) -> Handle

A tuple (a function over 1..n).

Source

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

Source

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.

Source

pub fn fcn_from_pairs(&mut self, pairs: &mut [(Handle, Handle)]) -> Handle

A function from (key, value) pairs with distinct keys, any order.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn closure(&self, h: Handle) -> Option<Closure<'_>>

The closure of a Lambda or SetPred node.

Source

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.

Source

pub fn interval(&mut self, lo: i64, hi: i64) -> Handle

lo..hi.

Source

pub fn is_finite(&self, h: Handle) -> bool

Whether a set is finite (symbolic sets over finite components).

Source

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.

Source

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.

Source

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

As Heap::materialize.

Source

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.

Source

pub fn elements(&mut self, h: Handle) -> Result<Vec<Handle>, Error>

The elements of a finite set (normalized) as a vector.

§Errors

As Heap::materialize.

Source

pub fn cursor(&mut self, h: Handle) -> Result<Cursor, Error>

A cursor over a set’s elements in canonical order.

§Errors

The value is not an enumerable set.

Source

pub fn cardinality(&mut self, h: Handle) -> Result<u64, Error>

The number of elements of a finite set.

§Errors

Not a finite set.

Source

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.

Source

pub const fn is_speculative(&self) -> bool

Whether candidate evaluation is keeping identities local to this Arena.

Source

pub fn state_identity(&mut self, h: Handle) -> Result<Handle, Error>

Interns for an ordinary run, or closes locally during candidate expansion.

§Errors

As Self::intern or Self::close_identity_local.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn work_interrupted(&self) -> bool

Whether this machine reached its caller-owned cooperative stop.

Source

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

Source

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

Source

pub fn int_mode(&self) -> IntMode

The integer semantics of this heap’s arithmetic.

Source

pub fn set_int_mode(&mut self, mode: IntMode)

Sets the integer semantics (from the run’s profile).

Source

pub fn int_from_i64(&mut self, v: i64) -> Handle

An integer, inline when it fits 61 bits.

Source

pub fn int_from_big(&mut self, v: &BigInt) -> Handle

An integer, inline when it fits 61 bits.

Source

pub fn is_int(&self, h: Handle) -> bool

Whether h is an integer of any size.

Source

pub fn big(&self, h: Handle) -> Option<BigInt>

The value of an integer handle of any size.

Source

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.

Source

pub fn int_arith( &mut self, op: IntOp, lhs: Handle, rhs: Handle, ) -> Result<Handle, Error>

op(a, b) under the heap’s IntMode.

§Errors

A non-integer operand; division by zero, % by a non-positive number, a negative exponent, 0^0; in TLC mode TLC’s overflow; in big mode a power above 2^26 bits (unsupported, as the reference).

Source

pub fn int_neg(&mut self, a: Handle) -> Result<Handle, Error>

-a under the heap’s IntMode.

§Errors

A non-integer operand; in TLC mode -(-2^31).

Trait Implementations§

Source§

impl Debug for Heap

Source§

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

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

impl Drop for Heap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Heap

§

impl !RefUnwindSafe for Heap

§

impl !Sync for Heap

§

impl !UnwindSafe for Heap

§

impl Forget for Heap

§

impl Move for Heap

§

impl Send for Heap

§

impl Unpin for Heap

§

impl UnsafeUnpin for Heap

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