Skip to main content

Module runtime_context

Module runtime_context 

Source
Expand description

Runtime context nodes (SRD 12 §“Runtime context nodes”).

These nodes project stable runtime surfaces — the current phase, the current cycle ordinal, the value of a dynamic control, the active rate-limiter target, the active fiber count — into GK-readable wires. They are the read-side of the reification principle (SRD 10 §“GK as the unified access surface”): any value a workload might want to read is reached through a Polydat binding, not a side channel.

Like the metric nodes (see metrics.rs), these are non-deterministic context projections — their output changes between cycles by definition, so the constant-folder is not allowed to collapse them. They read from globals / thread locals the runtime sets during bootstrap and on every cycle tick.

Structs§

Concurrency
Sugar for control("concurrency") — the current fiber count for the nearest phase. Intrinsically Nondeterministic — see [control].
Control
Read a dynamic control’s current reified-gauge value as f64, by walk-up from the live session root. 0.0 when there is no session root, the control is absent, or it has no reified gauge.
ControlBool
Read a dynamic control’s current value as a boolean — true iff its reified-gauge value is non-zero. Missing / unreified controls → false.
ControlSet
Polydat write node: submit an f64 write against the named control via the session root’s walk-up. Returns 1 if dispatched, 0 if not — either no session root is installed (outside a running scenario / pure-kernel test) or the control already reads exactly the requested value (idempotent writes are elided; see the fixpoint check in the body).
ControlStr
Read a dynamic control’s current value as its human-readable string (the erased-control value_string() rendering). Missing controls → "".
ControlU64
Read a dynamic control’s current value and cast to u64.
Cycle
Current cycle ordinal. Reads a thread-local set by the phase executor. For bindings that already declare cycle as a named input this is redundant; it exists so bindings which never named cycle explicitly can still reach it (SRD 10’s “cycle is not magic” rule — the node is context, not a privileged input).
FiberContext
Per-fiber execution context carried across the async call chain via a tokio::task_local! binding. Thread-locals are unsafe here because tokio’s work-stealing scheduler can migrate a task between worker threads at any .await; a task-local is bound to the task itself and survives migration.
Phase
Current phase name. Reads a thread-local set by the phase executor; "" when unset (outside a cycle, or in tests that install no phase).
PhaseElapsedMillis
Milliseconds elapsed since the CURRENT phase started; 0 outside a phase.
PhaseStartMillis
Epoch millis at which the CURRENT phase started; 0 outside a phase body.
Rate
Sugar for control("rate") — the current rate-limiter target (ops/sec). Intrinsically Nondeterministic (live control read) — see [control].

Functions§

empty_controls
An empty ControlMap for fibers / call sites that have no component (the read then falls back to the session-root walk).
session_root_handle
Public accessor for the runner-installed session root.
set_session_root
set_task_cycle
Update the cycle counter in the enclosing FiberContext. Safe to call outside a scope — the update is a no-op if there is no active fiber context (e.g. when the node is evaluated from a unit test that didn’t install one).
snapshot_controls
Snapshot the controls visible from component (its own controls plus any Subtree-scoped ancestor control, nearest-wins) into a lock-free ControlMap. Deadlock-safe: Component::control_snapshot acquires one tier’s lock at a time, never nested — so it is safe on the cadence-contended component tree. Computed once per phase, shared across the phase’s fibers.
with_fiber_context
Wrap a fiber’s async body in a FiberContext scope. Every runtime-context node read performed inside the future sees the phase name and cycle counter set here.

Type Aliases§

ControlMap
A lock-free, shareable snapshot of resolved control handles (see FiberContext::controls).