Skip to main content

flow_value/
lib.rs

1//! The Flow runtime value model.
2//!
3//! This crate is what a value *is* while a program runs, and the operations
4//! the language fixes on values rather than on any one program:
5//!
6//! - the built-in data types of `data.md` — unbounded [`Int`], exact
7//!   [`Decimal`], code-point [`Text`], [`Bytes`], [`List`], [`Dict`] and
8//!   [`Set`] sorted by key, [`Duration`] and [`Instant`] — with the operators
9//!   std declares for them, including where they fault ([`Fault`]);
10//! - records, enum values and tuples by declaration ([`Record`],
11//!   [`Variant`], [`Tuple`]);
12//! - `types.md`'s structural equality and total order over every data value
13//!   ([`compare`], [`equal`]), and the text form interpolation inserts
14//!   ([`interpolate`], [`text_form`]), written by the one walk every
15//!   spelling of a value shares ([`Spelling`], [`spell_within`]);
16//! - the values a run holds that are not data — functions and other
17//!   evaluator-made values ([`Native`]), task handles ([`TaskId`]) and host
18//!   tokens ([`HostToken`]) — which have none of those operations and are
19//!   refused by each of them ([`DataError`]).
20//!
21//! Every rule here is exact and independent of the host's word size, locale,
22//! hash order and floating-point unit: replay computes pure work again, so
23//! two implementations that disagreed on any result would disagree on a run.
24//!
25//! # What is deliberately absent
26//!
27//! **Types.** The checker owns types; at run time a value carries no type
28//! beyond the declaration a record or enum value needs for its text.
29//!
30//! **Encoding.** The value encoding and the history format are `abi.md`'s and
31//! `trace.md`'s and live with the protocol and the history; this crate
32//! exposes the parts an encoder reads and a decoder builds from.
33//!
34//! **Limits.** An `Int` has no bound and a `Text` no size here; the host's
35//! limits on a program's own values are the evaluator's to enforce, and every
36//! measure it needs — [`Int::bits`], [`Text::byte_len`], [`Bytes::len`] —
37//! costs constant time.
38//!
39//! # Structure
40//!
41//! History writes a value once and points at it afterwards, and writes a
42//! text, a list or a dictionary as a tree whose parts can be pointed at too
43//! (`trace.md`, *Values*). The structure that takes is the structure a value
44//! has here, so a writer reads it and a reader builds it again, sharing what
45//! was shared:
46//!
47//! - [`Value::identity`] tells a value apart from those made separately, so
48//!   a writer can point at a value it has written;
49//! - [`List::parts`] and [`List::from_parts`] give a list as its front, a
50//!   window onto a tree of shared [`Node`]s, and its back;
51//!   [`Dict::root`] and [`Dict::from_tree`] a dictionary as its tree;
52//!   [`Node::shape`], [`Node::leaf`] and [`Node::branch`] each node;
53//! - [`Text::root`], [`Text::of_block`] and [`Text::join_shared`] a text as
54//!   a tree of [`Node`]s whose leaves are [`Run`]s onto shared [`Block`]s.
55//!
56//! Every builder checks what it is given ([`StructureError`]) and keeps the
57//! trees balanced, rebalancing a tree another writer did not keep balanced,
58//! so a value read from history behaves as one made here.
59//!
60//! # Unicode
61//!
62//! Normalization, case mapping and grapheme segmentation use the tables of
63//! one Unicode version, [`UNICODE_VERSION`], which std's version fixes. Every
64//! table comes from a pinned crate; none is the Rust toolchain's.
65//!
66//! # Depth
67//!
68//! Equality, order, text and dropping walk a value with a stack on the heap,
69//! never the native one, so a value nested as deeply as memory allows is
70//! compared, printed and dropped like any other.
71
72#![cfg_attr(all(coverage, test), feature(coverage_attribute))]
73
74mod collection;
75mod decimal;
76mod error;
77mod int;
78mod render;
79mod shape;
80mod text;
81mod time;
82mod tree;
83mod value;
84
85pub use collection::{Dict, List, ListParts, Set};
86pub use decimal::{DIVISION_DIGITS, Decimal};
87pub use error::{DataError, Fault, StructureError};
88pub use int::Int;
89pub use render::{
90    Part, Spelling, interpolate, interpolate_within, spell_within, text_form, text_form_within,
91};
92pub use shape::{Record, Variant};
93pub use text::{Block, Bytes, Run, Text, UNICODE_VERSION};
94pub use time::{Duration, Instant};
95pub use tree::{Element, Keyed, Member, Node, Shape};
96pub use value::{
97    Carry, Difference, HostToken, Identity, Native, Parts, Path, Step, TaskId, Tuple, Value, Walk,
98    compare, equal,
99};
100
101pub use num_bigint::BigInt;
102
103#[cfg(test)]
104#[cfg_attr(coverage, coverage(off))]
105mod tests;