Skip to main content

Module stepcache

Module stepcache 

Source
Expand description

On by default with the compiled evaluator (EVERYSTATE_STEP_CACHE=off turns it off): a bounded cache of local steps, keyed on value ids.

A unit is an action instance of a compiled plan (what is left of an action below its top-level disjunctions, existential quantifiers and inlined definitions). When a unit is evaluated the compiled code notes what it reads of the current state: a whole variable, one element f[k], or whether a value is in a set / bag variable (Rec, in compile.rs). The unit’s result is a list of successors, each given per variable as a value or as a change to the parent’s value (an element put into or taken out of a set or bag, an EXCEPT at a path).

Everything an entry holds is a hashcons id: the bound values, the locations read (the key of f[k] is an id), what was found there, and each successor as the ids of the variables it changes. A hit is integer comparisons, and building a successor is copying the parent’s row of ids with a few replaced. A change (Put::Delta) is applied to the parent’s value once per (parent value, change): the result is remembered by id (Applied), as is what a location holds in a given value (Located).

Two kinds of entries share one table:

  • a template per (unit, bound values): the locations whose values pick the entry (every location an evaluation of the unit with these bound values has read), and a version that changes whenever that list does;
  • a leaf per (template version, what is at each of its locations): the successors.

Soundness: a hit compares the unit, the bound ids, the template version and the id found at every location of the template, so the state agrees with the evaluation that was stored on everything that evaluation read (the locations of a template include those of every evaluation stored under it, and ids are equal exactly when values are). The hash only finds the entry. Nothing is stored for an evaluation that failed, used the tree-walker (whose reads are not noted), whose changes could not be expressed, or that involves a value that cannot be interned.

Memory: one table of a fixed number of slots in buckets of WAYS (set-associative: two entries used by every state whose hashes meet in a slot would otherwise replace each other on every state, and a replaced template takes all its leaves with it); a full bucket gives up its oldest leaf for a new entry. Every entry is charged its own size plus that of the changes it holds, and an entry that would take the table over its budget (EVERYSTATE_STEP_CACHE_MB, default 32) is not stored.

Structs§

CacheStats
Found
A successor in Rows, in the order they were found.
Leaf
LocId
A location of a state: a whole variable, var[key], or whether key is in the set or bag var.
Memo
A direct-mapped memo of fixed size: (a u64, an id) -> a value; a newer value replaces the older one in its slot. (Slots are cells: a lookup is a load, with no borrow to check.)
Recipe
A successor found from a leaf whose row is not built yet: most are known states, which need none.
Recorded
A recorded evaluation of a unit, to be stored.
RowMeta
What Rows knows about its successors besides the ids of those that are built.
Rows
Successors as rows of ids, in the order they are found, with the action of each. A variable whose value cannot be interned is NOT_INTERNED + i, i an index into opaque.
RowsMark
Where Rows was, to go back to (Rows::truncate).
Table
Tmpl

Enums§

DOp
Entry
IdOp
A change (DOp) by the ids and words of its values.
Loc
LocKind
Put
The new value of a variable a successor changes.
Write

Constants§

ABSENT
What locate finds when the key is not in the domain, and whether a value is a member: outside the range of ids.
IN
OUT
RECIPE

Functions§

delta_word
The word (value_word) of the value with id parent after the changes ops, computed from the parent’s word without building that value: each change replaces the terms of the elements it changes (see value::fn_tag). None when a change would not apply (apply_ops would fail) or this cannot tell; the value has to be built then.
elem_at
f[k] without an error: None when k is not in the domain (or f is not a function).
elem_at_checked
f[k]: Some(None) when k is not in the domain (or f is not a function), None when that cannot be told (a comparison of k with the domain fails).
ids_of
The ids of the variables of a state; NOT_INTERNED for a value that cannot be interned.
leaf_hash
Where a leaf is found: its template version and key.
leaf_hash_start
leaf_hash of an empty key (the hash goes on with mix of each id of the key).
member_of
Whether e is in the set v, or in the domain of the function (bag) v. None when that cannot be told.
mix
store
Stores an evaluation of a unit in the state cur (ids of its variables): the template, extended with the locations this evaluation read, and a leaf. False when it cannot be stored.
template_hash
Where a template is found: the unit and the bound ids.
vsize
Bytes a value keeps alive, counted as if nothing were shared.

Type Aliases§

Applied
What a stored list of changes made of a given parent: (list, parent id) -> result id. Sound because both keys are identities: an id names one value (for the life of the table, which is that of a check), a list number one list of changes for the life of the thread.
Located
What is at (value id, key id, kind of location): the element of a function (or ABSENT), or whether a value is in a set or bag (IN / OUT). Finding it again costs a binary search with full comparisons of the keys (records, for a bag of messages), while the same value and key recur in many states. With identities for keys (see Applied): ((value id << 32 | key id) + 1, kind) -> what is there.
Slot
A slot of the table: (hash, size charged, entry). Shared, so that a successor found from a leaf can be built after the leaf was replaced (Recipe).
Words
The word of what a list of changes made of a value: (list, parent id) -> word. As Applied.