Skip to main content

Module node

Module node 

Source
Expand description

The node: blue processes reachable from blue (BLUE-GAPS G11).

Until this module, everything in this crate was reachable only from Rust: a blue program could not spawn, send or receive, and a NATS subscriber had to poll from the main program. A Node is the process runtime one interpreter’s program runs against, and install binds its words:

spawn(f[, args][, opts])    spawn_link(f[, args][, opts])
spawn_server(handler, state[, opts])                   opts: {scheduling: :normal | :idle}
send(pid, msg)              receive([pattern][, timeout_ms][, on_timeout])
self()   alive?(pid)        link(pid)  unlink(pid)     monitor(pid)  demonitor(ref)
exit(pid, reason)           trap_exit(flag)
supervisor(strategy, children[, max_restarts])         children(sup)
defmigrate(target, new_fn[, transform])
def_hash(f)
evict(pid, wire, peer)      accept(wire, timeout_ms)   (with a Carrier: comm-scavenger)

§The shapes, adopted rather than invented

  • Copy on send, share nothing (theory/BLUE.md §V.8, BLUE-EXCLUSIVITY §II.3): a message is deep-copied, and a spawned function is turned back into code and recompiled in the child (crate::code), never shared.
  • Erlang’s process vocabulary: links propagate abnormal exits unless the receiver traps them (then they arrive as [:exit, pid, reason]), monitors deliver [:down, ref, pid, reason], :kill cannot be trapped, a send to a dead process is dropped.
  • The supervisor strategies are Strategy’s, with intensity checked on the child that exited and the mailbox emptied on restart, exactly as the Rust-level crate::Supervisor does.
  • The interleaving is replayable (BLUE-EXCLUSIVITY §II.13): one thread, procs walked in spawn order, a fixed reduction quantum. What a process could not replay from its program alone — the messages it received, the host values it read, the pids it was handed — is recorded on its tape, and a crash writes the tape out (crate::trace). An :idle process is the one exception to the one thread: its slices run on a low-priority thread of its own while the node runs the rest (IdleLane::Apart), so where they fall among the others is the OS’s choice and not replayable; its own crash still replays from its tape. It still acts only while the root waits: a word it calls between waits holds until the next one. IdleLane::Held keeps the whole interleaving replayable by waiting for each idle slice.

§The root is the program; children are VM processes

The program a door evaluates is process ROOT (pid 0). It runs on whichever executor the door chose and is never preempted: it gives the other processes the CPU by waiting — receive, defmigrate — and its receive drives the scheduler until it has a message, its timeout passes, or nothing can ever send (a deadlock, reported rather than hung on). The program ends when the root does, as an escript does; a process the root never waited for does not run to completion.

Every other process runs on the bytecode VM, which is the executor that can preempt (a quantum) and park (receive on an empty mailbox costs nothing).

§What a host must provide

NodeConfig::child builds a fresh interpreter for a child. The node adds its own words to it, and rebinds every host name (blue_lang_waku’s host capabilities) to a recorder, so a child’s reads of the clock, the network or the filesystem land on its tape.

Structs§

Carrier
Meter
The host’s allocator meter, through which a node holds each process to the live-byte bound of the evaluation that spawned it (max_alloc_bytes).
Node
The process runtime one program runs against.
NodeConfig
What a node runs its processes under.

Enums§

ClockKind
How a node reads time.

Constants§

CARRIED_WORDS
DEFAULT_JOURNAL
Messages a held process’s mailbox journal keeps of each kind (taken, still waiting), when the host does not say.
DEFAULT_MAX_RESTARTS
Supervisor restarts of one child before it gives up, when the program does not say.
DEFAULT_MAX_TAPE
Tape entries one incarnation may record before its trace is marked truncated. A replay needs the whole tape, so a truncated trace says so rather than replaying a suffix.
DEFAULT_QUANTUM
Reductions per slice. BEAM uses 4 000; a blue reduction is one VM instruction, smaller than a BEAM reduction (a function call).
EVICTED
PROCESS_WORDS
Every word install binds that a blue program can spell.
ROOT
The program itself.
SERVER_NEXT
The word a server’s loop waits in. Not spellable, so not in PROCESS_WORDS.

Functions§

host_names
Every host name blue has, from the closed capability universe.
install
Bind the process words into the interpreter that runs a program, against node. The interpreter becomes the node’s root.
reason_value
The blue value of an exit reason.
set_journal_bound
How many messages of each kind a held process’s mailbox journal keeps; 0 keeps none. Only the first call counts, like set_trace_dir; a node built before any call keeps DEFAULT_JOURNAL.
set_trace_dir
Where nodes write crash traces. Only the first call counts, like blue_lang_runtime::set_execution_bounds; a node built before any call keeps its traces in memory only.

Type Aliases§

ChildFactory
A fresh interpreter for a child, before the node adds its words.