behavior-contracts 0.9.2 → 0.9.3
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.map +1 -1
- package/dist/behavior.js +18 -10
- package/dist/behavior.js.map +1 -1
- package/dist/generator/emit-shared-go.d.ts.map +1 -1
- package/dist/generator/emit-shared-go.js +40 -19
- package/dist/generator/emit-shared-go.js.map +1 -1
- package/dist/generator/emit-shared-rust.d.ts.map +1 -1
- package/dist/generator/emit-shared-rust.js +50 -30
- package/dist/generator/emit-shared-rust.js.map +1 -1
- package/dist/generator/emit-shared-typescript.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript.js +26 -4
- package/dist/generator/emit-shared-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 +50 -18
- 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 +43 -13
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/native-expr.d.ts +7 -0
- package/dist/generator/native-expr.d.ts.map +1 -1
- package/dist/generator/native-expr.js +11 -0
- package/dist/generator/native-expr.js.map +1 -1
- package/dist/generator/straightline.d.ts +5 -0
- package/dist/generator/straightline.d.ts.map +1 -1
- package/dist/generator/straightline.js +1 -0
- package/dist/generator/straightline.js.map +1 -1
- package/dist/generator/typed.d.ts +17 -11
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +19 -12
- package/dist/generator/typed.js.map +1 -1
- package/dist/plan.d.ts +7 -0
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +7 -2
- package/dist/plan.js.map +1 -1
- package/dist/primitives.d.ts +4 -3
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +8 -7
- package/dist/primitives.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,
|
|
5
|
+
import { buildTypePlan, deriveTypeRef, findDecl, guardedMapIntoIsCoverable, 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,16 +815,15 @@ 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`. #177: a guarded map WITH `into` is
|
|
819
|
-
//
|
|
820
|
-
//
|
|
821
|
-
//
|
|
822
|
-
//
|
|
823
|
-
//
|
|
824
|
-
//
|
|
825
|
-
//
|
|
826
|
-
|
|
827
|
-
if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsOpt(n, comp))
|
|
818
|
+
// a guarded map (`when`) IS covered when it has NO `into`. #177/#182: a guarded map WITH `into` is
|
|
819
|
+
// covered when the guard-skipped element has a well-defined skip value — the into field is OPT
|
|
820
|
+
// (skip → nil, #177) OR relationKind:connection (skip → the empty connection {items:[],cursor:null},
|
|
821
|
+
// #182). The augmented list is then homogeneous (kept element → present into, skipped → the skip
|
|
822
|
+
// value), EXACTLY run_behavior's applyInto (a skipped connection into is filled with unproducedValue
|
|
823
|
+
// ("connection"), an opt into stays absent → output conformance null). A REQUIRED non-connection into
|
|
824
|
+
// stays fail-closed: run_behavior FAILS MISSING_PROP on a skipped element there, so rejecting is
|
|
825
|
+
// byte-equal. The skip value below (goZero of the into row type) yields nil / connection-struct-zero.
|
|
826
|
+
if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsCoverable(n, comp))
|
|
828
827
|
return false;
|
|
829
828
|
if (m.policy !== undefined && m.policy !== "fail")
|
|
830
829
|
return false;
|
|
@@ -1998,6 +1997,14 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
1998
1997
|
const elemRowRef = mapElemRowRef(node, arrRef, plan);
|
|
1999
1998
|
const elemRowGo = renderTypeRef(elemRowRef);
|
|
2000
1999
|
const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), nodeWirePassthrough(node));
|
|
2000
|
+
// #177/#182 keep-with-skip-value: the into value for a guard-skipped element is driven by relationKind,
|
|
2001
|
+
// NOT by opt-ness (matching run_behavior applyInto, which fills a connection into with the empty
|
|
2002
|
+
// connection UNCONDITIONALLY on relationKind==="connection"):
|
|
2003
|
+
// - connection into → the connection-zero in the field's typed rep (goConnectionUnproduced): a required
|
|
2004
|
+
// `Conn` field → `Tn{}`, an OPT `*Conn` field → a non-nil `&Tn{}` (Some(empty connection), NOT nil).
|
|
2005
|
+
// `Tn{}`'s serializer normalizes nil items to [] → {items:[],cursor:null} (#182).
|
|
2006
|
+
// - non-connection into → the go zero (opt → nil = null, #177 keep-with-null; unchanged).
|
|
2007
|
+
const intoSkipZero = m.relationKind === "connection" ? goConnectionUnproduced(elemRowRef, elemRowRef) : goZero(elemRowRef);
|
|
2001
2008
|
// emit the per-element guard keep-gate (#108). `il` = indent, `elemVar` = the over element loop var.
|
|
2002
2009
|
// On skip: batched → `continue` (element excluded from items + keptOver); non-batched → `continue`.
|
|
2003
2010
|
const emitGuard = (il, elemVar, onSkip = ["continue"]) => {
|
|
@@ -2032,7 +2039,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2032
2039
|
lines.push(`${indent}\t\titems_${s} = append(items_${s}, ep_${s})`);
|
|
2033
2040
|
lines.push(`${indent}\t\tkeptIdx_${s} = append(keptIdx_${s}, oi_${s})`);
|
|
2034
2041
|
lines.push(`${indent}\t} else {`);
|
|
2035
|
-
lines.push(`${indent}\t\t${typedLocal(node.id)}[oi_${s}] = ${elemMat}(${elemLocal(s)},
|
|
2042
|
+
lines.push(`${indent}\t\t${typedLocal(node.id)}[oi_${s}] = ${elemMat}(${elemLocal(s)}, ${intoSkipZero})`);
|
|
2036
2043
|
lines.push(`${indent}\t}`);
|
|
2037
2044
|
lines.push(`${indent}}`);
|
|
2038
2045
|
lines.push(`${indent}if len(items_${s}) > 0 {`);
|
|
@@ -2098,10 +2105,11 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2098
2105
|
// (no dispatch, excluded from the result). The concrete Node_* returns ONE element WIRE (WireValue).
|
|
2099
2106
|
lines.push(`${indent}for mk_${s} := range over_${s} {`);
|
|
2100
2107
|
lines.push(`${indent}\t${elemLocal(s)} := over_${s}[mk_${s}]`);
|
|
2101
|
-
// #177 keep-with-
|
|
2102
|
-
// dropped — byte-equal to run_behavior's applyInto
|
|
2108
|
+
// #177/#182 keep-with-skip-value: a guard-skipped element is KEPT with into=intoSkipZero
|
|
2109
|
+
// (elemMat(over, nil | connZero)) instead of dropped — byte-equal to run_behavior's applyInto
|
|
2110
|
+
// (opt-into → null / connection-into → empty connection).
|
|
2103
2111
|
const nonBatchedSkip = keepWithNull
|
|
2104
|
-
? [`${typedLocal(node.id)} = append(${typedLocal(node.id)}, ${elemMat}(${elemLocal(s)},
|
|
2112
|
+
? [`${typedLocal(node.id)} = append(${typedLocal(node.id)}, ${elemMat}(${elemLocal(s)}, ${intoSkipZero}))`, "continue"]
|
|
2105
2113
|
: ["continue"];
|
|
2106
2114
|
for (const l of emitGuard(indent + "\t", elemLocal(s), nonBatchedSkip))
|
|
2107
2115
|
lines.push(l);
|
|
@@ -2528,8 +2536,19 @@ function renderGoWireBox(plan, srcExpr, wireSel, depth = 0) {
|
|
|
2528
2536
|
const items = `it${depth}`;
|
|
2529
2537
|
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
2538
|
}
|
|
2539
|
+
if (plan.k === "map") {
|
|
2540
|
+
// bc#181: typed map<V> → wire map, represented as a dynamic-keyed WireRow (there is NO WireMap type; a
|
|
2541
|
+
// declared map<V> is the dynamic-keyed twin of a record — the READ side de-boxes a WireRow INTO map<V>
|
|
2542
|
+
// the SAME way, emit-shared-debox `mapval`). Box EACH entry's VALUE recursively (box-once); keys carried
|
|
2543
|
+
// as dynamic strings, SORTED (Go map iteration is randomized) so the WireRow is DETERMINISTIC — matching
|
|
2544
|
+
// the canonical code-point key order the typed serialize / de-box use.
|
|
2545
|
+
const keys = `mk${depth}`;
|
|
2546
|
+
const key = `k${depth}`;
|
|
2547
|
+
const fields = `mf${depth}`;
|
|
2548
|
+
return `func() ${q}WireValue { ${keys} := make([]string, 0, len(${srcExpr})); for ${key} := range ${srcExpr} { ${keys} = append(${keys}, ${key}) }; sort.Strings(${keys}); ${fields} := []${q}WireField{}; for _, ${key} := range ${keys} { ${fields} = append(${fields}, ${q}WireField{Key: ${key}, Val: ${renderGoWireBox(plan.value, `${srcExpr}[${key}]`, wireSel, depth + 1)}}) }; return ${q}WireRowOf(${fields}) }()`;
|
|
2549
|
+
}
|
|
2531
2550
|
}
|
|
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
|
|
2551
|
+
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 element boxes ambiguously — opt present-vs-null on the wire is not statically pinned to run_behavior's Value pass-through — so it stays fail-closed rather than risk a divergence)`);
|
|
2533
2552
|
}
|
|
2534
2553
|
function makeGoExprBackend(zeroOut, resolveHead, plan,
|
|
2535
2554
|
// #174: cross-package selector for the shared wire constructors (`wire`); undefined/"" ⇒ in-package (bare).
|
|
@@ -2542,6 +2561,13 @@ wireSel) {
|
|
|
2542
2561
|
wireType: () => renderTypeRef({ kind: "value" }),
|
|
2543
2562
|
// bc#156/#160: box a value[] element into the opaque BC wire via the ONE box SSoT (owned element expr).
|
|
2544
2563
|
wireBox: (item) => renderGoWireBox(buildWirePlan(item.ref, { from: "top" }, { model: "port", field: "port", plan }, "in"), item.expr, wireSel),
|
|
2564
|
+
// bc#178: box EACH element of the typed slice into an arr<value> ([]WireValue) — the same per-element box
|
|
2565
|
+
// renderer as wireBox's list case, applied over the referenced array (box-once/element).
|
|
2566
|
+
wireBoxEachElem: (srcExpr, elemRef) => {
|
|
2567
|
+
const vt = renderTypeRef({ kind: "value" });
|
|
2568
|
+
const box = renderGoWireBox(buildWirePlan(elemRef, { from: "elem" }, { model: "port", field: "port", plan }, "in"), "__be", wireSel);
|
|
2569
|
+
return `func() []${vt} { __out := []${vt}{}; for _, __be := range ${srcExpr} { __out = append(__out, ${box}) }; return __out }()`;
|
|
2570
|
+
},
|
|
2545
2571
|
scalarType: (s) => goScalar(s),
|
|
2546
2572
|
strLit: (s) => JSON.stringify(s),
|
|
2547
2573
|
boolLit: (b) => (b ? "true" : "false"),
|
|
@@ -2747,13 +2773,17 @@ var ComponentNamesNativeRaw = []string{${native.map((c) => JSON.stringify(c.name
|
|
|
2747
2773
|
* mismatch Sprintf, `strings` for a concat builder, `sync` for a parallel stage). ExpectedSpecVersions
|
|
2748
2774
|
* stays as a local `var` for provenance, but the old `dslcontracts.SpecVersions` skew `init()` is GONE
|
|
2749
2775
|
* (change #5 — there is no runtime to skew against once the module is runtime-free). */
|
|
2750
|
-
function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needStrconv = false, wireImport, leafImport) {
|
|
2776
|
+
function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needStrconv = false, wireImport, leafImport, needSort = false) {
|
|
2751
2777
|
const sv = ctx.specVersions;
|
|
2752
2778
|
const imports = [];
|
|
2753
2779
|
if (needFmt)
|
|
2754
2780
|
imports.push(`\t"fmt"`);
|
|
2755
2781
|
if (needMath)
|
|
2756
2782
|
imports.push(`\t"math"`);
|
|
2783
|
+
// bc#181: `sort` is imported iff a generated typed→wire map box emits `sort.Strings` (deterministic
|
|
2784
|
+
// dynamic-key WireRow). Kept in std alphabetical order (math < sort < strconv) so gofmt is a no-op.
|
|
2785
|
+
if (needSort)
|
|
2786
|
+
imports.push(`\t"sort"`);
|
|
2757
2787
|
if (needStrconv)
|
|
2758
2788
|
imports.push(`\t"strconv"`);
|
|
2759
2789
|
if (needStrings)
|
|
@@ -2883,7 +2913,9 @@ function emit(ctx) {
|
|
|
2883
2913
|
// probe consts, so it references nothing from the shared package and must NOT import it (an unused import
|
|
2884
2914
|
// is a Go compile error). The `<sel>.` prefix covers both (wire.value is `<sel>.WireValue`).
|
|
2885
2915
|
const needWireImport = wire.import !== undefined && wire.selector !== undefined && runnerCodes.some((c) => c.includes(`${wire.selector}.`));
|
|
2886
|
-
|
|
2916
|
+
// bc#181: `sort` iff a generated typed→wire map box emitted `sort.Strings` (deterministic dynamic-key WireRow).
|
|
2917
|
+
const needSort = runnerCodes.some((c) => c.includes("sort.Strings"));
|
|
2918
|
+
const header = emitMinimalHeader(ctx, false, needSync, needFmt, needMath, needStrconv, needWireImport ? wire.import : undefined, leaf?.import, needSort);
|
|
2887
2919
|
const banner = `// COMBINED READ layer (bc#90 — the RUNTIME-FREE read de-box; STRUCT-ONLY, FULLY-NATIVE surface). A
|
|
2888
2920
|
// covered read is a strictly-sequential typed componentRef chain (point reads + relationKind:single
|
|
2889
2921
|
// children), emitted ONLY here: each node builds a native ports struct by direct field assignment (every
|