Skip to main content

Crate flow_value

Crate flow_value 

Source
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 — unbounded Int, exact Decimal, code-point Text, Bytes, List, Dict and Set sorted by key, Duration and Instant — 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:

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.
HostToken
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.
ListParts
What a List is 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::next from TaskId::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§

DataError
Why equality, ordering or text was refused.
Fault
Why an arithmetic operation produced no value.
Part
A part of an aggregate value, as a Spelling is 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.
StructureError
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 Native value 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 left orders against right.
equal
Returns whether left == right: structural equality, which holds exactly when compare answers Equal.
interpolate
Returns what interpolating value inserts: a Text value’s own code points, a Bytes, Duration or Instant value’s text unquoted, and any other data value’s text form.
interpolate_within
Returns what interpolating value inserts, as interpolate does, when its UTF-8 takes at most max_bytes bytes, and None otherwise.
spell_within
Writes value, known to spelling as at, when its UTF-8 takes at most max_bytes bytes, and returns None otherwise.
text_form
Returns value’s text form, with a Text, Bytes, Duration or Instant written as a quoted literal.
text_form_within
Returns value’s text form when its UTF-8 takes at most max_bytes bytes, and None otherwise.