Expand description
Marshalling between the interpreter’s RuntimeValue and the Send-able
[RtPayload] that crosses task/thread boundaries through channels.
materialize moves a value OUT of a task’s Rc-based heap into an owned,
self-contained RtPayload; rebuild reconstructs a fresh Rc-based value
in the receiving task’s heap. The pair mirrors RuntimeValue::deep_clone
but crosses the Send boundary. Values that cannot cross (closures) yield a
MarshalError; the Send/escape analysis (Phase 4) rejects them statically,
so this is a defensive backstop, not the primary gate.
Structs§
- Negotiated
- The encoding choices negotiated for sending TO a peer, from my profile and the peer’s advertised one.
- Peer
Profile - A peer’s PUBLISHED acceptance surface — the single declarative object it EXPOSES to the other side
AND that its own decoder ENFORCES. Declare it once: it is both advertised (in the handshake) and the
budget the decode path checks, so the two can never drift. Carries the resource budget
(
ReceiveLimits), the peer’s type-registry epoch (a content hash of its type table — when both peers’ epochs match, struct/enum NAMES need not travel, since both derive the same ids), and a feature bitset (FEAT_*). - Receive
Limits - A receiver’s admission-control budget — the limits it will accept from a sender, so a malicious or
buggy peer cannot exhaust the receiver’s memory, stack, or CPU. Enforced DURING decode, BEFORE the
offending allocation or recursion happens, so an over-budget message is refused cleanly (the decode
returns
None) rather than processed. A receiver advertises these in the capability handshake so a cooperative sender stays within them; an uncooperative one is still bounded by the enforcement. - Wire
Schema Cache - A connection-scoped schema dictionary (one per direction per peer). A struct
schema (type name + field names) is transmitted ONCE and referenced thereafter —
the RPC-grade win for streams of same-shaped struct messages. The mode picks the
id scheme (see
WireSchemaMode); every mode is corruption-free — a decoder that cannot resolve a reference returnsNonerather than mis-decoding. An optional keyframe interval re-emits a definition every k references so a late or lossy receiver self-heals. - Wire
Structs Cursor - A parse-once cursor over a record-list view (
T_STRUCTS_VIEW/T_STRUCTS_FVIEW): the schema and tables are read ONCE at open, then every(row, field)access is O(1) — pure arithmetic for the fixed-stride view, a two-u32offset jump for the variable view — with no per-call re-scan. - Wire
Type Registry - A program-derived registry of every struct/enum schema, shared by both ends of a Logos↔Logos link (each side builds it from the SAME program type definitions). Every type gets a stable small id — canonical by fingerprint, so declaration order is irrelevant and sender + receiver always agree. The codec ships the id instead of the type/field NAMES, and the receiver — running the same program — resolves it. This is the “duh, you use that” default that drops names off the wire entirely.
- Wire
View - A borrowed view over one wire message’s top-level value. Holds no owned data and never
decodes the rest of the message; reads are in place. Open it with
view_message.
Enums§
- GenCmp
- GenExpr
- A restricted, pure, TOTAL expression over the element index
i. Every op is total (div/mod by zero is 0, wrapping i64 arithmetic), and a malformed/hostile tree is bounded at decode by a node budget + depth cap, so evaluation can never panic, diverge, overflow, or escape. - Marshal
Error - Why a value could not be marshalled across a task boundary.
- Wire
Codec - The wire encoding for a message body.
- Wire
Column - One column of a
build_columnar_recordmessage — a borrowed slice that lands in the wire’s zero-copy aligned layout with no intermediateRuntimeValue. - Wire
Compression - The compression codec for an encoded body — the sender’s dial. The wire is
self-describing (the header carries the codec), so this is purely a sender
preference; any peer decodes any codec. Each is kept only if it actually shrank
the body (see
message_to_wire_with), so compression never hurts the fast path. - Wire
Compression Level - The compression effort dial — a sender-only preference (the codec output is
self-describing, so the decoder needs no knowledge of the level).
Fastfavors throughput,Maxfavors ratio,Balancedis the default middle. - Wire
Floats - How float arrays are encoded.
Memcpyis the raw 8-byte-per-element blob (the memory-bandwidth ceiling, the default).XorDeltaXORs each value’s bits with the previous and varint-codes the result — lossless and bit-exact (it operates on raw bits, so NaN/Inf/±0/subnormals are preserved), and far smaller for slowly-varying (time-series) columns. It is applied per-column only when it actually shrinks the column, so it never grows a message. - Wire
Goal - What the
message_to_wire_bestauto-tuner optimizes for. - Wire
Integrity - Whether a message carries an integrity checksum.
- Wire
Numerics - How integer arrays are laid out on the wire — the sender’s size↔speed dial. The decoder always handles every variant (each has its own tag), so this is purely a sender preference; mix freely on one relay.
- Wire
Schema Mode - How a connection-scoped schema dictionary identifies a struct schema on the wire. All modes are corruption-free; they trade size against robustness.
- Wire
Structure - Whether the encoder may replace a column with a closed-form generator when the
data is mathematically structured — the Futamura move on the wire: if the values
are described by a formula, ship the formula, not the values. Every form is
lossless and gated by an exact-match proof, so it can never change the decoded
value; the decoder always reconstructs (each form has its own tag).
Offby default (detection is an O(n) scan the speed dials skip), opt-in per send.
Constants§
- DEFAULT_
RECEIVE_ LIMITS - Generous-but-finite defaults: every real message passes (genuine nesting is almost always < 10
deep); only the pathological / adversarial ones are refused.
max_depthsits BELOW [MAX_ENCODE_DEPTH] on purpose — the recursive DECODER’s stack frame is heavier than the encoder’s (one giantmatch), so the depth that is safe to recurse on a small (wasm ~1 MiB) stack is lower than what we allow ourselves to encode. A deployment tightens these per peer through the handshake. - FEAT_
COMPUTED - The peer is willing to receive a shipped computation (subject to its acceptance contracts).
- FEAT_
DEFLATE - The peer understands DEFLATE-compressed frames.
- FEAT_
FEC - The peer can reconstruct FEC / erasure-coded redundant frames.
- FEAT_
LZ4 - The peer understands LZ4-compressed frames.
- FEAT_
TYPE_ ID - The peer can resolve type-id name elision against a shared type registry.
- FEAT_
ZSTD - The peer understands Zstd-compressed frames.
Functions§
- best_
compressed_ len - The smallest
bodycompresses to across the built-in compressors (deflate / lz4 / zstd), or its raw length when none helps — the “fair fight” size for an arbitrary byte string. This is the same shop-every-compressor rulemessage_to_wire_best’sSmallestgoal applies to the LOGOS wire, exposed so a benchmark can grant a COMPETITOR codec the identical compression opportunity: then a size comparison is compressed-vs-compressed (fair), not compressed-LOGOS-vs-raw-competitor. - build_
columnar_ record - Build a columnar record message in place — Cap’n Proto’s home turf. The named columns are
written DIRECTLY into the offset-table
T_STRUCT_VIEW+T_*_ALIGNEDwire layout from borrowed slices: no intermediateRuntimeValue, no second serialize pass over the data (each column is a singlememcpy). The receiver opens it withview_messageand reads ANY column in O(1) and zero-copy viaWireView::struct_field+WireView::as_i64_slice/WireView::as_f64_slice. - decode_
peer_ profile - Parse a peer’s advertised
PeerProfile. A version this build does not understand, or a truncated blob, yieldsNone— the caller then falls back to the conservative defaults (never mis-decodes). - decode_
value_ raw - Decode a value produced by
encode_value_raw(or by an AOT-generatedwire_encode) back into aRuntimeValue.Noneon any malformed or trailing-byte input. - deframe_
stream_ message - Deframe a batch stream message into its values, in order.
Noneifbytesis not a stream message; a frame that fails to decode is skipped (never a panic). - describe_
columns - Name the structural encoding of each column in a native wire message — the codec
explaining its own output, so “which dial won” is legible to a human. A single-column
message (int / float / string / bool list, a set, an int-keyed map) yields one name; a
record list (
T_STRUCTS) yields one"field: encoding"per field. Empty for a shape it does not model (compressed, JSON, a bare scalar, or a malformed frame) — the caller then shows a generic label. It reuses the real decode dispatch to skip each column body, so it can never drift from the format it reports on. - encode_
peer_ profile - Serialize a
PeerProfilefor the handshake — a version byte (so a future layout is recognized, not mis-parsed) followed by the budget, epoch, and feature bits. - encode_
value_ raw - Encode ONE value as the plain, self-describing recursive wire form — no envelope, no
framing, no columnar/compression/dedup transforms. This is the exact format the shared
logicaffeine_data::wirecore decodes, so aRuntimeValueencoded here round-trips through an AOT-generated type’swire_decode(and vice versa). The speed-first form used to hand a program AST to a compile-once native partial evaluator. - frame_
stream_ message - Frame a sequence of values as one batch STREAM message:
[magic][sender][framed value-message]*, each value length-delimited (viacrate::concurrency::stream::frame_for_stream) so the receiver deframes them incrementally and reads each in place. ONE relay publish ships the whole batch — Kafka-style streaming that amortizes per-message overhead — andAwait streamreassembles the list. Each value is encoded self-describingly so it round-trips without the type registry. - gen_
eval - Evaluate a generator at index
i. TOTAL: div/mod by zero is 0; all arithmetic wraps. - make_
handshake_ frame - Build a handshake frame advertising
from’sPeerProfile: the magic prefix, the sender identity, then the serialized profile. Published like any message but recognized + absorbed (not delivered as data) by the receiver. - materialize
- Move a value out of a task’s heap into a
Send-able payload. - message_
from_ wire - Decode a wire message (from
message_to_wire) into(sender, value), rebuilding the typed value in the local heap. Auto-detects the codec, integrity, and compression; a checksum mismatch, an unknown header, a bad inflate, trailing bytes, or any malformed input all returnNone— never a panic, never a half-rebuilt value. - message_
from_ wire_ cached - As
message_from_wire, but resolves schema references againstcacheand records schema definitions into it. - message_
from_ wire_ view - message_
to_ wire - Encode a directed peer message for the relay wire: the sender’s inbox topic
plus the FULL language value — scalars, collections, structs, inductives,
nested, type tags and all — as compact
bincodeunder the process default integrity ([default_integrity]). Closures, and channel/task handles (local to this process), cannot travel between machines and are reported with a clear error rather than silently dropped. - message_
to_ wire_ auto - The genuine no-brainer — “just send it.” Runs the full
WireGoal::Smallestbake-off ONLY when the payload is large enough for it to matter, and otherwise ships the plain default (so calling this on every message — including scalars and short strings — costs a single encode pass, not the N-pass search). The result is NEVER larger than the default, ALWAYS self-describing (so it interoperates with every peer, no hint), and round-trips exactly. This is the recommended default sender. - message_
to_ wire_ best - The no-brainer encoder — “just use this.” Picks the Pareto-optimal dial combination for
goaland ships it. Because every wire form is self-describing by its leading tag, this is purely an ENCODE-side decision: the decoder reconstructs viamessage_from_wirewith no hint, sobestinteroperates with every existing peer. - message_
to_ wire_ cached - As
message_to_wire_with, but a known struct schema is sent by reference instead of inline (per the cache’sWireSchemaMode). - message_
to_ wire_ negotiated - Encode a message TO a peer using EVERYTHING both sides support — the negotiated maximal crush.
Applies all the self-describing dials (any peer decodes them) via the size bake-off, but restricts
the receiver-capability knobs to the negotiated surface: only compression codecs the receiver can
decode, and type-id NAME ELISION only when epochs matched (
neg.use_type_id). Refuses to ship a computation the receiver declined. Stays MINIMAL in cost too: a tiny message that name-elision can’t help ships the plain default without paying for the search. Never larger than the default; always self-describing, so it round-trips on the receiver with no hint. - message_
to_ wire_ with - As
message_to_wire, with an explicit codec and integrity mode. - negotiate
- Negotiate how to send TO a peer from my profile + the peer’s advertised one. CONSERVATIVE: a capability is used only when BOTH sides expose it. This is where “expose properly” pays off — the sender automatically restricts itself to exactly the surface the receiver published, so it never ships a form the receiver can’t decode, won’t run code the receiver declined, and stays under the receiver’s size budget.
- parse_
handshake_ frame - Parse a handshake frame →
(sender, advertised profile).Nonewhendatais not a handshake (no magic) or is malformed — so a data message is never mistaken for one, and an unknown/garbage profile is ignored rather than mis-applied. - peek_
deferrable_ sender - Decode a received message LAZILY when its top-level value is a self-describing record-list view
(
T_STRUCTS_VIEW): returns(sender, List(WireStructs))holding the raw frame, so NO row is decoded until a field is touched — the production zero-copy receive (“no decode in production”, Cap’n Proto’s home). Any other shape (scalars, maps, single structs, cached/compressed bodies) falls back to a fullmessage_from_wiredecode, so every message still round-trips. The receiver opts in with theviewknob; without it, the eager path is used exactly as before. Peek a frame: if its top-level value is a self-describing DEFERRABLE view — a record list (T_STRUCTS_VIEW) or an aligned numeric column (T_INTS_ALIGNED/T_FLOATS_ALIGNED), all of which have no schema-cache dependency — return the sender so its decode can be deferred toAwait(lazy underview, eager otherwise).Nonefor anything else (scalars, single structs, maps, cached, or compressed bodies), which must decode eagerly in arrival order. The drain loop uses this to split deferrable views from order-sensitive messages. - peek_
stream_ sender - Is
bytesa batch stream message? If so, return its sender (soAwait stream … from <peer>matches it).Nonefor a normal message / FEC shard / anything else. - rebuild
- Reconstruct a fresh
Rc-based value in the receiving task’s heap. - view_
message - Open a borrowed, zero-alloc view over
bytes.Nonefor a compressed or JSON message (those must be inflated/decoded first — the view is over raw native bytes) or a malformed frame. Reads any single field in place afterward. - with_
compression - Back-compat convenience: compress with DEFLATE (what the bare
Send compressedkeyword selects). - with_
compression_ codec - Compress encoded bodies with
codec(kept only if smaller) for the duration off. Scoped so it never leaks. - with_
compression_ level - Set the compression effort for the duration of
f. Scoped so it never leaks. - with_
dedup - Encode
f’s value with Rc-dedup ON: shared subtrees ship once + backrefs. Self-describing by tag, so the receiver rebuilds the sharing with no knob of its own. The default (OFF) is byte-unchanged. - with_
fixed_ numerics - Convenience for
WireNumerics::Fixed(back-compat). - with_
flat_ lists - Run
fwith flat (columnar-free) list encoding forced on/off, restoring the prior value. - with_
floats - Encode float arrays under
modefor the duration off. Scoped — never leaks. - with_
integrity - The latency↔safety dial: run
fwith the checksum on (Checked) or off (Raw), overriding the process default for the duration. Scoped — never leaks.Rawis the fastest path (the FNV checksum is the bulk of small-message encode cost);Checkeddetects corruption. Pairs withwith_numerics/with_compression_codec. - with_
numerics - Encode integer arrays under
nfor the duration off. Scoped — never leaks. - with_
receive_ limits - Decode under
limitsfor the duration off— the receiver’s admission gate. Restores the prior limits afterward (so it nests). Pair withmessage_from_wire. - with_
struct_ view - Encode structs in the offset-table
T_STRUCT_VIEWlayout for the duration off, so aWireViewreads any single field in O(1) (the Cap’n Proto-beating random-access mode). Larger than the packed forms — it is the speed end of the size↔speed dial. - with_
structure - Enable structural (closed-form) integer encoding under
sfor the duration off. Scoped — never leaks. SeeWireStructure. - with_
type_ registry - Install a shared type registry for the duration of
f(consulted by BOTH encode and decode). Restores the previous registry on return or panic.