behavior-contracts 0.8.10 → 0.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -16
- package/cli-contract.yaml +46 -44
- package/dist/cli.js +16 -14
- package/dist/cli.js.map +1 -1
- package/dist/commands/codegen.d.ts +4 -3
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +8 -5
- package/dist/commands/codegen.js.map +1 -1
- package/dist/generated/commands.d.ts.map +1 -1
- package/dist/generated/commands.js +12 -16
- package/dist/generated/commands.js.map +1 -1
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +2 -2
- package/dist/generated/contract.js.map +1 -1
- package/dist/generated/program.d.ts +6 -8
- package/dist/generated/program.d.ts.map +1 -1
- package/dist/generated/program.js +6 -8
- package/dist/generated/program.js.map +1 -1
- package/dist/generated/types.d.ts +6 -8
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generator/core.d.ts +37 -20
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js +2 -1
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +19 -7
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +557 -408
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +27 -22
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +430 -482
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +2 -2
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -173,13 +173,34 @@ function pascal(s) {
|
|
|
173
173
|
function portsStructName(compName, nodeId) {
|
|
174
174
|
return `PortsNR${pascal(compName)}${pascal(nodeId)}`;
|
|
175
175
|
}
|
|
176
|
-
/**
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
/**
|
|
177
|
+
* resolveLeafSymbol — the op-agnostic transport symbol a covered leaf (= catalog component) is called
|
|
178
|
+
* through at its execution point. A consumer-supplied override (`leafTransport.symbols[component]`) wins;
|
|
179
|
+
* else the in-package DEFAULT convention `leaf_<sanitizedComponent>`. This is the ONE place leaf→symbol
|
|
180
|
+
* resolution lives (SSoT) — the runner call sites, the import block, and the test observe transport fns
|
|
181
|
+
* all read it. There is no per-node handler indirection: the leaf is one transport, not one method per node.
|
|
182
|
+
*/
|
|
183
|
+
function resolveLeafSymbol(component, leaf) {
|
|
184
|
+
return leaf?.symbols[component] ?? `leaf_${sanitize(component)}`;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* portFieldSpread — the covered node's port fields, in declared `Object.keys(ports)` order, each carrying
|
|
188
|
+
* its native ports-struct field name, its Copy-ness (borrow vs move), and its rendered field type. The ONE
|
|
189
|
+
* place the transport-call port spread is derived (SSoT): a runner call site spreads `<var>.<f>` (Copy) /
|
|
190
|
+
* `&<var>.<f>` (non-Copy); the test observe transport fn declares params of the matching type. Types come
|
|
191
|
+
* from the SAME `compilePortNode` lowering `emitPortsStruct` uses, so the spread can never disagree with
|
|
192
|
+
* the field types the ports struct declares.
|
|
193
|
+
*/
|
|
194
|
+
function portFieldSpread(ports, comp, plan, typedNodes, asBinding) {
|
|
195
|
+
const opts = asBinding !== undefined ? { asBinding, asBase: asBinding.name } : undefined;
|
|
196
|
+
return Object.keys(ports).map((pn) => {
|
|
197
|
+
const c = compilePortNode(ports[pn], comp, plan, typedNodes, (h) => typedNodes.has(h), `port '${pn}' of node '${comp.name}'`, opts);
|
|
198
|
+
return { field: portFieldName(pn), isCopy: typeRefIsCopy(c.ref), renderedType: c.renderedType ?? renderTypeRef(c.ref) };
|
|
199
|
+
});
|
|
179
200
|
}
|
|
180
|
-
/**
|
|
181
|
-
function
|
|
182
|
-
return `
|
|
201
|
+
/** leafCallArgs — the spread transport-call arguments for a ports-struct var (Copy→move, non-Copy→borrow). */
|
|
202
|
+
function leafCallArgs(varExpr, spread) {
|
|
203
|
+
return spread.map((p) => (p.isCopy ? `${varExpr}.${p.field}` : `&${varExpr}.${p.field}`)).join(", ");
|
|
183
204
|
}
|
|
184
205
|
/** InNR<Comp> — the concrete per-component input struct name (fields = inputPorts). */
|
|
185
206
|
function inStructName(compName) {
|
|
@@ -193,14 +214,17 @@ function inStructName(compName) {
|
|
|
193
214
|
// required/optional, present/absent, error assembly, fail-closed. The seam stays native: Probe/NumProbe
|
|
194
215
|
// are concrete enums and WireRow/WireList are monomorphized via mutual associated types (Row/List), so no
|
|
195
216
|
// boxed Value / dyn / Box crosses the boundary.
|
|
196
|
-
/** emitRustProbeWireTypes — the once-per-module probe enums +
|
|
197
|
-
*
|
|
198
|
-
*
|
|
217
|
+
/** emitRustProbeWireTypes — the once-per-module probe enums + the BC-OWNED concrete wire types + their
|
|
218
|
+
* classification. bc GENERATES the whole seam: `WireValue` is a self-contained (runtime-free) generic
|
|
219
|
+
* result the consumer's SINGLE op-agnostic transport builds and returns; the consumer implements NOTHING
|
|
220
|
+
* over it (no trait, no probe protocol). The generated inline de-box reads it via these inherent methods —
|
|
221
|
+
* static typed extraction lowers the generic result to the covered plane's typed values immediately, so no
|
|
222
|
+
* dynamic value crosses the covered/hot plane (bc#87). Numbers ride as raw text so BC owns overflow. */
|
|
199
223
|
function emitRustProbeWireTypes() {
|
|
200
224
|
return `// Probe<T> / NumProbe — the outcome of classifying one wire attribute against a declared type. Got carries
|
|
201
225
|
// the matched value (a NumProbe's raw numeric text, which the de-box parses + range-checks so overflow is
|
|
202
|
-
// BC's to detect); actual_wire_type is the producer's own wire tag (
|
|
203
|
-
//
|
|
226
|
+
// BC's to detect); actual_wire_type is the producer's own wire tag (S/N/BOOL/M/L/NULL); raw_value is the
|
|
227
|
+
// offending value stringified. Concrete enums — no boxed runtime value.
|
|
204
228
|
pub enum Probe<T> {
|
|
205
229
|
Got(T),
|
|
206
230
|
Wrong { actual_wire_type: String, raw_value: String },
|
|
@@ -215,46 +239,166 @@ pub enum NumProbe {
|
|
|
215
239
|
Absent,
|
|
216
240
|
}
|
|
217
241
|
|
|
218
|
-
// WireValue —
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
pub
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
242
|
+
// WireValue — the BC-OWNED, BC-GENERATED, self-contained (runtime-free) generic result the consumer's
|
|
243
|
+
// single op-agnostic transport returns. The consumer BUILDS it as it reads the producer (the raw I/O act)
|
|
244
|
+
// — WireValue::Str/Num/Bool/Null/Row/List, or the int()/float() constructors — and implements NOTHING over
|
|
245
|
+
// it. Numbers carry raw text (BC parses + range-checks → overflow is BC's to detect). A composite is a
|
|
246
|
+
// nested WireRow / WireList. NO trait, NO consumer classification protocol.
|
|
247
|
+
pub enum WireValue {
|
|
248
|
+
Str(String),
|
|
249
|
+
Num(String),
|
|
250
|
+
Bool(bool),
|
|
251
|
+
Null,
|
|
252
|
+
Row(WireRow),
|
|
253
|
+
List(WireList),
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// WireRow / WireList — a wire map (a DynamoDB "M") / wire array (an "L"). Native Vec-backed; the generated
|
|
257
|
+
// de-box probes them by declared field / element and owns strictness (required/optional, present/absent,
|
|
258
|
+
// error assembly). row/list probes return a BORROW (Probe<&WireRow>/Probe<&WireList>) so nested decode is
|
|
259
|
+
// zero-copy — only leaf scalars are cloned into the covered typed struct.
|
|
260
|
+
pub struct WireRow {
|
|
261
|
+
pub entries: Vec<(String, WireValue)>,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
pub struct WireList {
|
|
265
|
+
pub items: Vec<WireValue>,
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
impl WireValue {
|
|
269
|
+
// constructors the consumer's transport uses to build numeric results (numbers ride as raw text).
|
|
270
|
+
pub fn int(n: i64) -> Self {
|
|
271
|
+
WireValue::Num(n.to_string())
|
|
272
|
+
}
|
|
273
|
+
pub fn float(n: f64) -> Self {
|
|
274
|
+
WireValue::Num(n.to_string())
|
|
275
|
+
}
|
|
276
|
+
// the top result is always present (Some(self)); the field/elem probes share the same classifiers.
|
|
277
|
+
pub fn as_string(&self) -> Probe<String> {
|
|
278
|
+
probe_string_at(Some(self))
|
|
279
|
+
}
|
|
280
|
+
pub fn as_number(&self) -> NumProbe {
|
|
281
|
+
probe_number_at(Some(self))
|
|
282
|
+
}
|
|
283
|
+
pub fn as_bool(&self) -> Probe<bool> {
|
|
284
|
+
probe_bool_at(Some(self))
|
|
285
|
+
}
|
|
286
|
+
pub fn as_row(&self) -> Probe<&WireRow> {
|
|
287
|
+
probe_row_at(Some(self))
|
|
288
|
+
}
|
|
289
|
+
pub fn as_list(&self) -> Probe<&WireList> {
|
|
290
|
+
probe_list_at(Some(self))
|
|
291
|
+
}
|
|
292
|
+
fn tag(&self) -> &'static str {
|
|
293
|
+
match self {
|
|
294
|
+
WireValue::Str(_) => "S",
|
|
295
|
+
WireValue::Num(_) => "N",
|
|
296
|
+
WireValue::Bool(_) => "BOOL",
|
|
297
|
+
WireValue::Null => "NULL",
|
|
298
|
+
WireValue::Row(_) => "M",
|
|
299
|
+
WireValue::List(_) => "L",
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
fn raw(&self) -> String {
|
|
303
|
+
match self {
|
|
304
|
+
WireValue::Str(s) => s.clone(),
|
|
305
|
+
WireValue::Num(s) => s.clone(),
|
|
306
|
+
WireValue::Bool(b) => b.to_string(),
|
|
307
|
+
WireValue::Null => "null".to_string(),
|
|
308
|
+
WireValue::Row(_) | WireValue::List(_) => "[composite]".to_string(),
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
impl WireRow {
|
|
314
|
+
fn get(&self, field: &str) -> Option<&WireValue> {
|
|
315
|
+
self.entries.iter().find(|(k, _)| k.as_str() == field).map(|(_, v)| v)
|
|
316
|
+
}
|
|
317
|
+
pub fn keys(&self) -> Vec<String> {
|
|
318
|
+
self.entries.iter().map(|(k, _)| k.clone()).collect()
|
|
319
|
+
}
|
|
320
|
+
pub fn probe_string(&self, field: &str) -> Probe<String> {
|
|
321
|
+
probe_string_at(self.get(field))
|
|
322
|
+
}
|
|
323
|
+
pub fn probe_number(&self, field: &str) -> NumProbe {
|
|
324
|
+
probe_number_at(self.get(field))
|
|
325
|
+
}
|
|
326
|
+
pub fn probe_bool(&self, field: &str) -> Probe<bool> {
|
|
327
|
+
probe_bool_at(self.get(field))
|
|
328
|
+
}
|
|
329
|
+
pub fn probe_row(&self, field: &str) -> Probe<&WireRow> {
|
|
330
|
+
probe_row_at(self.get(field))
|
|
331
|
+
}
|
|
332
|
+
pub fn probe_list(&self, field: &str) -> Probe<&WireList> {
|
|
333
|
+
probe_list_at(self.get(field))
|
|
334
|
+
}
|
|
230
335
|
}
|
|
231
336
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
pub
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
fn
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
fn
|
|
243
|
-
|
|
244
|
-
|
|
337
|
+
impl WireList {
|
|
338
|
+
pub fn len(&self) -> usize {
|
|
339
|
+
self.items.len()
|
|
340
|
+
}
|
|
341
|
+
pub fn is_empty(&self) -> bool {
|
|
342
|
+
self.items.is_empty()
|
|
343
|
+
}
|
|
344
|
+
pub fn elem_string(&self, i: usize) -> Probe<String> {
|
|
345
|
+
probe_string_at(self.items.get(i))
|
|
346
|
+
}
|
|
347
|
+
pub fn elem_number(&self, i: usize) -> NumProbe {
|
|
348
|
+
probe_number_at(self.items.get(i))
|
|
349
|
+
}
|
|
350
|
+
pub fn elem_bool(&self, i: usize) -> Probe<bool> {
|
|
351
|
+
probe_bool_at(self.items.get(i))
|
|
352
|
+
}
|
|
353
|
+
pub fn elem_row(&self, i: usize) -> Probe<&WireRow> {
|
|
354
|
+
probe_row_at(self.items.get(i))
|
|
355
|
+
}
|
|
356
|
+
pub fn elem_list(&self, i: usize) -> Probe<&WireList> {
|
|
357
|
+
probe_list_at(self.items.get(i))
|
|
358
|
+
}
|
|
245
359
|
}
|
|
246
360
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
361
|
+
// the ONE classifier per kind, over an Option<&WireValue> (None = absent attribute/element). The BC-owned
|
|
362
|
+
// WireValue variant IS the wire tag — no consumer classification.
|
|
363
|
+
fn probe_string_at(v: Option<&WireValue>) -> Probe<String> {
|
|
364
|
+
match v {
|
|
365
|
+
None => Probe::Absent,
|
|
366
|
+
Some(WireValue::Str(s)) => Probe::Got(s.clone()),
|
|
367
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
368
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
fn probe_number_at(v: Option<&WireValue>) -> NumProbe {
|
|
372
|
+
match v {
|
|
373
|
+
None => NumProbe::Absent,
|
|
374
|
+
Some(WireValue::Num(s)) => NumProbe::Got { raw: s.clone(), actual_wire_type: "N".to_string() },
|
|
375
|
+
Some(WireValue::Null) => NumProbe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
376
|
+
Some(o) => NumProbe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
fn probe_bool_at(v: Option<&WireValue>) -> Probe<bool> {
|
|
380
|
+
match v {
|
|
381
|
+
None => Probe::Absent,
|
|
382
|
+
Some(WireValue::Bool(b)) => Probe::Got(*b),
|
|
383
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
384
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
fn probe_row_at(v: Option<&WireValue>) -> Probe<&WireRow> {
|
|
388
|
+
match v {
|
|
389
|
+
None => Probe::Absent,
|
|
390
|
+
Some(WireValue::Row(r)) => Probe::Got(r),
|
|
391
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
392
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
fn probe_list_at(v: Option<&WireValue>) -> Probe<&WireList> {
|
|
396
|
+
match v {
|
|
397
|
+
None => Probe::Absent,
|
|
398
|
+
Some(WireValue::List(l)) => Probe::Got(l),
|
|
399
|
+
Some(WireValue::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
400
|
+
Some(o) => Probe::Wrong { actual_wire_type: o.tag().to_string(), raw_value: o.raw() },
|
|
401
|
+
}
|
|
258
402
|
}`;
|
|
259
403
|
}
|
|
260
404
|
/**
|
|
@@ -766,65 +910,6 @@ function boundRustType(node, typedNodes, plan) {
|
|
|
766
910
|
return `Option<${renderTypeRef(bfRef.inner)}>`;
|
|
767
911
|
return `Option<${renderTypeRef(bfRef)}>`;
|
|
768
912
|
}
|
|
769
|
-
/**
|
|
770
|
-
* emitHandlerTrait — the per-component `HandlerNR<Comp>` trait: one concrete-typed `node_*` method per
|
|
771
|
-
* covered node. A componentRef node method takes the node's native ports struct + the typed produced-aware
|
|
772
|
-
* `bound` (change #3 — NO boxed Value) and returns Option<RawRowNR…> (None = unknown component,
|
|
773
|
-
* fail-closed). A covered map node's method takes the batch ports struct (batched) or the element ports
|
|
774
|
-
* struct (per-element). This is the fully-concrete, runtime-free replacement for the NativeRawComponentExec
|
|
775
|
-
* seam.
|
|
776
|
-
*/
|
|
777
|
-
function emitHandlerTrait(comp, typedNodes, plan, ap) {
|
|
778
|
-
// bc#97 (increment 2): async I/O model is PER-TERMINAL-NODE. A node whose terminal handler is declared
|
|
779
|
-
// async gets an `async fn node_*` (the consumer's impl returns a future the runner awaits at the call
|
|
780
|
-
// site); a sync terminal stays plain `fn node_*` (called directly, no await). Mixed sync+async in one
|
|
781
|
-
// trait is fine. `async fn` needs NO external runtime to compile — the future is `async fn` sugar over
|
|
782
|
-
// std, so the covered module stays runtime-free either way. Uniform ioModel:'async' ⇒ every method
|
|
783
|
-
// async (byte-identical to increment-1); ioModel unset/'sync' ⇒ every method plain `fn` (pre-#97).
|
|
784
|
-
const fnKwFor = (nodeId) => (ap.nodeIsAsync(nodeId) ? "async fn" : "fn");
|
|
785
|
-
const lines = [];
|
|
786
|
-
lines.push(`// ${handlerTraitName(comp.name)} — the CONCRETE per-component handler seam: one typed method`);
|
|
787
|
-
lines.push(`// per covered node (native ports struct IN, WIRE value OUT). No generic boxed-ports / boxed-value`);
|
|
788
|
-
lines.push(`// / dynamic accessor crosses the covered boundary — the consumer implements each node_* by`);
|
|
789
|
-
lines.push(`// returning its own wire payload as a WireValue; the generated inline de-box turns that into the`);
|
|
790
|
-
lines.push(`// node's concrete native result (see INTEGRATION.md §6).`);
|
|
791
|
-
lines.push(`pub trait ${handlerTraitName(comp.name)} {`);
|
|
792
|
-
// every covered node returns the consumer's WIRE (a single associated `Wire: WireValue`) — the producer's
|
|
793
|
-
// datum at the node's result-consumption point; the generated inline de-box classifies it against the
|
|
794
|
-
// STATICALLY declared type. A batched map returns one wire per element (Vec); a fanout returns the aligned
|
|
795
|
-
// per-id wires (Vec<Option<Wire>> — None = a DANGLING id). The `+ Send` bound lets the wire cross the
|
|
796
|
-
// parallel-stage runner's scoped fan-out threads.
|
|
797
|
-
const hasHandler = comp.body.some((n) => !("cond" in n));
|
|
798
|
-
if (hasHandler)
|
|
799
|
-
lines.push(` type Wire: WireValue + Send;`);
|
|
800
|
-
for (const n of comp.body) {
|
|
801
|
-
if ("cond" in n)
|
|
802
|
-
continue; // #108: a cond node has no handler method (pure Expression).
|
|
803
|
-
const method = nodeMethodName(n.id);
|
|
804
|
-
const fnKw = fnKwFor(n.id);
|
|
805
|
-
const bt = boundRustType(n, typedNodes, plan);
|
|
806
|
-
if ("fanout" in n) {
|
|
807
|
-
// fanout (v3): one batched dispatch of the deduped id list, returning the aligned element WIRES the
|
|
808
|
-
// runner de-boxes then dedupe/drops. Each aligned position is Option<Self::Wire> — None = a DANGLING
|
|
809
|
-
// id (the runner maps it to the zero elem row).
|
|
810
|
-
const portsT = `${portsStructName(comp.name, n.id)}Batch`;
|
|
811
|
-
lines.push(` ${fnKw} ${method}(&self, ports: &${portsT}, bound: ${bt}) -> Result<Vec<Option<Self::Wire>>, BehaviorError>;`);
|
|
812
|
-
continue;
|
|
813
|
-
}
|
|
814
|
-
if ("map" in n) {
|
|
815
|
-
const m = n.map;
|
|
816
|
-
const batched = m.batched === true;
|
|
817
|
-
const portsT = batched ? `${portsStructName(comp.name, n.id)}Batch` : portsStructName(comp.name, n.id);
|
|
818
|
-
// a map returns the element WIRE(s): batched → Vec<Self::Wire>, non-batched → Self::Wire.
|
|
819
|
-
const retT = batched ? "Vec<Self::Wire>" : "Self::Wire";
|
|
820
|
-
lines.push(` ${fnKw} ${method}(&self, ports: &${portsT}, bound: ${bt}) -> Result<${retT}, BehaviorError>;`);
|
|
821
|
-
continue;
|
|
822
|
-
}
|
|
823
|
-
lines.push(` ${fnKw} ${method}(&self, ports: &${portsStructName(comp.name, n.id)}, bound: ${bt}) -> Result<Self::Wire, BehaviorError>;`);
|
|
824
|
-
}
|
|
825
|
-
lines.push(`}`);
|
|
826
|
-
return lines.join("\n");
|
|
827
|
-
}
|
|
828
913
|
/** mapElemMaterializerName — the augmented-element copier for a covered map...into node.
|
|
829
914
|
* QUALIFIED by component name: two components may each carry a map node at the SAME
|
|
830
915
|
* recorder-scan index (e.g. both `…authorFollows` and `…groupsNested` have a map at `n4`),
|
|
@@ -1334,7 +1419,7 @@ function emitPortInit(pn, expr, comp, plan, typedNodes, isPrior, opts) {
|
|
|
1334
1419
|
function rustScalar(s) {
|
|
1335
1420
|
return s === "string" ? "String" : s === "int" ? "i64" : s === "float" ? "f64" : "bool";
|
|
1336
1421
|
}
|
|
1337
|
-
function emitNativeRawRunner(comp, plan, ap) {
|
|
1422
|
+
function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
1338
1423
|
const ep = execPlan(comp);
|
|
1339
1424
|
const order = ep.order;
|
|
1340
1425
|
const hasConcurrency = ep.parallelStageOf.size > 0;
|
|
@@ -1423,28 +1508,22 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1423
1508
|
const inParam = readsInput ? "in_" : "_in_";
|
|
1424
1509
|
const lines = [];
|
|
1425
1510
|
lines.push(`// run_native_raw_struct_${fn} — the STRUCT-RETURNING combined read (bc#77/#87/#94): the fully`);
|
|
1426
|
-
lines.push(`// de-plumbed CONCRETE path.
|
|
1427
|
-
lines.push(`//
|
|
1428
|
-
lines.push(`// (
|
|
1429
|
-
lines.push(`// simple string port lowers to a native Rust expr), dispatches the concrete node_* method, and`);
|
|
1430
|
-
lines.push(`// de-boxes the result wire INLINE (match wire.as_*() { … } fully unrolled — no decode helper) into`);
|
|
1511
|
+
lines.push(`// de-plumbed CONCRETE path. At each covered node's execution point it calls the op-agnostic leaf`);
|
|
1512
|
+
lines.push(`// TRANSPORT symbol DIRECTLY (the node's port fields spread — no per-node handler indirection) and`);
|
|
1513
|
+
lines.push(`// de-boxes the returned wire INLINE (match wire.as_*() { … } fully unrolled — no decode helper) into`);
|
|
1431
1514
|
lines.push(`// the node's outType struct cell — no boxed handler result, no generic enum crossing, no dispatch on a dynamic value on the covered plane. Node`);
|
|
1432
1515
|
lines.push(`// results are typed struct cells; a relation child reads the parent's REAL struct result via`);
|
|
1433
1516
|
lines.push(`// direct field access (child-present decision from the real parent value — relationSingle /`);
|
|
1434
1517
|
lines.push(`// connection converge). A real-concurrency stage (bc#87) is static parallel orchestration —`);
|
|
1435
|
-
lines.push(`// scoped worker threads (bounded by the static plan.concurrency) call the
|
|
1436
|
-
lines.push(`//
|
|
1437
|
-
lines.push(`//
|
|
1438
|
-
lines.push(`//
|
|
1439
|
-
|
|
1440
|
-
// bc#97: async propagation (uniform) — if the terminal handlers are async, every handler call awaits,
|
|
1518
|
+
lines.push(`// scoped worker threads (bounded by the static plan.concurrency) call the transport; preflight +`);
|
|
1519
|
+
lines.push(`// interpret are committed in ascending index order so the value / op multiset / failure`);
|
|
1520
|
+
lines.push(`// precedence byte-match run_behavior. The output is a typed struct/value assembled by struct`);
|
|
1521
|
+
lines.push(`// literal + field access — the consumer keeps it native.`);
|
|
1522
|
+
// bc#97: async propagation (uniform) — if the terminal handlers are async, every transport call awaits,
|
|
1441
1523
|
// so the runner is itself `async fn` and returns a future the (already-async) consumer awaits. Sync
|
|
1442
1524
|
// default emits `pub fn` exactly as before (byte-identical).
|
|
1443
1525
|
const fnKw = isAsync ? "pub async fn" : "pub fn";
|
|
1444
|
-
|
|
1445
|
-
const dispatchesHandler = comp.body.some((n) => "map" in n || "fanout" in n || "component" in n);
|
|
1446
|
-
lines.push(`${fnKw} run_native_raw_struct_${fn}${bound}(`);
|
|
1447
|
-
lines.push(` ${dispatchesHandler ? "handlers" : "_handlers"}: &H,`);
|
|
1526
|
+
lines.push(`${fnKw} run_native_raw_struct_${fn}(`);
|
|
1448
1527
|
lines.push(` ${inParam}: ${inStructName(comp.name)},`);
|
|
1449
1528
|
lines.push(`) -> Result<${outTy}, BehaviorError> {`);
|
|
1450
1529
|
for (const k of order.keys()) {
|
|
@@ -1462,16 +1541,16 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1462
1541
|
const i = order[k];
|
|
1463
1542
|
const stage = ep.parallelStageOf.get(i);
|
|
1464
1543
|
if (stage !== undefined && stage[0] === i) {
|
|
1465
|
-
lines.push(emitParallelStageArm(comp, stage, k, ep.concurrency, metas, typedNodes, plan, priorNodeAt));
|
|
1544
|
+
lines.push(emitParallelStageArm(comp, stage, k, ep.concurrency, metas, typedNodes, plan, priorNodeAt, leaf));
|
|
1466
1545
|
k += stage.length - 1;
|
|
1467
1546
|
continue;
|
|
1468
1547
|
}
|
|
1469
1548
|
if ("fanout" in comp.body[i]) {
|
|
1470
|
-
lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, ap.nodeIsAsync(comp.body[i].id)));
|
|
1549
|
+
lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id)));
|
|
1471
1550
|
continue;
|
|
1472
1551
|
}
|
|
1473
1552
|
if ("map" in comp.body[i]) {
|
|
1474
|
-
lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, ap.nodeIsAsync(comp.body[i].id)));
|
|
1553
|
+
lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id)));
|
|
1475
1554
|
continue;
|
|
1476
1555
|
}
|
|
1477
1556
|
// #108: a cond node — pure Expression (no handler). Compile via the runtime-free NativeExprCompiler.
|
|
@@ -1494,11 +1573,10 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1494
1573
|
closers.unshift(`${indent}}`);
|
|
1495
1574
|
indent += " ";
|
|
1496
1575
|
if (node.bindField !== undefined && parentIsGate) {
|
|
1497
|
-
// #125: a when(...) control-gate parent. gate
|
|
1498
|
-
//
|
|
1499
|
-
//
|
|
1500
|
-
//
|
|
1501
|
-
lines.push(`${indent}let bound_${s}: ${boundRustType(node, typedNodes, plan)} = Some("ok".to_string());`);
|
|
1576
|
+
// #125: a when(...) control-gate parent. produced_<gate> (= the gate's `if`) ALREADY carries the
|
|
1577
|
+
// skip, so past it the gate held — there is no further skip to gate here. The bindField:"ok" was
|
|
1578
|
+
// only a sentinel formerly passed to the handler; the leaf transport no longer receives `bound`, so
|
|
1579
|
+
// NO bound local is emitted (the child ports read the real data parent, not the gate).
|
|
1502
1580
|
}
|
|
1503
1581
|
else if (node.bindField !== undefined) {
|
|
1504
1582
|
// bind (change #3 — typed produced-aware bound): read the parent struct field DIRECTLY (typed
|
|
@@ -1526,15 +1604,19 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1526
1604
|
for (const pn of portNames) {
|
|
1527
1605
|
inits.push(emitPortInit(pn, node.ports[pn], comp, plan, typedNodes, (h) => priorNodeAt(h, k)));
|
|
1528
1606
|
}
|
|
1529
|
-
const boundArg = node.bindField !== undefined ? `bound_${s}` : "None";
|
|
1530
1607
|
// bc#97: derived per-node await — this point-read's future is awaited HERE (its result-consumption
|
|
1531
1608
|
// point) iff THIS node's terminal handler is async. A sync handler in the same async runner is called
|
|
1532
1609
|
// directly (no `.await`). The runner being `async fn` does not force every call site to await.
|
|
1533
1610
|
const awaitSfx = ap.nodeIsAsync(node.id) ? ".await" : "";
|
|
1611
|
+
// DIRECT leaf transport call: the resolved op-agnostic symbol, the node's port fields spread (Copy→move,
|
|
1612
|
+
// non-Copy→borrow). `bound` is NOT passed — it is BC's internal produced/skip gate, already enforced by
|
|
1613
|
+
// the surrounding `if bound_<s>.is_some()` / `if produced_<parent>` guards; the leaf never receives it.
|
|
1614
|
+
const call = `${resolveLeafSymbol(node.component, leaf)}(${leafCallArgs(`ports_${s}`, portFieldSpread(node.ports, comp, plan, typedNodes))})${awaitSfx}`;
|
|
1534
1615
|
lines.push(`${indent}let ports_${s} = ${structName} { ${inits.join(", ")} };`);
|
|
1535
|
-
// uniform seam: every covered node returns a single result WIRE
|
|
1536
|
-
//
|
|
1537
|
-
//
|
|
1616
|
+
// uniform seam: every covered node returns a single result WIRE; the inline de-box (renderResultDeBox)
|
|
1617
|
+
// classifies it against the STATICALLY declared result type and produces the structured Error Value on a
|
|
1618
|
+
// mismatch (byte-equal codes to run_behavior's outType check, so ≡ holds). The wire's concrete type is
|
|
1619
|
+
// inferred from the transport's return type (no annotation) — the wire trait methods resolve.
|
|
1538
1620
|
if (meta.policy === "continue") {
|
|
1539
1621
|
// continue: a failed node (leaf failure OR de-box mismatch) produces no Port — the downstream Skip
|
|
1540
1622
|
// propagation is what `continue` means. The inline de-box's mismatch breaks the labeled block (a
|
|
@@ -1542,7 +1624,7 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1542
1624
|
// are always 'fail' policy today — this arm is defensive.)
|
|
1543
1625
|
const label = `debox_${s}`;
|
|
1544
1626
|
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1545
|
-
lines.push(`${indent}if let Ok(wire_${s}) =
|
|
1627
|
+
lines.push(`${indent}if let Ok(wire_${s}) = ${call} {`);
|
|
1546
1628
|
lines.push(`${indent} let decoded_${s}: Result<${renderTypeRef(ref)}, BehaviorError> = '${label}: {`);
|
|
1547
1629
|
lines.push(`${indent} Ok(${renderResultDeBox(ref, `wire_${s}`, node.id, plan, `${indent} `, contFail)})`);
|
|
1548
1630
|
lines.push(`${indent} };`);
|
|
@@ -1554,7 +1636,7 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1554
1636
|
}
|
|
1555
1637
|
else {
|
|
1556
1638
|
const policyLit = meta.policy === "retry" ? "retry' policy (exhausted)" : "fail' policy";
|
|
1557
|
-
lines.push(`${indent}let wire_${s} = match
|
|
1639
|
+
lines.push(`${indent}let wire_${s} = match ${call} {`);
|
|
1558
1640
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1559
1641
|
lines.push(`${indent} Err(e) => return Err(BehaviorError { code: "OP_FAILED".to_string(), message: format!("operation '{}' failed under '${policyLit}: {}", ${rustStrLit(node.id)}, e.message), detail: e.detail }),`);
|
|
1560
1642
|
lines.push(`${indent}};`);
|
|
@@ -1597,7 +1679,7 @@ function emitNativeRawRunner(comp, plan, ap) {
|
|
|
1597
1679
|
* 3. COMMIT (ascending index): interpret policy + move the concrete row into the outType cell —
|
|
1598
1680
|
* lowest-index failure wins.
|
|
1599
1681
|
*/
|
|
1600
|
-
function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes, plan, priorNodeAt) {
|
|
1682
|
+
function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes, plan, priorNodeAt, leaf) {
|
|
1601
1683
|
const lines = [];
|
|
1602
1684
|
const ids = stage.map((i) => comp.body[i].id);
|
|
1603
1685
|
lines.push(` // ── bc#87 real-concurrency stage {${ids.map((x) => rustStrLit(x)).join(", ")}} — static parallel`);
|
|
@@ -1639,27 +1721,23 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1639
1721
|
const parentIsGate = node.parent !== undefined && isControlGate(comp.body.find((b) => b.id === node.parent));
|
|
1640
1722
|
let ind = " ";
|
|
1641
1723
|
const closers = [];
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1724
|
+
// bound is now purely the preflight skip-gate condition (the leaf transport no longer receives it), so
|
|
1725
|
+
// it is a plain local inside the produced block — NOT a stage-scoped mut (nothing captures it) and no
|
|
1726
|
+
// dead None init. A control-gate parent needs no bound at all (produced_<gate> already carries the skip).
|
|
1646
1727
|
if (gated) {
|
|
1647
1728
|
lines.push(` let mut ports_${s}: Option<${structName}> = None;`);
|
|
1648
1729
|
lines.push(`${ind}if produced_${sanitize(node.parent)}.get() {`);
|
|
1649
1730
|
closers.unshift(`${ind}}`);
|
|
1650
1731
|
ind += " ";
|
|
1651
|
-
if (node.bindField !== undefined && parentIsGate) {
|
|
1652
|
-
lines.push(`${ind}bound_${s} = Some("ok".to_string());`);
|
|
1653
|
-
}
|
|
1654
|
-
else if (node.bindField !== undefined) {
|
|
1732
|
+
if (node.bindField !== undefined && !parentIsGate) {
|
|
1655
1733
|
const parentRef = typedNodes.get(node.parent);
|
|
1656
1734
|
const { expr: bfExpr, ref: bfRef } = typedFieldAccess(`${typedCell(node.parent)}.borrow()`, parentRef, [node.bindField], plan);
|
|
1657
1735
|
if (bfRef.kind === "opt") {
|
|
1658
|
-
lines.push(`${ind}bound_${s} = ${bfExpr}.clone();`);
|
|
1736
|
+
lines.push(`${ind}let bound_${s}: ${boundRustType(node, typedNodes, plan)} = ${bfExpr}.clone();`);
|
|
1659
1737
|
}
|
|
1660
1738
|
else {
|
|
1661
1739
|
const owned = bfRef.kind === "scalar" && bfRef.scalar === "string" ? `(${bfExpr}).clone()` : `*(${bfExpr})`;
|
|
1662
|
-
lines.push(`${ind}bound_${s} = Some(${owned});`);
|
|
1740
|
+
lines.push(`${ind}let bound_${s}: ${boundRustType(node, typedNodes, plan)} = Some(${owned});`);
|
|
1663
1741
|
}
|
|
1664
1742
|
lines.push(`${ind}if bound_${s}.is_some() {`);
|
|
1665
1743
|
closers.unshift(`${ind}}`);
|
|
@@ -1679,19 +1757,19 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1679
1757
|
for (const c of closers)
|
|
1680
1758
|
lines.push(c);
|
|
1681
1759
|
}
|
|
1682
|
-
// 2) DISPATCH (bounded scoped threads).
|
|
1683
|
-
//
|
|
1684
|
-
//
|
|
1685
|
-
//
|
|
1760
|
+
// 2) DISPATCH (bounded scoped threads). Each worker calls the leaf TRANSPORT directly for its member's
|
|
1761
|
+
// CONCRETE ports and stores the returned wire in its slot. #125: the fan-out (slots / jobs / workers)
|
|
1762
|
+
// spans the COMPONENTREF members only — a control gate dispatches no handler (committed in preflight
|
|
1763
|
+
// above), so it is not a scoped-thread job. The wire's concrete type is inferred from the transport's
|
|
1764
|
+
// return (Result<_, BehaviorError>); it impls Send so it crosses the scoped threads.
|
|
1686
1765
|
const nMembers = refMembers.length;
|
|
1687
1766
|
const boundN = Math.min(concurrency, nMembers);
|
|
1688
1767
|
const jobsVar = `jobs_${sanitize(comp.name)}`;
|
|
1689
|
-
const hWire = `<H as ${handlerTraitName(comp.name)}>::Wire`;
|
|
1690
1768
|
for (const i of refMembers) {
|
|
1691
1769
|
const s = sanitize(comp.body[i].id);
|
|
1692
|
-
// every member's thread returns the result WIRE
|
|
1693
|
-
//
|
|
1694
|
-
lines.push(` let slot_${s}: std::sync::Mutex<Option<Result
|
|
1770
|
+
// every member's thread returns the result WIRE; the ascending COMMIT phase de-boxes it (so the wire —
|
|
1771
|
+
// not the decode — is what crosses the scoped threads).
|
|
1772
|
+
lines.push(` let slot_${s}: std::sync::Mutex<Option<Result<_, BehaviorError>>> = std::sync::Mutex::new(None);`);
|
|
1695
1773
|
}
|
|
1696
1774
|
lines.push(` let mut ${jobsVar}: Vec<usize> = Vec::new();`);
|
|
1697
1775
|
refMembers.forEach((i, slot) => {
|
|
@@ -1710,10 +1788,12 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1710
1788
|
refMembers.forEach((i, slot) => {
|
|
1711
1789
|
const node = comp.body[i];
|
|
1712
1790
|
const s = sanitize(node.id);
|
|
1713
|
-
|
|
1791
|
+
// DIRECT leaf transport call — the node's port fields spread off the preflight-built ports struct. No
|
|
1792
|
+
// `bound` (BC's internal produced/skip gate is already applied in preflight — the leaf never sees it).
|
|
1793
|
+
const call = `${resolveLeafSymbol(node.component, leaf)}(${leafCallArgs("ports", portFieldSpread(node.ports, comp, plan, typedNodes))})`;
|
|
1714
1794
|
lines.push(` ${slot} => {`);
|
|
1715
1795
|
lines.push(` let ports = ports_${s}.as_ref().expect("runnable member has ports");`);
|
|
1716
|
-
lines.push(` let row =
|
|
1796
|
+
lines.push(` let row = ${call};`);
|
|
1717
1797
|
lines.push(` *slot_${s}.lock().unwrap() = Some(row);`);
|
|
1718
1798
|
lines.push(` }`);
|
|
1719
1799
|
});
|
|
@@ -1768,7 +1848,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1768
1848
|
* - #93 shape 2: NON-batched map...into — dispatch ONCE PER ELEMENT (N physical requests), into per element.
|
|
1769
1849
|
* - #93 shape 3: BATCHED map NO into — dispatch once, collect each element from the concrete element row.
|
|
1770
1850
|
*/
|
|
1771
|
-
function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt,
|
|
1851
|
+
function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf,
|
|
1772
1852
|
// bc#97: whether THIS map node's terminal handler is async (derived per-node) — awaits the batched /
|
|
1773
1853
|
// per-element handler call at its consumption point iff true. Sync map handlers are called directly.
|
|
1774
1854
|
isAsync = false) {
|
|
@@ -1780,6 +1860,7 @@ isAsync = false) {
|
|
|
1780
1860
|
const s = sanitize(node.id);
|
|
1781
1861
|
const structName = portsStructName(comp.name, node.id);
|
|
1782
1862
|
const batch = `${structName}Batch`;
|
|
1863
|
+
const leafSym = resolveLeafSymbol(m.component, leaf);
|
|
1783
1864
|
// #108: over element type + the OWNED over-Vec expression (prior-node arr OR input array w/ elemType).
|
|
1784
1865
|
const { elemRef: overElemRef, overExpr } = mapOverElemInfo(comp, node, typedNodes, plan);
|
|
1785
1866
|
const elemMat = mapElemMaterializerName(comp.name, node.id);
|
|
@@ -1848,7 +1929,10 @@ isAsync = false) {
|
|
|
1848
1929
|
lines.push(`${indent}if !items_${s}.is_empty() {`);
|
|
1849
1930
|
lines.push(`${indent} let want_${s} = items_${s}.len();`);
|
|
1850
1931
|
lines.push(`${indent} let bp_${s} = ${batch} { items: items_${s} };`);
|
|
1851
|
-
|
|
1932
|
+
// DIRECT transport call — the batched dispatch takes the CONCRETE batch ports struct (shape unchanged
|
|
1933
|
+
// from the removed trait method; only the call target changes). Returns the aligned per-element wires
|
|
1934
|
+
// (Vec<Wire>). No `bound` (batched maps carry none).
|
|
1935
|
+
lines.push(`${indent} let row_${s} = match ${leafSym}(&bp_${s})${awaitSfx} {`);
|
|
1852
1936
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1853
1937
|
lines.push(`${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, "fail", e)),`);
|
|
1854
1938
|
lines.push(`${indent} };`);
|
|
@@ -1883,8 +1967,9 @@ isAsync = false) {
|
|
|
1883
1967
|
lines.push(l);
|
|
1884
1968
|
// Element Error Policy (scp-error.md): `skip` drops the failing element and proceeds (order is
|
|
1885
1969
|
// preserved; the leaf keeps the Error Value it produced). `error` (default) promotes the element
|
|
1886
|
-
// Failure to the map's Component Failure, carrying the leaf's detail through.
|
|
1887
|
-
|
|
1970
|
+
// Failure to the map's Component Failure, carrying the leaf's detail through. DIRECT transport call —
|
|
1971
|
+
// the element ports fields spread (resolved with the `$as` binding, exactly the element ports struct).
|
|
1972
|
+
lines.push(`${indent} let er_${s} = match ${leafSym}(${leafCallArgs(`ep_${s}`, portFieldSpread(m.ports, comp, plan, typedNodes, { name: asName, ref: overElemRef, plan }))})${awaitSfx} {`);
|
|
1888
1973
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1889
1974
|
if (m.elementPolicy === "skip") {
|
|
1890
1975
|
lines.push(`${indent} Err(_) => continue,`);
|
|
@@ -1917,12 +2002,13 @@ isAsync = false) {
|
|
|
1917
2002
|
* dangling (empty dedupeKey ≡ the interpreter's null/absent-key body), implicitSource strip (STRUCTURAL:
|
|
1918
2003
|
* the elem type already omits it), wrap into the connection struct { items, cursor: None }.
|
|
1919
2004
|
*/
|
|
1920
|
-
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, isAsync = false) {
|
|
2005
|
+
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, isAsync = false) {
|
|
1921
2006
|
const f = node.fanout;
|
|
1922
2007
|
const awaitSfx = isAsync ? ".await" : "";
|
|
1923
2008
|
const s = sanitize(node.id);
|
|
1924
2009
|
const structName = portsStructName(comp.name, node.id);
|
|
1925
2010
|
const batch = `${structName}Batch`;
|
|
2011
|
+
const leafSym = resolveLeafSymbol(f.component, leaf);
|
|
1926
2012
|
const connRef = typedNodes.get(node.id);
|
|
1927
2013
|
const elemRef = fanoutItemsElemRef(node, connRef, plan);
|
|
1928
2014
|
const elemName = renderTypeRef(elemRef);
|
|
@@ -1965,7 +2051,10 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, isAsync
|
|
|
1965
2051
|
lines.push(`${indent}if !pi_${s}.is_empty() {`);
|
|
1966
2052
|
lines.push(`${indent} let want_${s} = pi_${s}.len();`);
|
|
1967
2053
|
lines.push(`${indent} let bp_${s} = ${batch} { items: pi_${s} };`);
|
|
1968
|
-
|
|
2054
|
+
// DIRECT transport call — the batched fanout dispatch takes the CONCRETE batch ports struct (shape
|
|
2055
|
+
// unchanged; only the call target changes). Returns the aligned per-id element wires
|
|
2056
|
+
// (Vec<Option<Wire>> — None = a DANGLING id). No `bound`.
|
|
2057
|
+
lines.push(`${indent} let row_${s} = match ${leafSym}(&bp_${s})${awaitSfx} {`);
|
|
1969
2058
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1970
2059
|
lines.push(`${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, "fail", e)),`);
|
|
1971
2060
|
lines.push(`${indent} };`);
|
|
@@ -2133,8 +2222,8 @@ function valueLeafProduced(expr, ref, expected) {
|
|
|
2133
2222
|
function emitStructSurface(native) {
|
|
2134
2223
|
const names = native.map((c) => rustStrLit(c.name));
|
|
2135
2224
|
return `// COMPONENT_NAMES_NATIVE_RAW — covered reads exposed on the combined struct-native path. Each is
|
|
2136
|
-
// driven via run_native_raw_struct_<comp>(
|
|
2137
|
-
//
|
|
2225
|
+
// driven via run_native_raw_struct_<comp>(in_) -> Result<T, BehaviorError>: a STRUCT return (the consumer
|
|
2226
|
+
// builds the CONCRETE InNR_<comp> input + supplies the op-agnostic leaf transport symbols the runner calls).
|
|
2138
2227
|
// See INTEGRATION.md §6.
|
|
2139
2228
|
pub const COMPONENT_NAMES_NATIVE_RAW: [&str; ${names.length}] = [${names.join(", ")}];`;
|
|
2140
2229
|
}
|
|
@@ -2193,8 +2282,8 @@ ${emitStructSurface([])}
|
|
|
2193
2282
|
const defaults = emitDefaults(plan);
|
|
2194
2283
|
// #108: reset the native-expr helper-usage accumulator (set by the cond/guard compiler).
|
|
2195
2284
|
rustExprUsed.helpers = false;
|
|
2285
|
+
const leaf = ctx.leafTransport;
|
|
2196
2286
|
const structs = [];
|
|
2197
|
-
const handlerTraits = [];
|
|
2198
2287
|
const inStructs = [];
|
|
2199
2288
|
const elemMaterializers = [];
|
|
2200
2289
|
// every covered node returns a WireValue the inline de-box classifies — the wire seam (probe enums +
|
|
@@ -2217,34 +2306,52 @@ ${emitStructSurface([])}
|
|
|
2217
2306
|
else
|
|
2218
2307
|
structs.push(emitPortsStruct(c, n, undefined, plan, typedNodes)); // #129: typedNodes for prior-node arr leaf ports.
|
|
2219
2308
|
}
|
|
2220
|
-
handlerTraits.push(emitHandlerTrait(c, typedNodes, plan, asyncPlans.get(c.name)));
|
|
2221
2309
|
inStructs.push(emitInStruct(c, plan));
|
|
2222
2310
|
const mm = emitMapElemMaterializers(c, typedNodes, plan);
|
|
2223
2311
|
if (mm)
|
|
2224
2312
|
elemMaterializers.push(mm);
|
|
2225
2313
|
}
|
|
2226
|
-
const runners = native.map((c) => emitNativeRawRunner(c, plan, asyncPlans.get(c.name))).join("\n\n");
|
|
2314
|
+
const runners = native.map((c) => emitNativeRawRunner(c, plan, asyncPlans.get(c.name), leaf)).join("\n\n");
|
|
2227
2315
|
const structSurface = emitStructSurface(native);
|
|
2316
|
+
// Leaf transport import (SSoT resolution via resolveLeafSymbol): if the consumer names an import module,
|
|
2317
|
+
// bring the DISTINCT resolved transport symbols into the covered module's scope. Omitted → the symbols
|
|
2318
|
+
// resolve where the module is used (the covered module emits no `use`). cond nodes have no leaf.
|
|
2319
|
+
const importBlock = (() => {
|
|
2320
|
+
if (leaf?.import === undefined)
|
|
2321
|
+
return undefined;
|
|
2322
|
+
const syms = new Set();
|
|
2323
|
+
for (const c of native)
|
|
2324
|
+
for (const n of c.body) {
|
|
2325
|
+
const component = "fanout" in n ? n.fanout.component : "map" in n ? n.map.component : "cond" in n ? undefined : n.component;
|
|
2326
|
+
if (component !== undefined)
|
|
2327
|
+
syms.add(resolveLeafSymbol(component, leaf));
|
|
2328
|
+
}
|
|
2329
|
+
if (syms.size === 0)
|
|
2330
|
+
return undefined;
|
|
2331
|
+
return `// op-agnostic leaf transport symbols (consumer-supplied) — called directly at each covered node.\nuse ${leaf.import}::{${[...syms].sort().join(", ")}};`;
|
|
2332
|
+
})();
|
|
2228
2333
|
// (nonNative.length === 0 is guaranteed here — the fail-closed guard above threw otherwise.)
|
|
2229
2334
|
const banner = `#![allow(dead_code, unused_imports, non_snake_case)]
|
|
2230
2335
|
// GENERATED by behavior-contracts (bc#90, rust-typed-native — the RUNTIME-FREE read de-box; STRUCT-ONLY,
|
|
2231
2336
|
// FULLY-NATIVE). A covered read is a strictly-sequential typed componentRef chain (point reads +
|
|
2232
|
-
// relationKind:single children), emitted ONLY as a STRUCT-returning runner
|
|
2233
|
-
//
|
|
2234
|
-
// CONCRETE Rust value: String / bool / Vec<&str> projection / i64 limit —
|
|
2235
|
-
//
|
|
2236
|
-
// (
|
|
2237
|
-
// no output recursion) into the node's outType struct.
|
|
2238
|
-
//
|
|
2239
|
-
//
|
|
2240
|
-
//
|
|
2241
|
-
//
|
|
2242
|
-
//
|
|
2243
|
-
//
|
|
2244
|
-
//
|
|
2337
|
+
// relationKind:single children), emitted ONLY as a STRUCT-returning runner that calls the op-agnostic leaf
|
|
2338
|
+
// TRANSPORT symbol DIRECTLY at each covered node's execution point: native ports struct IN (direct
|
|
2339
|
+
// construction — every port is a CONCRETE Rust value: String / bool / Vec<&str> projection / i64 limit —
|
|
2340
|
+
// NO boxed Value, NO by-name accessor); the transport is called with the node's port fields spread and
|
|
2341
|
+
// returns the node's result WIRE (a value implementing WireValue), and the runner de-boxes it INLINE
|
|
2342
|
+
// (fully-unrolled probe/match — no decode helper, no output recursion) into the node's outType struct.
|
|
2343
|
+
// There is NO per-node handler indirection — a leaf is ONE transport, not one method per authored node.
|
|
2344
|
+
// The covered plane carries NO bc-runtime reference at all — failures use the LOCAL BehaviorError (same
|
|
2345
|
+
// codes, byte-equal to run_behavior). INLINE sequential (no plan driver) so a relation child reads the
|
|
2346
|
+
// parent's REAL struct result via direct field access and the child-present decision is made from the real
|
|
2347
|
+
// parent value — relationSingle / connection converge with run_behavior (fixes #323/#74). The exposed API
|
|
2348
|
+
// is run_native_raw_struct_<comp>(in_) over the CONCRETE InNR_<comp> input struct; the consumer supplies
|
|
2349
|
+
// the leaf transport symbols (default in-scope names leaf_<comp>, or a leafTransport import). This module
|
|
2350
|
+
// is FULLY NATIVE: a naive grep for boxing primitives OR for the bc-runtime crate finds nothing, by design.
|
|
2245
2351
|
use std::cell::RefCell;`;
|
|
2246
2352
|
const sections = [
|
|
2247
2353
|
banner,
|
|
2354
|
+
importBlock,
|
|
2248
2355
|
`// Local concrete failure type (runtime-free) — a covered runner returns Result<T, BehaviorError> over\n// THIS local type instead of a bc-runtime failure, so the fully-covered module imports ZERO bc runtime.\n${emitBehaviorErrorType()}`,
|
|
2249
2356
|
decls || undefined,
|
|
2250
2357
|
defaults || undefined,
|
|
@@ -2256,9 +2363,8 @@ use std::cell::RefCell;`;
|
|
|
2256
2363
|
? `// Native ports structs (one per componentRef node; typed per the static port type — CONCRETE).\n${structs.filter((r) => r.trim().length > 0).join("\n\n")}`
|
|
2257
2364
|
: undefined,
|
|
2258
2365
|
`// CONCRETE per-component input structs (fields = inputPorts).\n${inStructs.join("\n\n")}`,
|
|
2259
|
-
`// CONCRETE per-component handler traits (one node_* method per node — native ports IN, WIRE value OUT).\n${handlerTraits.join("\n\n")}`,
|
|
2260
2366
|
anyWire
|
|
2261
|
-
? `// strict de-box wire seam — the
|
|
2367
|
+
? `// strict de-box wire seam — the BC-OWNED, BC-GENERATED concrete WireValue (+ WireRow/WireList): the\n// consumer's single transport builds + returns it, implements NOTHING over it. The generated INLINE de-box\n// classifies it against the STATICALLY declared type and owns strictness (required/optional, present/absent,\n// error assembly, fail-closed). Self-contained concrete types — no trait, no boxed runtime value.\n${emitRustProbeWireTypes()}`
|
|
2262
2368
|
: undefined,
|
|
2263
2369
|
elemMaterializers.length
|
|
2264
2370
|
? `// map augmented-element copiers (pure struct field assignment — no dynamic value read).\n${elemMaterializers.join("\n\n")}`
|
|
@@ -2270,14 +2376,15 @@ use std::cell::RefCell;`;
|
|
|
2270
2376
|
}
|
|
2271
2377
|
/**
|
|
2272
2378
|
* rustTypedNativeObserve — the TEST-ONLY observe companion (a submodule string the test harness writes
|
|
2273
|
-
* alongside the covered module). It carries the typed->Value serializers (ser_*) +
|
|
2274
|
-
*
|
|
2275
|
-
*
|
|
2276
|
-
*
|
|
2277
|
-
*
|
|
2278
|
-
*
|
|
2379
|
+
* alongside the covered module). It carries the typed->Value serializers (ser_*) + the SCRIPTED analog of
|
|
2380
|
+
* the consumer's leaf transport symbols: free \`leaf_<comp>\` fns that drain a shared scripted static and
|
|
2381
|
+
* return the scripted wire (so the covered module's transport calls resolve to real fns), + an
|
|
2382
|
+
* observe_native_raw dispatch that fills the static from the per-case spec, decodes the generic input into
|
|
2383
|
+
* the concrete InNR_<comp>, drives the module-private struct runner, and serializes its result to a
|
|
2384
|
+
* canonical Value for the equivalence pin. Lives OUTSIDE the covered module so the module stays literal
|
|
2385
|
+
* whole-file zero (the ser_* / decode helpers are test glue, never on the consumer's read hot path).
|
|
2279
2386
|
*/
|
|
2280
|
-
export function rustTypedNativeObserve(ir, ioModel = "sync") {
|
|
2387
|
+
export function rustTypedNativeObserve(ir, ioModel = "sync", leaf) {
|
|
2281
2388
|
const components = ir.components;
|
|
2282
2389
|
const native = components.filter(isNativeRaw);
|
|
2283
2390
|
const plan = buildTypePlan(ir);
|
|
@@ -2294,213 +2401,66 @@ export function rustTypedNativeObserve(ir, ioModel = "sync") {
|
|
|
2294
2401
|
// every covered node returns a WireValue the inline de-box classifies — so the scripted wire adapter is
|
|
2295
2402
|
// needed whenever any component has a handler node.
|
|
2296
2403
|
const anyDeBox = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
2297
|
-
//
|
|
2298
|
-
//
|
|
2299
|
-
//
|
|
2300
|
-
//
|
|
2301
|
-
//
|
|
2404
|
+
// value_to_wire (TEST glue): builds the covered module's BC-OWNED concrete `WireValue` from a scripted bc
|
|
2405
|
+
// `Value` — the test-harness analog of the consumer's real transport (which builds `WireValue` as it reads
|
|
2406
|
+
// the producer). Numbers ride as raw text (WireValue::Num), matching how the de-box parses + range-checks;
|
|
2407
|
+
// the wire tags + classification live ONCE in the covered module's WireValue (probe_*_at), so this only
|
|
2408
|
+
// CONSTRUCTS — a scripted wrong-variant value maps to the corresponding WireValue variant and the covered
|
|
2409
|
+
// de-box classifies it (TYPE_MISMATCH ≡ run_behavior), no separate scripted classifier.
|
|
2302
2410
|
const wireAdapter = anyDeBox
|
|
2303
|
-
? `// ──
|
|
2304
|
-
fn
|
|
2411
|
+
? `// ── value_to_wire (TEST glue): scripted bc Value -> the covered module's BC-owned WireValue ──
|
|
2412
|
+
fn value_to_wire(v: &Value) -> WireValue {
|
|
2305
2413
|
match v {
|
|
2306
|
-
Value::Null =>
|
|
2307
|
-
Value::Bool(
|
|
2308
|
-
Value::Int(
|
|
2309
|
-
Value::
|
|
2310
|
-
Value::
|
|
2311
|
-
Value::
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
fn scripted_wire_raw(v: &Value) -> String {
|
|
2317
|
-
match v {
|
|
2318
|
-
Value::Null => "null".to_string(),
|
|
2319
|
-
Value::Bool(b) => b.to_string(),
|
|
2320
|
-
Value::Int(n) => n.to_string(),
|
|
2321
|
-
Value::Float(f) => f.to_string(),
|
|
2322
|
-
Value::Str(s) => s.clone(),
|
|
2323
|
-
Value::Arr(_) | Value::Obj(_) => "[composite]".to_string(),
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
fn probe_string_val(v: Option<&Value>) -> Probe<String> {
|
|
2328
|
-
match v {
|
|
2329
|
-
None => Probe::Absent,
|
|
2330
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2331
|
-
Some(Value::Str(s)) => Probe::Got(s.clone()),
|
|
2332
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
fn probe_number_val(v: Option<&Value>) -> NumProbe {
|
|
2337
|
-
match v {
|
|
2338
|
-
None => NumProbe::Absent,
|
|
2339
|
-
Some(Value::Null) => NumProbe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2340
|
-
Some(Value::Int(n)) => NumProbe::Got { raw: n.to_string(), actual_wire_type: "N".to_string() },
|
|
2341
|
-
Some(Value::Float(f)) => NumProbe::Got { raw: f.to_string(), actual_wire_type: "N".to_string() },
|
|
2342
|
-
Some(other) => NumProbe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
|
|
2346
|
-
fn probe_bool_val(v: Option<&Value>) -> Probe<bool> {
|
|
2347
|
-
match v {
|
|
2348
|
-
None => Probe::Absent,
|
|
2349
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2350
|
-
Some(Value::Bool(b)) => Probe::Got(*b),
|
|
2351
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
fn probe_row_val(v: Option<&Value>) -> Probe<ScriptedWireRow> {
|
|
2356
|
-
match v {
|
|
2357
|
-
None => Probe::Absent,
|
|
2358
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2359
|
-
Some(Value::Obj(pairs)) => Probe::Got(ScriptedWireRow { obj: pairs.clone() }),
|
|
2360
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
|
|
2364
|
-
fn probe_list_val(v: Option<&Value>) -> Probe<ScriptedWireList> {
|
|
2365
|
-
match v {
|
|
2366
|
-
None => Probe::Absent,
|
|
2367
|
-
Some(Value::Null) => Probe::Null { actual_wire_type: "NULL".to_string(), raw_value: "null".to_string() },
|
|
2368
|
-
Some(Value::Arr(items)) => Probe::Got(ScriptedWireList { items: items.clone() }),
|
|
2369
|
-
Some(other) => Probe::Wrong { actual_wire_type: scripted_wire_tag(other), raw_value: scripted_wire_raw(other) },
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
pub struct ScriptedWireRow {
|
|
2374
|
-
obj: Vec<(String, Value)>,
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
impl ScriptedWireRow {
|
|
2378
|
-
pub fn new(v: Value) -> Self {
|
|
2379
|
-
match v {
|
|
2380
|
-
Value::Obj(pairs) => ScriptedWireRow { obj: pairs },
|
|
2381
|
-
_ => ScriptedWireRow { obj: Vec::new() },
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
fn get(&self, field: &str) -> Option<&Value> {
|
|
2385
|
-
self.obj.iter().find(|(k, _)| k.as_str() == field).map(|(_, v)| v)
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
pub struct ScriptedWireList {
|
|
2390
|
-
items: Vec<Value>,
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
// ScriptedWireValue — a scripted node result wrapped as the uniform WireValue: a top value is always
|
|
2394
|
-
// present (Some), so as_* never observes Absent; a scripted null is Value::Null → Probe::Null.
|
|
2395
|
-
pub struct ScriptedWireValue {
|
|
2396
|
-
v: Value,
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
impl ScriptedWireValue {
|
|
2400
|
-
pub fn new(v: Value) -> Self {
|
|
2401
|
-
ScriptedWireValue { v }
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
|
|
2405
|
-
impl WireValue for ScriptedWireValue {
|
|
2406
|
-
type Row = ScriptedWireRow;
|
|
2407
|
-
fn as_string(&self) -> Probe<String> {
|
|
2408
|
-
probe_string_val(Some(&self.v))
|
|
2409
|
-
}
|
|
2410
|
-
fn as_number(&self) -> NumProbe {
|
|
2411
|
-
probe_number_val(Some(&self.v))
|
|
2412
|
-
}
|
|
2413
|
-
fn as_bool(&self) -> Probe<bool> {
|
|
2414
|
-
probe_bool_val(Some(&self.v))
|
|
2415
|
-
}
|
|
2416
|
-
fn as_row(&self) -> Probe<ScriptedWireRow> {
|
|
2417
|
-
probe_row_val(Some(&self.v))
|
|
2418
|
-
}
|
|
2419
|
-
fn as_list(&self) -> Probe<ScriptedWireList> {
|
|
2420
|
-
probe_list_val(Some(&self.v))
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
|
|
2424
|
-
impl WireRow for ScriptedWireRow {
|
|
2425
|
-
type List = ScriptedWireList;
|
|
2426
|
-
fn keys(&self) -> Vec<String> {
|
|
2427
|
-
self.obj.iter().map(|(k, _)| k.clone()).collect()
|
|
2428
|
-
}
|
|
2429
|
-
fn probe_string(&self, field: &str) -> Probe<String> {
|
|
2430
|
-
probe_string_val(self.get(field))
|
|
2431
|
-
}
|
|
2432
|
-
fn probe_number(&self, field: &str) -> NumProbe {
|
|
2433
|
-
probe_number_val(self.get(field))
|
|
2434
|
-
}
|
|
2435
|
-
fn probe_bool(&self, field: &str) -> Probe<bool> {
|
|
2436
|
-
probe_bool_val(self.get(field))
|
|
2437
|
-
}
|
|
2438
|
-
fn probe_row(&self, field: &str) -> Probe<Self> {
|
|
2439
|
-
probe_row_val(self.get(field))
|
|
2440
|
-
}
|
|
2441
|
-
fn probe_list(&self, field: &str) -> Probe<Self::List> {
|
|
2442
|
-
probe_list_val(self.get(field))
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
impl WireList for ScriptedWireList {
|
|
2447
|
-
type Row = ScriptedWireRow;
|
|
2448
|
-
fn len(&self) -> usize {
|
|
2449
|
-
self.items.len()
|
|
2450
|
-
}
|
|
2451
|
-
fn elem_string(&self, i: usize) -> Probe<String> {
|
|
2452
|
-
probe_string_val(self.items.get(i))
|
|
2453
|
-
}
|
|
2454
|
-
fn elem_number(&self, i: usize) -> NumProbe {
|
|
2455
|
-
probe_number_val(self.items.get(i))
|
|
2456
|
-
}
|
|
2457
|
-
fn elem_bool(&self, i: usize) -> Probe<bool> {
|
|
2458
|
-
probe_bool_val(self.items.get(i))
|
|
2459
|
-
}
|
|
2460
|
-
fn elem_row(&self, i: usize) -> Probe<Self::Row> {
|
|
2461
|
-
probe_row_val(self.items.get(i))
|
|
2462
|
-
}
|
|
2463
|
-
fn elem_list(&self, i: usize) -> Probe<Self> {
|
|
2464
|
-
probe_list_val(self.items.get(i))
|
|
2414
|
+
Value::Null => WireValue::Null,
|
|
2415
|
+
Value::Bool(b) => WireValue::Bool(*b),
|
|
2416
|
+
Value::Int(n) => WireValue::Num(n.to_string()),
|
|
2417
|
+
Value::Float(f) => WireValue::Num(f.to_string()),
|
|
2418
|
+
Value::Str(s) => WireValue::Str(s.clone()),
|
|
2419
|
+
Value::Arr(items) => WireValue::List(WireList { items: items.iter().map(value_to_wire).collect() }),
|
|
2420
|
+
Value::Obj(pairs) => WireValue::Row(WireRow {
|
|
2421
|
+
entries: pairs.iter().map(|(k, vv)| (k.clone(), value_to_wire(vv))).collect(),
|
|
2422
|
+
}),
|
|
2465
2423
|
}
|
|
2466
2424
|
}`
|
|
2467
2425
|
: "";
|
|
2468
|
-
// ──
|
|
2469
|
-
//
|
|
2470
|
-
|
|
2426
|
+
// ── op-agnostic leaf TRANSPORT fns (TEST glue) — the scripted analog of the consumer's transport
|
|
2427
|
+
// symbols. ONE free `leaf_<component>` per DISTINCT covered leaf (catalog component) in the IR (a
|
|
2428
|
+
// per-module leaf has one consistent shape — verified), draining the shared scripted-outcome static and
|
|
2429
|
+
// returning the scripted wire in EXACTLY the shape the removed per-node trait method returned. bc#87
|
|
2430
|
+
// parallel scoped threads share the static (Mutex-guarded); cases run sequentially so a shared static is
|
|
2431
|
+
// fine. Echo (#129/#141) reads the spread port params directly. ──
|
|
2432
|
+
const transportFns = [];
|
|
2433
|
+
const emittedLeaf = new Set();
|
|
2434
|
+
const drainStmt = (catalog, echoBind) => `let (is_err, err, ok, ${echoBind}) = next_scripted(${rustStrLit(catalog)}).ok_or_else(|| unknown_component(${rustStrLit(catalog)}))?;\n if is_err {\n return Err(leaf_failure(err));\n }`;
|
|
2435
|
+
const spreadParams = (spread) => spread.map((p) => `${p.field}: ${p.isCopy ? p.renderedType : `&${p.renderedType}`}`).join(", ");
|
|
2471
2436
|
for (const c of native) {
|
|
2472
2437
|
const ap = asyncPlans.get(c.name);
|
|
2473
|
-
// the scripted impl's node_* is `async fn` iff the trait's is (same per-node derivation).
|
|
2474
|
-
const fnKwFor = (nodeId) => (ap.nodeIsAsync(nodeId) ? "async fn" : "fn");
|
|
2475
2438
|
const typedNodes = new Map();
|
|
2476
2439
|
for (const n of c.body)
|
|
2477
2440
|
if (!isControlGate(n))
|
|
2478
2441
|
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
|
|
2479
|
-
const methods = [];
|
|
2480
2442
|
for (const n of c.body) {
|
|
2481
2443
|
if ("cond" in n)
|
|
2482
|
-
continue; // #108: a cond node has no
|
|
2483
|
-
const
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
const
|
|
2444
|
+
continue; // #108: a cond node has no leaf (pure Expression) — no transport fn.
|
|
2445
|
+
const catalog = "fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component;
|
|
2446
|
+
if (emittedLeaf.has(catalog))
|
|
2447
|
+
continue; // per-module a leaf has ONE consistent shape — emit once.
|
|
2448
|
+
emittedLeaf.add(catalog);
|
|
2449
|
+
const sym = resolveLeafSymbol(catalog, leaf);
|
|
2450
|
+
// async iff this catalog leaf's terminal handler is async (consistent per catalog component).
|
|
2451
|
+
const fnKw = ap.nodeIsAsync(n.id) ? "pub async fn" : "pub fn";
|
|
2488
2452
|
if ("fanout" in n) {
|
|
2489
|
-
// fanout: return the aligned per-id element WIRES (Vec<Option<
|
|
2453
|
+
// fanout: return the aligned per-id element WIRES (Vec<Option<WireValue>>); a null aligned
|
|
2490
2454
|
// body is a DANGLING id → None (the covered runner maps it to the zero element).
|
|
2491
|
-
const f = n.fanout;
|
|
2492
2455
|
const portsT = `${portsStructName(c.name, n.id)}Batch`;
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
if is_err {
|
|
2496
|
-
return Err(leaf_failure(err));
|
|
2497
|
-
}
|
|
2456
|
+
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<Option<WireValue>>, BehaviorError> {
|
|
2457
|
+
${drainStmt(catalog, "_echo")}
|
|
2498
2458
|
let arr = match ok { Some(Value::Arr(a)) => a, _ => Vec::new() };
|
|
2499
2459
|
let wires = arr
|
|
2500
2460
|
.into_iter()
|
|
2501
2461
|
.map(|ev| match ev {
|
|
2502
2462
|
Value::Null => None,
|
|
2503
|
-
_ => Some(
|
|
2463
|
+
_ => Some(value_to_wire(&ev)),
|
|
2504
2464
|
})
|
|
2505
2465
|
.collect();
|
|
2506
2466
|
Ok(wires)
|
|
@@ -2508,37 +2468,30 @@ impl WireList for ScriptedWireList {
|
|
|
2508
2468
|
continue;
|
|
2509
2469
|
}
|
|
2510
2470
|
if ("map" in n) {
|
|
2511
|
-
// map: batched → one WIRE per element (Vec<
|
|
2471
|
+
// map: batched → one WIRE per element (Vec<WireValue>); non-batched → one element WIRE.
|
|
2512
2472
|
const m = n.map;
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
let (is_err, err, ok, _echo) = self.next(${rustStrLit(m.component)}).ok_or_else(|| unknown_component(${rustStrLit(m.component)}))?;
|
|
2518
|
-
if is_err {
|
|
2519
|
-
return Err(leaf_failure(err));
|
|
2520
|
-
}
|
|
2473
|
+
if (m.batched === true) {
|
|
2474
|
+
const portsT = `${portsStructName(c.name, n.id)}Batch`;
|
|
2475
|
+
transportFns.push(`${fnKw} ${sym}(_batch: &${portsT}) -> Result<Vec<WireValue>, BehaviorError> {
|
|
2476
|
+
${drainStmt(catalog, "_echo")}
|
|
2521
2477
|
let arr = match ok { Some(Value::Arr(a)) => a, _ => Vec::new() };
|
|
2522
|
-
let wires = arr.
|
|
2478
|
+
let wires = arr.iter().map(value_to_wire).collect();
|
|
2523
2479
|
Ok(wires)
|
|
2524
2480
|
}`);
|
|
2525
2481
|
}
|
|
2526
2482
|
else {
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
Ok(ScriptedWireValue::new(ok.unwrap_or(Value::Null)))
|
|
2483
|
+
const { elemRef: overElemRef } = mapOverElemInfo(c, n, typedNodes, plan);
|
|
2484
|
+
const params = spreadParams(portFieldSpread(m.ports, c, plan, typedNodes, { name: m.as, ref: overElemRef, plan }));
|
|
2485
|
+
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<WireValue, BehaviorError> {
|
|
2486
|
+
${drainStmt(catalog, "_echo")}
|
|
2487
|
+
Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
2533
2488
|
}`);
|
|
2534
2489
|
}
|
|
2535
2490
|
continue;
|
|
2536
2491
|
}
|
|
2537
|
-
// componentRef:
|
|
2538
|
-
// the covered runner's INLINE de-box classifies it. A real consumer returns its own wire payload.
|
|
2492
|
+
// componentRef (point read): spread port fields; supports echo (#129/#141) reading the port params.
|
|
2539
2493
|
const node = n;
|
|
2540
|
-
|
|
2541
|
-
// input-port value flows into the de-boxed result and the runtime non-vacuity asserts survive.
|
|
2494
|
+
const ref = typedNodes.get(n.id);
|
|
2542
2495
|
const echoBranches = [];
|
|
2543
2496
|
if (ref.kind === "named") {
|
|
2544
2497
|
const decl = findDecl(plan, ref.name);
|
|
@@ -2555,13 +2508,13 @@ impl WireList for ScriptedWireList {
|
|
|
2555
2508
|
}
|
|
2556
2509
|
if (portRust === recordRust) {
|
|
2557
2510
|
// the port IS the whole record → echo it DIRECTLY (matching run_behavior's plain echo:port).
|
|
2558
|
-
const own = typeRefIsCopy(ref) ?
|
|
2559
|
-
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(
|
|
2511
|
+
const own = typeRefIsCopy(ref) ? `${portFieldName(pn)}` : `${portFieldName(pn)}.clone()`;
|
|
2512
|
+
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(value_to_wire(&${serializeTyped("tv", ref, plan)}));\n }`);
|
|
2560
2513
|
}
|
|
2561
2514
|
else if (fieldRust !== null && field !== undefined && portRust === fieldRust) {
|
|
2562
2515
|
// a scalar port wraps into the record's single field ({v: ports.X}).
|
|
2563
|
-
const own = typeRefIsCopy(field.type) ?
|
|
2564
|
-
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(
|
|
2516
|
+
const own = typeRefIsCopy(field.type) ? `${portFieldName(pn)}` : `${portFieldName(pn)}.clone()`;
|
|
2517
|
+
echoBranches.push(` if echo == ${rustStrLit(pn)} {\n let tv = ${own};\n return Ok(value_to_wire(&Value::Obj(vec![(${rustStrLit(field.name)}.to_string(), ${serializeTyped("tv", field.type, plan)})])));\n }`);
|
|
2565
2518
|
}
|
|
2566
2519
|
}
|
|
2567
2520
|
}
|
|
@@ -2569,23 +2522,16 @@ impl WireList for ScriptedWireList {
|
|
|
2569
2522
|
// #129: an arr node with an `items` port echoes the NATIVE port array (serialized element-by-element
|
|
2570
2523
|
// into a Value::Arr) so the node→leaf array dataflow test is non-vacuous.
|
|
2571
2524
|
const elemRef = ref.elem;
|
|
2572
|
-
echoBranches.push(` if echo == "items" {\n let tv = Value::Arr(
|
|
2525
|
+
echoBranches.push(` if echo == "items" {\n let tv = Value::Arr(${portFieldName("items")}.iter().map(|e| { let ev = e.clone(); ${serializeTyped("ev", elemRef, plan)} }).collect());\n return Ok(value_to_wire(&tv));\n }`);
|
|
2573
2526
|
}
|
|
2574
2527
|
const canEcho = echoBranches.length > 0;
|
|
2575
|
-
const
|
|
2576
|
-
const okBind = canEcho ? "(is_err, err, ok, echo)" : "(is_err, err, ok, _echo)";
|
|
2528
|
+
const params = spreadParams(portFieldSpread(node.ports, c, plan, typedNodes));
|
|
2577
2529
|
const echoBlock = canEcho ? `${echoBranches.join("\n")}\n` : "";
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
return Err(leaf_failure(err));
|
|
2582
|
-
}
|
|
2583
|
-
${echoBlock} Ok(ScriptedWireValue::new(ok.unwrap_or(Value::Null)))
|
|
2530
|
+
transportFns.push(`${fnKw} ${sym}(${params}) -> Result<WireValue, BehaviorError> {
|
|
2531
|
+
${drainStmt(catalog, canEcho ? "echo" : "_echo")}
|
|
2532
|
+
${echoBlock} Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
2584
2533
|
}`);
|
|
2585
2534
|
}
|
|
2586
|
-
const cHasHandler = c.body.some((n) => !("cond" in n));
|
|
2587
|
-
const wireAssoc = cHasHandler ? ` type Wire = ScriptedWireValue;\n` : "";
|
|
2588
|
-
traitImpls.push(`impl ${handlerTraitName(c.name)} for ScriptedNativeRaw {\n${wireAssoc}${methods.join("\n")}\n}`);
|
|
2589
2535
|
}
|
|
2590
2536
|
const arms = native
|
|
2591
2537
|
.map((c) => {
|
|
@@ -2598,80 +2544,80 @@ ${echoBlock} Ok(ScriptedWireValue::new(ok.unwrap_or(Value::Null)))
|
|
|
2598
2544
|
// bc#97: an async runner returns a Future — drive it to completion with the std-only block-on
|
|
2599
2545
|
// (bc_block_on) so observe_native_raw keeps its SYNC external signature (the harness is unchanged).
|
|
2600
2546
|
// The scripted async node_* return ready values, so the future needs no real executor / no runtime.
|
|
2601
|
-
const runnerCall = `super::run_native_raw_struct_${sanitize(c.name)}(
|
|
2547
|
+
const runnerCall = `super::run_native_raw_struct_${sanitize(c.name)}(in_)`;
|
|
2602
2548
|
const driven = asyncPlans.get(c.name).runnerIsAsync ? `bc_block_on(${runnerCall})` : runnerCall;
|
|
2603
2549
|
return ` ${rustStrLit(c.name)} => {\n let in_ = decode_${inStructName(c.name)}(input).map_err(to_rt_err)?;\n let tv = ${driven}.map_err(to_rt_err)?;\n Ok(${ser})\n }`;
|
|
2604
2550
|
})
|
|
2605
2551
|
.join("\n");
|
|
2606
|
-
// the scripted
|
|
2607
|
-
//
|
|
2608
|
-
//
|
|
2609
|
-
|
|
2610
|
-
//
|
|
2611
|
-
|
|
2612
|
-
//
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2552
|
+
// the scripted-outcome source is a MODULE-LEVEL static (Mutex<Option<HashMap>> + AtomicUsize), NOT a
|
|
2553
|
+
// per-call handler object: the free transport fns drain it, and observe_native_raw resets+fills it from
|
|
2554
|
+
// the per-case handlers spec before driving the runner. A static (not thread_local) so the bc#87 parallel
|
|
2555
|
+
// scoped threads — which call the transport fns concurrently — share it (Mutex-guarded). Cases run
|
|
2556
|
+
// sequentially in the harness, so one shared static per case is fine.
|
|
2557
|
+
const adapter = `// SCRIPTED_QUEUES — the shared scripted-outcome source the free leaf transport fns drain (TEST glue).
|
|
2558
|
+
// { "<component>": (queue, single) }. reset+filled per case by observe_native_raw. \`Mutex::new(None)\` is
|
|
2559
|
+
// a const initializer (no LazyLock/OnceLock needed). SCRIPTED_SEEN mirrors the old probe counter.
|
|
2560
|
+
static SCRIPTED_QUEUES: std::sync::Mutex<Option<std::collections::HashMap<String, (Vec<serde_json::Value>, bool)>>> =
|
|
2561
|
+
std::sync::Mutex::new(None);
|
|
2562
|
+
#[allow(dead_code)]
|
|
2563
|
+
static SCRIPTED_SEEN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
|
2618
2564
|
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
}
|
|
2630
|
-
ScriptedNativeRaw {
|
|
2631
|
-
queues: std::sync::Mutex::new(queues),
|
|
2632
|
-
seen: std::sync::atomic::AtomicUsize::new(0),
|
|
2633
|
-
}
|
|
2565
|
+
// fill_scripted — reset + load the shared static from the JSON handlers spec: { "<component>": {ok|error}
|
|
2566
|
+
// | [ {ok|error}, … ] }.
|
|
2567
|
+
fn fill_scripted(spec: &serde_json::Map<String, serde_json::Value>) {
|
|
2568
|
+
let mut map = std::collections::HashMap::new();
|
|
2569
|
+
for (name, raw) in spec {
|
|
2570
|
+
let (items, single) = match raw {
|
|
2571
|
+
serde_json::Value::Array(a) => (a.clone(), false),
|
|
2572
|
+
other => (vec![other.clone()], true),
|
|
2573
|
+
};
|
|
2574
|
+
map.insert(name.clone(), (items, single));
|
|
2634
2575
|
}
|
|
2576
|
+
*SCRIPTED_QUEUES.lock().unwrap() = Some(map);
|
|
2577
|
+
SCRIPTED_SEEN.store(0, std::sync::atomic::Ordering::SeqCst);
|
|
2578
|
+
}
|
|
2635
2579
|
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
}
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2580
|
+
// next_scripted — drain one scripted outcome for a component (last entry repeats — mirrors the reference
|
|
2581
|
+
// scripted handlers); None when the component has no scripted queue. Returns (is_error, err, ok_value,
|
|
2582
|
+
// echo). The bc#87 parallel-stage runner calls the transport fns from multiple threads, so the drain is
|
|
2583
|
+
// Mutex-guarded. #129: \`echo\` carries the reference scriptedHandlers' \`echo\` directive (e.g. "items")
|
|
2584
|
+
// so a scripted node can ECHO a named input PORT back — used to make the node→leaf array dataflow test
|
|
2585
|
+
// non-vacuous (the leaf returns its \`items\` port; a dropped/boxed array diverges).
|
|
2586
|
+
fn next_scripted(component: &str) -> Option<(bool, String, Option<Value>, String)> {
|
|
2587
|
+
SCRIPTED_SEEN.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
|
2588
|
+
let mut guard = SCRIPTED_QUEUES.lock().unwrap();
|
|
2589
|
+
let map = guard.as_mut()?;
|
|
2590
|
+
let (queue, single) = map.get_mut(component)?;
|
|
2591
|
+
let raw = if *single || queue.len() <= 1 { queue[0].clone() } else { queue.remove(0) };
|
|
2592
|
+
// normalize echo:port to the port NAME X so a de-box handler's echo comparison fires;
|
|
2593
|
+
// echo:items already names the port directly.
|
|
2594
|
+
let echo = {
|
|
2595
|
+
let e = raw.get("echo").and_then(|e| e.as_str()).unwrap_or("");
|
|
2596
|
+
if e == "port" { raw.get("port").and_then(|p| p.as_str()).unwrap_or("").to_string() } else { e.to_string() }
|
|
2597
|
+
};
|
|
2598
|
+
if let Some(okv) = raw.get("ok") {
|
|
2599
|
+
let v = behavior_contracts::decode_value(okv).expect("decode ok");
|
|
2600
|
+
Some((false, String::new(), Some(v), echo))
|
|
2601
|
+
} else {
|
|
2602
|
+
let e = raw.get("error").and_then(|e| e.as_str()).unwrap_or("").to_string();
|
|
2603
|
+
Some((true, e, None, echo))
|
|
2660
2604
|
}
|
|
2661
2605
|
}`;
|
|
2662
|
-
|
|
2663
|
-
void observeBound;
|
|
2606
|
+
void needSync;
|
|
2664
2607
|
return `// GENERATED test-only observe companion (bc#77/#94) — NOT part of the covered module. Serializes the
|
|
2665
|
-
// struct-native runner's result to a canonical Value for the equivalence pin, and carries the
|
|
2666
|
-
//
|
|
2667
|
-
//
|
|
2668
|
-
//
|
|
2669
|
-
// byte-compare the STRUCT-only covered read against
|
|
2670
|
-
// (reads its pub run_native_raw_struct_* + the CONCRETE
|
|
2671
|
-
//
|
|
2672
|
-
//
|
|
2673
|
-
//
|
|
2674
|
-
|
|
2608
|
+
// struct-native runner's result to a canonical Value for the equivalence pin, and carries the SCRIPTED
|
|
2609
|
+
// analog of the consumer's leaf transport symbols: free \`leaf_<comp>\` fns that drain a shared scripted
|
|
2610
|
+
// static and return the scripted wire (exactly the shape the removed per-node trait method returned). The
|
|
2611
|
+
// consumer never uses this (it keeps the model native + supplies its own transport fns over its own wire
|
|
2612
|
+
// payload); it exists only so the test harness can byte-compare the STRUCT-only covered read against
|
|
2613
|
+
// run_behavior. A submodule of the covered module (reads its pub run_native_raw_struct_* + the CONCRETE
|
|
2614
|
+
// structs — incl. the LOCAL BehaviorError — via super::*, and its \`leaf_<comp>\` fns resolve the covered
|
|
2615
|
+
// module's transport calls). bc#90 / runtime-free: the covered module's BehaviorError is LOCAL, so this
|
|
2616
|
+
// test-glue companion refers to it via super::* (as \`BehaviorError\`) and refers to the bc-runtime failure
|
|
2617
|
+
// type FULLY-QUALIFIED (\`behavior_contracts::BehaviorError\`) only where it bridges at the observe boundary.
|
|
2618
|
+
// The transport-fn signatures spread the port fields, so they carry \`&String\`/\`&Vec\` params and (for
|
|
2619
|
+
// point reads) many args — clippy::ptr_arg / too_many_arguments are TEST-glue-only allows here.
|
|
2620
|
+
#![allow(dead_code, unused_imports, unused_variables, non_snake_case, clippy::ptr_arg, clippy::too_many_arguments, clippy::needless_lifetimes, clippy::type_complexity)]
|
|
2675
2621
|
use behavior_contracts::Value;
|
|
2676
2622
|
use super::*;
|
|
2677
2623
|
|
|
@@ -2738,17 +2684,19 @@ ${wireAdapter}
|
|
|
2738
2684
|
|
|
2739
2685
|
${adapter}
|
|
2740
2686
|
|
|
2741
|
-
// scripted
|
|
2742
|
-
|
|
2687
|
+
// scripted leaf transport fns (one per covered leaf — the free op-agnostic transport the covered runner
|
|
2688
|
+
// calls directly; test glue draining the shared scripted static).
|
|
2689
|
+
${transportFns.join("\n\n")}
|
|
2743
2690
|
|
|
2744
|
-
// observe_native_raw
|
|
2745
|
-
//
|
|
2746
|
-
//
|
|
2691
|
+
// observe_native_raw resets+fills the shared scripted static from the per-case handlers spec, then drives
|
|
2692
|
+
// the covered struct-native runner and serializes to a canonical Value (test only). No handler object is
|
|
2693
|
+
// passed — the runner calls the free \`leaf_<comp>\` transport fns above directly.
|
|
2747
2694
|
pub fn observe_native_raw(
|
|
2748
2695
|
name: &str,
|
|
2749
|
-
|
|
2696
|
+
spec: &serde_json::Map<String, serde_json::Value>,
|
|
2750
2697
|
input: &[(String, Value)],
|
|
2751
2698
|
) -> Result<Value, behavior_contracts::BehaviorError> {
|
|
2699
|
+
fill_scripted(spec);
|
|
2752
2700
|
match name {
|
|
2753
2701
|
${arms}
|
|
2754
2702
|
other => Err(behavior_contracts::BehaviorError::new("UNKNOWN_ENTRY", format!("component '{other}' is not a covered read (fail-closed)"))),
|