behavior-contracts 0.11.23 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-contract.yaml +27 -20
- package/dist/authoring.d.ts +4 -4
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +11 -23
- package/dist/authoring.js.map +1 -1
- package/dist/behavior.d.ts +3 -3
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +7 -10
- package/dist/behavior.js.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.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/generated/program.js +4 -4
- package/dist/generated/program.js.map +1 -1
- package/dist/generator/core.d.ts +13 -10
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-native-dynamic.d.ts +203 -0
- package/dist/generator/emit-native-dynamic.d.ts.map +1 -0
- package/dist/generator/emit-native-dynamic.js +736 -0
- package/dist/generator/emit-native-dynamic.js.map +1 -0
- package/dist/generator/emit-native-php.d.ts +4 -0
- package/dist/generator/emit-native-php.d.ts.map +1 -0
- package/dist/generator/emit-native-php.js +668 -0
- package/dist/generator/emit-native-php.js.map +1 -0
- package/dist/generator/emit-native-python.d.ts +4 -0
- package/dist/generator/emit-native-python.d.ts.map +1 -0
- package/dist/generator/emit-native-python.js +592 -0
- package/dist/generator/emit-native-python.js.map +1 -0
- package/dist/generator/emit-php.d.ts +4 -0
- package/dist/generator/emit-php.d.ts.map +1 -1
- package/dist/generator/emit-php.js +6 -2
- package/dist/generator/emit-php.js.map +1 -1
- package/dist/generator/emit-python.d.ts +4 -0
- package/dist/generator/emit-python.d.ts.map +1 -1
- package/dist/generator/emit-python.js +2 -2
- package/dist/generator/emit-python.js.map +1 -1
- package/dist/generator/emit-shared-typescript.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript.js +15 -20
- 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 -553
- 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 -471
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +2 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +9 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/native-coverage.d.ts +162 -0
- package/dist/generator/native-coverage.d.ts.map +1 -0
- package/dist/generator/native-coverage.js +412 -0
- package/dist/generator/native-coverage.js.map +1 -0
- package/dist/generator/native-expr.d.ts +1 -1
- package/dist/generator/native-expr.d.ts.map +1 -1
- package/dist/generator/typed.d.ts +6 -0
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +17 -0
- package/dist/generator/typed.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { entryPortOrder, GeneratorFailure } from "./core.js";
|
|
2
|
-
import { isControlGate,
|
|
2
|
+
import { isControlGate, 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
5
|
import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef, lowerProducedAwareRead, unproducedInSlot } from "./typed.js";
|
|
6
|
-
import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, buildComponentPlan, nodeNarrowedPaths,
|
|
6
|
+
import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, buildComponentPlan, nodeNarrowedPaths, } from "./straightline.js";
|
|
7
7
|
import { NativeExprCompiler } from "./native-expr.js";
|
|
8
|
+
import { NativeCoverage, buildTypedNodes, fanoutItemsElemRef, mapElemRowRef, resolveOverOrFail } from "./native-coverage.js";
|
|
8
9
|
import { buildDeBoxPlan, buildWirePlan, notationOfRef } from "./emit-shared-debox.js";
|
|
9
10
|
const PKG = "dslcontracts";
|
|
10
11
|
/** resolveGoWire — the BC-OWNED wire type names the de-box classifies a node result against. bc OWNS +
|
|
@@ -484,7 +485,7 @@ func WireListOf(items []WireValue) WireValue { return WireValue{kind: wireList,
|
|
|
484
485
|
func WireRowOfFields(fields []WireField) WireRow { return WireRow{entries: fields} }
|
|
485
486
|
|
|
486
487
|
// IsNull — is this the wire null value? A batched/fanout transport returns a WireList of aligned results; a
|
|
487
|
-
// DANGLING fanout id is a WireNull element the covered runner
|
|
488
|
+
// DANGLING fanout id is a WireNull element (the covered runner classifies it with the row probe).
|
|
488
489
|
func (w WireValue) IsNull() bool { return w.kind == wireNull }
|
|
489
490
|
|
|
490
491
|
func (w *WireValue) wireTag() string {
|
|
@@ -674,17 +675,7 @@ func ProbeListOf(w *WireValue) ListProbe {
|
|
|
674
675
|
}
|
|
675
676
|
}`;
|
|
676
677
|
}
|
|
677
|
-
|
|
678
|
-
function mapFanoutElemRef(node, typedNodes, plan) {
|
|
679
|
-
const ref = typedNodes.get(node.id);
|
|
680
|
-
if ("fanout" in node)
|
|
681
|
-
return fanoutItemsElemRef(node, ref, plan);
|
|
682
|
-
return mapElemRowRef(node, ref, plan);
|
|
683
|
-
}
|
|
684
|
-
/** scalar TypeRef → PortFieldType (native go scalar kind). */
|
|
685
|
-
function goScalarPortField(scalar) {
|
|
686
|
-
return scalar === "string" ? "string" : scalar === "int" ? "int64" : scalar === "float" ? "float64" : "bool";
|
|
687
|
-
}
|
|
678
|
+
// ── native ports struct (mirrors the native emitter: typed fields, direct assignment) ──
|
|
688
679
|
/**
|
|
689
680
|
* goNativeResolveHead — the ONE ref-head resolver the runtime-free native-expr compiler reads, for cond
|
|
690
681
|
* `if`/branches, a map/fanout `when` guard, AND a port. A head is a `$as` element binding, a prior body
|
|
@@ -738,409 +729,13 @@ function compilePortNode(node, comp, plan, typedNodes, isPrior, where, expected,
|
|
|
738
729
|
// no separate input-side integrity gate exists.
|
|
739
730
|
return c;
|
|
740
731
|
}
|
|
741
|
-
/**
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
* Value-typed input) FAILS CLOSED — the covered read plane admits NO boxed escape (there is no
|
|
749
|
-
* `dslcontracts.Value` fallback on the native module). `where` names the emission site for the error.
|
|
750
|
-
*/
|
|
751
|
-
function portFieldGoType(node, comp, plan, typedNodes, expected, where = "port", opts) {
|
|
752
|
-
const c = compilePortNode(node, comp, plan, typedNodes, (h) => typedNodes.has(h), where, expected, opts);
|
|
753
|
-
return renderTypeRef(c.ref);
|
|
754
|
-
}
|
|
755
|
-
function staticArrElems(node) {
|
|
756
|
-
if (node === null || typeof node !== "object" || Array.isArray(node))
|
|
757
|
-
return null;
|
|
758
|
-
const keys = Object.keys(node);
|
|
759
|
-
if (keys.length !== 1 || keys[0] !== "arr")
|
|
760
|
-
return null;
|
|
761
|
-
const arg = node.arr;
|
|
762
|
-
return Array.isArray(arg) ? arg : null;
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* isNativeRawComponent — a component covered by the combined read emitter. Strictly sequential
|
|
766
|
-
* (no real concurrency), body is ALL componentRef (no map/cond), default 'fail'/'continue'
|
|
767
|
-
* policy, relationKind is single/connection or absent, and EVERY node carries outType + the
|
|
768
|
-
* component carries outputType. the relation bindField ARE the point — inline exec makes
|
|
769
|
-
* the child-present decision from the real parent result. Ports AND the output are evaluated via
|
|
770
|
-
* the primitive SSoT over a Value-space portScope (so a dynamic operator in a port or an
|
|
771
|
-
* obj-assembly output is fine — the SSoT handles fail-closed semantics; only the RESULT plane +
|
|
772
|
-
* PORT container go native). A covered SHAPE that lacks outType is a fail-closed error raised at
|
|
773
|
-
* emit (see assertTypedCoverage) — never a silent re-box.
|
|
774
|
-
*/
|
|
775
|
-
/**
|
|
776
|
-
* numLiteralGoExpr — a BARE numeric port literal (JSON number, e.g. the `limit: 20` Query port).
|
|
777
|
-
* `classifyExpr` deliberately leaves a bare number `dynamic` (its checked int/float range rules are
|
|
778
|
-
* the evaluate SSoT, expr.go evalNumberLiteral), so a plain number never reaches the str/bool/null
|
|
779
|
-
* static branch. But a number literal IS statically resolvable to a native Go Value: the SAME
|
|
780
|
-
* range check the runtime applies is performed HERE at generation time (integral literal in the
|
|
781
|
-
* safe 2^53-1 window → int64; a fractional/exponent literal → the checked float64). Returns the Go
|
|
782
|
-
* expression for the literal's Value, or null when the node is not a bare number OR the integral
|
|
783
|
-
* literal is out of the safe window (that out-of-range case keeps the runtime INVALID_LITERAL
|
|
784
|
-
* semantics — the port is NOT covered natively, so the whole component falls through, never a
|
|
785
|
-
* silently-wrong inline). Mirrors coderuntime.evalNumberLiteral exactly.
|
|
786
|
-
*/
|
|
787
|
-
const NUM_SAFE_INT = 9007199254740991; // 2^53 - 1 (expr.go safeInt)
|
|
788
|
-
function numLiteralGoExpr(node) {
|
|
789
|
-
if (typeof node !== "number" || !Number.isFinite(node))
|
|
790
|
-
return null;
|
|
791
|
-
if (Number.isInteger(node)) {
|
|
792
|
-
if (node < -NUM_SAFE_INT || node > NUM_SAFE_INT)
|
|
793
|
-
return null; // out of safe window → not covered (runtime INVALID_LITERAL)
|
|
794
|
-
return `${PKG}.Value(int64(${node}))`;
|
|
795
|
-
}
|
|
796
|
-
// fractional / exponent literal → checked float64 (finite, already guaranteed above).
|
|
797
|
-
return `${PKG}.Value(float64(${node}))`;
|
|
798
|
-
}
|
|
799
|
-
/** A port node is static (literal / ref / concat of those / static arr / bare number literal) —
|
|
800
|
-
* resolvable to a native Go Value with no NewObj / no evaluate interpreter. */
|
|
801
|
-
/** planForComp — a TypePlan for a single component (its named types are component-scoped, so a
|
|
802
|
-
* one-component IR yields the same plan the full-IR build would for this component). */
|
|
803
|
-
function planForComp(comp) {
|
|
804
|
-
return buildTypePlan({ irVersion: 2, exprVersion: 2, components: [comp] });
|
|
805
|
-
}
|
|
806
|
-
/** buildTypedNodes — the prior-node typed-local TypeRef map for a component (control-gate nodes are
|
|
807
|
-
* typeless; a map node carries its produced-array ref). An untyped node is omitted (not an error here). */
|
|
808
|
-
function buildTypedNodes(comp, plan) {
|
|
809
|
-
const typedNodes = new Map();
|
|
810
|
-
for (const n of comp.body) {
|
|
811
|
-
if (isControlGate(n))
|
|
812
|
-
continue;
|
|
813
|
-
try {
|
|
814
|
-
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan));
|
|
815
|
-
}
|
|
816
|
-
catch {
|
|
817
|
-
/* untyped node — omit */
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return typedNodes;
|
|
821
|
-
}
|
|
822
|
-
/** mapAsBinding — the `$as` element binding for a map/fanout node's element ports (the over-element
|
|
823
|
-
* TypeRef), or undefined when the over source does not resolve (an uncovered map). */
|
|
824
|
-
function mapAsBinding(comp, node, typedNodes, plan) {
|
|
825
|
-
try {
|
|
826
|
-
return { name: node.map.as, ref: mapOverElemInfo(comp, node, typedNodes, plan).elemRef, plan };
|
|
827
|
-
}
|
|
828
|
-
catch {
|
|
829
|
-
return undefined;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
/** portIsStatic — the ELIGIBILITY gate ASKS the one port lowering (compilePortNode / native-expr)
|
|
833
|
-
* whether it can lower this port, rather than re-deriving the shape rules — so the gate and the emitter
|
|
834
|
-
* can never disagree. A port that does not lower (or lowers fallibly) fails closed. */
|
|
835
|
-
function portIsStatic(node, comp, plan, typedNodes, expected, asBinding, narrowed) {
|
|
836
|
-
try {
|
|
837
|
-
void 0;
|
|
838
|
-
// #170: eligibility asks the SAME lowering emission uses, with the SAME node narrowing — so a
|
|
839
|
-
// gate/guard-proven opt-in-required port is judged covered iff it also emits (they cannot disagree).
|
|
840
|
-
// #173: with the SAME declared `expected` port type (covered iff it materializes to that type).
|
|
841
|
-
const opts = asBinding !== undefined ? { asBinding, asBase: asBinding.name, narrowed } : narrowed !== undefined ? { narrowed } : undefined;
|
|
842
|
-
compilePortNode(node, comp, plan, typedNodes, (h) => typedNodes.has(h), "port", expected, opts);
|
|
843
|
-
return true;
|
|
844
|
-
}
|
|
845
|
-
catch {
|
|
846
|
-
return false;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
/** The output must lower to a typed struct/value with no Value-scope read: a ref whose head is a
|
|
850
|
-
* BODY NODE (typed), an obj/arr of native-lowerable outputs, or a concat of them. A ref to an
|
|
851
|
-
* input param or a non-concat operator is NOT native-lowerable here (falls through). */
|
|
852
|
-
function outputIsNativeLowerable(comp) {
|
|
853
|
-
const bodyIds = new Set(comp.body.map((n) => n.id));
|
|
854
|
-
const walk = (node) => {
|
|
855
|
-
const arr = staticArrElems(node);
|
|
856
|
-
if (arr !== null)
|
|
857
|
-
return arr.every(walk);
|
|
858
|
-
if (node !== null && typeof node === "object" && !Array.isArray(node)) {
|
|
859
|
-
const keys = Object.keys(node);
|
|
860
|
-
if (keys.length === 1 && keys[0] === "obj") {
|
|
861
|
-
const obj = node.obj;
|
|
862
|
-
return Object.keys(obj).every((k) => walk(obj[k]));
|
|
863
|
-
}
|
|
864
|
-
if (keys.length === 1 && keys[0] === "arr")
|
|
865
|
-
return true; // handled by staticArrElems above
|
|
866
|
-
}
|
|
867
|
-
const e = classifyExpr(node);
|
|
868
|
-
if (e.kind === "str" || e.kind === "bool" || e.kind === "null")
|
|
869
|
-
return true;
|
|
870
|
-
// ref OR refOpt to a body node (typed). refOpt is how a produced-aware output reads a skippable
|
|
871
|
-
// relation child: the head node's produced flag gates it, yielding opt-nil when unproduced.
|
|
872
|
-
if (e.kind === "ref")
|
|
873
|
-
return bodyIds.has(e.path[0]); // must ref a body node (typed), not input
|
|
874
|
-
if (e.kind === "concat")
|
|
875
|
-
return e.parts.every((p) => walk(reconstructG(p)));
|
|
876
|
-
return false;
|
|
877
|
-
};
|
|
878
|
-
return walk(comp.output);
|
|
879
|
-
}
|
|
880
|
-
/** A native-raw component MUST be fully typed (outType on every node + outputType). */
|
|
881
|
-
function isFullyTyped(comp) {
|
|
882
|
-
if (comp.outputType === undefined)
|
|
883
|
-
return false;
|
|
884
|
-
for (const n of comp.body) {
|
|
885
|
-
// #125: a control-gate cond is a typeless skip marker (A3) — it never de-boxes a result, so it is
|
|
886
|
-
// exempt from the "every node carries outType" de-box requirement (matches type-gate's exemption).
|
|
887
|
-
if (isControlGate(n))
|
|
888
|
-
continue;
|
|
889
|
-
if (n.outType === undefined)
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
return true;
|
|
893
|
-
}
|
|
894
|
-
function isNativeRaw(comp) {
|
|
895
|
-
return isSequentialComponentRefRead(comp) && isFullyTyped(comp);
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* coveredMapNode — the #86 part 2 covered map shape (nestedBatchGet). A BATCHED `map` node whose:
|
|
899
|
-
* - over is a static ref (to a prior node's typed collection field OR an input array),
|
|
900
|
-
* - `into` is set (zip-attach the batched handler result onto every over element),
|
|
901
|
-
* - every element port is static (literal / ref into the element binding / concat / static arr),
|
|
902
|
-
* - element outType is a NAMED struct (the augmented element type — over element + the into field),
|
|
903
|
-
* - no `when` guard (guard+into => heterogeneous elements, not one []T — stays boxed),
|
|
904
|
-
* - relationKind single/connection or absent (every Error Policy Kind is covered — goPolicyArm).
|
|
905
|
-
* This is the struct-native de-box of a typed `map...into` element collection: build the per-element
|
|
906
|
-
* native ports struct, dispatch the batched handler ONCE (RawValue out), and assemble each augmented
|
|
907
|
-
* element struct by copying the over element's typed fields + materializing the into field from the
|
|
908
|
-
* aligned batch raw — NO boxed Value on any plane.
|
|
909
|
-
*/
|
|
910
|
-
function coveredMapNode(n, bodyIds, comp) {
|
|
911
|
-
if (n === null || typeof n !== "object" || !("map" in n))
|
|
912
|
-
return false;
|
|
913
|
-
const m = n.map;
|
|
914
|
-
// #86 pt2: batched map...into. #93 shape 2/3: (non-)batched map...into / connection-collect. #108:
|
|
915
|
-
// a guarded map (`when`) IS covered when it has NO `into`. #177/#182/#232: a `map...into` ALWAYS has a
|
|
916
|
-
// well-defined unproduced value for the into field — the into field is OPT (unproduced → nil, #177) OR
|
|
917
|
-
// relationKind:connection (unproduced → the empty connection {items:[],cursor:null}, #182). The type
|
|
918
|
-
// gate (`mapIntoHoldsUnproduced`, run for every component at the codegen entry) rejects anything else
|
|
919
|
-
// BEFORE any emitter sees it (#232), so the augmented list is homogeneous here by construction (kept
|
|
920
|
-
// element → present into, unproduced → the skip value), EXACTLY run_behavior's applyInto. The skip
|
|
921
|
-
// value below (goZero of the into row type) yields nil / connection-struct-zero.
|
|
922
|
-
if (m.relationKind !== undefined && m.relationKind !== "connection")
|
|
923
|
-
return false;
|
|
924
|
-
// A map node must carry an outType (its ELEMENT type per the recorder SoT — authoring.ts recordMap
|
|
925
|
-
// holds `node.outType = mapElem`, the PRE-array-wrap element; the emitter synthesizes the produced
|
|
926
|
-
// `[]element`). A map WITHOUT outType is uncovered. Legacy hand-built IR that already carries the
|
|
927
|
-
// The map node's outType is the ELEMENT type; mapNodeArrRef wraps it to the produced array ref.
|
|
928
|
-
// bc#164: an OPAQUE ELEMENT (`outType:"value"` on an output-passthrough map — mapNodeElemIsOpaqueWire,
|
|
929
|
-
// the shared rule) IS covered: each element wire is stored AS-IS in the produced list (no de-box, no
|
|
930
|
-
// per-op re-box), exactly as the componentRef path treats a passthrough result. Any other non-compound
|
|
931
|
-
// element type stays uncovered (loud), as before.
|
|
932
|
-
const outT = n.outType;
|
|
933
|
-
// #225: 純式 map(`transform`)の要素は**式から native に組む**(ワイヤも de-box も無い)ので、要素型が
|
|
934
|
-
// スカラでも被覆される — 宣言型 materializer が組めれば良く、組めなければそこで loud に落ちる。
|
|
935
|
-
// Component map は要素 wire を de-box するので従来どおり compound / opaque wire に限る。
|
|
936
|
-
const isTransformMap = mapTransformExpr(m) !== undefined;
|
|
937
|
-
if (outT === undefined)
|
|
938
|
-
return false;
|
|
939
|
-
if (!isTransformMap && typeof outT !== "object" && !mapNodeElemIsOpaqueWire(n))
|
|
940
|
-
return false;
|
|
941
|
-
// `over` element type must be STATICALLY resolvable: a ref to a PRIOR BODY NODE's typed arr field
|
|
942
|
-
// (mapOverElemType) OR a ref to an INPUT array port that carries `elemType` (#108 — the C3 "BC does
|
|
943
|
-
// not infer" rule: an input array WITHOUT elemType stays fail-closed / uncovered).
|
|
944
|
-
const overE = classifyExpr(m.over);
|
|
945
|
-
if (overE.kind !== "ref")
|
|
946
|
-
return false;
|
|
947
|
-
const head = overE.path[0];
|
|
948
|
-
if (!bodyIds.has(head)) {
|
|
949
|
-
// input-array over: covered only when the input port declares elemType (#108 — the C3 "BC does not
|
|
950
|
-
// infer" rule: an input array WITHOUT elemType stays uncovered). #177 (A): an OPT input array
|
|
951
|
-
// (`{opt:{arr}}`, required:false) IS covered — its null iterates EMPTY (goOverElemInfo.optArr → the arm
|
|
952
|
-
// binds `over` via a nil-safe deref, `range` over a nil slice = 0), byte-equal to run_behavior.
|
|
953
|
-
if (overE.path.length !== 1)
|
|
954
|
-
return false;
|
|
955
|
-
const schema = comp.inputPorts?.[head];
|
|
956
|
-
if (schema === undefined || schema.elemType === undefined)
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
959
|
-
// 純式 map(#222)は port を持たない: 被覆条件は「要素式が宣言された要素型へ native に materialize
|
|
960
|
-
// できること」で、それは compilePortNode(宣言型 materializer)が失敗したときに loud に落ちる。
|
|
961
|
-
const ports = (m.ports ?? {});
|
|
962
|
-
const plan = planForComp(comp);
|
|
963
|
-
const typedNodes = buildTypedNodes(comp, plan);
|
|
964
|
-
const asBinding = mapAsBinding(comp, n, typedNodes, plan);
|
|
965
|
-
const narrowed = nodeNarrowedPaths(comp, n);
|
|
966
|
-
const mSchemas = m.portSchemas;
|
|
967
|
-
for (const p of Object.keys(ports))
|
|
968
|
-
if (!portIsStatic(ports[p], comp, plan, typedNodes, inputPortTypeRef(mSchemas?.[p], plan), asBinding, narrowed))
|
|
969
|
-
return false;
|
|
970
|
-
return true;
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* coveredFanoutNode (v3) — a FANOUT node (first-class `@refs` id-list fan-out) is covered when:
|
|
974
|
-
* - over is a static ref to a PRIOR BODY NODE's typed arr field OR an INPUT array port with elemType,
|
|
975
|
-
* - every element port is static (literal / ref into the $as binding / concat / static arr),
|
|
976
|
-
* - relationKind connection (guard-checked by the guard/builder); every Error Policy Kind is covered.
|
|
977
|
-
* The fanout de-boxes to: one deduped batched dispatch → first-seen dedupe (by the elem's dedupeKey
|
|
978
|
-
* field) + dangling drop + implicitSource strip + connection wrap {items, cursor:nil} — NO boxed Value.
|
|
979
|
-
*/
|
|
980
|
-
function coveredFanoutNode(n, bodyIds, comp) {
|
|
981
|
-
if (n === null || typeof n !== "object" || !("fanout" in n))
|
|
982
|
-
return false;
|
|
983
|
-
const f = n.fanout;
|
|
984
|
-
if (f.relationKind !== "connection")
|
|
985
|
-
return false;
|
|
986
|
-
const overE = classifyExpr(f.over);
|
|
987
|
-
if (overE.kind !== "ref")
|
|
988
|
-
return false;
|
|
989
|
-
const head = overE.path[0];
|
|
990
|
-
if (!bodyIds.has(head)) {
|
|
991
|
-
// input-array over: covered only when the port declares elemType (C3 — no inference). #177 (A): an OPT
|
|
992
|
-
// input array (`{opt:{arr}}`, required:false) IS covered — its null iterates EMPTY (goOverElemInfo.optArr
|
|
993
|
-
// → nil-safe deref, `range`/`len` over a nil slice = 0), byte-equal to run_behavior.
|
|
994
|
-
if (overE.path.length !== 1)
|
|
995
|
-
return false;
|
|
996
|
-
const schema = comp.inputPorts?.[head];
|
|
997
|
-
if (schema === undefined || schema.elemType === undefined)
|
|
998
|
-
return false;
|
|
999
|
-
}
|
|
1000
|
-
const ports = f.ports;
|
|
1001
|
-
const plan = planForComp(comp);
|
|
1002
|
-
const typedNodes = buildTypedNodes(comp, plan);
|
|
1003
|
-
let asBinding;
|
|
1004
|
-
try {
|
|
1005
|
-
asBinding = { name: f.as, ref: fanoutOverElemInfo(comp, n, typedNodes, plan).elemRef, plan };
|
|
1006
|
-
}
|
|
1007
|
-
catch {
|
|
1008
|
-
asBinding = undefined;
|
|
1009
|
-
}
|
|
1010
|
-
const fSchemas = f.portSchemas;
|
|
1011
|
-
for (const p of Object.keys(ports))
|
|
1012
|
-
if (!portIsStatic(ports[p], comp, plan, typedNodes, inputPortTypeRef(fSchemas?.[p], plan), asBinding))
|
|
1013
|
-
return false;
|
|
1014
|
-
return true;
|
|
1015
|
-
}
|
|
1016
|
-
/** A covered read SHAPE (typing-independent) — sequential componentRef reads + covered map...into,
|
|
1017
|
-
* OR a real-concurrency staged plan (bc#87) whose parallel-stage members are plain componentRef point
|
|
1018
|
-
* reads. A real-concurrency plan whose parallel members include a map / bindField-relation child is
|
|
1019
|
-
* NOT covered here (falls through) — the static-parallel orchestration covers the componentRef fan-out
|
|
1020
|
-
* (the GroupAccessRead shape); a parallel map/relation-child stage is a further shape (out of scope). */
|
|
1021
|
-
function isSequentialComponentRefRead(comp) {
|
|
1022
|
-
return coverageRejectReason(comp) === null;
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* coverageRejectReason — the DIAGNOSTIC twin of isSequentialComponentRefRead (bc#86/#89). Returns
|
|
1026
|
-
* null when the component IS a covered native read; otherwise a SPECIFIC human-readable reason naming
|
|
1027
|
-
* the exact disqualifier and the offending node id. The predicate logic is IDENTICAL to
|
|
1028
|
-
* isSequentialComponentRefRead (which is defined as `coverageRejectReason(c) === null`) so the two can
|
|
1029
|
-
* never disagree. This is the message the fail-closed dispatch surfaces per non-native component — the
|
|
1030
|
-
* user's signal to add native coverage, fix a genuinely-dynamic spec, or use the --ir dynamic surface.
|
|
1031
|
-
*/
|
|
1032
|
-
function coverageRejectReason(comp) {
|
|
1033
|
-
const crPlan = planForComp(comp);
|
|
1034
|
-
const crTypedNodes = buildTypedNodes(comp, crPlan);
|
|
1035
|
-
const ep = execPlan(comp);
|
|
1036
|
-
if (ep === null)
|
|
1037
|
-
return "component is not a straight-line/staged sequential exec plan (no static exec plan)";
|
|
1038
|
-
// A parallel-stage member must be a componentRef node (no map) so the static parallel orchestration
|
|
1039
|
-
// is a clean fan-out — the bounded-concurrency error-precedence protocol is proven for that shape.
|
|
1040
|
-
// A map child inside a parallel stage still falls through (its per-element loop is a further shape).
|
|
1041
|
-
// #114: a bindField relation child (single|connection) IS covered inside a parallel stage — the
|
|
1042
|
-
// sibling hasMany fan-out (parent → members ∥ permissions). Its bound-key skip-gate is preflighted
|
|
1043
|
-
// per member (from the settled parent) BEFORE dispatch, so the parallel fan-out keeps run_behavior's
|
|
1044
|
-
// per-member skip semantics; the per-node relationKind constraint below (single|connection) applies
|
|
1045
|
-
// to it too. A non-single/connection bindField member is rejected by that shared check.
|
|
1046
|
-
for (const [i] of ep.parallelStageOf) {
|
|
1047
|
-
const n = comp.body[i];
|
|
1048
|
-
// #125/#108: a cond node IS allowed as a parallel-stage member — it is a pure Expression (no
|
|
1049
|
-
// dispatch), evaluated in preflight ascending order, so its produced flag / typed result cell is
|
|
1050
|
-
// settled before any dispatch. It carries no handler and no boxed result, so it does not disturb the
|
|
1051
|
-
// bounded-concurrency error-precedence protocol (which governs the componentRef fan-out members).
|
|
1052
|
-
// Covers BOTH the when(...) control-gate cond (#136, {ok}/null skip marker) AND the Φ-merge VALUE
|
|
1053
|
-
// cond (#108, has outType, then/else are data branches — the sibling Φ-join). The cond's own
|
|
1054
|
-
// validity (a value cond REQUIRES outType; a control gate is exempt) is enforced by the per-node
|
|
1055
|
-
// cond check below, so a parallel value cond without outType still loud-rejects there.
|
|
1056
|
-
// #225: 純式 map(`map.transform` — Component 呼びなし)も同じ性質を持つ: handler も boxed result も
|
|
1057
|
-
// 無い変換なので、昇順 preflight で確定させれば bounded-concurrency の error-precedence 協定
|
|
1058
|
-
// (componentRef fan-out メンバを統べる)を乱さない。cond の免除根拠がそのまま当てはまる。
|
|
1059
|
-
if ("cond" in n)
|
|
1060
|
-
continue;
|
|
1061
|
-
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
1062
|
-
continue;
|
|
1063
|
-
if (!("component" in n))
|
|
1064
|
-
return `node '${n.id}' is a non-componentRef member of a parallel stage (not native-covered)`;
|
|
1065
|
-
}
|
|
1066
|
-
const bodyIds = new Set(comp.body.map((b) => b.id));
|
|
1067
|
-
for (const n of comp.body) {
|
|
1068
|
-
// A read of a node that can be unproduced at that point (scp-error.md "Dependency rules for continue":
|
|
1069
|
-
// the interpreters read its unproduced value — null, or NULL_REF through it) has no native lowering here:
|
|
1070
|
-
// the native read takes the node's struct as produced, which would hand on its ZERO value. Fail closed.
|
|
1071
|
-
const unguarded = unguardedUnproducibleReads(comp, n);
|
|
1072
|
-
if (unguarded.length > 0)
|
|
1073
|
-
return `node '${n.id}' reads node '${unguarded[0]}', which can be unproduced when '${n.id}' reads it — the unproduced read is not native-covered`;
|
|
1074
|
-
if ("cond" in n) {
|
|
1075
|
-
// #125: a when(...) control-gate cond (`{if, then:{obj:{ok:true}}, else:null}`) は制御スキップ
|
|
1076
|
-
// マーカーで出力データ型を持たない(A3 の意図的 typeless design)— outType を要求しない。gate は
|
|
1077
|
-
// if を native bool へコンパイルし produced_<gate> に写すだけで、分岐内ノードは既存の
|
|
1078
|
-
// `parent=gate, bindField:"ok"` skip-gate(run_behavior の null-binding skip)が実行選択する。
|
|
1079
|
-
if (isControlGate(n))
|
|
1080
|
-
continue;
|
|
1081
|
-
// #108: a DATA-JOIN cond node (Φ 合流) is native-covered — its `if`/`then`/`else` compile to native
|
|
1082
|
-
// expressions via the runtime-free NativeExprCompiler (byte-equal to run_behavior's cond lower). If an
|
|
1083
|
-
// expression is not statically compilable (uncovered op / refOpt / opt operand / type mismatch), the
|
|
1084
|
-
// compiler fails closed at emit (a loud GeneratorFailure) — never a silent box. A data-join cond
|
|
1085
|
-
// requires outType(合流値を de-box する対象だから — control gate だけがこの要求を免除される)。
|
|
1086
|
-
if (n.outType === undefined)
|
|
1087
|
-
return `node '${n.id}' cond has no outType (required to de-box the branch join)`;
|
|
1088
|
-
continue;
|
|
1089
|
-
}
|
|
1090
|
-
if ("fanout" in n) {
|
|
1091
|
-
// v3: a first-class fanout node (deduped connection list-in fan-out) IS covered when its over is a
|
|
1092
|
-
// covered ref (prior-node arr / input array with elemType) and its element ports are static.
|
|
1093
|
-
if (!coveredFanoutNode(n, bodyIds, comp))
|
|
1094
|
-
return `node '${n.id}' is a non-covered fanout shape (over an input array without elemType, or a dynamic element port)`;
|
|
1095
|
-
continue;
|
|
1096
|
-
}
|
|
1097
|
-
if ("map" in n) {
|
|
1098
|
-
// #86 pt2 batched map...into / #93 shape 2/3 / #108 guarded map (no into) / map-over-input (with
|
|
1099
|
-
// elemType) ARE covered. A non-covered map shape (guard+into heterogeneous / over-input without
|
|
1100
|
-
// elemType) falls through to the loud fail-closed reject.
|
|
1101
|
-
if (!coveredMapNode(n, bodyIds, comp))
|
|
1102
|
-
return `node '${n.id}' is a non-covered map shape (guard+into heterogeneous, or over an input array without elemType)`;
|
|
1103
|
-
continue;
|
|
1104
|
-
}
|
|
1105
|
-
if (!("component" in n))
|
|
1106
|
-
return `node '${n.id}' is not a componentRef, map, or cond node (not native-covered)`;
|
|
1107
|
-
const cr = n;
|
|
1108
|
-
// Every Error Policy Kind IS covered on a componentRef: `continue` makes the node unproduced, which the
|
|
1109
|
-
// produced-aware output lowering (typed.ts `lowerProducedAwareRead`, driven by the same canSkip the
|
|
1110
|
-
// bindField skip uses) already renders, and `retry` shares `fail`'s control flow with the Kind named
|
|
1111
|
-
// (the attempts themselves are Runtime-owned — scp-error.md §Separating Policy Kind and Tuning, which
|
|
1112
|
-
// in native mode is the per-Component leaf transport). Proven by real go build + run, not by assertion.
|
|
1113
|
-
// #86 part 1: a relation child WITH bindField IS covered. When the
|
|
1114
|
-
// bound parent field is null/absent the child is UNPRODUCED — the produced-aware output lowering
|
|
1115
|
-
// (`lowerProducedAwareRead`, handed to the ONE output recursion so it reaches every output slot) then
|
|
1116
|
-
// yields the unproduced rep (null / opt-nil) for a ref/refOpt into it, matching run_behavior's
|
|
1117
|
-
// bindUnproduced. #93 shape 1: a bindField on a relationKind:connection child is ALSO covered — the
|
|
1118
|
-
// connection's unproduced rep is the empty connection {items:[],cursor:null}
|
|
1119
|
-
// (unproducedValue("connection")), which `unproducedInSlot` emits explicitly for a skipped connection
|
|
1120
|
-
// node (a ref into it yields {items:[],cursor:null}, matching run_behavior).
|
|
1121
|
-
// relationKind の閉集合は `connection` の 1 値で、**注記の不在**が「未生成は null」を意味する。ゆえに
|
|
1122
|
-
// bindField 由来 skip は 2 形(connection = 空 connection / 不在 = null)とも produced-aware 出力が
|
|
1123
|
-
// 表現でき、被覆条件は無い(かつての「明示的に single と書け」は既定値の重複綴りの要求だった)。
|
|
1124
|
-
if (cr.relationKind !== undefined && cr.relationKind !== "connection")
|
|
1125
|
-
return `relationKind '${cr.relationKind}' not native-covered (node '${n.id}')`;
|
|
1126
|
-
// #170: a control-gate child's ports may narrow a gate-proven opt ref to non-null (the (a3) gated read).
|
|
1127
|
-
const crNarrowed = nodeNarrowedPaths(comp, cr);
|
|
1128
|
-
for (const p of Object.keys(cr.ports))
|
|
1129
|
-
if (portIsStatic(cr.ports[p], comp, crPlan, crTypedNodes, inputPortTypeRef(cr.portSchemas?.[p], crPlan), undefined, crNarrowed) === false)
|
|
1130
|
-
return `node '${n.id}' port '${p}' is not statically resolvable`;
|
|
1131
|
-
}
|
|
1132
|
-
if (!outputIsNativeLowerable(comp))
|
|
1133
|
-
return "output is not natively lowerable";
|
|
1134
|
-
return null;
|
|
1135
|
-
}
|
|
1136
|
-
/** Fail closed if a covered read SHAPE lacks the typed annotations (no silent boxed re-box). */
|
|
1137
|
-
function assertTypedCoverage(comp) {
|
|
1138
|
-
if (!isSequentialComponentRefRead(comp))
|
|
1139
|
-
return;
|
|
1140
|
-
if (isFullyTyped(comp))
|
|
1141
|
-
return;
|
|
1142
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go combined read (bc#77): component '${comp.name}' is a sequential componentRef read but lacks outType/outputType on every node — the combined emitter de-boxes the RESULT into the node's outType struct, so a covered read MUST be fully typed (bc#45). Add outType annotations, or regenerate on go-straightline-native (boxed result).`);
|
|
1143
|
-
}
|
|
732
|
+
/** goCoverage — the ONE native coverage rule (native-coverage.ts) bound to the Go port lowering: eligibility
|
|
733
|
+
* asks {@link compilePortNode} — the SAME lowering emission uses, with the SAME narrowing and declared port
|
|
734
|
+
* type — so a port is judged covered iff it also emits. */
|
|
735
|
+
const goCoverage = new NativeCoverage("go", "go typed-native", (node, comp, plan, typedNodes, expected, { asBinding, narrowed }) => {
|
|
736
|
+
const opts = asBinding !== undefined ? { asBinding, asBase: asBinding.name, narrowed } : narrowed !== undefined ? { narrowed } : undefined;
|
|
737
|
+
compilePortNode(node, comp, plan, typedNodes, (h) => typedNodes.has(h), "port", expected, opts);
|
|
738
|
+
});
|
|
1144
739
|
/**
|
|
1145
740
|
* resolveLeafSymbol — the op-agnostic transport symbol a covered leaf (= catalog component) is called
|
|
1146
741
|
* through at its execution point. A consumer-supplied override (`leafTransport.symbols[component]`) wins;
|
|
@@ -1233,51 +828,19 @@ function mapElemMaterializerName(compName, nodeId) {
|
|
|
1233
828
|
return `materializeMapElemNR_${sanitize(compName)}_${nodeId.replace(/[^A-Za-z0-9_]/g, "_")}`;
|
|
1234
829
|
}
|
|
1235
830
|
/**
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
if (connRef.kind !== "named") {
|
|
1243
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go fanout (v3): node '${node.id}' outType must be a connection struct {items,cursor} (got ${JSON.stringify(connRef.kind)}).`);
|
|
1244
|
-
}
|
|
1245
|
-
const decl = findDecl(plan, connRef.name);
|
|
1246
|
-
const itemsField = decl.fields.find((fd) => fd.name === "items");
|
|
1247
|
-
if (!itemsField || itemsField.type.kind !== "arr") {
|
|
1248
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go fanout (v3): node '${node.id}' connection struct '${connRef.name}' has no 'items' array field.`);
|
|
1249
|
-
}
|
|
1250
|
-
return itemsField.type.elem;
|
|
1251
|
-
}
|
|
1252
|
-
/**
|
|
1253
|
-
* goOverElemInfo — the ONE resolver of a fanout/map `over` to its element TypeRef + native Go over-slice
|
|
1254
|
-
* expression (fanoutOverElemInfo / mapOverElemInfo both delegate here — single definition, no forked twin).
|
|
1255
|
-
*
|
|
1256
|
-
* `optArr` is true when the over's declared type is `{opt:{arr}}` (a prior-node opt-arr field OR an OPT
|
|
1257
|
-
* input array port). #177 (A): a null opt-arr over then iterates EMPTY — the emitted `overExpr` is a
|
|
1258
|
-
* `*[]E` pointer (nil when the optional collection is absent), which the arm binds via a nil-safe deref so
|
|
1259
|
-
* `range`/`len` see a 0-length slice, byte-equal to run_behavior's empty iteration. A REQUIRED arr (nil)
|
|
1260
|
-
* still fails run_behavior FANOUT/MAP_OVER_NOT_ARRAY, so it stays optArr:false (non-covered on null).
|
|
831
|
+
* goOverElemInfo — the Go read of a fanout/map `over` collection: the element TypeRef, the optional-array
|
|
832
|
+
* flag and the source come from the ONE resolver {@link resolveOverOrFail} (native-coverage.ts); this
|
|
833
|
+
* renders only the native Go over-slice expression of that source (fanoutOverElemInfo / mapOverElemInfo
|
|
834
|
+
* both delegate here). #177 (A): for an `optArr` over the emitted `overExpr` is a `*[]E` pointer (nil when
|
|
835
|
+
* the optional collection is absent), which the arm binds via a nil-safe deref so `range`/`len` see a
|
|
836
|
+
* 0-length slice, byte-equal to run_behavior's empty iteration.
|
|
1261
837
|
*/
|
|
1262
838
|
function goOverElemInfo(comp, over, typedNodes, plan, nodeId, label) {
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
return { elemRef: ref.elem, overExpr: expr, optArr: false };
|
|
1269
|
-
if (ref.kind === "opt" && ref.inner.kind === "arr")
|
|
1270
|
-
return { elemRef: ref.inner.elem, overExpr: expr, optArr: true };
|
|
1271
|
-
}
|
|
1272
|
-
if (e.kind === "ref" && e.path.length === 1) {
|
|
1273
|
-
const schema = comp.inputPorts?.[e.path[0]];
|
|
1274
|
-
const et = schema?.elemType;
|
|
1275
|
-
// #192: read the input port via the goInputHeadRef seam (single input-ref path) — not a parallel `in.<Field>`.
|
|
1276
|
-
const head = goInputHeadRef(e.path[0], comp, plan);
|
|
1277
|
-
if (et !== undefined && head !== null)
|
|
1278
|
-
return { elemRef: deriveTypeRef(et, plan), overExpr: head.expr, optArr: inputPortIsOptional(schema) };
|
|
1279
|
-
}
|
|
1280
|
-
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).`);
|
|
839
|
+
const r = resolveOverOrFail("go", comp, over, typedNodes, plan, nodeId, label);
|
|
840
|
+
const overExpr = r.source.kind === "node"
|
|
841
|
+
? goTypedInternals.typedFieldAccess(typedLocal(r.source.head), typedNodes.get(r.source.head), r.source.path, plan).expr
|
|
842
|
+
: goInputHeadRef(r.source.port, comp, plan).expr; // #192: the input port via the goInputHeadRef seam
|
|
843
|
+
return { elemRef: r.elemRef, overExpr, optArr: r.optArr };
|
|
1281
844
|
}
|
|
1282
845
|
/**
|
|
1283
846
|
* goBindOver — emit the `over_<s>` binding lines. A non-opt over binds the slice directly; an opt-arr over
|
|
@@ -1298,33 +861,6 @@ function goBindOver(indent, s, overExpr, optArr, overElemGo) {
|
|
|
1298
861
|
function fanoutOverElemInfo(comp, node, typedNodes, plan) {
|
|
1299
862
|
return goOverElemInfo(comp, node.fanout.over, typedNodes, plan, node.id, "fanout (v3)");
|
|
1300
863
|
}
|
|
1301
|
-
/** mapNodeArrRef — the map node's PRODUCED-ARRAY TypeRef from its `outType`.
|
|
1302
|
-
*
|
|
1303
|
-
* A map node's `outType` is its ELEMENT type (scp-error.md "Map element type"), so the produced array
|
|
1304
|
-
* is `{arr: element}`. This is the same reading the compiler applies when it resolves what a node
|
|
1305
|
-
* result reference has (`type-gate`: `"map" in n ? {arr:ot} : ot`) — the emitter follows that SSoT
|
|
1306
|
-
* rather than inspecting the annotation's shape, so an element that is ITSELF an `arr` stays
|
|
1307
|
-
* expressible (element `arr(T)` produces `arr(arr(T))`). */
|
|
1308
|
-
function mapNodeArrRef(node, plan) {
|
|
1309
|
-
const outT = node.outType;
|
|
1310
|
-
return deriveTypeRef({ arr: outT }, plan);
|
|
1311
|
-
}
|
|
1312
|
-
/** mapElemRowRef — the handler's per-element RETURN shape for a covered map node: the `into` field's
|
|
1313
|
-
* type (into) or the element outType directly (no-into). This is the type of RawElem_<comp>_<node>. */
|
|
1314
|
-
function mapElemRowRef(node, arrRef, plan) {
|
|
1315
|
-
const m = node.map;
|
|
1316
|
-
if (m.into === undefined)
|
|
1317
|
-
return arrRef.elem;
|
|
1318
|
-
if (arrRef.elem.kind !== "named") {
|
|
1319
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go combined map (#86 pt2): node '${node.id}' element outType must be a named struct (got ${JSON.stringify(arrRef.elem.kind)}) — the augmented element de-boxes into a struct. Regenerate as boxed typed/straight-line.`);
|
|
1320
|
-
}
|
|
1321
|
-
const decl = findDecl(plan, arrRef.elem.name);
|
|
1322
|
-
const intoField = decl.fields.find((f) => f.name === m.into);
|
|
1323
|
-
if (!intoField) {
|
|
1324
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go combined map (#86 pt2): element struct '${arrRef.elem.name}' has no '${m.into}' (into) field.`);
|
|
1325
|
-
}
|
|
1326
|
-
return intoField.type;
|
|
1327
|
-
}
|
|
1328
864
|
/**
|
|
1329
865
|
* emitMapElemMaterializers — for each covered map...into node, emit the AUGMENTED-element copier: copy
|
|
1330
866
|
* the over element's typed fields + place the already-de-boxed `into` value into its field. Pure struct
|
|
@@ -1347,7 +883,7 @@ function emitMapElemMaterializers(comp, typedNodes, plan) {
|
|
|
1347
883
|
// over element type (all element fields EXCEPT the into field): these come from the over element
|
|
1348
884
|
// struct (the parent collection element). We copy each by same-named field access.
|
|
1349
885
|
const overFields = decl.fields.filter((f) => f.name !== intoKey);
|
|
1350
|
-
const intoRowRef = mapElemRowRef(n, arrRef, plan);
|
|
886
|
+
const intoRowRef = mapElemRowRef("go", n, arrRef, plan);
|
|
1351
887
|
const fn = mapElemMaterializerName(comp.name, n.id);
|
|
1352
888
|
const overElemGo = mapOverElemType(comp, n, typedNodes, plan);
|
|
1353
889
|
const lines = [];
|
|
@@ -1379,38 +915,7 @@ function mapOverElemInfo(comp, node, typedNodes, plan) {
|
|
|
1379
915
|
function mapOverElemType(comp, node, typedNodes, plan) {
|
|
1380
916
|
return renderTypeRef(mapOverElemInfo(comp, node, typedNodes, plan).elemRef);
|
|
1381
917
|
}
|
|
1382
|
-
|
|
1383
|
-
if (staticArrElems(node) !== null)
|
|
1384
|
-
return "static";
|
|
1385
|
-
const e = classifyExpr(node);
|
|
1386
|
-
switch (e.kind) {
|
|
1387
|
-
case "str":
|
|
1388
|
-
case "bool":
|
|
1389
|
-
case "null":
|
|
1390
|
-
case "ref":
|
|
1391
|
-
return "static";
|
|
1392
|
-
case "concat":
|
|
1393
|
-
return e.parts.every((p) => classifyPort(reconstructG(p)) === "static") ? "static" : "dynamic";
|
|
1394
|
-
default:
|
|
1395
|
-
return "dynamic";
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
function reconstructG(e) {
|
|
1399
|
-
switch (e.kind) {
|
|
1400
|
-
case "str":
|
|
1401
|
-
return e.value;
|
|
1402
|
-
case "bool":
|
|
1403
|
-
return e.value;
|
|
1404
|
-
case "null":
|
|
1405
|
-
return null;
|
|
1406
|
-
case "ref":
|
|
1407
|
-
return { [e.opt ? "refOpt" : "ref"]: e.path };
|
|
1408
|
-
case "concat":
|
|
1409
|
-
return { concat: e.parts.map(reconstructG) };
|
|
1410
|
-
case "dynamic":
|
|
1411
|
-
return e.node;
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
918
|
+
// ── the combined runner (INLINE sequential, native ports in, raw struct out) ────────────
|
|
1414
919
|
// bc#90 / runtime-free: the old nvVE-based `emitStaticVE` / `valueLeaf` port lowering (which built
|
|
1415
920
|
// `dslcontracts.Value` leaves via the nv* helpers) is REMOVED — every covered port now lowers to a
|
|
1416
921
|
// FULLY NATIVE Go value in emitPortInit (string / bool / static-string-array / number literal), and a
|
|
@@ -1585,6 +1090,10 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1585
1090
|
// de-boxes it INLINE (so the wire — not the decode — is what the goroutine writes to its slot).
|
|
1586
1091
|
lines.push(`\t\tvar wire_${s} ${wire.value}`);
|
|
1587
1092
|
lines.push(`\t\tvar row_${s}Err error`);
|
|
1093
|
+
// a panic the leaf transport raises on the worker goroutine is recovered there and re-raised on the
|
|
1094
|
+
// caller's goroutine at this member's commit (≡ RunPlan, go/coderuntime/plan.go) — an unrecovered panic
|
|
1095
|
+
// on a spawned goroutine ends the whole process, beyond the reach of the caller's recover.
|
|
1096
|
+
lines.push(`\t\tvar repanic_${s} func()`);
|
|
1588
1097
|
lines.push(`\t\trun_${s} := false`);
|
|
1589
1098
|
// the op-agnostic transport payload (#183): a WireRow of the node's boxed ports, built in preflight and
|
|
1590
1099
|
// read (by value) inside the goroutine — the ONE arg the spec-named leaf transport takes for ALL roles.
|
|
@@ -1666,6 +1175,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1666
1175
|
lines.push(`\t\t\tgo func() {`);
|
|
1667
1176
|
lines.push(`\t\t\t\tdefer wg.Done()`);
|
|
1668
1177
|
lines.push(`\t\t\t\tdefer func() { <-sem }()`);
|
|
1178
|
+
lines.push(`\t\t\t\tdefer func() {`, `\t\t\t\t\tif r := recover(); r != nil {`, `\t\t\t\t\t\trepanic_${s} = func() { panic(r) }`, `\t\t\t\t\t}`, `\t\t\t\t}()`);
|
|
1669
1179
|
// DIRECT leaf transport call — ONE op-agnostic symbol, ONE WireRow payload (the preflight-built ports).
|
|
1670
1180
|
// No `bound` (BC's internal produced/skip gate is already applied in preflight — the leaf never sees it).
|
|
1671
1181
|
const call = goLeafCall(resolveLeafSymbol(node.component, leaf, node.leafSymbol), `payload_${s}`);
|
|
@@ -1689,6 +1199,8 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1689
1199
|
if (portsFallible(i))
|
|
1690
1200
|
lines.push(`\t\tif perr_${s} != nil {`, `\t\t\treturn ${zeroOut}, perr_${s}`, `\t\t}`);
|
|
1691
1201
|
lines.push(`\t\tif run_${s} {`);
|
|
1202
|
+
// a leaf panic surfaces HERE, at this member's index, on the caller's goroutine (≡ RunPlan's commit).
|
|
1203
|
+
lines.push(`\t\t\tif repanic_${s} != nil {`, `\t\t\t\trepanic_${s}()`, `\t\t\t}`);
|
|
1692
1204
|
if (meta.policy === "continue") {
|
|
1693
1205
|
// continue: a failed member (leaf failure OR de-box mismatch) commits no Port (defensive — covered
|
|
1694
1206
|
// componentRef members are always 'fail' policy today). A local skip, NOT a runner-wide propagate.
|
|
@@ -2029,7 +1541,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
|
|
|
2029
1541
|
// it against the element ref (the `into` field's type for map...into, else the element type). A de-box
|
|
2030
1542
|
// mismatch fails closed regardless of elementPolicy (matching the interpreter's whole-node outType
|
|
2031
1543
|
// throw); elementPolicy still governs the handler's own leaf failures only.
|
|
2032
|
-
const elemRowRef = mapElemRowRef(node, arrRef, plan);
|
|
1544
|
+
const elemRowRef = mapElemRowRef("go", node, arrRef, plan);
|
|
2033
1545
|
const elemRowGo = renderTypeRef(elemRowRef);
|
|
2034
1546
|
const renderElemDeBox = (target, src, il) => renderResultDeBox(elemRowRef, target, src, node.id, plan, il, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node));
|
|
2035
1547
|
// #177/#182 keep-with-skip-value: the into value for a guard-skipped element is driven by relationKind,
|
|
@@ -2261,7 +1773,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
|
|
|
2261
1773
|
const wvQ = goWireQ(wireSel);
|
|
2262
1774
|
const leafSym = resolveLeafSymbol(f.component, leaf, f.leafSymbol);
|
|
2263
1775
|
const connRef = typedNodes.get(node.id);
|
|
2264
|
-
const elemRef = fanoutItemsElemRef(node, connRef, plan);
|
|
1776
|
+
const elemRef = fanoutItemsElemRef("go", node, connRef, plan);
|
|
2265
1777
|
const elemGo = renderTypeRef(elemRef);
|
|
2266
1778
|
const { elemRef: overElemRef, overExpr, optArr: overOptArr } = fanoutOverElemInfo(comp, node, typedNodes, plan);
|
|
2267
1779
|
const overElemGo = renderTypeRef(overElemRef);
|
|
@@ -2308,27 +1820,28 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
|
|
|
2308
1820
|
// empty id-list => empty connection (handler not called), matching run_behavior.
|
|
2309
1821
|
lines.push(`${indent}if len(pi_${s}) > 0 {`);
|
|
2310
1822
|
// ONE op-agnostic transport call: batch payload WireRow {items:[…]}; result is a WireList of the aligned
|
|
2311
|
-
// per-id element wires (read via `.Items`). A DANGLING id is a WireNull element
|
|
2312
|
-
//
|
|
1823
|
+
// per-id element wires (read via `.Items`). A DANGLING id is a WireNull element (or a row whose dedupeKey is
|
|
1824
|
+
// absent / null) — dropped under drop:dangling, kept and failed by the de-box under drop:none. No `bound`.
|
|
2313
1825
|
lines.push(`${indent}\tfo_${s}, fo_${s}Err := ${goLeafCall(leafSym, goPayloadBatch(`pi_${s}`, wireSel))}`);
|
|
2314
1826
|
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}`);
|
|
2315
1827
|
lines.push(`${indent}\tfw_${s} := fo_${s}.Items`);
|
|
2316
1828
|
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}`);
|
|
2317
1829
|
// ── THE ONE dedupe/drop (mirrors fanoutDedupDrop verbatim): first-seen dedupe by dedupeKey field;
|
|
2318
|
-
// drop dangling (
|
|
1830
|
+
// drop dangling (non-row body / absent or null dedupeKey); implicitSource strip is
|
|
2319
1831
|
// structural (the elem type already omits it). cursor is always nil (connection wrap).
|
|
2320
1832
|
lines.push(`${indent}\tseen_${s} := make(map[string]struct{}, len(fw_${s}))`);
|
|
2321
1833
|
lines.push(`${indent}\titems_${s} = make([]${elemGo}, 0, len(fw_${s}))`);
|
|
2322
1834
|
lines.push(`${indent}\tfor fi_${s} := range fw_${s} {`);
|
|
2323
|
-
lines.push(`${indent}\t\tvar el_${s} ${elemGo}`);
|
|
2324
|
-
lines.push(`${indent}\t\tif !fw_${s}[fi_${s}].IsNull() {`);
|
|
2325
|
-
lines.push(renderResultDeBox(elemRef, `el_${s}`, `fw_${s}[fi_${s}]`, node.id, plan, `${indent}\t\t\t`, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node)));
|
|
2326
|
-
lines.push(`${indent}\t\t}`);
|
|
2327
|
-
lines.push(`${indent}\t\tkey_${s} := el_${s}.${dkGo}`);
|
|
2328
1835
|
if (f.drop === "dangling") {
|
|
2329
|
-
// dangling: a body whose dedupeKey is
|
|
2330
|
-
|
|
1836
|
+
// dangling ≡ fanoutDedupDrop: a body that is not a row, or whose dedupeKey is absent / null, is dropped.
|
|
1837
|
+
// A present key — the empty string included — is a real row and is kept (de-boxed and deduped below).
|
|
1838
|
+
lines.push(`${indent}\t\tif dr_${s} := fw_${s}[fi_${s}].AsRow(); dr_${s}.Kind != probeGot {`, `${indent}\t\t\tcontinue`, `${indent}\t\t} else if dk_${s} := dr_${s}.Got.ProbeString(${JSON.stringify(f.dedupeKey)}); dk_${s}.Kind == probeAbsent || dk_${s}.Kind == probeNull {`, `${indent}\t\t\tcontinue`, `${indent}\t\t}`);
|
|
2331
1839
|
}
|
|
1840
|
+
// every kept body is de-boxed strictly: under drop:none a dangling body (null) is kept as-is by
|
|
1841
|
+
// fanoutDedupDrop and fails the element type exactly as run_behavior's outType check does.
|
|
1842
|
+
lines.push(`${indent}\t\tvar el_${s} ${elemGo}`);
|
|
1843
|
+
lines.push(renderResultDeBox(elemRef, `el_${s}`, `fw_${s}[fi_${s}]`, node.id, plan, `${indent}\t\t`, returnZeroFail(zeroOut), wireSel, nodeWirePassthrough(node)));
|
|
1844
|
+
lines.push(`${indent}\t\tkey_${s} := el_${s}.${dkGo}`);
|
|
2332
1845
|
lines.push(`${indent}\t\tif _, dup_${s} := seen_${s}[key_${s}]; dup_${s} {`, `${indent}\t\t\tcontinue`, `${indent}\t\t}`);
|
|
2333
1846
|
lines.push(`${indent}\t\tseen_${s}[key_${s}] = struct{}{}`);
|
|
2334
1847
|
lines.push(`${indent}\t\titems_${s} = append(items_${s}, el_${s})`);
|
|
@@ -2930,11 +2443,10 @@ var ExpectedSpecVersions = map[string]int64{"behavior": ${sv.behavior}, "express
|
|
|
2930
2443
|
}
|
|
2931
2444
|
// ── module assembly ──────────────────────────────────────────────────────────────────
|
|
2932
2445
|
function emit(ctx) {
|
|
2933
|
-
//
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
const native = ctx.ir.components
|
|
2937
|
-
const nonNative = ctx.ir.components.filter((c) => !isNativeRaw(c));
|
|
2446
|
+
// FAIL CLOSED (bc#86/#89): the native codegen surface is native-only — every component must be a covered,
|
|
2447
|
+
// fully typed native read (the ONE coverage rule, native-coverage.ts), or generation fails LOUDLY naming
|
|
2448
|
+
// each uncovered component and its specific reason (never a silently boxed component).
|
|
2449
|
+
const native = goCoverage.assertCovered(ctx.ir.components);
|
|
2938
2450
|
const plan = buildTypePlan(ctx.ir);
|
|
2939
2451
|
const wire = resolveGoWire(ctx);
|
|
2940
2452
|
// bc#156: renderTypeRef({kind:"value"}) must resolve to the SAME wire type name the transport returns
|
|
@@ -2989,22 +2501,7 @@ function emit(ctx) {
|
|
|
2989
2501
|
// bc#90: the ONLY std-lib `fmt.Sprintf` site on the covered plane is the batched-map result-count
|
|
2990
2502
|
// mismatch error — so `fmt` is imported iff a covered component has a batched map node.
|
|
2991
2503
|
const needFmt = native.some((c) => c.body.some((n) => ("map" in n && n.map.batched === true) || "fanout" in n));
|
|
2992
|
-
// The FULLY-covered module
|
|
2993
|
-
// bc-runtime import at all (bc#90).
|
|
2994
|
-
// FAIL CLOSED (bc#86/#89): the --typed-native (native codegen) surface is native-only. If ANY
|
|
2995
|
-
// component is not a covered native read, we do NOT silently box it through the straight-line
|
|
2996
|
-
// emitter (the old concealment) — we throw a LOUD GeneratorFailure naming every uncovered component
|
|
2997
|
-
// and its specific reject reason. A fully-covered module (nonNative.length === 0) is unchanged: the
|
|
2998
|
-
// minimal, runtime-free header.
|
|
2999
|
-
if (nonNative.length > 0) {
|
|
3000
|
-
const rejects = nonNative
|
|
3001
|
-
.map((c) => ` - component '${c.name}': ${coverageRejectReason(c) ?? "not a covered native read"}`)
|
|
3002
|
-
.join("\n");
|
|
3003
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go typed-native (native codegen) surface: ${nonNative.length} component(s) are NOT a covered native read:\n${rejects}\n\n` +
|
|
3004
|
-
`The --typed-native (native codegen) surface is native-only and fail-closed: it does not silently ` +
|
|
3005
|
-
`box uncovered shapes. Implement native coverage for this shape, fix the spec if the shape is ` +
|
|
3006
|
-
`genuinely runtime-dynamic, or generate this component on the --ir dynamic interpreter surface.`);
|
|
3007
|
-
}
|
|
2504
|
+
// The FULLY-covered module gets a MINIMAL, RUNTIME-FREE header — NO bc-runtime import at all (bc#90).
|
|
3008
2505
|
// #108: `math` is imported iff the native-expr compiler emitted a fallible helper (bcExpr_modF uses
|
|
3009
2506
|
// math.Mod). The helper library itself is baked into the module only when used (goExprUsed.helpers).
|
|
3010
2507
|
const needMath = goExprUsed.helpers;
|