1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright 2024-2026 Jonathan Shook
// SPDX-License-Identifier: Apache-2.0
//! GK context API — the public-facing surface of a GK context
//! (compiled program + per-fiber evaluation state, fused as
//! one thing for callers).
//!
//! ## Architecture
//!
//! A "context" is the user's view of a GK kernel. Internally it
//! splits into:
//!
//! - **Compiled context** — the program (immutable, shared
//! across fibers via `Arc<GkProgram>`).
//! - **Context state** — the per-fiber evaluation state (input
//! buffers, node output buffers, dirty flags). Each fiber has
//! its own state instance; the program is shared.
//!
//! Externally there is one type ([`GkKernel`]) and three
//! traits that partition its surface:
//!
//! - [`Dataflow`] — write inputs / read wires. Four core
//! methods: indexed `set_wire(idx, …)` / `get_wire(idx)` and
//! named `set_wire(name, …)` / `get_wire(name)`. All other
//! data accessors (memoized handles, plans, projections)
//! should build on these.
//! - [`Metadata`] — read-only diagnostic and structural data
//! about the context: input/output names and types, scope
//! layering, GK graph matter, init-binding sets, scope
//! coordinates. No data flow.
//! - [`Construction`] — the two sanctioned construction paths:
//! root from source matter, and subscope built against this
//! context with new gk matter.
//!
//! [`GkKernel`]: super::GkKernel
use crate;
/// A wire reference — either a pre-resolved index (fast path)
/// or a name (resolved against the context's input map).
///
/// Lets `set_wire` / `get_wire` accept either form so callers
/// can hold an index when they have one and a name when they
/// don't, without needing two distinct method names.
///
/// Sealed: only the in-crate impls (`usize`, `&str`, `String`)
/// are valid wire keys. External implementors are not
/// permitted because the resolution semantics are tied to the
/// context's input layout.
/// Read-only metadata about a GK context: structural shape,
/// types, names, scope layering. Everything that's a property
/// of the compiled program (or fiber-state instance) but
/// isn't itself a runtime value.
/// Data interface to a GK context: write inputs, read wires.
///
/// Four core methods. The indexed pair is the fast path;
/// the named pair resolves against the context's metadata
/// then delegates to the indexed pair.
///
/// Every other data accessor in the codebase (memoized
/// handles, pull plans, named projections) is built on these
/// four. Callers that don't need to peek at the compiled
/// program or per-fiber state should use this trait
/// exclusively.
/// Construction interface — the two sanctioned construction
/// paths. Per the kernel-construction invariant:
///
/// 1. **Root** — built from gk matter, no parent.
/// 2. **Subscope** — built from gk matter against an existing
/// context.
///
/// Both paths take the same typed gk matter
/// ([`super::super::subcontext::GkMatter`]). The only
/// difference is whether a parent context supervises
/// construction. Nothing else is allowed.