behavior-contracts 0.11.18 → 0.11.19

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.
Files changed (43) hide show
  1. package/cli-contract.yaml +9 -4
  2. package/dist/behavior.d.ts +16 -7
  3. package/dist/behavior.d.ts.map +1 -1
  4. package/dist/behavior.js +19 -8
  5. package/dist/behavior.js.map +1 -1
  6. package/dist/cli.js +4 -2
  7. package/dist/cli.js.map +1 -1
  8. package/dist/expr-eval.d.ts +8 -1
  9. package/dist/expr-eval.d.ts.map +1 -1
  10. package/dist/expr-eval.js +11 -2
  11. package/dist/expr-eval.js.map +1 -1
  12. package/dist/generated/contract.d.ts.map +1 -1
  13. package/dist/generated/contract.js +2 -2
  14. package/dist/generated/contract.js.map +1 -1
  15. package/dist/generator/core.d.ts +4 -2
  16. package/dist/generator/core.d.ts.map +1 -1
  17. package/dist/generator/core.js.map +1 -1
  18. package/dist/generator/emit-shared-go-typed.d.ts +8 -12
  19. package/dist/generator/emit-shared-go-typed.d.ts.map +1 -1
  20. package/dist/generator/emit-shared-go-typed.js +40 -25
  21. package/dist/generator/emit-shared-go-typed.js.map +1 -1
  22. package/dist/generator/emit-shared-rust-typed.d.ts +12 -16
  23. package/dist/generator/emit-shared-rust-typed.d.ts.map +1 -1
  24. package/dist/generator/emit-shared-rust-typed.js +45 -30
  25. package/dist/generator/emit-shared-rust-typed.js.map +1 -1
  26. package/dist/generator/emit-straightline-typed-typescript.d.ts.map +1 -1
  27. package/dist/generator/emit-straightline-typed-typescript.js +15 -23
  28. package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
  29. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  30. package/dist/generator/emit-typed-native-go.js +154 -142
  31. package/dist/generator/emit-typed-native-go.js.map +1 -1
  32. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  33. package/dist/generator/emit-typed-native-rust.js +550 -285
  34. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  35. package/dist/generator/native-expr.d.ts +49 -6
  36. package/dist/generator/native-expr.d.ts.map +1 -1
  37. package/dist/generator/native-expr.js +87 -21
  38. package/dist/generator/native-expr.js.map +1 -1
  39. package/dist/generator/typed.d.ts +149 -0
  40. package/dist/generator/typed.d.ts.map +1 -1
  41. package/dist/generator/typed.js +106 -1
  42. package/dist/generator/typed.js.map +1 -1
  43. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { entryPortOrder, GeneratorFailure } from "./core.js";
2
2
  import { isControlGate, mapNodeElemIsOpaqueWire, mapTransformExpr, nodeWirePassthrough } from "../behavior.js";
3
3
  import { goStraightlineInternals } from "./emit-shared-go.js";
4
4
  import { goTypedInternals } from "./emit-shared-go-typed.js";
5
- import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
5
+ import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef, lowerProducedAwareRead, unproducedInSlot } from "./typed.js";
6
6
  import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, buildComponentPlan, nodeNarrowedPaths, } from "./straightline.js";
7
7
  import { NativeExprCompiler } from "./native-expr.js";
8
8
  import { buildDeBoxPlan, buildWirePlan, notationOfRef } from "./emit-shared-debox.js";
@@ -172,8 +172,15 @@ function goTypeOfPlan(plan) {
172
172
  * enclosing list / map loop supplies (empty for top / field). Mirrors the interpreter's outType check,
173
173
  * but TOTAL over the grammar (opt(named)/arr(arr)/map(opt)…) and inlined — the type is baked all the way
174
174
  * through by the TS compiler, and every seam call resolves to a CONCRETE consumer type (no dispatch).
175
+ *
176
+ * #289: `wireSel` is the shared-package selector (the SAME one the box direction threads — see
177
+ * {@link renderGoWireBox}). Cross-package the classifiers live in the shared package W beside the wire
178
+ * TYPE, so the ONE access that calls a FREE classifier (mapval) must qualify it through {@link goWireQ};
179
+ * every other access is a METHOD on an already-qualified value and needs nothing. It sits BEFORE the
180
+ * defaulted params on purpose: a default would let a recursion site silently fall back to the bare form
181
+ * — the exact #174/#289 defect — so the compiler makes every site name it.
175
182
  */
176
- function renderGoDeBox(plan, target, srcExpr, ctr, indent, fail, idxExpr = "") {
183
+ function renderGoDeBox(plan, target, srcExpr, ctr, indent, fail, wireSel, idxExpr = "", hoist = null, memoRef = "") {
177
184
  const I = indent;
178
185
  const I1 = indent + "\t";
179
186
  const I2 = indent + "\t\t";
@@ -193,16 +200,22 @@ function renderGoDeBox(plan, target, srcExpr, ctr, indent, fail, idxExpr = "") {
193
200
  const pv = `p${id}`;
194
201
  const kindSuffix = plan.k === "list" ? "List" : plan.k === "scalar" ? (plan.scalar === "string" ? "String" : plan.scalar === "bool" ? "Bool" : plan.scalar === "int" ? "Int" : "Float") : "Row";
195
202
  // the probe call for this node's access (top → As*, field/mapval → Probe*(key), elem → Elem*(i)).
203
+ // #279: a field under a repetition reads through the result set's resolved column position (Probe*At);
204
+ // one that is de-boxed once has nothing to amortise and keeps the plain by-name read.
196
205
  const probeCall = (() => {
197
206
  switch (plan.access.from) {
198
207
  case "top":
199
208
  return `${srcExpr}.As${kindSuffix}()`;
200
209
  case "field":
201
- return `${srcExpr}.Probe${kindSuffix}(${JSON.stringify(plan.access.key)})`;
210
+ return memoRef === ""
211
+ ? `${srcExpr}.Probe${kindSuffix}(${JSON.stringify(plan.access.key)})`
212
+ : `${srcExpr}.Probe${kindSuffix}At(${JSON.stringify(plan.access.key)}, ${memoRef})`;
202
213
  case "elem":
203
214
  return `${srcExpr}.Elem${kindSuffix}(${idxExpr})`;
204
215
  case "mapval":
205
- return `Probe${kindSuffix}Of(${idxExpr})`;
216
+ // the ONE de-box access that calls a FREE classifier instead of a method on the wire value — so it
217
+ // is the ONE that has to carry the shared-package selector (#289).
218
+ return `${goWireQ(wireSel)}Probe${kindSuffix}Of(${idxExpr})`;
206
219
  }
207
220
  })();
208
221
  const mismatch = fail(`deTypeMismatch(${ml}, ${fl}, ${nl}, ${pv}.ActualWireType, ${pv}.Raw)`);
@@ -244,9 +257,13 @@ function renderGoDeBox(plan, target, srcExpr, ctr, indent, fail, idxExpr = "") {
244
257
  }
245
258
  }
246
259
  else if (plan.k === "record") {
260
+ // #279: under a repetition the record's column POSITIONS live in ONE `at<id>` array declared OUTSIDE
261
+ // the loop, so every row of the result set reuses the resolution the first row paid for.
262
+ if (hoist !== null && plan.fields.length > 0)
263
+ hoist.push(`var at${id} [${plan.fields.length}]int`);
264
+ const slot = (j) => (hoist === null ? "" : `&at${id}[${j}]`);
247
265
  lines.push(`${I1}var rec${id} ${plan.typeName}`);
248
- for (const f of plan.fields)
249
- lines.push(renderGoDeBox(f.plan, `rec${id}.${goFieldName(f.name)}`, `${pv}.Got`, ctr, I1, fail));
266
+ plan.fields.forEach((f, j) => lines.push(renderGoDeBox(f.plan, `rec${id}.${goFieldName(f.name)}`, `${pv}.Got`, ctr, I1, fail, wireSel, "", hoist, slot(j))));
250
267
  for (const l of wrapAssign(`rec${id}`))
251
268
  lines.push(l);
252
269
  }
@@ -259,11 +276,19 @@ function renderGoDeBox(plan, target, srcExpr, ctr, indent, fail, idxExpr = "") {
259
276
  lines.push(l);
260
277
  }
261
278
  else if (plan.k === "list") {
279
+ // #279: the loop IS the result set — the element subtree's column positions are declared before it, so
280
+ // the scan the first row pays for is the only scan the whole list pays for. An OUTER repetition already
281
+ // owns a declaration site, and hoisting all the way out is strictly better, so only the outermost emits.
262
282
  const elemGo = goTypeOfPlan(plan.elem);
283
+ const loopHoist = hoist ?? [];
284
+ const body = renderGoDeBox(plan.elem, `el${id}`, `${pv}.Got`, ctr, I2, fail, wireSel, `i${id}`, loopHoist);
285
+ if (hoist === null)
286
+ for (const d of loopHoist)
287
+ lines.push(`${I1}${d}`);
263
288
  lines.push(`${I1}list${id} := make([]${elemGo}, 0, ${pv}.Got.Len())`);
264
289
  lines.push(`${I1}for i${id} := 0; i${id} < ${pv}.Got.Len(); i${id}++ {`);
265
290
  lines.push(`${I2}var el${id} ${elemGo}`);
266
- lines.push(renderGoDeBox(plan.elem, `el${id}`, `${pv}.Got`, ctr, I2, fail, `i${id}`));
291
+ lines.push(body);
267
292
  lines.push(`${I2}list${id} = append(list${id}, el${id})`);
268
293
  lines.push(`${I1}}`);
269
294
  for (const l of wrapAssign(`list${id}`))
@@ -272,11 +297,16 @@ function renderGoDeBox(plan, target, srcExpr, ctr, indent, fail, idxExpr = "") {
272
297
  else {
273
298
  // map(V): the wire value is a producer map; enumerate its keys, decode each value as V.
274
299
  const valGo = goTypeOfPlan(plan.value);
300
+ const mapHoist = hoist ?? [];
301
+ const body = renderGoDeBox(plan.value, `mv${id}`, `${pv}.Got`, ctr, I2, fail, wireSel, `&ents${id}[i${id}].Val`, mapHoist);
302
+ if (hoist === null)
303
+ for (const d of mapHoist)
304
+ lines.push(`${I1}${d}`);
275
305
  lines.push(`${I1}ents${id} := ${pv}.Got.Entries()`);
276
306
  lines.push(`${I1}m${id} := make(map[string]${valGo}, len(ents${id}))`);
277
307
  lines.push(`${I1}for i${id} := range ents${id} {`);
278
308
  lines.push(`${I2}var mv${id} ${valGo}`);
279
- lines.push(renderGoDeBox(plan.value, `mv${id}`, `${pv}.Got`, ctr, I2, fail, `&ents${id}[i${id}].Val`));
309
+ lines.push(body);
280
310
  lines.push(`${I2}m${id}[ents${id}[i${id}].Key] = mv${id}`);
281
311
  lines.push(`${I1}}`);
282
312
  for (const l of wrapAssign(`m${id}`))
@@ -317,9 +347,10 @@ function componentZeroOut(comp, plan) {
317
347
  * control flow. This is the ONE de-box call the runner arms share (componentRef result + map/fanout
318
348
  * element) — no per-position predicate, no helper decode fn. `ctr` hands out unique temp suffixes: the
319
349
  * sequential runner threads ONE counter across all its at-fn-scope nodes so siblings never collide;
320
- * loop/if-scoped arms (map / fanout / parallel commit) may pass a fresh one. */
321
- function renderResultDeBox(ref, target, srcExpr, nodeId, plan, indent, fail, passthrough = false, ctr = { n: 0 }) {
322
- return renderGoDeBox(buildDeBoxPlan(ref, { from: "top" }, { model: nodeId, field: nodeId, plan }, passthrough), target, srcExpr, ctr, indent, fail);
350
+ * loop/if-scoped arms (map / fanout / parallel commit) may pass a fresh one. `wireSel` is the shared-package
351
+ * selector every arm already holds (`wire.selector` / the arm's `wireSel`) — see {@link renderGoDeBox}. */
352
+ function renderResultDeBox(ref, target, srcExpr, nodeId, plan, indent, fail, wireSel, passthrough = false, ctr = { n: 0 }) {
353
+ return renderGoDeBox(buildDeBoxPlan(ref, { from: "top" }, { model: nodeId, field: nodeId, plan }, passthrough), target, srcExpr, ctr, indent, fail, wireSel);
323
354
  }
324
355
  /** emitProbeWireTypes — the once-per-module probe kind consts + probe RESULT structs. A numeric probe's
325
356
  * Got is the producer's NATIVE number (int64 / float64 — nothing to parse, nothing to range-check); every
@@ -507,9 +538,19 @@ func (w WireValue) AsBool() BoolProbe { return ProbeBoolOf(&w) }
507
538
  func (w WireValue) AsRow() RowProbe { return ProbeRowOf(&w) }
508
539
  func (w WireValue) AsList() ListProbe { return ProbeListOf(&w) }
509
540
 
510
- func (r WireRow) get(field string) *WireValue {
541
+ // at — the ONE field lookup. \`pos\` is the position the column resolved to in an EARLIER row of the SAME
542
+ // result set: the key is verified to still sit there (one compare) and only a row that does not match is
543
+ // scanned again, so a result set resolves each column name ONCE and every later row reads it by index.
544
+ // Scanning per field instead cost O(columns²) per row — the de-box reads every declared field, and each
545
+ // read walked the row. The reuse needs NO stable-layout assumption from the producer: the verify IS the
546
+ // read's guard, and a differing row just re-resolves. nil = the producer did not send the field.
547
+ func (r WireRow) at(field string, pos *int) *WireValue {
548
+ if *pos < len(r.entries) && r.entries[*pos].Key == field {
549
+ return &r.entries[*pos].Val
550
+ }
511
551
  for i := range r.entries {
512
552
  if r.entries[i].Key == field {
553
+ *pos = i
513
554
  return &r.entries[i].Val
514
555
  }
515
556
  }
@@ -519,12 +560,22 @@ func (r WireRow) get(field string) *WireValue {
519
560
  // materialising a []string of keys per row and then looking each one up again.
520
561
  func (r WireRow) Entries() []WireField { return r.entries }
521
562
 
522
- func (r WireRow) ProbeString(field string) StringProbe { return ProbeStringOf(r.get(field)) }
523
- func (r WireRow) ProbeInt(field string) IntProbe { return ProbeIntOf(r.get(field)) }
524
- func (r WireRow) ProbeFloat(field string) FloatProbe { return ProbeFloatOf(r.get(field)) }
525
- func (r WireRow) ProbeBool(field string) BoolProbe { return ProbeBoolOf(r.get(field)) }
526
- func (r WireRow) ProbeRow(field string) RowProbe { return ProbeRowOf(r.get(field)) }
527
- func (r WireRow) ProbeList(field string) ListProbe { return ProbeListOf(r.get(field)) }
563
+ // Probe<Kind> — read a field BY NAME, once (the payload read the consumer's leaf transport does: each of
564
+ // its ports is read one time, so there is no position to carry). Probe<Kind>At is the SAME read carrying
565
+ // the result set's resolved position — what the generated per-row de-box calls.
566
+ func (r WireRow) ProbeString(field string) StringProbe { pos := 0; return ProbeStringOf(r.at(field, &pos)) }
567
+ func (r WireRow) ProbeInt(field string) IntProbe { pos := 0; return ProbeIntOf(r.at(field, &pos)) }
568
+ func (r WireRow) ProbeFloat(field string) FloatProbe { pos := 0; return ProbeFloatOf(r.at(field, &pos)) }
569
+ func (r WireRow) ProbeBool(field string) BoolProbe { pos := 0; return ProbeBoolOf(r.at(field, &pos)) }
570
+ func (r WireRow) ProbeRow(field string) RowProbe { pos := 0; return ProbeRowOf(r.at(field, &pos)) }
571
+ func (r WireRow) ProbeList(field string) ListProbe { pos := 0; return ProbeListOf(r.at(field, &pos)) }
572
+
573
+ func (r WireRow) ProbeStringAt(field string, pos *int) StringProbe { return ProbeStringOf(r.at(field, pos)) }
574
+ func (r WireRow) ProbeIntAt(field string, pos *int) IntProbe { return ProbeIntOf(r.at(field, pos)) }
575
+ func (r WireRow) ProbeFloatAt(field string, pos *int) FloatProbe { return ProbeFloatOf(r.at(field, pos)) }
576
+ func (r WireRow) ProbeBoolAt(field string, pos *int) BoolProbe { return ProbeBoolOf(r.at(field, pos)) }
577
+ func (r WireRow) ProbeRowAt(field string, pos *int) RowProbe { return ProbeRowOf(r.at(field, pos)) }
578
+ func (r WireRow) ProbeListAt(field string, pos *int) ListProbe { return ProbeListOf(r.at(field, pos)) }
528
579
 
529
580
  func (l WireList) Len() int { return len(l.items) }
530
581
  func (l WireList) ElemString(i int) StringProbe { return ProbeStringOf(&l.items[i]) }
@@ -1054,17 +1105,18 @@ function coverageRejectReason(comp) {
1054
1105
  return `node '${n.id}' is not a componentRef, map, or cond node (not native-covered)`;
1055
1106
  const cr = n;
1056
1107
  // Every Error Policy Kind IS covered on a componentRef: `continue` makes the node unproduced, which the
1057
- // produced-aware output lowering (emitProducedAwareValue, driven by the same canSkip the bindField skip
1058
- // uses) already renders, and `retry` shares `fail`'s control flow with the Kind named in the failure
1108
+ // produced-aware output lowering (typed.ts `lowerProducedAwareRead`, driven by the same canSkip the
1109
+ // bindField skip uses) already renders, and `retry` shares `fail`'s control flow with the Kind named
1059
1110
  // (the attempts themselves are Runtime-owned — scp-error.md §Separating Policy Kind and Tuning, which
1060
1111
  // in native mode is the per-Component leaf transport). Proven by real go build + run, not by assertion.
1061
1112
  // #86 part 1: a relation child WITH bindField IS covered. When the
1062
1113
  // bound parent field is null/absent the child is UNPRODUCED — the produced-aware output lowering
1063
- // (emitProducedAwareValue) then yields the unproduced rep (null / opt-nil) for a ref/refOpt into
1064
- // it, matching run_behavior's writeUnproduced. #93 shape 1: a bindField on a relationKind:connection
1065
- // child is ALSO covered — the connection's unproduced rep is the empty connection {items:[],cursor:null}
1066
- // (unproducedValue("connection")), which emitProducedAwareValue emits explicitly for a skipped
1067
- // connection node (a ref into it yields {items:[],cursor:null}, matching run_behavior).
1114
+ // (`lowerProducedAwareRead`, handed to the ONE output recursion so it reaches every output slot) then
1115
+ // yields the unproduced rep (null / opt-nil) for a ref/refOpt into it, matching run_behavior's
1116
+ // writeUnproduced. #93 shape 1: a bindField on a relationKind:connection child is ALSO covered — the
1117
+ // connection's unproduced rep is the empty connection {items:[],cursor:null}
1118
+ // (unproducedValue("connection")), which `unproducedInSlot` emits explicitly for a skipped connection
1119
+ // node (a ref into it yields {items:[],cursor:null}, matching run_behavior).
1068
1120
  // relationKind の閉集合は `connection` の 1 値で、**注記の不在**が「未生成は null」を意味する。ゆえに
1069
1121
  // bindField 由来 skip は 2 形(connection = 空 connection / 不在 = null)とも produced-aware 出力が
1070
1122
  // 表現でき、被覆条件は無い(かつての「明示的に single と書け」は既定値の重複綴りの要求だった)。
@@ -1395,7 +1447,7 @@ function emitPortWireField(pn, expr, comp, plan, typedNodes, isPrior, expected,
1395
1447
  // #238: a port lowering hoists its fallible statements into the payload-entry closure, whose early
1396
1448
  // return is `return <GO_PORTS_ZERO>, err` — NOT the runner's own zero (see goPortEntries).
1397
1449
  const c = compilePortNode(expr, comp, plan, typedNodes, isPrior, `port '${pn}'`, expected, { ...opts, earlyZero: GO_PORTS_ZERO });
1398
- const q = opts?.wireSel !== undefined && opts.wireSel !== "" ? `${opts.wireSel}.` : "";
1450
+ const q = goWireQ(opts?.wireSel);
1399
1451
  const boxed = renderGoWireBox(buildWirePlan(c.ref, { from: "top" }, { model: "port", field: pn, plan }, "in"), c.expr, opts?.wireSel);
1400
1452
  return { stmts: c.stmts, field: `${q}WireField{Key: ${JSON.stringify(pn)}, Val: ${boxed}}` };
1401
1453
  }
@@ -1633,7 +1685,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1633
1685
  lines.push(`\t\t\tif row_${s}Err == nil {`);
1634
1686
  lines.push(`\t\t\t\tdec_${s}, dec_${s}DErr := func() (${nodeGo}, error) {`);
1635
1687
  lines.push(`\t\t\t\t\tvar out ${nodeGo}`);
1636
- lines.push(renderResultDeBox(ref, "out", `wire_${s}`, node.id, plan, "\t\t\t\t\t", nodeZeroFail, nodeWirePassthrough(node)));
1688
+ lines.push(renderResultDeBox(ref, "out", `wire_${s}`, node.id, plan, "\t\t\t\t\t", nodeZeroFail, wire.selector, nodeWirePassthrough(node)));
1637
1689
  lines.push(`\t\t\t\t\treturn out, nil`);
1638
1690
  lines.push(`\t\t\t\t}()`);
1639
1691
  lines.push(`\t\t\t\tif dec_${s}DErr == nil {`);
@@ -1646,7 +1698,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1646
1698
  lines.push(`\t\t\tif row_${s}Err != nil {`);
1647
1699
  lines.push(`\t\t\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${JSON.stringify(meta.policy === "retry" ? "retry" : "fail")}, row_${s}Err)`);
1648
1700
  lines.push(`\t\t\t}`);
1649
- lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, "\t\t\t", returnZeroFail(zeroOut), nodeWirePassthrough(node)));
1701
+ lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, "\t\t\t", returnZeroFail(zeroOut), wire.selector, nodeWirePassthrough(node)));
1650
1702
  lines.push(`\t\t\tproduced_${s} = true`);
1651
1703
  }
1652
1704
  lines.push(`\t\t}`);
@@ -1816,7 +1868,7 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
1816
1868
  // interpreter checks the declared outType in wrappedExec, OUTSIDE the policy interpretation, and
1817
1869
  // throws — so it must propagate here too, or the two surfaces disagree on the same IR.
1818
1870
  lines.push(`${indent}if wire_${s}, wire_${s}Err := ${call}; wire_${s}Err == nil {`);
1819
- lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, `${indent}\t`, returnZeroFail(zeroOut), nodeWirePassthrough(node), seqCtr));
1871
+ lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, `${indent}\t`, returnZeroFail(zeroOut), wire.selector, nodeWirePassthrough(node), seqCtr));
1820
1872
  lines.push(`${indent}\tproduced_${s} = true`);
1821
1873
  lines.push(`${indent}}`);
1822
1874
  }
@@ -1826,7 +1878,7 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
1826
1878
  lines.push(`${indent}if wire_${s}Err != nil {`);
1827
1879
  lines.push(`${indent}\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${policyLit}, wire_${s}Err)`);
1828
1880
  lines.push(`${indent}}`);
1829
- lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, indent, returnZeroFail(zeroOut), nodeWirePassthrough(node), seqCtr));
1881
+ lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, indent, returnZeroFail(zeroOut), wire.selector, nodeWirePassthrough(node), seqCtr));
1830
1882
  lines.push(`${indent}produced_${s} = true`);
1831
1883
  }
1832
1884
  for (const c of closers)
@@ -1854,12 +1906,12 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
1854
1906
  skippableKind.set(id, rk);
1855
1907
  }
1856
1908
  }
1857
- const out = skippable.size > 0
1858
- ? emitProducedAwareValue(comp.output, outRef, typedNodes, plan, skippable, skippableKind, comp.name, "<output>")
1859
- : emitTypedValue(comp.output, outRef, typedNodes, plan, comp.name, "<output>");
1909
+ // ONE output recursion (#295): the produced-aware read is a REF-position lowering handed to it, not a
1910
+ // second recursion — so it reaches EVERY slot the recursion descends into, an array element included.
1911
+ const out = emitTypedValue(comp.output, outRef, typedNodes, plan, comp.name, "<output>", skippable.size > 0 ? goSlotRefLowering(typedNodes, plan, skippable, skippableKind, comp.name) : undefined);
1860
1912
  // top-level output that is a bare node-result (not an obj/arr assembly): its honest `ref` must equal the
1861
1913
  // declared component output type, or the emitted `return <out>, nil` does not compile.
1862
- checkOutputFieldType(comp.name, "<output>", outRef, out.ref, plan);
1914
+ checkOutputFieldType(comp.name, "<output>", outRef, out.ref);
1863
1915
  lines.push(`\treturn ${out.expr}, nil`);
1864
1916
  lines.push(`}`);
1865
1917
  return { code: lines.join("\n"), outRef: out.ref ?? outRef };
@@ -1965,18 +2017,21 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1965
2017
  // throw); elementPolicy still governs the handler's own leaf failures only.
1966
2018
  const elemRowRef = mapElemRowRef(node, arrRef, plan);
1967
2019
  const elemRowGo = renderTypeRef(elemRowRef);
1968
- const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), nodeWirePassthrough(node));
2020
+ const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node));
1969
2021
  // #177/#182 keep-with-skip-value: the into value for a guard-skipped element is driven by relationKind,
1970
2022
  // NOT by opt-ness (matching run_behavior applyInto, which fills a connection into with the empty
1971
2023
  // connection UNCONDITIONALLY on relationKind==="connection"):
1972
- // - connection into → the connection-zero in the field's typed rep (goConnectionUnproduced): a required
1973
- // `Conn` field → `Tn{}`, an OPT `*Conn` field → a non-nil `&Tn{}` (Some(empty connection), NOT nil).
1974
- // `Tn{}`'s serializer normalizes nil items to [] → {items:[],cursor:null} (#182).
2024
+ // - connection into → the connection-zero in the field's typed rep: a required `Conn` field → `Tn{}`, an
2025
+ // OPT `*Conn` field → a non-nil `&Tn{}` (Some(empty connection), NOT nil). `Tn{}`'s serializer
2026
+ // normalizes nil items to [] → {items:[],cursor:null} (#182).
1975
2027
  // - non-connection into → the go zero (opt → nil = null, #177 keep-with-null; unchanged).
2028
+ // That IS the produced-aware output read's unproduced arm, at a different position — so it reads the SAME
2029
+ // rule (typed.ts `unproducedInSlot`) with the same go spellings, not a second copy of it. The `into` attach
2030
+ // point always receives the child result WHOLE (there is no path into it), hence `whole: true`.
1976
2031
  // LAZY: the skip value exists only for a GUARDED map...into (the two call sites below). An opaque-wire
1977
2032
  // element (bc#164) has no zero — and no `into` either (mapElemRowRef requires a named struct for into),
1978
2033
  // so computing it eagerly would fail-close a shape that never uses it.
1979
- const intoSkipZero = () => (m.relationKind === "connection" ? goConnectionUnproduced(elemRowRef, elemRowRef) : goZero(elemRowRef));
2034
+ const intoSkipZero = () => unproducedInSlot(elemRowRef, m.relationKind, true, GO_PRODUCED_AWARE);
1980
2035
  // emit the per-element guard keep-gate (#108). `il` = indent, `elemVar` = the over element loop var.
1981
2036
  // On skip: batched → `continue` (element excluded from items + keptOver); non-batched → `continue`.
1982
2037
  const emitGuard = (il, elemVar, onSkip = ["continue"]) => {
@@ -2253,7 +2308,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
2253
2308
  lines.push(`${indent}\tfor fi_${s} := range fw_${s} {`);
2254
2309
  lines.push(`${indent}\t\tvar el_${s} ${elemGo}`);
2255
2310
  lines.push(`${indent}\t\tif !fw_${s}[fi_${s}].IsNull() {`);
2256
- lines.push(renderResultDeBox(elemRef, `el_${s}`, `fw_${s}[fi_${s}]`, node.id, plan, `${indent}\t\t\t`, returnZeroFail(zeroOut), nodeWirePassthrough(node)));
2311
+ lines.push(renderResultDeBox(elemRef, `el_${s}`, `fw_${s}[fi_${s}]`, node.id, plan, `${indent}\t\t\t`, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node)));
2257
2312
  lines.push(`${indent}\t\t}`);
2258
2313
  lines.push(`${indent}\t\tkey_${s} := el_${s}.${dkGo}`);
2259
2314
  if (f.drop === "dangling") {
@@ -2360,104 +2415,53 @@ function emitCondArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut)
2360
2415
  return lines.join("\n");
2361
2416
  }
2362
2417
  /**
2363
- * emitProducedAwareValue — the #86 part 1 produced-aware output lowering (go). It mirrors the
2364
- * boxed-typed emitTypedValue, but a `ref`/`refOpt` whose HEAD is a skippable relation child is
2365
- * gated on that node's `produced_<id>` flag: when the child is UNPRODUCED (bound parent field was
2366
- * null/absent), run_behavior's writeUnproduced makes the node null, so a refOpt into it yields null
2367
- * (the output opt field => nil). We emit that exactly: `if produced_<head> { <typed field access> }
2368
- * else { <unproduced-rep for the expected type> }`. Obj/arr/concat/literal recurse; a ref into a
2369
- * NON-skippable node delegates to the plain typed field access (identical to emitTypedValue).
2418
+ * GO_PRODUCED_AWARE — the go SPELLINGS of the shared produced-aware output lowering (typed.ts
2419
+ * {@link lowerProducedAwareRead} / {@link unproducedInSlot}). Only the syntax lives here: Go has no
2420
+ * expression `if` (hence the IIFE) and `&<expr>` on a temporary is not addressable (hence the fresh
2421
+ * pointer). The rule — which arm, what the unproduced arm holds, which type both arms must agree on, and
2422
+ * when the slot cannot represent the unproduced read — is language-neutral and is NOT restated here.
2370
2423
  */
2371
- function emitProducedAwareValue(node, expected, typedNodes, plan, skippable, skippableKind, compName, fieldPath) {
2372
- // ref / refOpt (classifyExpr encodes both as kind:"ref" with .opt).
2373
- const e = classifyExpr(node);
2374
- if (e.kind === "ref" && e.path.length >= 1 && typedNodes.has(e.path[0])) {
2375
- const head = e.path[0];
2376
- const baseRef = typedNodes.get(head);
2377
- if (skippable.has(head)) {
2378
- // produced-aware: gate the field access on produced_<head>. The unproduced branch yields the
2379
- // node's unproduced rep per run_behavior's writeUnproduced (unproducedValue(relationKind)):
2380
- // - single / absent → null (opt-nil);
2381
- // - connection (#93 shape 1) → the empty connection {items:[],cursor:null}. Because a WHOLE
2382
- // connection node has no field path (e.path.length===1), the unproduced rep is the struct
2383
- // zero of the connection struct (its serializer normalizes a nil items slice to [] and the
2384
- // nil cursor to null) — matching unproducedValue("connection") byte-for-byte.
2385
- const { expr, ref } = goTypedInternals.typedFieldAccess(typedLocal(head), baseRef, e.path.slice(1), plan);
2386
- const producedFlag = `produced_${sanitize(head)}`;
2387
- // The value placed into this output field is `producedExpr` — valueLeafTyped returns a *T (opt-wrap)
2388
- // iff the field is opt and the value is not; otherwise the bare `ref` value. Its rendered type must
2389
- // equal the func()'s declared return type = renderTypeRef(expected). That is exactly what the Go
2390
- // compiler checks, so this fires IFF the emitted module would not compile (type mismatch).
2391
- const placed = expected && expected.kind === "opt" && ref.kind !== "opt" ? { kind: "opt", inner: ref } : ref;
2392
- checkOutputFieldType(compName, fieldPath, expected, placed, plan);
2393
- const producedExpr = valueLeafTyped(expr, ref, e.opt, expected);
2394
- const outTy = expected ? renderTypeRef(expected) : renderTypeRef(ref);
2395
- const isConn = skippableKind.get(head) === "connection" && e.path.length === 1;
2396
- // For a connection whole-node ref, the unproduced rep is the connection struct zero (empty
2397
- // items + nil cursor), even if the output field is opt (refOpt): run_behavior always writes the
2398
- // empty connection, never null. For single/field-access, the expected-type zero (nil for opt).
2399
- const unproduced = isConn ? goConnectionUnproduced(ref, expected) : goZero(expected ?? ref);
2400
- return {
2401
- expr: `func() ${outTy} { if ${producedFlag} { return ${producedExpr} }; return ${unproduced} }()`,
2402
- ref: expected ?? ref,
2403
- };
2404
- }
2405
- // non-skippable node ref — identical to emitTypedValue's typed field access. Its `ref` is returned
2406
- // honestly (not laundered), so the placing site — the obj-field assembly below, or the top-level call —
2407
- // runs checkOutputFieldType against the field type.
2408
- const { expr, ref } = goTypedInternals.typedFieldAccess(typedLocal(head), baseRef, e.path.slice(1), plan);
2409
- return { expr, ref };
2410
- }
2411
- // obj-assembly: recurse each field with the produced-aware lowering (the struct fields may each
2412
- // ref a skippable node). Only handle the covered named-struct obj output.
2413
- if (node !== null && typeof node === "object" && !Array.isArray(node)) {
2414
- const keys = Object.keys(node);
2415
- if (keys.length === 1 && keys[0] === "obj" && expected && expected.kind === "named") {
2416
- const decl = findDecl(plan, expected.name);
2417
- const fields = node.obj;
2418
- const inits = decl.fields.map((f) => {
2419
- const childPath = fieldPath === "" ? f.name : `${fieldPath}.${f.name}`;
2420
- const sub = emitProducedAwareValue(fields[f.name], f.type, typedNodes, plan, skippable, skippableKind, compName, childPath);
2421
- // Non-skippable field: sub.ref is the honest value type → catches a mismatch here. A skippable field
2422
- // launders sub.ref to expected, but its own produced-arm check (above) already fired.
2423
- checkOutputFieldType(compName, childPath, f.type, sub.ref, plan);
2424
- return `${goFieldName(f.name)}: ${sub.expr}`;
2425
- });
2426
- return { expr: `${expected.name}{${inits.join(", ")}}`, ref: expected };
2427
- }
2428
- }
2429
- // everything else (literal / non-skippable ref / obj-of-non-named / arr / concat) — delegate to
2430
- // the plain typed lowering (no skippable head reachable there in the covered corpus).
2431
- return emitTypedValue(node, expected, typedNodes, plan, compName, fieldPath);
2432
- }
2433
- /** Lower a typed field-access expr to the EXPECTED output type (used in the produced branch). When
2434
- * the expected type is `opt` and the accessed value is already a *T pointer (the field itself is
2435
- * opt), pass it through; when the accessed value is a bare leaf and expected is opt, take its addr. */
2436
- function valueLeafTyped(expr, ref, opt, expected) {
2437
- void opt;
2438
- if (expected && expected.kind === "opt") {
2439
- if (ref.kind === "opt")
2440
- return expr; // *T already
2441
- // wrap a bare value in a fresh pointer (matches renderTypeRef(opt)=*T).
2442
- return `func() ${renderTypeRef(expected)} { __v := ${expr}; return &__v }()`;
2443
- }
2444
- return expr;
2445
- }
2424
+ const GO_PRODUCED_AWARE = {
2425
+ producedFlag: (head) => `produced_${sanitize(head)}`,
2426
+ optSome: (valueExpr, placed) => `func() ${renderTypeRef(placed)} { __v := ${valueExpr}; return &__v }()`,
2427
+ zero: goZero,
2428
+ conditional: (cond, present, absent, placed) => `func() ${renderTypeRef(placed)} { if ${cond} { return ${present} }; return ${absent} }()`,
2429
+ };
2446
2430
  /**
2447
- * goConnectionUnproduced — the unproduced rep for a SKIPPED relationKind:connection node (#93 shape
2448
- * 1): the empty connection {items:[],cursor:null}. The connection outType is a named struct whose
2449
- * serializer normalizes a nil items slice to [] and a nil cursor to null, so the struct ZERO
2450
- * (`Tn{}`) serializes to exactly unproducedValue("connection"). When the output field is opt
2451
- * (refOpt into the connection), run_behavior still writes the empty connection (never null), so we
2452
- * wrap the struct zero in a fresh pointer rather than yielding nil.
2431
+ * goSlotRefLowering — the go binding of the ONE output recursion's node-result-reference seam
2432
+ * ({@link SlotRefLowering}), used when ANY covered node can SKIP (#86 part 1).
2433
+ *
2434
+ * `ref`/`refOpt` into a SKIPPABLE node lowers through the shared produced-aware rule; into any other typed
2435
+ * node it is the plain typed field access (identical to what the recursion's own `ref` branch emits, but
2436
+ * reached through `classifyExpr` so `refOpt` resolves here too). Anything else returns undefined and the ONE
2437
+ * recursion keeps handling it.
2453
2438
  */
2454
- function goConnectionUnproduced(nodeRef, expected) {
2455
- const connRef = expected && expected.kind === "opt" ? expected.inner : (expected ?? nodeRef);
2456
- const zero = goZero(connRef);
2457
- if (expected && expected.kind === "opt") {
2458
- return `func() ${renderTypeRef(expected)} { __c := ${zero}; return &__c }()`;
2459
- }
2460
- return zero;
2439
+ function goSlotRefLowering(typedNodes, plan, skippable, skippableKind, compName) {
2440
+ return (node, declared, fieldPath) => {
2441
+ // ref / refOpt (classifyExpr encodes both as kind:"ref" with .opt).
2442
+ const e = classifyExpr(node);
2443
+ if (e.kind !== "ref" || e.path.length < 1 || !typedNodes.has(e.path[0]))
2444
+ return undefined;
2445
+ const head = e.path[0];
2446
+ const { expr, ref } = goTypedInternals.typedFieldAccess(typedLocal(head), typedNodes.get(head), e.path.slice(1), plan);
2447
+ // a NON-skippable node's `ref` is returned honestly (not laundered), so the PLACING site runs
2448
+ // checkOutputFieldType against the slot type.
2449
+ if (!skippable.has(head))
2450
+ return { expr, ref };
2451
+ return lowerProducedAwareRead({
2452
+ path: e.path,
2453
+ relationKind: skippableKind.get(head),
2454
+ optional: e.opt,
2455
+ valueExpr: expr,
2456
+ value: ref,
2457
+ declared,
2458
+ compName,
2459
+ fieldPath,
2460
+ check: checkOutputFieldType,
2461
+ spell: GO_PRODUCED_AWARE,
2462
+ plan,
2463
+ });
2464
+ };
2461
2465
  }
2462
2466
  /** Go zero value for a TypeRef (used as the error return of the struct runner). */
2463
2467
  function goZero(ref) {
@@ -2548,7 +2552,7 @@ function renderGoWireBox(plan, srcExpr, wireSel, depth = 0) {
2548
2552
  // package alongside the wire TYPE, so qualify them with the same selector (`wire.WireFloat(...)`,
2549
2553
  // `[]wire.WireField{…}`); in-package they are local (bare). Without this the type is `wire.WireValue` but the
2550
2554
  // ctor is a bare `WireFloat` → does not compile.
2551
- const q = wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : "";
2555
+ const q = goWireQ(wireSel);
2552
2556
  // boxBase — box a BASE-typed (non-opt) expr per the plan's kind. Both the required (optDepth 0) path and the
2553
2557
  // opt arm (after its null-guard + deref) fold through this ONE walk, so the opt element reuses the SAME
2554
2558
  // per-kind box (no parallel path). The union is exhausted below; the trailing throw is a bare exhaustiveness
@@ -2620,6 +2624,7 @@ function makeGoExprBackend(zeroOut, resolveHead, plan,
2620
2624
  // #174: cross-package selector for the shared wire constructors (`wire`); undefined/"" ⇒ in-package (bare).
2621
2625
  wireSel) {
2622
2626
  const used = goExprUsed;
2627
+ const q = goWireQ(wireSel);
2623
2628
  return {
2624
2629
  lang: "go",
2625
2630
  freshTemp: () => `ex_${goExprTempSeq++}`,
@@ -2629,10 +2634,12 @@ wireSel) {
2629
2634
  wireBox: (item) => renderGoWireBox(buildWirePlan(item.ref, { from: "top" }, { model: "port", field: "port", plan }, "in"), item.expr, wireSel),
2630
2635
  // bc#178: box EACH element of the typed slice into an arr<value> ([]WireValue) — the same per-element box
2631
2636
  // renderer as wireBox's list case, applied over the referenced array (box-once/element).
2632
- wireBoxEachElem: (srcExpr, elemRef) => {
2637
+ // `range` walks the slice's own backing array — Go owes no copy here (which is why `src.borrowed` is a
2638
+ // Rust-only concern and never set on this surface; see NativeExprBackend.wireBoxEachElem).
2639
+ wireBoxEachElem: (src, elemRef) => {
2633
2640
  const vt = renderTypeRef({ kind: "value" });
2634
2641
  const box = renderGoWireBox(buildWirePlan(elemRef, { from: "elem" }, { model: "port", field: "port", plan }, "in"), "__be", wireSel);
2635
- return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${srcExpr} { __out = append(__out, ${box}) }; return __out }()`;
2642
+ return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${src.expr} { __out = append(__out, ${box}) }; return __out }()`;
2636
2643
  },
2637
2644
  scalarType: (s) => goScalar(s),
2638
2645
  strLit: (s) => JSON.stringify(s),
@@ -2658,11 +2665,14 @@ wireSel) {
2658
2665
  return `(${parts.join(" + ")})`;
2659
2666
  },
2660
2667
  notOp: (a) => `(!${a})`,
2668
+ // #309: go has no clippy — the complement of a float ordering compare is spelled with the plain `!`
2669
+ // (`(!(a > b))`, the form this surface has always emitted), so the go module is byte-unchanged.
2670
+ negPartialOrdCmp: (op, a, b) => `(!(${a} ${op === "lt" ? "<" : op === "le" ? "<=" : op === "gt" ? ">" : ">="} ${b}))`,
2661
2671
  structLit: (name, inits) => `${name}{${inits.map((i) => `${goFieldName(i.field)}: ${i.expr}`).join(", ")}}`,
2662
2672
  arrLit: (elemTy, items) => `[]${elemTy}{${items.join(", ")}}`,
2663
2673
  // #209: the opaque wire built directly from an inline composite literal at a `value` port.
2664
- wireRowLit: (entries) => `${wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : ""}WireRowOf([]${wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : ""}WireField{${entries.map((e) => `{Key: ${JSON.stringify(e.key)}, Val: ${e.expr}}`).join(", ")}})`,
2665
- wireListLit: (items) => `${wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : ""}WireListOf([]${wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : ""}WireValue{${items.join(", ")}})`,
2674
+ wireRowLit: (entries) => `${q}WireRowOf([]${q}WireField{${entries.map((e) => `{Key: ${JSON.stringify(e.key)}, Val: ${e.expr}}`).join(", ")}})`,
2675
+ wireListLit: (items) => `${q}WireListOf([]${q}WireValue{${items.join(", ")}})`,
2666
2676
  // #209: a string-keyed map literal — `map[string]V{"k": v, …}`. Go maps are unordered; the shared
2667
2677
  // serializer (`serMap`) emits keys in code-point order, so entry order here is not observable.
2668
2678
  mapLit: (valueTy, entries) => `map[string]${valueTy}{${entries.map((e) => `${JSON.stringify(e.key)}: ${e.expr}`).join(", ")}}`,
@@ -2688,10 +2698,12 @@ wireSel) {
2688
2698
  // ONE box SSoT (renderGoWireBox — the SAME call shape as wireBox) and keeping absent nil. A self-contained
2689
2699
  // IIFE (no hoisted stmts): bind the pointer ONCE, nil ⇒ nil (absent stays absent — NOT WireNull, that is
2690
2700
  // the required-`value` collapse), present ⇒ box the deref'd inner and return its address.
2691
- optMapWireBox: (optExpr, innerRef) => {
2701
+ // Go has no ownership to track (a struct/slice IS a value), so `src.borrowed` is never set and the
2702
+ // compiled `expr` is always what this boxes — see NativeExprBackend.optMapWireBox.
2703
+ optMapWireBox: (src, innerRef) => {
2692
2704
  const vt = renderTypeRef({ kind: "value" });
2693
2705
  const box = renderGoWireBox(buildWirePlan(innerRef, { from: "top" }, { model: "port", field: "port", plan }, "in"), "__ov", wireSel);
2694
- return `func() *${vt} { __oo := ${optExpr}; if __oo == nil { return nil }; __ov := (*__oo); __ob := ${box}; return &__ob }()`;
2706
+ return `func() *${vt} { __oo := ${src.expr}; if __oo == nil { return nil }; __ov := (*__oo); __ob := ${box}; return &__ob }()`;
2695
2707
  },
2696
2708
  // opt (`*T`) defaulted to a PURE default — an immediately-invoked func literal: bind the pointer ONCE,
2697
2709
  // deref when present, else yield the default (evaluated only when absent — run_behavior's lazy right).