behavior-contracts 0.11.17 → 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.
- package/cli-contract.yaml +9 -4
- package/dist/behavior.d.ts +16 -7
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +19 -8
- package/dist/behavior.js.map +1 -1
- package/dist/cli.js +4 -2
- package/dist/cli.js.map +1 -1
- package/dist/expr-eval.d.ts +8 -1
- package/dist/expr-eval.d.ts.map +1 -1
- package/dist/expr-eval.js +11 -2
- package/dist/expr-eval.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/generator/core.d.ts +4 -2
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-shared-go-typed.d.ts +8 -12
- package/dist/generator/emit-shared-go-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-go-typed.js +40 -25
- package/dist/generator/emit-shared-go-typed.js.map +1 -1
- package/dist/generator/emit-shared-rust-typed.d.ts +12 -16
- package/dist/generator/emit-shared-rust-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-rust-typed.js +45 -30
- package/dist/generator/emit-shared-rust-typed.js.map +1 -1
- package/dist/generator/emit-shared-typescript-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript-typed.js +10 -2
- package/dist/generator/emit-shared-typescript-typed.js.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.d.ts.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js +15 -23
- package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +185 -141
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +556 -283
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/native-expr.d.ts +73 -7
- package/dist/generator/native-expr.d.ts.map +1 -1
- package/dist/generator/native-expr.js +121 -39
- package/dist/generator/native-expr.js.map +1 -1
- package/dist/generator/typed.d.ts +165 -0
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +156 -1
- package/dist/generator/typed.js.map +1 -1
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
322
|
-
|
|
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
|
-
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
func (r WireRow)
|
|
526
|
-
func (r WireRow)
|
|
527
|
-
func (r WireRow)
|
|
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 (
|
|
1058
|
-
// uses) already renders, and `retry` shares `fail`'s control flow with the Kind named
|
|
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
|
-
// (
|
|
1064
|
-
//
|
|
1065
|
-
//
|
|
1066
|
-
//
|
|
1067
|
-
// connection
|
|
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
|
|
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
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
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
|
|
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
|
|
1973
|
-
//
|
|
1974
|
-
//
|
|
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
|
|
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
|
-
*
|
|
2364
|
-
*
|
|
2365
|
-
*
|
|
2366
|
-
*
|
|
2367
|
-
*
|
|
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
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
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
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2452
|
-
*
|
|
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
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
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) {
|
|
@@ -2505,6 +2509,22 @@ let goExprTempSeq = 0;
|
|
|
2505
2509
|
/** module-level accumulator: set true when the native-expr compiler emits a fallible helper call
|
|
2506
2510
|
* (so emit() includes the helper library + imports `math`). Reset at the start of each emit(). */
|
|
2507
2511
|
const goExprUsed = { helpers: false };
|
|
2512
|
+
/**
|
|
2513
|
+
* Parenthesize a TypeName-form composite literal (`Ident{…}` / `pkg.Ident{…}`) so it is safe as the BASE
|
|
2514
|
+
* of a selector (`x.Field`) or the operand of a `range`/`if`/`for` header. Go's grammar forbids a BARE
|
|
2515
|
+
* `TypeName{…}` composite literal there — the `{` is parsed as the block open — so `range DynamicWherePlan{…}.Frags`
|
|
2516
|
+
* fails to parse. `[]T{…}` / `map[…]…{…}` / `[N]T{…}` (LiteralType forms that start with `[`/`map`) are
|
|
2517
|
+
* unambiguous and are left untouched, as is anything already parenthesized or a plain variable/selector.
|
|
2518
|
+
* Wrapping is semantically identity (`(T{…}).F` ≡ `T{…}.F`) so it never changes the output for a base that
|
|
2519
|
+
* was already valid. This is the ONE place the wire-box walk turns a materialized struct literal into a
|
|
2520
|
+
* selector base, so it is the single, general place the ambiguity is resolved.
|
|
2521
|
+
*/
|
|
2522
|
+
function goParenIfTypeNameComposite(expr) {
|
|
2523
|
+
// A TypeName composite literal: a (possibly package-qualified) identifier immediately followed by `{`,
|
|
2524
|
+
// and the whole expression is that one literal (ends at the matching `}`). Slice/map/array literals start
|
|
2525
|
+
// with `[`/`map[`; a selector/deref/paren base starts with `(`/`*`/`[` — none match this anchor.
|
|
2526
|
+
return /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*\{.*\}$/s.test(expr) ? `(${expr})` : expr;
|
|
2527
|
+
}
|
|
2508
2528
|
/** GoNativeExprBackend — renders native-expr for Go. `zeroOut` is the runner's error-return zero
|
|
2509
2529
|
* value; `resolveHead` maps a ref head (input port / input-array $as elem / prior node) to a typed
|
|
2510
2530
|
* base expr. Sets goExprUsed.helpers when a fallible helper is emitted (so emit() bakes the helper lib). */
|
|
@@ -2532,7 +2552,7 @@ function renderGoWireBox(plan, srcExpr, wireSel, depth = 0) {
|
|
|
2532
2552
|
// package alongside the wire TYPE, so qualify them with the same selector (`wire.WireFloat(...)`,
|
|
2533
2553
|
// `[]wire.WireField{…}`); in-package they are local (bare). Without this the type is `wire.WireValue` but the
|
|
2534
2554
|
// ctor is a bare `WireFloat` → does not compile.
|
|
2535
|
-
const q = wireSel
|
|
2555
|
+
const q = goWireQ(wireSel);
|
|
2536
2556
|
// boxBase — box a BASE-typed (non-opt) expr per the plan's kind. Both the required (optDepth 0) path and the
|
|
2537
2557
|
// opt arm (after its null-guard + deref) fold through this ONE walk, so the opt element reuses the SAME
|
|
2538
2558
|
// per-kind box (no parallel path). The union is exhausted below; the trailing throw is a bare exhaustiveness
|
|
@@ -2555,7 +2575,7 @@ function renderGoWireBox(plan, srcExpr, wireSel, depth = 0) {
|
|
|
2555
2575
|
if (plan.k === "record") {
|
|
2556
2576
|
// typed struct → wire map: box each declared field off its native struct field (no probe — the value is
|
|
2557
2577
|
// already typed), assemble a WireRow of (name, WireValue) in declared-field order.
|
|
2558
|
-
const entries = plan.fields.map((f) => `{Key: ${JSON.stringify(f.name)}, Val: ${renderGoWireBox(f.plan, `${baseSrc}.${goFieldName(f.name)}`, wireSel, depth + 1)}}`);
|
|
2578
|
+
const entries = plan.fields.map((f) => `{Key: ${JSON.stringify(f.name)}, Val: ${renderGoWireBox(f.plan, `${goParenIfTypeNameComposite(baseSrc)}.${goFieldName(f.name)}`, wireSel, depth + 1)}}`);
|
|
2559
2579
|
return `${q}WireRowOf([]${q}WireField{${entries.join(", ")}})`;
|
|
2560
2580
|
}
|
|
2561
2581
|
if (plan.k === "list") {
|
|
@@ -2604,6 +2624,7 @@ function makeGoExprBackend(zeroOut, resolveHead, plan,
|
|
|
2604
2624
|
// #174: cross-package selector for the shared wire constructors (`wire`); undefined/"" ⇒ in-package (bare).
|
|
2605
2625
|
wireSel) {
|
|
2606
2626
|
const used = goExprUsed;
|
|
2627
|
+
const q = goWireQ(wireSel);
|
|
2607
2628
|
return {
|
|
2608
2629
|
lang: "go",
|
|
2609
2630
|
freshTemp: () => `ex_${goExprTempSeq++}`,
|
|
@@ -2613,10 +2634,12 @@ wireSel) {
|
|
|
2613
2634
|
wireBox: (item) => renderGoWireBox(buildWirePlan(item.ref, { from: "top" }, { model: "port", field: "port", plan }, "in"), item.expr, wireSel),
|
|
2614
2635
|
// bc#178: box EACH element of the typed slice into an arr<value> ([]WireValue) — the same per-element box
|
|
2615
2636
|
// renderer as wireBox's list case, applied over the referenced array (box-once/element).
|
|
2616
|
-
|
|
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) => {
|
|
2617
2640
|
const vt = renderTypeRef({ kind: "value" });
|
|
2618
2641
|
const box = renderGoWireBox(buildWirePlan(elemRef, { from: "elem" }, { model: "port", field: "port", plan }, "in"), "__be", wireSel);
|
|
2619
|
-
return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${
|
|
2642
|
+
return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${src.expr} { __out = append(__out, ${box}) }; return __out }()`;
|
|
2620
2643
|
},
|
|
2621
2644
|
scalarType: (s) => goScalar(s),
|
|
2622
2645
|
strLit: (s) => JSON.stringify(s),
|
|
@@ -2642,11 +2665,14 @@ wireSel) {
|
|
|
2642
2665
|
return `(${parts.join(" + ")})`;
|
|
2643
2666
|
},
|
|
2644
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}))`,
|
|
2645
2671
|
structLit: (name, inits) => `${name}{${inits.map((i) => `${goFieldName(i.field)}: ${i.expr}`).join(", ")}}`,
|
|
2646
2672
|
arrLit: (elemTy, items) => `[]${elemTy}{${items.join(", ")}}`,
|
|
2647
2673
|
// #209: the opaque wire built directly from an inline composite literal at a `value` port.
|
|
2648
|
-
wireRowLit: (entries) => `${
|
|
2649
|
-
wireListLit: (items) => `${
|
|
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(", ")}})`,
|
|
2650
2676
|
// #209: a string-keyed map literal — `map[string]V{"k": v, …}`. Go maps are unordered; the shared
|
|
2651
2677
|
// serializer (`serMap`) emits keys in code-point order, so entry order here is not observable.
|
|
2652
2678
|
mapLit: (valueTy, entries) => `map[string]${valueTy}{${entries.map((e) => `${JSON.stringify(e.key)}: ${e.expr}`).join(", ")}}`,
|
|
@@ -2661,6 +2687,24 @@ wireSel) {
|
|
|
2661
2687
|
// construction: the gated child / guarded element only runs when the ref is non-null (the nil case is
|
|
2662
2688
|
// statically unreachable in the proven scope). NOT a default — there is no fallback value.
|
|
2663
2689
|
narrowUnwrap: (optExpr, _innerRef) => `(*(${optExpr}))`,
|
|
2690
|
+
// #275: wrap a present inner value in SOME. Go opt is `*T` and cannot take `&<literal/temporary>`, so
|
|
2691
|
+
// hoist the value to a temp and return its address (`_optN := <inner>; &_optN`). The temp escapes to the
|
|
2692
|
+
// heap (address taken + returned) — the standard Go opt-present form, the write twin of optNone's `nil`.
|
|
2693
|
+
optSome: (innerExpr, _innerTy) => {
|
|
2694
|
+
const t = `ex_${goExprTempSeq++}`;
|
|
2695
|
+
return { stmts: [`${t} := ${innerExpr}`], expr: `&${t}` };
|
|
2696
|
+
},
|
|
2697
|
+
// #275: carry an opt<S> (`*S`) through into opt<value> (`*WireValue`), boxing the PRESENT inner via the
|
|
2698
|
+
// ONE box SSoT (renderGoWireBox — the SAME call shape as wireBox) and keeping absent nil. A self-contained
|
|
2699
|
+
// IIFE (no hoisted stmts): bind the pointer ONCE, nil ⇒ nil (absent stays absent — NOT WireNull, that is
|
|
2700
|
+
// the required-`value` collapse), present ⇒ box the deref'd inner and return its address.
|
|
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) => {
|
|
2704
|
+
const vt = renderTypeRef({ kind: "value" });
|
|
2705
|
+
const box = renderGoWireBox(buildWirePlan(innerRef, { from: "top" }, { model: "port", field: "port", plan }, "in"), "__ov", wireSel);
|
|
2706
|
+
return `func() *${vt} { __oo := ${src.expr}; if __oo == nil { return nil }; __ov := (*__oo); __ob := ${box}; return &__ob }()`;
|
|
2707
|
+
},
|
|
2664
2708
|
// opt (`*T`) defaulted to a PURE default — an immediately-invoked func literal: bind the pointer ONCE,
|
|
2665
2709
|
// deref when present, else yield the default (evaluated only when absent — run_behavior's lazy right).
|
|
2666
2710
|
optUnwrapOr: (optExpr, defaultExpr, innerTy) => `func() ${innerTy} { if v := ${optExpr}; v != nil { return *v }; return ${defaultExpr} }()`,
|