Skip to main content

Module table

Module table 

Source
Expand description

Tables and the ways to refer to them: the trait Table that a table’s value type implements, the declaration TableDef, the captured value type TableType, the registry-assigned number TableId, and the typed table keys TableName<T> and TableHandle<T>.

A table is typed data that one stage writes beside the frozen trees and other stages read; its identity is its registered dotted name, never its Rust type, and that name is also a capability, the capability of the table having been written (Table).

§Names, value types and table numbers

A feature declares a table (TableDef) under a dotted name that the feature owns (flm.labels, flm.lowered.html), with one Rust value type. When the registry is built, each declared table receives a TableId, a number that the store uses as the table’s key.

The name, not the Rust type, identifies a table, because one Rust type can hold several tables: the type holding lowered trees is declared once per backend, so the type alone cannot say which table is meant. The value type is captured at declaration as a TableType (its Rust TypeId together with its operations as plain function pointers), so that the store, its fold (fold_outs) and the inspection dumps (crate::dump) can handle every table without naming its Rust type.

When the registry is built, it compares the value type of every table reference in a stage’s declarations with the table’s declared value type. At every access through a typed table key, ComputedView::get, StageOut::table and Run::table compare the key’s value type with the declared one and return AccessError::TypeMismatch on a mismatch, so the conversion back to the value type behind the key cannot fail.

§Typed table keys

A reader or a writer refers to a table through a typed table key, which carries the table’s name and its value type, so that a read returns the value already typed:

  • a TableName<T> constant, for a table with a name fixed at compile time; the crate that defines the value type exports it beside the type (pub const LABELS: TableName<Labels> = TableName::new("flm.labels"));
  • a TableHandle<T>, for a table declared under a name computed at run time;
  • the value type itself, when it implements SingletonTable because exactly one table uses it: T::NAME is then the name that the store’s singleton methods use.

The read and write methods of a stage (ComputedView::get, StageOut::table, StageCx::get), Run::table and Externals::install accept any TableKey. Every typed table key has a type-erased form, TableRef (the name plus the identity of the value type), which stage declarations, plans and messages carry.

§A table’s name is a capability

Every table’s name is also a capability: the capability of the table having been written. A stage that declares a write of the table therefore provides that capability, and a stage that declares a read of it requires it; the registry derives both. See stages, capabilities, and plans.

Structs§

TableDef
A table as a feature declares it: its name, which is also its capability; its value type; its description; and the feature that owns it.
TableHandle
A typed table key for a table whose name is known only at run time.
TableId
The number of a declared table within one registry; the store keys its tables by it.
TableName
A typed table key for a table whose name is fixed at compile time.
TableRef
The type-erased form of a typed table key: the table’s name together with the identity of the value type the key expects.
TableType
A table value type’s identity and operations, captured when the table is declared, so that the store, its fold (fold_outs) and the inspection dumps (crate::dump) can handle every table without naming its Rust type.

Enums§

PieceClass
What a table piece holds: data keyed by node address, nothing, or a fact about the document as a whole.

Traits§

ProjectCx
The context through which a table writes node addresses, tree identifiers and trees when it serializes itself for inspection (Table::project).
SingletonTable
A table value type that exactly one table uses: NAME is that table’s name.
Table
The trait of a table’s value type.
TableKey
A typed table key: a value that refers to a table together with its value type, namely a TableName, a TableHandle, or a reference to either.