Skip to main content

bb_runtime/engine/
call_context.rs

1//! Per-function-call invocation context.
2//!
3//! Stored on `Engine.pending_calls[body_exec_id]` when an
4//! `OpDispatch::FunctionCall` fires. Encodes the runtime aliasing
5//! the body's nodes need to read inputs from the caller's scope
6//! (zero-copy) and the output forwarding map that lands body outputs
7//! back at the caller's slots when they complete.
8
9use std::collections::HashMap;
10
11use crate::engine::dispatch_entry::FunctionKey;
12use crate::ids::{ExecId, NodeSiteId};
13
14/// Per-call invocation context, keyed by the body's fresh
15/// `ExecId` in `Engine.pending_calls`.
16#[derive(Debug)]
17pub struct CallContext {
18    /// The caller's `ExecId` - where input slots live and where
19    /// output forwarding writes back.
20    pub parent_exec_id: ExecId,
21
22    /// The called function's symbol-table key. Stamped onto the
23    /// `engine.function_call` tracing span so traces attribute body
24    /// activity to the calling function.
25    pub target: FunctionKey,
26
27    /// Formal parameter name → caller-side `NodeSiteId`. Body
28    /// nodes that consume a formal input look up the alias here
29    /// and read from `slot_table[(alias_site, parent_exec_id)]`.
30    /// No value copy - body reads from caller's slot directly.
31    pub input_aliases: HashMap<String, NodeSiteId>,
32
33    /// Body-side `NodeSiteId` → caller-side `NodeSiteId`. When
34    /// `write_outputs` writes to a body output site, the value is
35    /// also moved to the matching caller site at
36    /// `parent_exec_id`, and `push_ready_consumers` is re-run for
37    /// the caller's downstream.
38    pub output_forwarding: HashMap<NodeSiteId, NodeSiteId>,
39
40    /// Decremented each time an output is forwarded; the entry
41    /// is dropped from `pending_calls` when this reaches zero.
42    pub outputs_remaining: usize,
43}