Expand description
The Flow runtime value model.
This crate is what a value is while a program runs, and the operations the language fixes on values rather than on any one program:
- the built-in data types of
data.md— unboundedInt, exactDecimal, code-pointText,Bytes,List,DictandSetsorted by key,DurationandInstant— with the operators std declares for them, including where they fault (Fault); - records, enum values and tuples by declaration (
Record,Variant,Tuple); types.md’s structural equality and total order over every data value (compare,equal), and the text form interpolation inserts (interpolate,text_form), written by the one walk every spelling of a value shares (Spelling,spell_within);- the values a run holds that are not data — functions and other
evaluator-made values (
Native), task handles (TaskId) and host tokens (HostToken) — which have none of those operations and are refused by each of them (DataError).
Every rule here is exact and independent of the host’s word size, locale, hash order and floating-point unit: replay computes pure work again, so two implementations that disagreed on any result would disagree on a run.
§What is deliberately absent
Types. The checker owns types; at run time a value carries no type beyond the declaration a record or enum value needs for its text.
Encoding. The value encoding and the history format are abi.md’s and
trace.md’s and live with the protocol and the history; this crate
exposes the parts an encoder reads and a decoder builds from.
Limits. An Int has no bound and a Text no size here; the host’s
limits on a program’s own values are the evaluator’s to enforce, and every
measure it needs — Int::bits, Text::byte_len, Bytes::len —
costs constant time.
§Structure
History writes a value once and points at it afterwards, and writes a
text, a list or a dictionary as a tree whose parts can be pointed at too
(trace.md, Values). The structure that takes is the structure a value
has here, so a writer reads it and a reader builds it again, sharing what
was shared:
Value::identitytells a value apart from those made separately, so a writer can point at a value it has written;List::partsandList::from_partsgive a list as its front, a window onto a tree of sharedNodes, and its back;Dict::rootandDict::from_treea dictionary as its tree;Node::shape,Node::leafandNode::brancheach node;Text::root,Text::of_blockandText::join_shareda text as a tree ofNodes whose leaves areRuns onto sharedBlocks.
Every builder checks what it is given (StructureError) and keeps the
trees balanced, rebalancing a tree another writer did not keep balanced,
so a value read from history behaves as one made here.
§Unicode
Normalization, case mapping and grapheme segmentation use the tables of
one Unicode version, UNICODE_VERSION, which std’s version fixes. Every
table comes from a pinned crate; none is the Rust toolchain’s.
§Depth
Equality, order, text and dropping walk a value with a stack on the heap, never the native one, so a value nested as deeply as memory allows is compared, printed and dropped like any other.
Structs§
- BigInt
- A big signed integer type.
- Block
- A block of UTF-8 that runs of text are windows onto, shared between them.
- Bytes
- A finite sequence of bytes: raw, unnormalized, ordered lexicographically by unsigned byte value with a proper prefix first.
- Decimal
- An exact decimal number.
- Dict
- A dictionary: keys mapped to values, sorted by key.
- Difference
- Where two values first differ (
Value::first_difference). - Duration
- A length of time, ordered by length.
- Host
Token - The token a host chose for a host type value. Flow stores it, compares
nothing about it, and hands it back unchanged (
abi.md). - Identity
- What tells a value apart from the values alive that were made separately
(
Value::identity): the kind of value, and the addresses of the shared parts it is made of. - Instant
- A point in time, ordered chronologically.
- Int
- An integer, with no bound.
- List
- A list: a finite sequence, in order.
- List
Parts - What a
Listis made of (List::parts). - Member
- A set’s member: a value that is its own key.
- Native
- A value the evaluator owns, carried opaquely.
- Node
- A shared node of a tree: a whole tree, or a part of one.
- Parts
- The parts of a value (
Value::parts), in order. - Path
- Steps into a value from the whole of it, outermost first.
- Record
- A record value.
- Run
- The bytes of a shared block from one offset up to another, both between characters: one leaf of a text’s tree.
- Set
- A set: distinct values, sorted.
- TaskId
- Which task a task handle names. What the number means is the evaluator’s,
which makes each one with
TaskId::nextfromTaskId::FIRST. - Text
- A finite sequence of Unicode code points, stored as UTF-8.
- Tuple
- A tuple’s parts, in order.
- Variant
- An enum value.
- Walk
- A value and every part inside it, each before its own parts
(
Value::walk).
Enums§
- Data
Error - Why equality, ordering or text was refused.
- Fault
- Why an arithmetic operation produced no value.
- Part
- A part of an aggregate value, as a
Spellingis asked about it. - Shape
- What a node holds: its elements, when it is a leaf, or its two subtrees, when it is a branch.
- Step
- One step into a value from the aggregate that holds it.
- Structure
Error - Why a value could not be built from the parts given for it.
- Value
- A run-time value.
Constants§
- DIVISION_
DIGITS - How many significant digits a quotient with no finite expansion keeps.
- UNICODE_
VERSION - The Unicode version normalization, case mapping and grapheme segmentation
use (
data.md, Text).
Traits§
- Carry
- What a
Nativevalue carries, and what it can say of itself. - Element
- What a tree holds: a list’s elements, a dictionary’s entries as key and value pairs, a set’s members, or a text’s runs. No other type is one.
- Keyed
- An element kept in key order: a dictionary’s entry, or a set’s member.
- Spelling
- What a walk that writes a value knows of each value beyond the value
itself: nothing, for the text form, or its type, for the value notation,
which writes a newtype’s constructor and a whole
Decimal’s point. Every spelling shares the walk and the spelling of every other part.
Functions§
- compare
- Returns how
leftorders againstright. - equal
- Returns whether
left == right: structural equality, which holds exactly whencompareanswersEqual. - interpolate
- Returns what interpolating
valueinserts: aTextvalue’s own code points, aBytes,DurationorInstantvalue’s text unquoted, and any other data value’s text form. - interpolate_
within - Returns what interpolating
valueinserts, asinterpolatedoes, when its UTF-8 takes at mostmax_bytesbytes, andNoneotherwise. - spell_
within - Writes
value, known tospellingasat, when its UTF-8 takes at mostmax_bytesbytes, and returnsNoneotherwise. - text_
form - Returns
value’s text form, with aText,Bytes,DurationorInstantwritten as a quoted literal. - text_
form_ within - Returns
value’s text form when its UTF-8 takes at mostmax_bytesbytes, andNoneotherwise.