pub struct Graph { /* private fields */ }Expand description
Recording context every DSL method writes into.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty Graph. Module::build() wraps the body in
with_function(self.name(), ...) automatically.
Sourcepub fn take_pending_errors(&mut self) -> Vec<BuildError>
pub fn take_pending_errors(&mut self) -> Vec<BuildError>
Drain accumulated recorder errors.
Sourcepub fn output(&mut self, name: &str, handle: Output)
pub fn output(&mut self, name: &str, handle: Output)
Register a named output port. Idempotent — a second call for
the same (target_idx, name) returns the prior handle.
Sourcepub fn net_out(&mut self, name: &str, peers: Output, value: Output)
pub fn net_out(&mut self, name: &str, peers: Output, value: Output)
Emit a wire.Send to peers (a Vec<PeerId> at dispatch)
and register name as a network output. The compiler’s
partition_by_wire_ops cuts here; synthesize_wire_recvs
materializes the matching wire.Recv.
Sourcepub fn bundle(&mut self, parts: &[Output]) -> Output
pub fn bundle(&mut self, parts: &[Output]) -> Output
Pack N typed Outputs into one composite. Receiver pairs
with Self::unbundle. Composite envelope is
bb_ir::types::TYPE_COMPOSITE. Panics on empty parts.
Sourcepub fn unbundle(
&mut self,
composite: Output,
part_types: &[&'static TypeNode],
) -> Vec<Output>
pub fn unbundle( &mut self, composite: Output, part_types: &[&'static TypeNode], ) -> Vec<Output>
Extract a composite Output back into its N child Outputs.
part_types declares the expected child TypeNodes positionally;
the runtime op validates the envelope’s child count against the
declared length and emits one BytesValue-shaped output per
child, named child_{i} and typed against part_types[i] via
the stamped ValueInfoProto.denotation. Downstream consumers
decode against that denotation, matching the wire.Recv pattern.
Panics with a recording-time error if part_types is empty —
the matching g.bundle cannot have produced a zero-child
envelope.
Sourcepub fn lookup_output(&self, name: &str) -> Option<Output>
pub fn lookup_output(&self, name: &str) -> Option<Output>
Look up a previously-registered output port by name on the
current recording target. Returns None when neither
output(name, ...) nor an enclosing scope has registered
the port — callers report BuildError::MissingOutputPort.
Sourcepub fn record_build_error(&mut self, err: BuildError)
pub fn record_build_error(&mut self, err: BuildError)
Push a crate::module::BuildError onto the recorder’s
pending-errors queue. Used by methods that must keep their
existing return shape (e.g. Graph::wire returns the typed
output triple) but want a typed-error escape from a panic.
Sourcepub fn finish(self) -> RecordedModule
pub fn finish(self) -> RecordedModule
Extract the recorded function body for the compiler to
consume. Called by Module::build() after module.op()
returns. The chosen-path install constructs concrete
instances via the inventory’s construct_fn at install
time; the IR carries no instance state.
Sourcepub fn register_generic<T: 'static>(
&mut self,
instance: &T,
_required_trait: &'static str,
) -> u32
pub fn register_generic<T: 'static>( &mut self, instance: &T, _required_trait: &'static str, ) -> u32
Pointer-identity-keyed slot allocation for generic
placeholders. Appends "__slot_<slot_id>" to
FunctionProto.attribute on first encounter.
Sourcepub fn input(&mut self, name: &str) -> Output
pub fn input(&mut self, name: &str) -> Output
Declare a Module input by name. Lands with
bb_ir::types::TYPE_BYTES sentinel; the TypeSolver
narrows it later. Propagates up the recording-target chain
in Open mode so enclosing CALL NodeProtos stay
referenceable.
Sourcepub fn next_site_name(&mut self) -> String
pub fn next_site_name(&mut self) -> String
Allocate a fresh value-name. Monotonic counter; format
"v<n>".
Sourcepub fn declare_value_info(&mut self, name: &str, type_node: &'static TypeNode)
pub fn declare_value_info(&mut self, name: &str, type_node: &'static TypeNode)
Stamp a ValueInfoProto for name on the current target.
Idempotent. Recorders call this on every minted output.
Sourcepub fn push_node(&mut self, node: NodeProto)
pub fn push_node(&mut self, node: NodeProto)
Push a NodeProto into the active target. Stamps
MODULE_INSTANCE_KEY with the joined with_function chain;
an existing stamp is prefixed (preserves replayed hierarchy).
Sourcepub fn with_function<F>(
&mut self,
name: &str,
bindings: &[(String, Output)],
body: F,
) -> Vec<(String, String)>
pub fn with_function<F>( &mut self, name: &str, bindings: &[(String, Output)], body: F, ) -> Vec<(String, String)>
Record body into a sub-FunctionProto named name and emit
a CALL in the outer target. Top-level wraps fold the body
into function[0] instead of synthesizing a CALL.
bindings pre-loads formal→actual handles so
g.input(formal) inside body returns the actual.
Returns (child_port_name, parent_call_output_name) pairs
for non-top-level wraps; empty for top-level (g.output
registers directly in the parent scope).
Sourcepub fn function(&self) -> &FunctionProto
pub fn function(&self) -> &FunctionProto
Read-only view of the recorded FunctionProto. ’s
compiler + the acceptance tests read everything from here -
the proto is the single source of truth.