behavior-contracts 0.11.18 → 0.11.20
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 +14 -6
- 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-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 +188 -160
- 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 +550 -285
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/native-expr.d.ts +49 -6
- package/dist/generator/native-expr.d.ts.map +1 -1
- package/dist/generator/native-expr.js +87 -21
- package/dist/generator/native-expr.js.map +1 -1
- package/dist/generator/typed.d.ts +149 -0
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +106 -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 と書け」は既定値の重複綴りの要求だった)。
|
|
@@ -1109,6 +1161,16 @@ function leafSymbolBare(component, leaf, specSymbol) {
|
|
|
1109
1161
|
function resolveLeafSymbol(component, leaf, specSymbol) {
|
|
1110
1162
|
return `${goLeafSel(leaf)}${leafSymbolBare(component, leaf, specSymbol)}`;
|
|
1111
1163
|
}
|
|
1164
|
+
/** The entry's `context.Context` parameter: the caller's per-call context (request scope, cancellation,
|
|
1165
|
+
* deadline, values), handed to every leaf transport the entry calls. Go has no goroutine-local storage,
|
|
1166
|
+
* so this parameter is the only way a transport learns which call it is serving. */
|
|
1167
|
+
const GO_CTX_PARAM = "ctx";
|
|
1168
|
+
/** goLeafCall — the ONE spelling of a leaf transport call: `<sym>(ctx, <payload>)`. Every call site (point /
|
|
1169
|
+
* parallel member / map element / batched map / fanout) goes through here, so the transport signature
|
|
1170
|
+
* `<Leaf>(ctx context.Context, payload WireRow) (WireValue, error)` is fixed in one place. */
|
|
1171
|
+
function goLeafCall(sym, payloadExpr) {
|
|
1172
|
+
return `${sym}(${GO_CTX_PARAM}, ${payloadExpr})`;
|
|
1173
|
+
}
|
|
1112
1174
|
/** goWireQ — the shared-package selector qualifier (`wire.`) for the BC-owned wire ctors/types, or "" in-package. */
|
|
1113
1175
|
function goWireQ(wireSel) {
|
|
1114
1176
|
return wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : "";
|
|
@@ -1149,11 +1211,12 @@ function goPackageName(ns) {
|
|
|
1149
1211
|
const safe = ns.replace(/[^A-Za-z0-9]/g, "").toLowerCase();
|
|
1150
1212
|
return safe.length > 0 && /[a-z_]/.test(safe[0]) ? safe : "behaviors";
|
|
1151
1213
|
}
|
|
1152
|
-
/**
|
|
1214
|
+
/** Names a positional-parameter name must not collide with (prefixed with `p_` if it does): the Go
|
|
1215
|
+
* keywords and predeclared constants, plus the entry's own context parameter. */
|
|
1153
1216
|
const GO_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1154
1217
|
"break", "case", "chan", "const", "continue", "default", "defer", "else", "fallthrough", "for", "func",
|
|
1155
1218
|
"go", "goto", "if", "import", "interface", "map", "package", "range", "return", "select", "struct",
|
|
1156
|
-
"switch", "type", "var", "nil", "true", "false", "iota", "in",
|
|
1219
|
+
"switch", "type", "var", "nil", "true", "false", "iota", "in", GO_CTX_PARAM,
|
|
1157
1220
|
]);
|
|
1158
1221
|
/** #192: an input port's positional PARAMETER name — a valid, unexported (lower-first) Go identifier
|
|
1159
1222
|
* from the port name. The single naming for a port's param at both the entry signature and every input
|
|
@@ -1395,7 +1458,7 @@ function emitPortWireField(pn, expr, comp, plan, typedNodes, isPrior, expected,
|
|
|
1395
1458
|
// #238: a port lowering hoists its fallible statements into the payload-entry closure, whose early
|
|
1396
1459
|
// return is `return <GO_PORTS_ZERO>, err` — NOT the runner's own zero (see goPortEntries).
|
|
1397
1460
|
const c = compilePortNode(expr, comp, plan, typedNodes, isPrior, `port '${pn}'`, expected, { ...opts, earlyZero: GO_PORTS_ZERO });
|
|
1398
|
-
const q = opts?.wireSel
|
|
1461
|
+
const q = goWireQ(opts?.wireSel);
|
|
1399
1462
|
const boxed = renderGoWireBox(buildWirePlan(c.ref, { from: "top" }, { model: "port", field: pn, plan }, "in"), c.expr, opts?.wireSel);
|
|
1400
1463
|
return { stmts: c.stmts, field: `${q}WireField{Key: ${JSON.stringify(pn)}, Val: ${boxed}}` };
|
|
1401
1464
|
}
|
|
@@ -1604,7 +1667,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1604
1667
|
lines.push(`\t\t\t\tdefer func() { <-sem }()`);
|
|
1605
1668
|
// DIRECT leaf transport call — ONE op-agnostic symbol, ONE WireRow payload (the preflight-built ports).
|
|
1606
1669
|
// No `bound` (BC's internal produced/skip gate is already applied in preflight — the leaf never sees it).
|
|
1607
|
-
const call =
|
|
1670
|
+
const call = goLeafCall(resolveLeafSymbol(node.component, leaf, node.leafSymbol), `payload_${s}`);
|
|
1608
1671
|
lines.push(`\t\t\t\twire_${s}, row_${s}Err = ${call}`);
|
|
1609
1672
|
lines.push(`\t\t\t}()`);
|
|
1610
1673
|
lines.push(`\t\t}`);
|
|
@@ -1633,7 +1696,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1633
1696
|
lines.push(`\t\t\tif row_${s}Err == nil {`);
|
|
1634
1697
|
lines.push(`\t\t\t\tdec_${s}, dec_${s}DErr := func() (${nodeGo}, error) {`);
|
|
1635
1698
|
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)));
|
|
1699
|
+
lines.push(renderResultDeBox(ref, "out", `wire_${s}`, node.id, plan, "\t\t\t\t\t", nodeZeroFail, wire.selector, nodeWirePassthrough(node)));
|
|
1637
1700
|
lines.push(`\t\t\t\t\treturn out, nil`);
|
|
1638
1701
|
lines.push(`\t\t\t\t}()`);
|
|
1639
1702
|
lines.push(`\t\t\t\tif dec_${s}DErr == nil {`);
|
|
@@ -1646,7 +1709,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1646
1709
|
lines.push(`\t\t\tif row_${s}Err != nil {`);
|
|
1647
1710
|
lines.push(`\t\t\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${JSON.stringify(meta.policy === "retry" ? "retry" : "fail")}, row_${s}Err)`);
|
|
1648
1711
|
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)));
|
|
1712
|
+
lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, "\t\t\t", returnZeroFail(zeroOut), wire.selector, nodeWirePassthrough(node)));
|
|
1650
1713
|
lines.push(`\t\t\tproduced_${s} = true`);
|
|
1651
1714
|
}
|
|
1652
1715
|
lines.push(`\t\t}`);
|
|
@@ -1707,10 +1770,12 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
|
|
|
1707
1770
|
// single ${wire.value}); the runner de-boxes it INLINE (fully-unrolled probe/match — no decode helper, no
|
|
1708
1771
|
// output recursion) into the node's outType struct.
|
|
1709
1772
|
// #192: 1:1 map of the authored signature — positional params (one per input port, box removed), not
|
|
1710
|
-
// an `In_<comp>` struct
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
.
|
|
1773
|
+
// an `In_<comp>` struct — after the caller's `context.Context`, which every leaf transport call receives.
|
|
1774
|
+
// Go allows unused function params, so no `_ = param` guard is needed.
|
|
1775
|
+
const entryParams = [
|
|
1776
|
+
`${GO_CTX_PARAM} context.Context`,
|
|
1777
|
+
...entryPortOrder(comp, declared).map((p) => `${goParamName(p)} ${inputPortGoType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)}`),
|
|
1778
|
+
].join(", ");
|
|
1714
1779
|
lines.push(`func ${runnerName(comp.name)}(${entryParams}) (${outStructType}, error) {`);
|
|
1715
1780
|
for (const k of order.keys()) {
|
|
1716
1781
|
const node = comp.body[order[k]];
|
|
@@ -1802,7 +1867,7 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
|
|
|
1802
1867
|
// DIRECT leaf transport call: the resolved op-agnostic symbol, ONE WireRow payload. `bound` is NOT
|
|
1803
1868
|
// passed — it is BC's internal produced/skip gate, already enforced by the surrounding
|
|
1804
1869
|
// `if bound_<s> != nil` / `if produced_<parent>` guards; the leaf never receives it.
|
|
1805
|
-
const call =
|
|
1870
|
+
const call = goLeafCall(resolveLeafSymbol(node.component, leaf, node.leafSymbol), `payload_${s}`);
|
|
1806
1871
|
lines.push(...pe.lines);
|
|
1807
1872
|
lines.push(...goPortsFailFast(indent, pe.err, zeroOut));
|
|
1808
1873
|
lines.push(`${indent}payload_${s} := ${goPayloadRow(pe.entries, wire.selector)}`);
|
|
@@ -1816,7 +1881,7 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
|
|
|
1816
1881
|
// interpreter checks the declared outType in wrappedExec, OUTSIDE the policy interpretation, and
|
|
1817
1882
|
// throws — so it must propagate here too, or the two surfaces disagree on the same IR.
|
|
1818
1883
|
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));
|
|
1884
|
+
lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, `${indent}\t`, returnZeroFail(zeroOut), wire.selector, nodeWirePassthrough(node), seqCtr));
|
|
1820
1885
|
lines.push(`${indent}\tproduced_${s} = true`);
|
|
1821
1886
|
lines.push(`${indent}}`);
|
|
1822
1887
|
}
|
|
@@ -1826,7 +1891,7 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
|
|
|
1826
1891
|
lines.push(`${indent}if wire_${s}Err != nil {`);
|
|
1827
1892
|
lines.push(`${indent}\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${policyLit}, wire_${s}Err)`);
|
|
1828
1893
|
lines.push(`${indent}}`);
|
|
1829
|
-
lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, indent, returnZeroFail(zeroOut), nodeWirePassthrough(node), seqCtr));
|
|
1894
|
+
lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, indent, returnZeroFail(zeroOut), wire.selector, nodeWirePassthrough(node), seqCtr));
|
|
1830
1895
|
lines.push(`${indent}produced_${s} = true`);
|
|
1831
1896
|
}
|
|
1832
1897
|
for (const c of closers)
|
|
@@ -1854,12 +1919,12 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
|
|
|
1854
1919
|
skippableKind.set(id, rk);
|
|
1855
1920
|
}
|
|
1856
1921
|
}
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1922
|
+
// ONE output recursion (#295): the produced-aware read is a REF-position lowering handed to it, not a
|
|
1923
|
+
// second recursion — so it reaches EVERY slot the recursion descends into, an array element included.
|
|
1924
|
+
const out = emitTypedValue(comp.output, outRef, typedNodes, plan, comp.name, "<output>", skippable.size > 0 ? goSlotRefLowering(typedNodes, plan, skippable, skippableKind, comp.name) : undefined);
|
|
1860
1925
|
// top-level output that is a bare node-result (not an obj/arr assembly): its honest `ref` must equal the
|
|
1861
1926
|
// declared component output type, or the emitted `return <out>, nil` does not compile.
|
|
1862
|
-
checkOutputFieldType(comp.name, "<output>", outRef, out.ref
|
|
1927
|
+
checkOutputFieldType(comp.name, "<output>", outRef, out.ref);
|
|
1863
1928
|
lines.push(`\treturn ${out.expr}, nil`);
|
|
1864
1929
|
lines.push(`}`);
|
|
1865
1930
|
return { code: lines.join("\n"), outRef: out.ref ?? outRef };
|
|
@@ -1965,18 +2030,21 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1965
2030
|
// throw); elementPolicy still governs the handler's own leaf failures only.
|
|
1966
2031
|
const elemRowRef = mapElemRowRef(node, arrRef, plan);
|
|
1967
2032
|
const elemRowGo = renderTypeRef(elemRowRef);
|
|
1968
|
-
const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), nodeWirePassthrough(node));
|
|
2033
|
+
const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node));
|
|
1969
2034
|
// #177/#182 keep-with-skip-value: the into value for a guard-skipped element is driven by relationKind,
|
|
1970
2035
|
// NOT by opt-ness (matching run_behavior applyInto, which fills a connection into with the empty
|
|
1971
2036
|
// connection UNCONDITIONALLY on relationKind==="connection"):
|
|
1972
|
-
// - connection into → the connection-zero in the field's typed rep
|
|
1973
|
-
//
|
|
1974
|
-
//
|
|
2037
|
+
// - connection into → the connection-zero in the field's typed rep: a required `Conn` field → `Tn{}`, an
|
|
2038
|
+
// OPT `*Conn` field → a non-nil `&Tn{}` (Some(empty connection), NOT nil). `Tn{}`'s serializer
|
|
2039
|
+
// normalizes nil items to [] → {items:[],cursor:null} (#182).
|
|
1975
2040
|
// - non-connection into → the go zero (opt → nil = null, #177 keep-with-null; unchanged).
|
|
2041
|
+
// That IS the produced-aware output read's unproduced arm, at a different position — so it reads the SAME
|
|
2042
|
+
// rule (typed.ts `unproducedInSlot`) with the same go spellings, not a second copy of it. The `into` attach
|
|
2043
|
+
// point always receives the child result WHOLE (there is no path into it), hence `whole: true`.
|
|
1976
2044
|
// LAZY: the skip value exists only for a GUARDED map...into (the two call sites below). An opaque-wire
|
|
1977
2045
|
// element (bc#164) has no zero — and no `into` either (mapElemRowRef requires a named struct for into),
|
|
1978
2046
|
// so computing it eagerly would fail-close a shape that never uses it.
|
|
1979
|
-
const intoSkipZero = () => (m.relationKind
|
|
2047
|
+
const intoSkipZero = () => unproducedInSlot(elemRowRef, m.relationKind, true, GO_PRODUCED_AWARE);
|
|
1980
2048
|
// emit the per-element guard keep-gate (#108). `il` = indent, `elemVar` = the over element loop var.
|
|
1981
2049
|
// On skip: batched → `continue` (element excluded from items + keptOver); non-batched → `continue`.
|
|
1982
2050
|
const emitGuard = (il, elemVar, onSkip = ["continue"]) => {
|
|
@@ -2040,7 +2108,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2040
2108
|
lines.push(`${indent}if len(items_${s}) > 0 {`);
|
|
2041
2109
|
// ONE op-agnostic transport call: the batch is a WireRow {items:[…]}; the result is a WireList whose
|
|
2042
2110
|
// aligned elements are read via `.Items` (byte-equal to run_behavior's aligned batch result).
|
|
2043
|
-
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym
|
|
2111
|
+
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${goLeafCall(leafSym, goPayloadBatch(`items_${s}`, wireSel))}`);
|
|
2044
2112
|
lines.push(`${indent}\tif mo_${s}Err != nil {`, ...onComponentFailure(`mo_${s}Err`).map((l) => `${indent}\t\t${l}`), `${indent}\t}`);
|
|
2045
2113
|
lines.push(`${indent}\tmi_${s} := mo_${s}.Items`);
|
|
2046
2114
|
lines.push(`${indent}\tif len(mi_${s}) != len(items_${s}) {`, `${indent}\t\treturn ${zeroOut}, ${goErr("MAP_BATCH_RESULT_MISMATCH", `fmt.Sprintf("map '${node.id}': batched handler must return a list aligned to items (want %d)", len(items_${s}))`)}`, `${indent}\t}`);
|
|
@@ -2071,7 +2139,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2071
2139
|
// empty items => empty result (handler not called), matching run_behavior.
|
|
2072
2140
|
lines.push(`${indent}if len(items_${s}) > 0 {`);
|
|
2073
2141
|
// ONE op-agnostic transport call: batch payload WireRow {items:[…]}; result WireList read via `.Items`.
|
|
2074
|
-
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym
|
|
2142
|
+
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${goLeafCall(leafSym, goPayloadBatch(`items_${s}`, wireSel))}`);
|
|
2075
2143
|
lines.push(`${indent}\tif mo_${s}Err != nil {`, ...onComponentFailure(`mo_${s}Err`).map((l) => `${indent}\t\t${l}`), `${indent}\t}`);
|
|
2076
2144
|
lines.push(`${indent}\tmi_${s} := mo_${s}.Items`);
|
|
2077
2145
|
lines.push(`${indent}\tif len(mi_${s}) != len(items_${s}) {`, `${indent}\t\treturn ${zeroOut}, ${goErr("MAP_BATCH_RESULT_MISMATCH", `fmt.Sprintf("map '${node.id}': batched handler must return a list aligned to items (want %d)", len(items_${s}))`)}`, `${indent}\t}`);
|
|
@@ -2116,7 +2184,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2116
2184
|
// conveyed by the payload here, so bound stays nil. Byte-equivalence holds because the bound value only
|
|
2117
2185
|
// feeds handler-internal logic. Element Error Policy (scp-error.md): `skip` drops the failing element
|
|
2118
2186
|
// and proceeds (order preserved); `error` (default) promotes the element Failure to the map's Failure.
|
|
2119
|
-
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym
|
|
2187
|
+
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${goLeafCall(leafSym, `ep_${s}`)}`);
|
|
2120
2188
|
if (m.elementPolicy === "skip") {
|
|
2121
2189
|
lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\tcontinue`, `${indent}\t}`);
|
|
2122
2190
|
}
|
|
@@ -2241,7 +2309,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
|
|
|
2241
2309
|
// ONE op-agnostic transport call: batch payload WireRow {items:[…]}; result is a WireList of the aligned
|
|
2242
2310
|
// per-id element wires (read via `.Items`). A DANGLING id is a WireNull element → the zero element (empty
|
|
2243
2311
|
// dedupeKey), which the dangling drop below excludes. No `bound`.
|
|
2244
|
-
lines.push(`${indent}\tfo_${s}, fo_${s}Err := ${leafSym
|
|
2312
|
+
lines.push(`${indent}\tfo_${s}, fo_${s}Err := ${goLeafCall(leafSym, goPayloadBatch(`pi_${s}`, wireSel))}`);
|
|
2245
2313
|
lines.push(`${indent}\tif fo_${s}Err != nil {`, ...(contPolicy ? [`${indent}\t\tskipped_${s} = true`, `${indent}\t\tbreak`] : [`${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${policyLit}, fo_${s}Err)`]), `${indent}\t}`);
|
|
2246
2314
|
lines.push(`${indent}\tfw_${s} := fo_${s}.Items`);
|
|
2247
2315
|
lines.push(`${indent}\tif len(fw_${s}) != len(pi_${s}) {`, `${indent}\t\treturn ${zeroOut}, ${goErr("FANOUT_BATCH_RESULT_MISMATCH", `fmt.Sprintf("fanout '${node.id}': batched handler must return a list aligned to the deduped id list (want %d)", len(pi_${s}))`)}`, `${indent}\t}`);
|
|
@@ -2253,7 +2321,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
|
|
|
2253
2321
|
lines.push(`${indent}\tfor fi_${s} := range fw_${s} {`);
|
|
2254
2322
|
lines.push(`${indent}\t\tvar el_${s} ${elemGo}`);
|
|
2255
2323
|
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)));
|
|
2324
|
+
lines.push(renderResultDeBox(elemRef, `el_${s}`, `fw_${s}[fi_${s}]`, node.id, plan, `${indent}\t\t\t`, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node)));
|
|
2257
2325
|
lines.push(`${indent}\t\t}`);
|
|
2258
2326
|
lines.push(`${indent}\t\tkey_${s} := el_${s}.${dkGo}`);
|
|
2259
2327
|
if (f.drop === "dangling") {
|
|
@@ -2360,104 +2428,53 @@ function emitCondArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut)
|
|
|
2360
2428
|
return lines.join("\n");
|
|
2361
2429
|
}
|
|
2362
2430
|
/**
|
|
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).
|
|
2431
|
+
* GO_PRODUCED_AWARE — the go SPELLINGS of the shared produced-aware output lowering (typed.ts
|
|
2432
|
+
* {@link lowerProducedAwareRead} / {@link unproducedInSlot}). Only the syntax lives here: Go has no
|
|
2433
|
+
* expression `if` (hence the IIFE) and `&<expr>` on a temporary is not addressable (hence the fresh
|
|
2434
|
+
* pointer). The rule — which arm, what the unproduced arm holds, which type both arms must agree on, and
|
|
2435
|
+
* when the slot cannot represent the unproduced read — is language-neutral and is NOT restated here.
|
|
2370
2436
|
*/
|
|
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
|
-
}
|
|
2437
|
+
const GO_PRODUCED_AWARE = {
|
|
2438
|
+
producedFlag: (head) => `produced_${sanitize(head)}`,
|
|
2439
|
+
optSome: (valueExpr, placed) => `func() ${renderTypeRef(placed)} { __v := ${valueExpr}; return &__v }()`,
|
|
2440
|
+
zero: goZero,
|
|
2441
|
+
conditional: (cond, present, absent, placed) => `func() ${renderTypeRef(placed)} { if ${cond} { return ${present} }; return ${absent} }()`,
|
|
2442
|
+
};
|
|
2446
2443
|
/**
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2452
|
-
*
|
|
2444
|
+
* goSlotRefLowering — the go binding of the ONE output recursion's node-result-reference seam
|
|
2445
|
+
* ({@link SlotRefLowering}), used when ANY covered node can SKIP (#86 part 1).
|
|
2446
|
+
*
|
|
2447
|
+
* `ref`/`refOpt` into a SKIPPABLE node lowers through the shared produced-aware rule; into any other typed
|
|
2448
|
+
* node it is the plain typed field access (identical to what the recursion's own `ref` branch emits, but
|
|
2449
|
+
* reached through `classifyExpr` so `refOpt` resolves here too). Anything else returns undefined and the ONE
|
|
2450
|
+
* recursion keeps handling it.
|
|
2453
2451
|
*/
|
|
2454
|
-
function
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2452
|
+
function goSlotRefLowering(typedNodes, plan, skippable, skippableKind, compName) {
|
|
2453
|
+
return (node, declared, fieldPath) => {
|
|
2454
|
+
// ref / refOpt (classifyExpr encodes both as kind:"ref" with .opt).
|
|
2455
|
+
const e = classifyExpr(node);
|
|
2456
|
+
if (e.kind !== "ref" || e.path.length < 1 || !typedNodes.has(e.path[0]))
|
|
2457
|
+
return undefined;
|
|
2458
|
+
const head = e.path[0];
|
|
2459
|
+
const { expr, ref } = goTypedInternals.typedFieldAccess(typedLocal(head), typedNodes.get(head), e.path.slice(1), plan);
|
|
2460
|
+
// a NON-skippable node's `ref` is returned honestly (not laundered), so the PLACING site runs
|
|
2461
|
+
// checkOutputFieldType against the slot type.
|
|
2462
|
+
if (!skippable.has(head))
|
|
2463
|
+
return { expr, ref };
|
|
2464
|
+
return lowerProducedAwareRead({
|
|
2465
|
+
path: e.path,
|
|
2466
|
+
relationKind: skippableKind.get(head),
|
|
2467
|
+
optional: e.opt,
|
|
2468
|
+
valueExpr: expr,
|
|
2469
|
+
value: ref,
|
|
2470
|
+
declared,
|
|
2471
|
+
compName,
|
|
2472
|
+
fieldPath,
|
|
2473
|
+
check: checkOutputFieldType,
|
|
2474
|
+
spell: GO_PRODUCED_AWARE,
|
|
2475
|
+
plan,
|
|
2476
|
+
});
|
|
2477
|
+
};
|
|
2461
2478
|
}
|
|
2462
2479
|
/** Go zero value for a TypeRef (used as the error return of the struct runner). */
|
|
2463
2480
|
function goZero(ref) {
|
|
@@ -2548,7 +2565,7 @@ function renderGoWireBox(plan, srcExpr, wireSel, depth = 0) {
|
|
|
2548
2565
|
// package alongside the wire TYPE, so qualify them with the same selector (`wire.WireFloat(...)`,
|
|
2549
2566
|
// `[]wire.WireField{…}`); in-package they are local (bare). Without this the type is `wire.WireValue` but the
|
|
2550
2567
|
// ctor is a bare `WireFloat` → does not compile.
|
|
2551
|
-
const q = wireSel
|
|
2568
|
+
const q = goWireQ(wireSel);
|
|
2552
2569
|
// boxBase — box a BASE-typed (non-opt) expr per the plan's kind. Both the required (optDepth 0) path and the
|
|
2553
2570
|
// opt arm (after its null-guard + deref) fold through this ONE walk, so the opt element reuses the SAME
|
|
2554
2571
|
// per-kind box (no parallel path). The union is exhausted below; the trailing throw is a bare exhaustiveness
|
|
@@ -2620,6 +2637,7 @@ function makeGoExprBackend(zeroOut, resolveHead, plan,
|
|
|
2620
2637
|
// #174: cross-package selector for the shared wire constructors (`wire`); undefined/"" ⇒ in-package (bare).
|
|
2621
2638
|
wireSel) {
|
|
2622
2639
|
const used = goExprUsed;
|
|
2640
|
+
const q = goWireQ(wireSel);
|
|
2623
2641
|
return {
|
|
2624
2642
|
lang: "go",
|
|
2625
2643
|
freshTemp: () => `ex_${goExprTempSeq++}`,
|
|
@@ -2629,10 +2647,12 @@ wireSel) {
|
|
|
2629
2647
|
wireBox: (item) => renderGoWireBox(buildWirePlan(item.ref, { from: "top" }, { model: "port", field: "port", plan }, "in"), item.expr, wireSel),
|
|
2630
2648
|
// bc#178: box EACH element of the typed slice into an arr<value> ([]WireValue) — the same per-element box
|
|
2631
2649
|
// renderer as wireBox's list case, applied over the referenced array (box-once/element).
|
|
2632
|
-
|
|
2650
|
+
// `range` walks the slice's own backing array — Go owes no copy here (which is why `src.borrowed` is a
|
|
2651
|
+
// Rust-only concern and never set on this surface; see NativeExprBackend.wireBoxEachElem).
|
|
2652
|
+
wireBoxEachElem: (src, elemRef) => {
|
|
2633
2653
|
const vt = renderTypeRef({ kind: "value" });
|
|
2634
2654
|
const box = renderGoWireBox(buildWirePlan(elemRef, { from: "elem" }, { model: "port", field: "port", plan }, "in"), "__be", wireSel);
|
|
2635
|
-
return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${
|
|
2655
|
+
return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${src.expr} { __out = append(__out, ${box}) }; return __out }()`;
|
|
2636
2656
|
},
|
|
2637
2657
|
scalarType: (s) => goScalar(s),
|
|
2638
2658
|
strLit: (s) => JSON.stringify(s),
|
|
@@ -2658,11 +2678,14 @@ wireSel) {
|
|
|
2658
2678
|
return `(${parts.join(" + ")})`;
|
|
2659
2679
|
},
|
|
2660
2680
|
notOp: (a) => `(!${a})`,
|
|
2681
|
+
// #309: go has no clippy — the complement of a float ordering compare is spelled with the plain `!`
|
|
2682
|
+
// (`(!(a > b))`, the form this surface has always emitted), so the go module is byte-unchanged.
|
|
2683
|
+
negPartialOrdCmp: (op, a, b) => `(!(${a} ${op === "lt" ? "<" : op === "le" ? "<=" : op === "gt" ? ">" : ">="} ${b}))`,
|
|
2661
2684
|
structLit: (name, inits) => `${name}{${inits.map((i) => `${goFieldName(i.field)}: ${i.expr}`).join(", ")}}`,
|
|
2662
2685
|
arrLit: (elemTy, items) => `[]${elemTy}{${items.join(", ")}}`,
|
|
2663
2686
|
// #209: the opaque wire built directly from an inline composite literal at a `value` port.
|
|
2664
|
-
wireRowLit: (entries) => `${
|
|
2665
|
-
wireListLit: (items) => `${
|
|
2687
|
+
wireRowLit: (entries) => `${q}WireRowOf([]${q}WireField{${entries.map((e) => `{Key: ${JSON.stringify(e.key)}, Val: ${e.expr}}`).join(", ")}})`,
|
|
2688
|
+
wireListLit: (items) => `${q}WireListOf([]${q}WireValue{${items.join(", ")}})`,
|
|
2666
2689
|
// #209: a string-keyed map literal — `map[string]V{"k": v, …}`. Go maps are unordered; the shared
|
|
2667
2690
|
// serializer (`serMap`) emits keys in code-point order, so entry order here is not observable.
|
|
2668
2691
|
mapLit: (valueTy, entries) => `map[string]${valueTy}{${entries.map((e) => `${JSON.stringify(e.key)}: ${e.expr}`).join(", ")}}`,
|
|
@@ -2688,10 +2711,12 @@ wireSel) {
|
|
|
2688
2711
|
// ONE box SSoT (renderGoWireBox — the SAME call shape as wireBox) and keeping absent nil. A self-contained
|
|
2689
2712
|
// IIFE (no hoisted stmts): bind the pointer ONCE, nil ⇒ nil (absent stays absent — NOT WireNull, that is
|
|
2690
2713
|
// the required-`value` collapse), present ⇒ box the deref'd inner and return its address.
|
|
2691
|
-
|
|
2714
|
+
// Go has no ownership to track (a struct/slice IS a value), so `src.borrowed` is never set and the
|
|
2715
|
+
// compiled `expr` is always what this boxes — see NativeExprBackend.optMapWireBox.
|
|
2716
|
+
optMapWireBox: (src, innerRef) => {
|
|
2692
2717
|
const vt = renderTypeRef({ kind: "value" });
|
|
2693
2718
|
const box = renderGoWireBox(buildWirePlan(innerRef, { from: "top" }, { model: "port", field: "port", plan }, "in"), "__ov", wireSel);
|
|
2694
|
-
return `func() *${vt} { __oo := ${
|
|
2719
|
+
return `func() *${vt} { __oo := ${src.expr}; if __oo == nil { return nil }; __ov := (*__oo); __ob := ${box}; return &__ob }()`;
|
|
2695
2720
|
},
|
|
2696
2721
|
// opt (`*T`) defaulted to a PURE default — an immediately-invoked func literal: bind the pointer ONCE,
|
|
2697
2722
|
// deref when present, else yield the default (evaluated only when absent — run_behavior's lazy right).
|
|
@@ -2860,9 +2885,12 @@ var ComponentNamesNativeRaw = []string{${native.map((c) => JSON.stringify(c.name
|
|
|
2860
2885
|
* mismatch Sprintf, `strings` for a concat builder, `sync` for a parallel stage). ExpectedSpecVersions
|
|
2861
2886
|
* stays as a local `var` for provenance, but the old `dslcontracts.SpecVersions` skew `init()` is GONE
|
|
2862
2887
|
* (change #5 — there is no runtime to skew against once the module is runtime-free). */
|
|
2863
|
-
function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needStrconv = false, wireImport, leafImport, needSort = false) {
|
|
2888
|
+
function emitMinimalHeader(ctx, needContext, needStrings, needSync, needFmt, needMath, needStrconv = false, wireImport, leafImport, needSort = false) {
|
|
2864
2889
|
const sv = ctx.specVersions;
|
|
2865
2890
|
const imports = [];
|
|
2891
|
+
// `context` — every entry takes the caller's context.Context (std alphabetical order: context < fmt).
|
|
2892
|
+
if (needContext)
|
|
2893
|
+
imports.push(`\t"context"`);
|
|
2866
2894
|
if (needFmt)
|
|
2867
2895
|
imports.push(`\t"fmt"`);
|
|
2868
2896
|
if (needMath)
|
|
@@ -2991,7 +3019,7 @@ function emit(ctx) {
|
|
|
2991
3019
|
const needWireImport = wire.import !== undefined && wire.selector !== undefined && runnerCodes.some((c) => c.includes(`${wire.selector}.`));
|
|
2992
3020
|
// bc#181: `sort` iff a generated typed→wire map box emitted `sort.Strings` (deterministic dynamic-key WireRow).
|
|
2993
3021
|
const needSort = runnerCodes.some((c) => c.includes("sort.Strings"));
|
|
2994
|
-
const header = emitMinimalHeader(ctx, false, needSync, needFmt, needMath, needStrconv, needWireImport ? wire.import : undefined, leaf?.import, needSort);
|
|
3022
|
+
const header = emitMinimalHeader(ctx, native.length > 0, false, needSync, needFmt, needMath, needStrconv, needWireImport ? wire.import : undefined, leaf?.import, needSort);
|
|
2995
3023
|
const banner = `// COMBINED READ layer (bc#90 — the RUNTIME-FREE read de-box; STRUCT-ONLY, FULLY-NATIVE surface). A
|
|
2996
3024
|
// covered read is a strictly-sequential typed componentRef chain (point reads + relation children
|
|
2997
3025
|
// children), emitted ONLY here: each node builds a native ports struct by direct field assignment (every
|
|
@@ -3005,10 +3033,10 @@ function emit(ctx) {
|
|
|
3005
3033
|
// run_behavior). Exec is INLINE sequential (no plan driver) so a relation child reads the parent's REAL
|
|
3006
3034
|
// struct result via direct field access and the child-present decision is made from the real parent value —
|
|
3007
3035
|
// relation / connection converge with run_behavior (fixes #323/#74). The exposed API is the 1:1
|
|
3008
|
-
// STRUCT-returning entry <Method>(<positional params>) (the In_<comp> box removed
|
|
3009
|
-
//
|
|
3010
|
-
// FULLY NATIVE: a naive grep
|
|
3011
|
-
// boxing primitives OR for the bc-runtime package finds nothing, by design (bc#90/runtime-free).`;
|
|
3036
|
+
// STRUCT-returning entry <Method>(ctx, <positional params>) (the In_<comp> box removed; ctx is the caller's
|
|
3037
|
+
// context.Context, passed to every transport call); the consumer supplies the leaf transport symbols
|
|
3038
|
+
// (default same-package Leaf_<comp>, or a leafTransport import). This module is FULLY NATIVE: a naive grep
|
|
3039
|
+
// for boxing primitives OR for the bc-runtime package finds nothing, by design (bc#90/runtime-free).`;
|
|
3012
3040
|
const sections = [
|
|
3013
3041
|
banner,
|
|
3014
3042
|
`// Local concrete failure type (runtime-free) — a covered runner returns *BehaviorError (satisfies\n// error) instead of a bc-runtime failure, so the fully-covered module imports ZERO bc runtime.\n${behaviorErrorType}`,
|