behavior-contracts 0.9.0 → 0.9.2
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/dist/behavior.d.ts +19 -0
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +137 -12
- package/dist/behavior.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +149 -51
- 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 +146 -50
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/typed.d.ts +19 -1
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +24 -0
- package/dist/generator/typed.js.map +1 -1
- package/dist/type-gate.d.ts.map +1 -1
- package/dist/type-gate.js +6 -56
- package/dist/type-gate.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { GeneratorFailure } from "./core.js";
|
|
|
2
2
|
import { isControlGate, 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, guardedMapIntoIsOpt, inputPortIsOptional, inputPortTypeRef } 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";
|
|
@@ -815,10 +815,16 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
815
815
|
return false;
|
|
816
816
|
const m = n.map;
|
|
817
817
|
// #86 pt2: batched map...into. #93 shape 2/3: (non-)batched map...into / connection-collect. #108:
|
|
818
|
-
// a guarded map (`when`) IS covered when it has NO `into`
|
|
819
|
-
//
|
|
820
|
-
//
|
|
821
|
-
|
|
818
|
+
// a guarded map (`when`) IS covered when it has NO `into`. #177: a guarded map WITH `into` is covered
|
|
819
|
+
// ONLY when the into field is OPT — the augmented list is then homogeneous []ElemWithOptInto (kept
|
|
820
|
+
// element → present into, guard-skipped element → into=nil), which is EXACTLY run_behavior's applyInto
|
|
821
|
+
// pass-through (behavior.ts:846 — a skipped element is pushed unaugmented) followed by output
|
|
822
|
+
// conformance materializing the absent opt-into field as null (behavior.ts:597 — keep-with-null). A
|
|
823
|
+
// REQUIRED into field stays fail-closed: run_behavior FAILS MISSING_PROP on a skipped element there,
|
|
824
|
+
// so rejecting is byte-equal. Opt-ness is read from the into field's declared type (the map node's
|
|
825
|
+
// element outType); an element type that does not resolve to a named struct with the into field →
|
|
826
|
+
// fail-closed (the resolvers below would reject it anyway).
|
|
827
|
+
if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsOpt(n, comp))
|
|
822
828
|
return false;
|
|
823
829
|
if (m.policy !== undefined && m.policy !== "fail")
|
|
824
830
|
return false;
|
|
@@ -839,7 +845,10 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
839
845
|
return false;
|
|
840
846
|
const head = overE.path[0];
|
|
841
847
|
if (!bodyIds.has(head)) {
|
|
842
|
-
// input-array over: covered only when the input port declares elemType (#108
|
|
848
|
+
// input-array over: covered only when the input port declares elemType (#108 — the C3 "BC does not
|
|
849
|
+
// infer" rule: an input array WITHOUT elemType stays uncovered). #177 (A): an OPT input array
|
|
850
|
+
// (`{opt:{arr}}`, required:false) IS covered — its null iterates EMPTY (goOverElemInfo.optArr → the arm
|
|
851
|
+
// binds `over` via a nil-safe deref, `range` over a nil slice = 0), byte-equal to run_behavior.
|
|
843
852
|
if (overE.path.length !== 1)
|
|
844
853
|
return false;
|
|
845
854
|
const schema = comp.inputPorts?.[head];
|
|
@@ -878,6 +887,9 @@ function coveredFanoutNode(n, bodyIds, comp) {
|
|
|
878
887
|
return false;
|
|
879
888
|
const head = overE.path[0];
|
|
880
889
|
if (!bodyIds.has(head)) {
|
|
890
|
+
// input-array over: covered only when the port declares elemType (C3 — no inference). #177 (A): an OPT
|
|
891
|
+
// input array (`{opt:{arr}}`, required:false) IS covered — its null iterates EMPTY (goOverElemInfo.optArr
|
|
892
|
+
// → nil-safe deref, `range`/`len` over a nil slice = 0), byte-equal to run_behavior.
|
|
881
893
|
if (overE.path.length !== 1)
|
|
882
894
|
return false;
|
|
883
895
|
const schema = comp.inputPorts?.[head];
|
|
@@ -1166,24 +1178,52 @@ function fanoutItemsElemRef(node, connRef, plan) {
|
|
|
1166
1178
|
}
|
|
1167
1179
|
return itemsField.type.elem;
|
|
1168
1180
|
}
|
|
1169
|
-
/**
|
|
1170
|
-
*
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1181
|
+
/**
|
|
1182
|
+
* goOverElemInfo — the ONE resolver of a fanout/map `over` to its element TypeRef + native Go over-slice
|
|
1183
|
+
* expression (fanoutOverElemInfo / mapOverElemInfo both delegate here — single definition, no forked twin).
|
|
1184
|
+
*
|
|
1185
|
+
* `optArr` is true when the over's declared type is `{opt:{arr}}` (a prior-node opt-arr field OR an OPT
|
|
1186
|
+
* input array port). #177 (A): a null opt-arr over then iterates EMPTY — the emitted `overExpr` is a
|
|
1187
|
+
* `*[]E` pointer (nil when the optional collection is absent), which the arm binds via a nil-safe deref so
|
|
1188
|
+
* `range`/`len` see a 0-length slice, byte-equal to run_behavior's empty iteration. A REQUIRED arr (nil)
|
|
1189
|
+
* still fails run_behavior FANOUT/MAP_OVER_NOT_ARRAY, so it stays optArr:false (non-covered on null).
|
|
1190
|
+
*/
|
|
1191
|
+
function goOverElemInfo(comp, over, typedNodes, plan, nodeId, label) {
|
|
1192
|
+
const e = classifyExpr(over);
|
|
1174
1193
|
if (e.kind === "ref" && e.path.length >= 1 && typedNodes.has(e.path[0])) {
|
|
1175
1194
|
const baseRef = typedNodes.get(e.path[0]);
|
|
1176
1195
|
const { expr, ref } = goTypedInternals.typedFieldAccess(typedLocal(e.path[0]), baseRef, e.path.slice(1), plan);
|
|
1177
1196
|
if (ref.kind === "arr")
|
|
1178
|
-
return { elemRef: ref.elem, overExpr: expr };
|
|
1197
|
+
return { elemRef: ref.elem, overExpr: expr, optArr: false };
|
|
1198
|
+
if (ref.kind === "opt" && ref.inner.kind === "arr")
|
|
1199
|
+
return { elemRef: ref.inner.elem, overExpr: expr, optArr: true };
|
|
1179
1200
|
}
|
|
1180
1201
|
if (e.kind === "ref" && e.path.length === 1) {
|
|
1181
1202
|
const schema = comp.inputPorts?.[e.path[0]];
|
|
1182
1203
|
const et = schema?.elemType;
|
|
1183
1204
|
if (et !== undefined)
|
|
1184
|
-
return { elemRef: deriveTypeRef(et, plan), overExpr: `in.${goFieldName(e.path[0])}
|
|
1205
|
+
return { elemRef: deriveTypeRef(et, plan), overExpr: `in.${goFieldName(e.path[0])}`, optArr: inputPortIsOptional(schema) };
|
|
1185
1206
|
}
|
|
1186
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go
|
|
1207
|
+
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go ${label}: '${nodeId}' 'over' must be a ref to a prior node's typed arr field OR an input array port with a declared elemType (got ${JSON.stringify(over)}). BC does not infer input-array element types (consumer-interface C3).`);
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* goBindOver — emit the `over_<s>` binding lines. A non-opt over binds the slice directly; an opt-arr over
|
|
1211
|
+
* (#177 (A)) binds a nil-able `[]E` via a nil-safe deref of the `*[]E` expr, so a null optional collection
|
|
1212
|
+
* iterates as 0 elements (byte-equal to run_behavior). `overElemGo` is the element Go type.
|
|
1213
|
+
*/
|
|
1214
|
+
function goBindOver(indent, s, overExpr, optArr, overElemGo) {
|
|
1215
|
+
if (!optArr)
|
|
1216
|
+
return [`${indent}over_${s} := ${overExpr}`];
|
|
1217
|
+
return [
|
|
1218
|
+
`${indent}var over_${s} []${overElemGo}`,
|
|
1219
|
+
`${indent}if ${overExpr} != nil {`,
|
|
1220
|
+
`${indent}\tover_${s} = *${overExpr}`,
|
|
1221
|
+
`${indent}}`,
|
|
1222
|
+
];
|
|
1223
|
+
}
|
|
1224
|
+
/** fanoutOverElemInfo (v3) — delegates to {@link goOverElemInfo} reading the FanoutNode.fanout spec. */
|
|
1225
|
+
function fanoutOverElemInfo(comp, node, typedNodes, plan) {
|
|
1226
|
+
return goOverElemInfo(comp, node.fanout.over, typedNodes, plan, node.id, "fanout (v3)");
|
|
1187
1227
|
}
|
|
1188
1228
|
/** mapNodeArrRef — the map node's PRODUCED-ARRAY TypeRef from its `outType`.
|
|
1189
1229
|
*
|
|
@@ -1260,23 +1300,7 @@ function emitMapElemMaterializers(comp, typedNodes, plan) {
|
|
|
1260
1300
|
* A map over an input array WITHOUT elemType is fail-closed (BC does not infer — consumer-interface C3).
|
|
1261
1301
|
*/
|
|
1262
1302
|
function mapOverElemInfo(comp, node, typedNodes, plan) {
|
|
1263
|
-
|
|
1264
|
-
const e = classifyExpr(m.over);
|
|
1265
|
-
if (e.kind === "ref" && e.path.length >= 1 && typedNodes.has(e.path[0])) {
|
|
1266
|
-
const baseRef = typedNodes.get(e.path[0]);
|
|
1267
|
-
const { expr, ref } = goTypedInternals.typedFieldAccess(typedLocal(e.path[0]), baseRef, e.path.slice(1), plan);
|
|
1268
|
-
if (ref.kind === "arr")
|
|
1269
|
-
return { elemRef: ref.elem, overExpr: expr };
|
|
1270
|
-
}
|
|
1271
|
-
// input-array over (#108): the head is an input port; its declared elemType is the element type.
|
|
1272
|
-
if (e.kind === "ref" && e.path.length === 1) {
|
|
1273
|
-
const schema = comp.inputPorts?.[e.path[0]];
|
|
1274
|
-
const et = schema?.elemType;
|
|
1275
|
-
if (et !== undefined) {
|
|
1276
|
-
return { elemRef: deriveTypeRef(et, plan), overExpr: `in.${goFieldName(e.path[0])}` };
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go combined map (#108): map '${node.id}' 'over' must be a ref to a prior node's typed arr field OR an input array port with a declared elemType (got ${JSON.stringify(m.over)}). BC does not infer input-array element types (consumer-interface C3).`);
|
|
1303
|
+
return goOverElemInfo(comp, node.map.over, typedNodes, plan, node.id, "combined map (#108)");
|
|
1280
1304
|
}
|
|
1281
1305
|
/** The Go type of the over-element (back-compat shim). */
|
|
1282
1306
|
function mapOverElemType(comp, node, typedNodes, plan) {
|
|
@@ -1431,7 +1455,8 @@ function emitInDecoder(comp, plan) {
|
|
|
1431
1455
|
// materializeExpr returns the must*-based decode (panics on a malformed corpus element — test glue).
|
|
1432
1456
|
lines.push(`\t\t\tdec = append(dec, ${mat})`);
|
|
1433
1457
|
lines.push(`\t\t}`);
|
|
1434
|
-
|
|
1458
|
+
// #177 (A): an OPTIONAL array port field is `*[]E` (inputPortTypeRef opt → pointer), so take its address.
|
|
1459
|
+
lines.push(`\t\tin.${field} = ${inputPortIsOptional(schema) ? "&dec" : "dec"}`);
|
|
1435
1460
|
lines.push(`\t}`);
|
|
1436
1461
|
continue;
|
|
1437
1462
|
}
|
|
@@ -1908,6 +1933,10 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1908
1933
|
const batched = m.batched === true;
|
|
1909
1934
|
const hasInto = m.into !== undefined;
|
|
1910
1935
|
const hasGuard = m.when !== undefined;
|
|
1936
|
+
// #177 keep-with-null: a guarded map WITH `into` keeps guard-skipped elements with the (opt) into
|
|
1937
|
+
// field set to nil (coveredMapNode only admits this when the into field is opt). This differs from a
|
|
1938
|
+
// guarded NO-into map, which DROPs skipped elements. Byte-equal to run_behavior's applyInto keep-with-null.
|
|
1939
|
+
const keepWithNull = hasGuard && hasInto;
|
|
1911
1940
|
const s = sanitize(node.id);
|
|
1912
1941
|
// #154 cross-package: a BATCHED map's element + batch ports structs live in the shared package (they
|
|
1913
1942
|
// cross the transport boundary as a whole value), so reference them selector-qualified here. A
|
|
@@ -1921,7 +1950,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1921
1950
|
const asName = m.as;
|
|
1922
1951
|
// over collection element type + the native over-slice expression (#108: prior-node arr OR input array
|
|
1923
1952
|
// with elemType). The $as element is a value of `overElemRef` (input-array element or prior-node elem).
|
|
1924
|
-
const { elemRef: overElemRef, overExpr } = mapOverElemInfo(comp, node, typedNodes, plan);
|
|
1953
|
+
const { elemRef: overElemRef, overExpr, optArr: overOptArr } = mapOverElemInfo(comp, node, typedNodes, plan);
|
|
1925
1954
|
const overElemGo = renderTypeRef(overElemRef);
|
|
1926
1955
|
const elemMat = mapElemMaterializerName(comp.name, node.id);
|
|
1927
1956
|
const priorHere = (head) => priorNodeAt(head, atPos);
|
|
@@ -1956,9 +1985,12 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1956
1985
|
closers.unshift(`${indent}}`);
|
|
1957
1986
|
indent += "\t";
|
|
1958
1987
|
}
|
|
1959
|
-
// over collection (typed field access to the parent node's arr — no serialize).
|
|
1960
|
-
|
|
1961
|
-
|
|
1988
|
+
// over collection (typed field access to the parent node's arr — no serialize; opt-arr → nil-safe deref).
|
|
1989
|
+
for (const l of goBindOver(indent, s, overExpr, overOptArr, overElemGo))
|
|
1990
|
+
lines.push(l);
|
|
1991
|
+
// #177 batched keep-with-null assembles the result BY INDEX (over-order, kept slots filled post-dispatch),
|
|
1992
|
+
// so it needs a full-length backing slice; every other shape appends in kept order.
|
|
1993
|
+
lines.push(`${indent}${typedLocal(node.id)} = make(${elemGo}, ${batched && keepWithNull ? `len(over_${s})` : `0, len(over_${s})`})`);
|
|
1962
1994
|
// each element is de-boxed strictly INLINE: the handler returns the per-element WIRE and the arm decodes
|
|
1963
1995
|
// it against the element ref (the `into` field's type for map...into, else the element type). A de-box
|
|
1964
1996
|
// mismatch fails closed regardless of elementPolicy (matching the interpreter's whole-node outType
|
|
@@ -1968,7 +2000,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1968
2000
|
const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), nodeWirePassthrough(node));
|
|
1969
2001
|
// emit the per-element guard keep-gate (#108). `il` = indent, `elemVar` = the over element loop var.
|
|
1970
2002
|
// On skip: batched → `continue` (element excluded from items + keptOver); non-batched → `continue`.
|
|
1971
|
-
const emitGuard = (il, elemVar) => {
|
|
2003
|
+
const emitGuard = (il, elemVar, onSkip = ["continue"]) => {
|
|
1972
2004
|
const g = mkGuard(elemVar);
|
|
1973
2005
|
if (g === null)
|
|
1974
2006
|
return [];
|
|
@@ -1976,11 +2008,46 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1976
2008
|
for (const st of g.stmts)
|
|
1977
2009
|
out.push(`${il}${st}`);
|
|
1978
2010
|
out.push(`${il}if !(${g.expr}) {`);
|
|
1979
|
-
|
|
2011
|
+
for (const a of onSkip)
|
|
2012
|
+
out.push(`${il}\t${a}`);
|
|
1980
2013
|
out.push(`${il}}`);
|
|
1981
2014
|
return out;
|
|
1982
2015
|
};
|
|
1983
|
-
if (batched) {
|
|
2016
|
+
if (batched && keepWithNull) {
|
|
2017
|
+
// #177 BATCHED keep-with-null (guarded map...into, opt into): first pass records, per over element in
|
|
2018
|
+
// ORDER, whether it is kept (guard true → build its ports, remember its over-index) or skipped (guard
|
|
2019
|
+
// false → materialize the augmented element in place with into=nil). ONE batched dispatch over the kept
|
|
2020
|
+
// ports, then the aligned rows are de-boxed and zipped back onto their over-index slots. Byte-equal to
|
|
2021
|
+
// run_behavior: batched keptIdx-aligned collect + applyInto (skipped element unaugmented → opt-into null).
|
|
2022
|
+
const g = mkGuard(elemLocal(s));
|
|
2023
|
+
lines.push(`${indent}items_${s} := make([]${structName}, 0, len(over_${s}))`);
|
|
2024
|
+
lines.push(`${indent}keptIdx_${s} := make([]int, 0, len(over_${s}))`);
|
|
2025
|
+
lines.push(`${indent}for oi_${s} := range over_${s} {`);
|
|
2026
|
+
lines.push(`${indent}\t${elemLocal(s)} := over_${s}[oi_${s}]`);
|
|
2027
|
+
for (const st of g.stmts)
|
|
2028
|
+
lines.push(`${indent}\t${st}`);
|
|
2029
|
+
lines.push(`${indent}\tif ${g.expr} {`);
|
|
2030
|
+
for (const l of buildPorts(indent + "\t\t", elemLocal(s)))
|
|
2031
|
+
lines.push(l);
|
|
2032
|
+
lines.push(`${indent}\t\titems_${s} = append(items_${s}, ep_${s})`);
|
|
2033
|
+
lines.push(`${indent}\t\tkeptIdx_${s} = append(keptIdx_${s}, oi_${s})`);
|
|
2034
|
+
lines.push(`${indent}\t} else {`);
|
|
2035
|
+
lines.push(`${indent}\t\t${typedLocal(node.id)}[oi_${s}] = ${elemMat}(${elemLocal(s)}, nil)`);
|
|
2036
|
+
lines.push(`${indent}\t}`);
|
|
2037
|
+
lines.push(`${indent}}`);
|
|
2038
|
+
lines.push(`${indent}if len(items_${s}) > 0 {`);
|
|
2039
|
+
lines.push(`${indent}\tbp_${s} := ${batchStruct}{Items: items_${s}}`);
|
|
2040
|
+
lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym}(bp_${s})`);
|
|
2041
|
+
lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", mo_${s}Err)`, `${indent}\t}`);
|
|
2042
|
+
lines.push(`${indent}\tif len(mo_${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}`);
|
|
2043
|
+
lines.push(`${indent}\tfor mk_${s} := range items_${s} {`);
|
|
2044
|
+
lines.push(`${indent}\t\tvar dec_${s} ${elemRowGo}`);
|
|
2045
|
+
lines.push(renderElemDeBox(`dec_${s}`, `mo_${s}[mk_${s}]`, `${indent}\t\t`));
|
|
2046
|
+
lines.push(`${indent}\t\t${typedLocal(node.id)}[keptIdx_${s}[mk_${s}]] = ${elemMat}(over_${s}[keptIdx_${s}[mk_${s}]], dec_${s})`);
|
|
2047
|
+
lines.push(`${indent}\t}`);
|
|
2048
|
+
lines.push(`${indent}}`);
|
|
2049
|
+
}
|
|
2050
|
+
else if (batched) {
|
|
1984
2051
|
// BATCHED (#86 pt2 into / #93 shape 3 no-into / #108 guarded no-into): build kept-element ports,
|
|
1985
2052
|
// dispatch ONCE. The concrete Node_* returns the aligned per-element WIRES ([]WireValue) or an error.
|
|
1986
2053
|
// With a guard, `items` (and, for into, `keptOver`) hold only kept elements — matching run_behavior's
|
|
@@ -2031,7 +2098,12 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2031
2098
|
// (no dispatch, excluded from the result). The concrete Node_* returns ONE element WIRE (WireValue).
|
|
2032
2099
|
lines.push(`${indent}for mk_${s} := range over_${s} {`);
|
|
2033
2100
|
lines.push(`${indent}\t${elemLocal(s)} := over_${s}[mk_${s}]`);
|
|
2034
|
-
|
|
2101
|
+
// #177 keep-with-null: a guard-skipped element is KEPT with into=nil (elemMat(over,nil)) instead of
|
|
2102
|
+
// dropped — byte-equal to run_behavior's applyInto pass-through + opt-into null.
|
|
2103
|
+
const nonBatchedSkip = keepWithNull
|
|
2104
|
+
? [`${typedLocal(node.id)} = append(${typedLocal(node.id)}, ${elemMat}(${elemLocal(s)}, nil))`, "continue"]
|
|
2105
|
+
: ["continue"];
|
|
2106
|
+
for (const l of emitGuard(indent + "\t", elemLocal(s), nonBatchedSkip))
|
|
2035
2107
|
lines.push(l);
|
|
2036
2108
|
for (const l of buildPorts(indent + "\t", elemLocal(s)))
|
|
2037
2109
|
lines.push(l);
|
|
@@ -2094,7 +2166,8 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
|
|
|
2094
2166
|
const connRef = typedNodes.get(node.id);
|
|
2095
2167
|
const elemRef = fanoutItemsElemRef(node, connRef, plan);
|
|
2096
2168
|
const elemGo = renderTypeRef(elemRef);
|
|
2097
|
-
const { elemRef: overElemRef, overExpr } = fanoutOverElemInfo(comp, node, typedNodes, plan);
|
|
2169
|
+
const { elemRef: overElemRef, overExpr, optArr: overOptArr } = fanoutOverElemInfo(comp, node, typedNodes, plan);
|
|
2170
|
+
const overElemGo = renderTypeRef(overElemRef);
|
|
2098
2171
|
const asName = f.as;
|
|
2099
2172
|
const priorHere = (head) => priorNodeAt(head, atPos);
|
|
2100
2173
|
const portNames = Object.keys(f.ports);
|
|
@@ -2121,8 +2194,9 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
|
|
|
2121
2194
|
closers.unshift(`${indent}}`);
|
|
2122
2195
|
indent += "\t";
|
|
2123
2196
|
}
|
|
2124
|
-
// over id-list (typed field access — no serialize) → per-id ports (all ids
|
|
2125
|
-
|
|
2197
|
+
// over id-list (typed field access — no serialize; opt-arr → nil-safe deref) → per-id ports (all ids).
|
|
2198
|
+
for (const l of goBindOver(indent, s, overExpr, overOptArr, overElemGo))
|
|
2199
|
+
lines.push(l);
|
|
2126
2200
|
lines.push(`${indent}var items_${s} []${elemGo}`);
|
|
2127
2201
|
lines.push(`${indent}pi_${s} := make([]${structName}, 0, len(over_${s}))`);
|
|
2128
2202
|
lines.push(`${indent}for _, ${elemLocal(s)} := range over_${s} {`);
|
|
@@ -2406,14 +2480,25 @@ const goExprUsed = { helpers: false };
|
|
|
2406
2480
|
/**
|
|
2407
2481
|
* renderGoWireBox — the ONE inline BOX renderer (typed→wire) for Go, the mirror of renderRustWireBox. Folds
|
|
2408
2482
|
* a language-neutral {@link WirePlan} (`dir:"in"`) into a Go EXPRESSION evaluating to a `WireValue` built
|
|
2409
|
-
* from the OWNED `srcExpr`.
|
|
2410
|
-
*
|
|
2411
|
-
*
|
|
2483
|
+
* from the OWNED `srcExpr`. The walk is TOTAL over the plan's non-opt kinds (bc#178) — the write-side twin
|
|
2484
|
+
* of the read-side de-box, and RECURSIVE over the declared element type so a compound bound value crosses
|
|
2485
|
+
* the leaf-param boundary EXACTLY ONCE (box-once; NO decode→re-box round-trip — the input is already the
|
|
2486
|
+
* native typed value):
|
|
2487
|
+
* - `value` identity (already the opaque BC wire);
|
|
2488
|
+
* - `scalar` wrap in its wire ctor (WireStr/WireInt/WireFloat/WireBool);
|
|
2489
|
+
* - `record` box each declared field to its wire ctor recursively, assemble a WireRow of (name, WireValue)
|
|
2490
|
+
* entries — the typed `obj<…>` → wire map ("M") crossing (the real op-agnostic `arr<value>`
|
|
2491
|
+
* batch-write param fed a typed `arr<obj>`);
|
|
2492
|
+
* - `list` box each element recursively into a WireList ("L").
|
|
2493
|
+
* A `map` value or an OPT-wrapped element (optDepth > 0) boxes AMBIGUOUSLY (map key order / opt present-vs-null
|
|
2494
|
+
* on the wire are not statically pinned to run_behavior's Value pass-through), so it stays FAIL-CLOSED LOUD
|
|
2495
|
+
* rather than risk a divergence — strict-typing, no silent box. `depth` names the loop/element locals uniquely.
|
|
2412
2496
|
*/
|
|
2413
|
-
function renderGoWireBox(plan, srcExpr, wireSel) {
|
|
2414
|
-
// #174: cross-package (`--shared-types-import`) the wire CONSTRUCTORS live in the shared
|
|
2415
|
-
// the wire TYPE, so qualify them with the same selector (`wire.WireFloat(...)
|
|
2416
|
-
// (bare). Without this the type is `wire.WireValue` but the
|
|
2497
|
+
function renderGoWireBox(plan, srcExpr, wireSel, depth = 0) {
|
|
2498
|
+
// #174: cross-package (`--shared-types-import`) the wire CONSTRUCTORS + composite TYPES live in the shared
|
|
2499
|
+
// package alongside the wire TYPE, so qualify them with the same selector (`wire.WireFloat(...)`,
|
|
2500
|
+
// `[]wire.WireField{…}`); in-package they are local (bare). Without this the type is `wire.WireValue` but the
|
|
2501
|
+
// ctor is a bare `WireFloat` → does not compile.
|
|
2417
2502
|
const q = wireSel !== undefined && wireSel !== "" ? `${wireSel}.` : "";
|
|
2418
2503
|
if (plan.optDepth === 0) {
|
|
2419
2504
|
if (plan.k === "value")
|
|
@@ -2430,8 +2515,21 @@ function renderGoWireBox(plan, srcExpr, wireSel) {
|
|
|
2430
2515
|
return `${q}WireBool(${srcExpr})`;
|
|
2431
2516
|
}
|
|
2432
2517
|
}
|
|
2518
|
+
if (plan.k === "record") {
|
|
2519
|
+
// typed struct → wire map: box each declared field off its native struct field (no probe — the value is
|
|
2520
|
+
// already typed), assemble a WireRow of (name, WireValue) in declared-field order.
|
|
2521
|
+
const entries = plan.fields.map((f) => `{Key: ${JSON.stringify(f.name)}, Val: ${renderGoWireBox(f.plan, `${srcExpr}.${goFieldName(f.name)}`, wireSel, depth + 1)}}`);
|
|
2522
|
+
return `${q}WireRowOf([]${q}WireField{${entries.join(", ")}})`;
|
|
2523
|
+
}
|
|
2524
|
+
if (plan.k === "list") {
|
|
2525
|
+
// typed slice → wire list: box each element recursively (box-once, no round-trip). An empty slice yields
|
|
2526
|
+
// an empty (non-nil) WireList — byte-equal to run_behavior's [] pass-through.
|
|
2527
|
+
const e = `e${depth}`;
|
|
2528
|
+
const items = `it${depth}`;
|
|
2529
|
+
return `func() ${q}WireValue { ${items} := []${q}WireValue{}; for _, ${e} := range ${srcExpr} { ${items} = append(${items}, ${renderGoWireBox(plan.elem, e, wireSel, depth + 1)}) }; return ${q}WireListOf(${items}) }()`;
|
|
2530
|
+
}
|
|
2433
2531
|
}
|
|
2434
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go wire box: a value[] element of type '${plan.expectedType}' is not
|
|
2532
|
+
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go wire box: a value[] element of type '${plan.expectedType}' is not native-covered by the typed→wire box (an opt-wrapped or map element boxes ambiguously — fail-closed rather than risk a run_behavior divergence)`);
|
|
2435
2533
|
}
|
|
2436
2534
|
function makeGoExprBackend(zeroOut, resolveHead, plan,
|
|
2437
2535
|
// #174: cross-package selector for the shared wire constructors (`wire`); undefined/"" ⇒ in-package (bare).
|