pub struct GkKernel {
pub constants_folded: usize,
/* private fields */
}Expand description
A compiled GK kernel: an Arc<GkProgram> plus one GkState.
§Invariants
- Scope coordinates are always populated. After construction
scope_coordsreflects this kernel’s place in the comprehension chain: leaf-first list ofsuper::ScopeCoordfrom the kernel’s own scope up through every enclosing comprehension. Root-scope kernels (no parent) start with their own coords (or empty).Self::materialize_wiring_from_outerre-computes the path so post-bind it includes the outer’s chain. Consumers (presentation layer, inspector, scope-aware diagnostics) callSelf::scope_coordinateswithout needing to walk the scope tree themselves. See [super::scope_coords].
Fields§
§constants_folded: usizeNumber of init-time constants folded during compilation.
Implementations§
Source§impl GkKernel
impl GkKernel
Sourcepub fn mark_inherited_outputs<I>(&mut self, names: I)where
I: IntoIterator<Item = String>,
pub fn mark_inherited_outputs<I>(&mut self, names: I)where
I: IntoIterator<Item = String>,
Mark a set of output names as inherited (cascade-only)
on the program. Must be called immediately after
construction, before the Arc<GkProgram> is shared.
Panics if the Arc has other references.
Sourcepub fn commit_write_throughs(&mut self)
pub fn commit_write_throughs(&mut self)
SRD-67 Phase 5 — per-cycle commit. Pulls each write- through’s synthetic source output and stores its value through the corresponding cell-bound input slot for the declared export name. Reads of that name in the parent or in sibling kernels share the same cell and observe the write on the next read.
No-op when the kernel carries no write-throughs.
Sourcepub fn set_cursor_schemas(&mut self, schemas: Vec<SourceSchema>)
pub fn set_cursor_schemas(&mut self, schemas: Vec<SourceSchema>)
Set source schemas on the program (called by the compiler).
Sourcepub fn set_ast(&mut self, ast: Arc<GkFile>)
pub fn set_ast(&mut self, ast: Arc<GkFile>)
Attach the parsed AST as live program metadata. Called by every DSL compile entry point immediately after the assembler produces the kernel, while the program Arc is still uniquely owned. The subscope synthesizer (SRD-13f §“Wire-reference classification”) queries this to integrate parent bindings’ matter into child scopes.
Sourcepub fn state_ref(&self) -> &GkState
pub fn state_ref(&self) -> &GkState
Read-only access to the kernel’s evaluation state. Used by callers (e.g. the scope-init pass) that need to inspect pulled values without consuming the kernel.
Sourcepub fn set_inputs(&mut self, coords: &[u64])
pub fn set_inputs(&mut self, coords: &[u64])
Convenience: set coordinate inputs on the owned state.
Sourcepub fn get_input(&self, name: &str) -> Option<Value>
pub fn get_input(&self, name: &str) -> Option<Value>
Read an input value by name. Cell-aware: cell-bound slots return the cell’s current value.
Sourcepub fn input_names(&self) -> Vec<String>
pub fn input_names(&self) -> Vec<String>
Return the names of the inputs.
Sourcepub fn output_names(&self) -> Vec<&str>
pub fn output_names(&self) -> Vec<&str>
Return the names of all available output variates.
Sourcepub fn get_constant(&self, name: &str) -> Option<&Value>
pub fn get_constant(&self, name: &str) -> Option<&Value>
Read the value of a named output that was folded to a constant.
Underlying primitive — prefer Self::lookup for
scope-aware name resolution. This method only succeeds for
constant-folded outputs whose buffer is populated; it
returns None for auto-passthrough outputs (where the
value lives in the input slot) and for cycle-dependent
outputs that haven’t been pulled.
Sourcepub fn lookup(&self, name: &str) -> Option<Value>
pub fn lookup(&self, name: &str) -> Option<Value>
Look up a name in this kernel’s scope.
The canonical scope-aware read documented by SRD-16 §“Visibility Rules: Shadowing”: own-scope folded outputs shadow inherited extern values, with auto-passthrough outputs falling through to the input slot transparently.
Resolution order:
- Folded output buffer (compile-time constants).
- Cell-aware input read (covers extern values bound via
materialize_wiring_from_outer, auto-passthrough outputs frominput ...: u64/extern, andshared-cell-backed slots — the cell is queried on every read so reads pick up writes from sibling kernels intrinsically).
Returns None when the name doesn’t resolve in either
tier or when the resolved value is Value::None (unset).
Returns Value (owned, not borrowed) because shared-cell
reads acquire a Mutex and clone out — there’s no
long-lived borrow into the cell. For non-shared slots
the clone is cheap (Value’s Clone is Arc-based for
vectors, primitive copy otherwise).
This is the single read API for scope-aware name lookup and is cell-aware by default — callers don’t need to know whether a name is shared or not.
Sourcepub fn advance_broadcasts(&mut self)
pub fn advance_broadcasts(&mut self)
SRD-13f Push B.2 — advance this kernel’s broadcast
state: pull every output that has an attached
broadcast cell, forcing the eval cone to recompute
against current inputs and writing the fresh value
through the cell. Descendant kernels with input slots
cell-attached to these outputs then observe the
current value on their next read_input without any
per-fiber-write coordination.
Intended to run once per cycle on each per-fiber outer kernel whose outputs are visible to inner scopes. The alternative — validity-bit + auto-pull-on-stale-read — would put the trigger fully inside the GK engine (so inner reads transparently fetch fresh values), but requires the engine to track upstream dependencies across the cell boundary. This eager-broadcast form is simpler and lives entirely within the kernel’s own surface: callers ask the kernel to advance its broadcasts; the kernel does the pulls; cells receive the values.
Every shared cell visible at this kernel’s scope —
own input slots’ attached cells unioned with the
transit cells inherited from ancestors. The typed
ScopeKernel::shared_cells_in_scope delegates here.
Used by materialize_wiring_from_outer to compute the parent’s
full visible cell set and propagate it to the child.
Public for the typed surface; semantics are the same
as the typed accessor.
Sourcepub fn for_iteration(
canonical: &Arc<GkKernel>,
parent: &Arc<GkKernel>,
bindings: &[(String, Value)],
) -> Arc<GkKernel> ⓘ
pub fn for_iteration( canonical: &Arc<GkKernel>, parent: &Arc<GkKernel>, bindings: &[(String, Value)], ) -> Arc<GkKernel> ⓘ
Construct a per-iteration kernel: clone canonical’s
program, bind it to parent’s scope, and pre-load every
(var, value) binding into the corresponding input slot.
This is the canonical recipe for materialising the scope
kernel at one specific iteration position — the runtime
dispatcher uses it before descending into a comprehension
iteration’s children, and the pre-map walker uses it for
the same purpose so nested for_each clauses with
outer-iter-var interpolation (vec_{profile}) resolve
at pre-map time.
Owning the recipe here ensures both consumers produce
identical kernels for identical inputs; previously each
site reimplemented the three-step from_program →
materialize_wiring_from_outer → set_input dance and could (and
did) drift.
Sourcepub fn scope_coordinates(&self) -> &[ScopeCoord]
pub fn scope_coordinates(&self) -> &[ScopeCoord]
The leaf-first scope coordinate path — see the
[super::scope_coords] module doc for the formal
definition. Always reflects the current binding state:
after Self::materialize_wiring_from_outer the path includes the
outer kernel’s full chain; for root scopes the path is
just this kernel’s own coords (or empty).
Sourcepub fn scope_values(&self) -> Vec<(String, Value)>
pub fn scope_values(&self) -> Vec<(String, Value)>
Extract the scope values that were set via materialize_wiring_from_outer.
Returns [(name, value)] for inputs that are not at their
default. Used by OpBuilder to inject the same values into
every fiber’s state, including per-op-template kernels
whose input layout differs from this kernel’s. The name-
keyed shape is the cross-kernel-safe contract: an index
captured against this kernel’s layout is meaningless when
applied to a kernel synthesised from a different source
(different extern declaration order, lazy-cascade omissions,
etc.). Naming the binding makes the cross-scope write
unambiguous — a missing name on the target program is a
no-op rather than a silently mis-routed write.
Sourcepub fn into_program(self) -> Arc<GkProgram> ⓘ
pub fn into_program(self) -> Arc<GkProgram> ⓘ
Extract the program for concurrent use.
Source§impl GkKernel
impl GkKernel
Sourcepub fn build_subscope(
&self,
matter: GkMatter<'_>,
) -> Result<GkKernel, ContractViolation>
pub fn build_subscope( &self, matter: GkMatter<'_>, ) -> Result<GkKernel, ContractViolation>
THE subscope-construction path. Per the kernel-construction
invariant, this is the ONE method through which a parent
kernel produces a child. compile_gk produces root
kernels; everything else is a subscope and routes here.
Cell propagation, scope-coordinate plumbing, and Rule 2
write-throughs flow from self (the parent) into the
returned child. Returns the child kernel plus any
write-through bindings finalize produced (empty for the
program-matter form, populated for the source-matter
form when a result-LHS collides with a parent shared
cell).
Trait Implementations§
Source§impl Construction for GkKernel
impl Construction for GkKernel
Source§type Error = ContractViolation
type Error = ContractViolation
Source§impl Dataflow for GkKernel
impl Dataflow for GkKernel
Source§fn set_wire_idx(&mut self, idx: usize, value: Value)
fn set_wire_idx(&mut self, idx: usize, value: Value)
idx. Out-of-range indices are
a programming error (the caller already had a resolved
index); panics in debug, no-ops in release.Source§fn get_wire_idx(&self, idx: usize) -> Value
fn get_wire_idx(&self, idx: usize) -> Value
idx. Out-of-range
behaviour mirrors set_wire_idx.Source§impl Metadata for GkKernel
impl Metadata for GkKernel
Source§fn find_input(&self, name: &str) -> Option<usize>
fn find_input(&self, name: &str) -> Option<usize>
Source§fn input_names(&self) -> Vec<String>
fn input_names(&self) -> Vec<String>
Source§fn output_names(&self) -> Vec<String>
fn output_names(&self) -> Vec<String>
Source§fn coord_count(&self) -> usize
fn coord_count(&self) -> usize
Auto Trait Implementations§
impl Freeze for GkKernel
impl !RefUnwindSafe for GkKernel
impl Send for GkKernel
impl Sync for GkKernel
impl Unpin for GkKernel
impl UnsafeUnpin for GkKernel
impl !UnwindSafe for GkKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more