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,22 +1,15 @@
|
|
|
1
1
|
import { entryPortOrder, GeneratorFailure } from "./core.js";
|
|
2
|
-
import { mapTransformExpr, isControlGate,
|
|
2
|
+
import { mapTransformExpr, isControlGate, nodeWirePassthrough } from "../behavior.js";
|
|
3
3
|
import { rustStraightlineInternals } from "./emit-shared-rust.js";
|
|
4
4
|
import { rustTypedInternals } from "./emit-shared-rust-typed.js";
|
|
5
5
|
import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef, lowerProducedAwareRead, unproducedInSlot } from "./typed.js";
|
|
6
|
-
import {
|
|
6
|
+
import { execPlan, analyzeSequentialOps, opsLiteralOf, classifyExpr, 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 { buildAsyncPlans } from "./async-plan.js";
|
|
9
|
-
import { buildDeBoxPlan, buildWirePlan
|
|
10
|
+
import { buildDeBoxPlan, buildWirePlan } from "./emit-shared-debox.js";
|
|
10
11
|
const { sanitize, rustStrLit } = rustStraightlineInternals;
|
|
11
12
|
const { typeRefIsCopy, rustFieldName, renderTypeRef, typedCell, typedFieldAccess, serializeTyped, emitTypeDecls, emitDefaults, emitTypedValue, rustCellRead, rustCellPathRead, checkOutputFieldType, emitMarshallers, emitMarshalHelpers, } = rustTypedInternals;
|
|
12
|
-
/** rustErr — build the LOCAL concrete error value for a behavior/plan failure on the covered read
|
|
13
|
-
* plane (runtime-free). The covered module declares a local `BehaviorError` (see emitBehaviorErrorType);
|
|
14
|
-
* the runner returns `Result<_, BehaviorError>` over THAT local type. This REPLACES the old
|
|
15
|
-
* `behavior_contracts::BehaviorError::new(...)` (the last error-plane runtime coupling) — the SAME codes
|
|
16
|
-
* are preserved verbatim so the observed failure is byte-equal to run_behavior. */
|
|
17
|
-
function rustErr(code, msgExpr) {
|
|
18
|
-
return `BehaviorError::new(${JSON.stringify(code)}, ${msgExpr})`;
|
|
19
|
-
}
|
|
20
13
|
/** emitErrorTypeDefs — the LOCAL concrete error TYPE (ErrorKind + ErrorDetail + BehaviorError + impls),
|
|
21
14
|
* runtime-free. Baked into the covered module (no --shared-types-import) OR into the shared crate (#165,
|
|
22
15
|
* --shared-types-import) so a cross-crate transport can return `Result<WireValue, BehaviorError>`. Codes
|
|
@@ -183,9 +176,6 @@ fn de_missing_field(model: &str, field: &str, expected: &str) -> BehaviorError {
|
|
|
183
176
|
function emitBehaviorErrorType() {
|
|
184
177
|
return `${emitErrorTypeDefs()}\n\n${emitErrorHelpers()}`;
|
|
185
178
|
}
|
|
186
|
-
function pascal(s) {
|
|
187
|
-
return s.replace(/[^A-Za-z0-9]+/g, " ").split(" ").filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("") || "X";
|
|
188
|
-
}
|
|
189
179
|
/**
|
|
190
180
|
* resolveLeafSymbol — the op-agnostic transport symbol a covered leaf (= catalog component) is called
|
|
191
181
|
* through at its execution point. A consumer-supplied override (`leafTransport.symbols[component]`) wins;
|
|
@@ -782,22 +772,7 @@ const returnErrFail = (errValueExpr) => `return Err(${errValueExpr})`;
|
|
|
782
772
|
function renderResultDeBox(ref, srcExpr, nodeId, plan, indent, fail = returnErrFail, passthrough = false) {
|
|
783
773
|
return renderRustDeBox(buildDeBoxPlan(ref, { from: "top" }, { model: nodeId, field: nodeId, plan }, passthrough), srcExpr, { n: 0 }, indent, fail, null);
|
|
784
774
|
}
|
|
785
|
-
/**
|
|
786
|
-
function mapFanoutElemRef(node, typedNodes, plan) {
|
|
787
|
-
const ref = typedNodes.get(node.id);
|
|
788
|
-
if ("fanout" in node)
|
|
789
|
-
return fanoutItemsElemRef(node, ref, plan);
|
|
790
|
-
return mapElemRowRef(node, ref, plan);
|
|
791
|
-
}
|
|
792
|
-
function staticArrElems(node) {
|
|
793
|
-
if (node === null || typeof node !== "object" || Array.isArray(node))
|
|
794
|
-
return null;
|
|
795
|
-
const keys = Object.keys(node);
|
|
796
|
-
if (keys.length !== 1 || keys[0] !== "arr")
|
|
797
|
-
return null;
|
|
798
|
-
const arg = node.arr;
|
|
799
|
-
return Array.isArray(arg) ? arg : null;
|
|
800
|
-
}
|
|
775
|
+
/** #108: a `$as` element-binding resolver for map ports (rust twin). */
|
|
801
776
|
/**
|
|
802
777
|
* portFieldRustType — the NATIVE Rust type for a covered port field (bc#90 / runtime-free). The covered
|
|
803
778
|
* ports struct carries NO `Value` field: every port lowers to a concrete Rust type.
|
|
@@ -888,15 +863,13 @@ function compilePortNode(node, comp, plan, typedNodes, isPrior, where, expected,
|
|
|
888
863
|
// no separate input-side integrity gate exists.
|
|
889
864
|
return c;
|
|
890
865
|
}
|
|
891
|
-
/**
|
|
892
|
-
*
|
|
893
|
-
*
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
return renderTypeRef(c.ref);
|
|
899
|
-
}
|
|
866
|
+
/** rustCoverage — the ONE native coverage rule (native-coverage.ts) bound to the Rust port lowering: eligibility
|
|
867
|
+
* asks {@link compilePortNode} — the SAME lowering emission uses, with the SAME narrowing and declared port
|
|
868
|
+
* type — so a port is judged covered iff it also emits. */
|
|
869
|
+
const rustCoverage = new NativeCoverage("rust", "rust typed-native", (node, comp, plan, typedNodes, expected, { asBinding, narrowed }) => {
|
|
870
|
+
const opts = asBinding !== undefined ? { asBinding, asBase: asBinding.name, narrowed } : narrowed !== undefined ? { narrowed } : undefined;
|
|
871
|
+
compilePortNode(node, comp, plan, typedNodes, (h) => typedNodes.has(h), "port", expected, opts);
|
|
872
|
+
});
|
|
900
873
|
// ── native expression compiler backend (#108) — cond `if` / map `when` / cond branches (Rust) ────────
|
|
901
874
|
//
|
|
902
875
|
// The runtime-free native expression compiler (native-expr.ts) mirrors run_behavior's cond/guard with
|
|
@@ -1269,33 +1242,6 @@ function boundRustType(node, typedNodes, plan) {
|
|
|
1269
1242
|
function mapElemMaterializerName(compName, nodeId) {
|
|
1270
1243
|
return `materialize_map_elem_${sanitize(compName)}_${typedCell(nodeId)}`;
|
|
1271
1244
|
}
|
|
1272
|
-
/** mapNodeArrRef — the map node's PRODUCED-ARRAY TypeRef from its `outType`.
|
|
1273
|
-
*
|
|
1274
|
-
* A map node's `outType` is its ELEMENT type (scp-error.md "Map element type"), so the produced array
|
|
1275
|
-
* is `{arr: element}`. This is the same reading the compiler applies when it resolves what a node
|
|
1276
|
-
* result reference has (`type-gate`: `"map" in n ? {arr:ot} : ot`) — the emitter follows that SSoT
|
|
1277
|
-
* rather than inspecting the annotation's shape, so an element that is ITSELF an `arr` stays
|
|
1278
|
-
* expressible (element `arr(T)` produces `arr(arr(T))`). */
|
|
1279
|
-
function mapNodeArrRef(node, plan) {
|
|
1280
|
-
const outT = node.outType;
|
|
1281
|
-
return deriveTypeRef({ arr: outT }, plan);
|
|
1282
|
-
}
|
|
1283
|
-
/** mapElemRowRef — the handler's per-element RETURN shape for a covered map node: the `into` field's
|
|
1284
|
-
* type (into) or the element outType directly (no-into). This is the type of RawElemNR<Comp><Node>. */
|
|
1285
|
-
function mapElemRowRef(node, arrRef, plan) {
|
|
1286
|
-
const m = node.map;
|
|
1287
|
-
if (m.into === undefined)
|
|
1288
|
-
return arrRef.elem;
|
|
1289
|
-
if (arrRef.elem.kind !== "named") {
|
|
1290
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust combined map (#86 pt2): node '${node.id}' element outType must be a named struct — regenerate as boxed typed/straight-line.`);
|
|
1291
|
-
}
|
|
1292
|
-
const decl = findDecl(plan, arrRef.elem.name);
|
|
1293
|
-
const intoField = decl.fields.find((f) => f.name === m.into);
|
|
1294
|
-
if (!intoField) {
|
|
1295
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust combined map (#86 pt2): element struct '${arrRef.elem.name}' has no '${m.into}' (into) field.`);
|
|
1296
|
-
}
|
|
1297
|
-
return intoField.type;
|
|
1298
|
-
}
|
|
1299
1245
|
/**
|
|
1300
1246
|
* emitMapElemMaterializers — for each covered map...into node, emit the AUGMENTED-element copier: copy
|
|
1301
1247
|
* the over element's typed fields + place the already-de-boxed `into` value into its field. Pure struct
|
|
@@ -1311,9 +1257,8 @@ function emitMapElemMaterializers(comp, typedNodes, plan) {
|
|
|
1311
1257
|
if (m.into === undefined)
|
|
1312
1258
|
continue;
|
|
1313
1259
|
const arrRef = typedNodes.get(n.id);
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1260
|
+
// the into element is a named struct with an `into` field (mapElemRowRef fails closed otherwise).
|
|
1261
|
+
const intoRowRef = mapElemRowRef("rust", n, arrRef, plan);
|
|
1317
1262
|
const elemRef = arrRef.elem;
|
|
1318
1263
|
const decl = findDecl(plan, elemRef.name);
|
|
1319
1264
|
const intoKey = m.into;
|
|
@@ -1321,7 +1266,6 @@ function emitMapElemMaterializers(comp, typedNodes, plan) {
|
|
|
1321
1266
|
const overFields = decl.fields.filter((f) => f.name !== intoKey);
|
|
1322
1267
|
const overElemTy = mapOverElemType(comp, n, typedNodes, plan);
|
|
1323
1268
|
const fn = mapElemMaterializerName(comp.name, n.id);
|
|
1324
|
-
const intoRowRef = mapElemRowRef(n, arrRef, plan);
|
|
1325
1269
|
const inits = [];
|
|
1326
1270
|
// Copy scalars (i64/f64/bool) copy directly; String/named/arr/opt clone (clippy clone_on_copy clean).
|
|
1327
1271
|
for (const f of overFields) {
|
|
@@ -1392,39 +1336,23 @@ function rustOverAccess(s, place, optArr, awaits) {
|
|
|
1392
1336
|
};
|
|
1393
1337
|
}
|
|
1394
1338
|
/**
|
|
1395
|
-
* rustOverElemInfo — the
|
|
1396
|
-
*
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1339
|
+
* rustOverElemInfo — the Rust read of a fanout/map `over` collection (map/fanout twins both delegate). The
|
|
1340
|
+
* element TypeRef, the optional-array flag and WHERE the collection lives come from the ONE resolver
|
|
1341
|
+
* {@link resolveOverOrFail} (native-coverage.ts); {@link rustOverAccess} renders how an arm may read it,
|
|
1342
|
+
* given whether the arm suspends.
|
|
1399
1343
|
*
|
|
1400
1344
|
* An opt-arr over (a prior-node `{opt:{arr}}` field OR an OPT input array port) iterates EMPTY on null
|
|
1401
1345
|
* (#177 (A)), byte-equal to run_behavior. A REQUIRED arr still fails run_behavior FANOUT/MAP_OVER_NOT_ARRAY.
|
|
1402
1346
|
*/
|
|
1403
1347
|
function rustOverElemInfo(comp, over, typedNodes, plan, nodeId, label) {
|
|
1404
1348
|
const s = sanitize(nodeId);
|
|
1405
|
-
const
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
return { elemRef: ref.elem, over: (awaits) => rustOverAccess(s, cell, false, awaits) };
|
|
1413
|
-
if (ref.kind === "opt" && ref.inner.kind === "arr")
|
|
1414
|
-
return { elemRef: ref.inner.elem, over: (awaits) => rustOverAccess(s, cell, true, awaits) };
|
|
1415
|
-
}
|
|
1416
|
-
if (e.kind === "ref" && e.path.length === 1) {
|
|
1417
|
-
const schema = comp.inputPorts?.[e.path[0]];
|
|
1418
|
-
const et = schema?.elemType;
|
|
1419
|
-
// #192: read the input array port by its positional PARAM name (= rustFieldName(port), same name
|
|
1420
|
-
// source as the seam) — box removed, no `in_.` prefix.
|
|
1421
|
-
if (et !== undefined) {
|
|
1422
|
-
const local = { at: "local", expr: rustFieldName(e.path[0]) };
|
|
1423
|
-
const optArr = inputPortIsOptional(schema);
|
|
1424
|
-
return { elemRef: deriveTypeRef(et, plan), over: (awaits) => rustOverAccess(s, local, optArr, awaits) };
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust ${label}: '${nodeId}' 'over' must be a ref to a prior node's typed arr field OR an input array port with a declared elemType. BC does not infer input-array element types (consumer-interface C3).`);
|
|
1349
|
+
const r = resolveOverOrFail("rust", comp, over, typedNodes, plan, nodeId, label);
|
|
1350
|
+
// #192: an input array port is read by its positional PARAM name (= rustFieldName(port), same name source
|
|
1351
|
+
// as the seam) — box removed, no `in_.` prefix.
|
|
1352
|
+
const place = r.source.kind === "node"
|
|
1353
|
+
? { at: "cell", cell: typedCell(r.source.head), fieldPath: r.source.path.map((p) => `.${rustFieldName(p)}`).join("") }
|
|
1354
|
+
: { at: "local", expr: rustFieldName(r.source.port) };
|
|
1355
|
+
return { elemRef: r.elemRef, over: (awaits) => rustOverAccess(s, place, r.optArr, awaits) };
|
|
1428
1356
|
}
|
|
1429
1357
|
function mapOverElemInfo(comp, node, typedNodes, plan) {
|
|
1430
1358
|
return rustOverElemInfo(comp, node.map.over, typedNodes, plan, node.id, "combined map (#108)");
|
|
@@ -1434,345 +1362,10 @@ function mapOverElemType(comp, node, typedNodes, plan) {
|
|
|
1434
1362
|
return renderTypeRef(mapOverElemInfo(comp, node, typedNodes, plan).elemRef);
|
|
1435
1363
|
}
|
|
1436
1364
|
// ── eligibility ─────────────────────────────────────────────────────────────────────
|
|
1437
|
-
function reconstructR(e) {
|
|
1438
|
-
switch (e.kind) {
|
|
1439
|
-
case "str":
|
|
1440
|
-
return e.value;
|
|
1441
|
-
case "bool":
|
|
1442
|
-
return e.value;
|
|
1443
|
-
case "null":
|
|
1444
|
-
return null;
|
|
1445
|
-
case "ref":
|
|
1446
|
-
return { [e.opt ? "refOpt" : "ref"]: e.path };
|
|
1447
|
-
case "concat":
|
|
1448
|
-
return { concat: e.parts.map(reconstructR) };
|
|
1449
|
-
case "dynamic":
|
|
1450
|
-
return e.node;
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* numLiteralRustExpr — a BARE numeric port literal (JSON number, e.g. the `limit: 20` Query port).
|
|
1455
|
-
* `classifyExpr` leaves a bare number `dynamic` (its checked int/float range rules are the evaluate
|
|
1456
|
-
* SSoT), so it never reaches the static str/bool/null branch — but a number literal IS statically
|
|
1457
|
-
* resolvable to a native `Value`: the SAME range check the runtime applies (integral literal in the
|
|
1458
|
-
* safe 2^53-1 window → Value::Int; a fractional/exponent literal → the checked Value::Float) is
|
|
1459
|
-
* performed HERE at generation time. Returns the Rust expression for the literal's Value, or null
|
|
1460
|
-
* when the node is not a bare number OR an integral literal is out of the safe window (keeping the
|
|
1461
|
-
* runtime INVALID_LITERAL semantics — the port is not covered natively, the component falls through).
|
|
1462
|
-
* Mirrors behavior_contracts eval of a bare number literal exactly.
|
|
1463
|
-
*/
|
|
1464
|
-
const NUM_SAFE_INT_R = 9007199254740991; // 2^53 - 1 (expr safeInt)
|
|
1465
|
-
function numLiteralRustExpr(node) {
|
|
1466
|
-
if (typeof node !== "number" || !Number.isFinite(node))
|
|
1467
|
-
return null;
|
|
1468
|
-
if (Number.isInteger(node)) {
|
|
1469
|
-
if (node < -NUM_SAFE_INT_R || node > NUM_SAFE_INT_R)
|
|
1470
|
-
return null; // out of safe window → not covered
|
|
1471
|
-
return `Value::Int(${node}i64)`;
|
|
1472
|
-
}
|
|
1473
|
-
// fractional / exponent literal → checked f64 (finite, guaranteed above).
|
|
1474
|
-
return `Value::Float(${node}f64)`;
|
|
1475
|
-
}
|
|
1476
|
-
/** A port node is static (literal / ref / concat of those / static arr / bare number literal) —
|
|
1477
|
-
* resolvable to a native Value with no Obj / no evaluate interpreter. */
|
|
1478
|
-
/** planForComp — a TypePlan for a single component (its named types are component-scoped). */
|
|
1479
|
-
function planForComp(comp) {
|
|
1480
|
-
return buildTypePlan({ irVersion: 2, exprVersion: 2, components: [comp] });
|
|
1481
|
-
}
|
|
1482
|
-
/** buildTypedNodes — the prior-node typed-cell TypeRef map (control-gate nodes typeless; a map node
|
|
1483
|
-
* carries its produced-array ref). An untyped node is omitted. */
|
|
1484
|
-
function buildTypedNodes(comp, plan) {
|
|
1485
|
-
const typedNodes = new Map();
|
|
1486
|
-
for (const n of comp.body) {
|
|
1487
|
-
if (isControlGate(n))
|
|
1488
|
-
continue;
|
|
1489
|
-
try {
|
|
1490
|
-
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan));
|
|
1491
|
-
}
|
|
1492
|
-
catch {
|
|
1493
|
-
/* untyped node — omit */
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
return typedNodes;
|
|
1497
|
-
}
|
|
1498
|
-
/** mapAsBinding — the `$as` element binding for a map node's element ports, or undefined (uncovered). */
|
|
1499
|
-
function mapAsBinding(comp, node, typedNodes, plan) {
|
|
1500
|
-
try {
|
|
1501
|
-
return { name: node.map.as, ref: mapOverElemInfo(comp, node, typedNodes, plan).elemRef, plan };
|
|
1502
|
-
}
|
|
1503
|
-
catch {
|
|
1504
|
-
return undefined;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
/** portIsStatic — the ELIGIBILITY gate ASKS the one port lowering (compilePortNode / native-expr) whether
|
|
1508
|
-
* it can lower this port. A port that does not lower (or lowers fallibly) fails closed. */
|
|
1509
|
-
function portIsStatic(node, comp, plan, typedNodes, expected, asBinding, narrowed) {
|
|
1510
|
-
try {
|
|
1511
|
-
// #170: eligibility asks the SAME lowering emission uses, with the SAME node narrowing — so a
|
|
1512
|
-
// gate/guard-proven opt-in-required port is judged covered iff it also emits (they cannot disagree).
|
|
1513
|
-
// #173: with the SAME declared `expected` port type (so covered iff it materializes to that type).
|
|
1514
|
-
const opts = asBinding !== undefined ? { asBinding, asBase: asBinding.name, narrowed } : narrowed !== undefined ? { narrowed } : undefined;
|
|
1515
|
-
compilePortNode(node, comp, plan, typedNodes, (h) => typedNodes.has(h), "port", expected, opts);
|
|
1516
|
-
return true;
|
|
1517
|
-
}
|
|
1518
|
-
catch {
|
|
1519
|
-
return false;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
/** The output must lower to a typed struct/value with no scope read: a ref to a BODY NODE, an
|
|
1523
|
-
* obj/arr of such, or a concat. A ref to an input param / non-concat operator is not lowerable. */
|
|
1524
|
-
function outputIsNativeLowerable(comp) {
|
|
1525
|
-
const bodyIds = new Set(comp.body.map((n) => n.id));
|
|
1526
|
-
const walk = (node) => {
|
|
1527
|
-
const arr = staticArrElems(node);
|
|
1528
|
-
if (arr !== null)
|
|
1529
|
-
return arr.every(walk);
|
|
1530
|
-
if (node !== null && typeof node === "object" && !Array.isArray(node)) {
|
|
1531
|
-
const keys = Object.keys(node);
|
|
1532
|
-
if (keys.length === 1 && keys[0] === "obj") {
|
|
1533
|
-
const obj = node.obj;
|
|
1534
|
-
return Object.keys(obj).every((k) => walk(obj[k]));
|
|
1535
|
-
}
|
|
1536
|
-
if (keys.length === 1 && keys[0] === "arr")
|
|
1537
|
-
return true;
|
|
1538
|
-
}
|
|
1539
|
-
const e = classifyExpr(node);
|
|
1540
|
-
if (e.kind === "str" || e.kind === "bool" || e.kind === "null")
|
|
1541
|
-
return true;
|
|
1542
|
-
if (e.kind === "ref")
|
|
1543
|
-
return bodyIds.has(e.path[0]);
|
|
1544
|
-
if (e.kind === "concat")
|
|
1545
|
-
return e.parts.every((p) => walk(reconstructR(p)));
|
|
1546
|
-
return false;
|
|
1547
|
-
};
|
|
1548
|
-
return walk(comp.output);
|
|
1549
|
-
}
|
|
1550
|
-
/**
|
|
1551
|
-
* coveredMapNode — the #86 part 2 covered map shape (nestedBatchGet), rust twin of the go predicate.
|
|
1552
|
-
*/
|
|
1553
|
-
function coveredMapNode(n, bodyIds, comp) {
|
|
1554
|
-
if (n === null || typeof n !== "object" || !("map" in n))
|
|
1555
|
-
return false;
|
|
1556
|
-
const m = n.map;
|
|
1557
|
-
// #108 (rust twin of the go predicate): a guarded map (`when`) IS covered with NO `into`. #177/#182/#232:
|
|
1558
|
-
// a `map...into` ALWAYS has a well-defined unproduced value for the into field — OPT (unproduced → None,
|
|
1559
|
-
// #177) OR relationKind:connection (unproduced → the empty connection {items:[],cursor:null}, #182).
|
|
1560
|
-
// Byte-equal to run_behavior applyInto. The type gate (`mapIntoHoldsUnproduced`, run for every component
|
|
1561
|
-
// at the codegen entry) rejects anything else BEFORE any emitter sees it (#232). over element type must be
|
|
1562
|
-
// statically resolvable: prior-node arr field, or an input array port carrying `elemType` (BC does not
|
|
1563
|
-
// infer — consumer-interface C3).
|
|
1564
|
-
if (m.relationKind !== undefined && m.relationKind !== "connection")
|
|
1565
|
-
return false;
|
|
1566
|
-
// A map node must carry an outType (its ELEMENT type per the recorder SoT — authoring.ts recordMap
|
|
1567
|
-
// holds `node.outType = mapElem`, the PRE-array-wrap element; the emitter synthesizes the produced
|
|
1568
|
-
// `[]element`). A map WITHOUT outType is uncovered. (Legacy hand-built IR that already carries the
|
|
1569
|
-
// `{arr:element}` produced form is ALSO accepted — mapNodeElemRef normalizes both to the element.)
|
|
1570
|
-
// bc#164: an OPAQUE ELEMENT (`outType:"value"` on an output-passthrough map — mapNodeElemIsOpaqueWire,
|
|
1571
|
-
// the shared rule) IS covered: each element wire is stored AS-IS in the produced list (no de-box, no
|
|
1572
|
-
// per-op re-box), exactly as the componentRef path treats a passthrough result. Any other non-compound
|
|
1573
|
-
// element type stays uncovered (loud), as before.
|
|
1574
|
-
const outT = n.outType;
|
|
1575
|
-
// #225: 純式 map(`transform`)の要素は**式から native に組む**(ワイヤも de-box も無い)ので、要素型が
|
|
1576
|
-
// スカラでも被覆される — 宣言型 materializer が組めれば良く、組めなければそこで loud に落ちる。
|
|
1577
|
-
// Component map は要素 wire を de-box するので従来どおり compound / opaque wire に限る。
|
|
1578
|
-
const isTransformMap = mapTransformExpr(m) !== undefined;
|
|
1579
|
-
if (outT === undefined)
|
|
1580
|
-
return false;
|
|
1581
|
-
if (!isTransformMap && typeof outT !== "object" && !mapNodeElemIsOpaqueWire(n))
|
|
1582
|
-
return false;
|
|
1583
|
-
const overE = classifyExpr(m.over);
|
|
1584
|
-
if (overE.kind !== "ref")
|
|
1585
|
-
return false;
|
|
1586
|
-
const head = overE.path[0];
|
|
1587
|
-
if (!bodyIds.has(head)) {
|
|
1588
|
-
// input-array over: covered only when the port declares elemType (#108 — C3, no inference). #177 (A):
|
|
1589
|
-
// an OPT input array (`{opt:{arr}}`, required:false) IS covered — its null iterates EMPTY
|
|
1590
|
-
// (rustOverAccess collapses None to an empty collection), byte-equal to run_behavior.
|
|
1591
|
-
if (overE.path.length !== 1)
|
|
1592
|
-
return false;
|
|
1593
|
-
const schema = comp.inputPorts?.[head];
|
|
1594
|
-
if (schema === undefined || schema.elemType === undefined)
|
|
1595
|
-
return false;
|
|
1596
|
-
}
|
|
1597
|
-
// 純式 map(#222)は port を持たない: 被覆条件は「要素式が宣言された要素型へ native に materialize
|
|
1598
|
-
// できること」で、それは compilePortNode(宣言型 materializer)が失敗したときに loud に落ちる。
|
|
1599
|
-
const ports = (m.ports ?? {});
|
|
1600
|
-
const plan = planForComp(comp);
|
|
1601
|
-
const typedNodes = buildTypedNodes(comp, plan);
|
|
1602
|
-
const asBinding = mapAsBinding(comp, n, typedNodes, plan);
|
|
1603
|
-
const narrowed = nodeNarrowedPaths(comp, n);
|
|
1604
|
-
const mSchemas = m.portSchemas;
|
|
1605
|
-
for (const p of Object.keys(ports))
|
|
1606
|
-
if (!portIsStatic(ports[p], comp, plan, typedNodes, inputPortTypeRef(mSchemas?.[p], plan), asBinding, narrowed))
|
|
1607
|
-
return false;
|
|
1608
|
-
return true;
|
|
1609
|
-
}
|
|
1610
|
-
/** coveredFanoutNode (v3, rust twin) — a first-class fanout node is covered when its over is a covered
|
|
1611
|
-
* ref (prior-node arr / input array with elemType) and its element ports are static. See the go twin. */
|
|
1612
|
-
function coveredFanoutNode(n, bodyIds, comp) {
|
|
1613
|
-
if (n === null || typeof n !== "object" || !("fanout" in n))
|
|
1614
|
-
return false;
|
|
1615
|
-
const f = n.fanout;
|
|
1616
|
-
if (f.relationKind !== "connection")
|
|
1617
|
-
return false;
|
|
1618
|
-
const overE = classifyExpr(f.over);
|
|
1619
|
-
if (overE.kind !== "ref")
|
|
1620
|
-
return false;
|
|
1621
|
-
const head = overE.path[0];
|
|
1622
|
-
if (!bodyIds.has(head)) {
|
|
1623
|
-
// input-array over: covered only when the port declares elemType (C3 — no inference). #177 (A): an OPT
|
|
1624
|
-
// input array (`{opt:{arr}}`, required:false) IS covered — its null iterates EMPTY
|
|
1625
|
-
// (rustOverAccess collapses None to an empty collection), byte-equal to run_behavior.
|
|
1626
|
-
if (overE.path.length !== 1)
|
|
1627
|
-
return false;
|
|
1628
|
-
const schema = comp.inputPorts?.[head];
|
|
1629
|
-
if (schema === undefined || schema.elemType === undefined)
|
|
1630
|
-
return false;
|
|
1631
|
-
}
|
|
1632
|
-
const ports = f.ports;
|
|
1633
|
-
const plan = planForComp(comp);
|
|
1634
|
-
const typedNodes = buildTypedNodes(comp, plan);
|
|
1635
|
-
let asBinding;
|
|
1636
|
-
try {
|
|
1637
|
-
asBinding = { name: f.as, ref: fanoutOverElemInfo(comp, n, typedNodes, plan).elemRef, plan };
|
|
1638
|
-
}
|
|
1639
|
-
catch {
|
|
1640
|
-
asBinding = undefined;
|
|
1641
|
-
}
|
|
1642
|
-
const fSchemas = f.portSchemas;
|
|
1643
|
-
for (const p of Object.keys(ports))
|
|
1644
|
-
if (!portIsStatic(ports[p], comp, plan, typedNodes, inputPortTypeRef(fSchemas?.[p], plan), asBinding))
|
|
1645
|
-
return false;
|
|
1646
|
-
return true;
|
|
1647
|
-
}
|
|
1648
|
-
/** fanoutItemsElemRef (v3, rust twin) — the connection items element TypeRef for a covered fanout node. */
|
|
1649
|
-
function fanoutItemsElemRef(node, connRef, plan) {
|
|
1650
|
-
if (connRef.kind !== "named")
|
|
1651
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust fanout (v3): node '${node.id}' outType must be a connection struct {items,cursor} (got ${JSON.stringify(connRef.kind)}).`);
|
|
1652
|
-
const decl = findDecl(plan, connRef.name);
|
|
1653
|
-
const itemsField = decl.fields.find((fd) => fd.name === "items");
|
|
1654
|
-
if (!itemsField || itemsField.type.kind !== "arr")
|
|
1655
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust fanout (v3): node '${node.id}' connection struct '${connRef.name}' has no 'items' array field.`);
|
|
1656
|
-
return itemsField.type.elem;
|
|
1657
|
-
}
|
|
1658
1365
|
/** fanoutOverElemInfo (v3, rust twin) — delegates to {@link rustOverElemInfo} reading the fanout spec. */
|
|
1659
1366
|
function fanoutOverElemInfo(comp, node, typedNodes, plan) {
|
|
1660
1367
|
return rustOverElemInfo(comp, node.fanout.over, typedNodes, plan, node.id, "fanout (v3)");
|
|
1661
1368
|
}
|
|
1662
|
-
/** A covered read SHAPE with static ports + native-lowerable output (+ covered map...into), OR a
|
|
1663
|
-
* real-concurrency staged plan (bc#87) whose parallel-stage members are plain componentRef point reads. */
|
|
1664
|
-
function isSequentialComponentRefRead(comp) {
|
|
1665
|
-
return coverageRejectReason(comp) === null;
|
|
1666
|
-
}
|
|
1667
|
-
/**
|
|
1668
|
-
* coverageRejectReason — the DIAGNOSTIC twin of isSequentialComponentRefRead (bc#86/#89), rust twin of
|
|
1669
|
-
* the go predicate. Returns null when the component IS a covered native read; otherwise a SPECIFIC
|
|
1670
|
-
* human-readable reason naming the exact disqualifier and the offending node id. The predicate logic is
|
|
1671
|
-
* IDENTICAL to isSequentialComponentRefRead (defined as `coverageRejectReason(c) === null`) so the two
|
|
1672
|
-
* can never disagree. This is the message the fail-closed dispatch surfaces per non-native component.
|
|
1673
|
-
*/
|
|
1674
|
-
function coverageRejectReason(comp) {
|
|
1675
|
-
const crPlan = planForComp(comp);
|
|
1676
|
-
const crTypedNodes = buildTypedNodes(comp, crPlan);
|
|
1677
|
-
const ep = execPlan(comp);
|
|
1678
|
-
if (ep === null)
|
|
1679
|
-
return "component is not a straight-line/staged sequential exec plan (no static exec plan)";
|
|
1680
|
-
// #114: a bindField relation child (single|connection) IS covered inside a parallel stage — the
|
|
1681
|
-
// sibling hasMany fan-out (parent → members ∥ permissions). Its bound-key skip-gate is preflighted
|
|
1682
|
-
// per member (from the settled parent) BEFORE dispatch, so the scoped-thread fan-out keeps
|
|
1683
|
-
// run_behavior's per-member skip semantics; the shared relationKind constraint below (single|
|
|
1684
|
-
// connection) applies to it too. A map member still falls through (its per-element loop is a further
|
|
1685
|
-
// shape). Kept fail-closed: a non-componentRef member is rejected.
|
|
1686
|
-
for (const [i] of ep.parallelStageOf) {
|
|
1687
|
-
const n = comp.body[i];
|
|
1688
|
-
// #125/#108: a cond node IS allowed as a parallel-stage member — it is a pure Expression (no
|
|
1689
|
-
// dispatch), settled in ascending preflight order, so its produced flag / typed result cell is
|
|
1690
|
-
// settled before any dispatch. No handler, no boxed result — it does not disturb the bounded-
|
|
1691
|
-
// concurrency error-precedence protocol. Covers BOTH the when(...) control-gate cond (#136,
|
|
1692
|
-
// {ok}/null skip marker) AND the Φ-merge VALUE cond (#108, has outType — the sibling Φ-join). A
|
|
1693
|
-
// value cond's outType requirement is enforced by the per-node cond check below, so a parallel
|
|
1694
|
-
// value cond without outType still loud-rejects there.
|
|
1695
|
-
// #225: 純式 map(`map.transform`)も cond と同じ性質(handler も boxed result も無い変換)なので、
|
|
1696
|
-
// 昇順 preflight で確定させれば error-precedence 協定を乱さない。免除根拠は go 側と同一。
|
|
1697
|
-
if ("cond" in n)
|
|
1698
|
-
continue;
|
|
1699
|
-
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
1700
|
-
continue;
|
|
1701
|
-
if (!("component" in n))
|
|
1702
|
-
return `node '${n.id}' is a non-componentRef member of a parallel stage (not native-covered)`;
|
|
1703
|
-
}
|
|
1704
|
-
const bodyIds = new Set(comp.body.map((b) => b.id));
|
|
1705
|
-
for (const n of comp.body) {
|
|
1706
|
-
// A read of a node that can be unproduced at that point (scp-error.md "Dependency rules for continue":
|
|
1707
|
-
// the interpreters read its unproduced value — null, or NULL_REF through it) has no native lowering here:
|
|
1708
|
-
// the native read takes the node's struct as produced, which would hand on its ZERO value. Fail closed.
|
|
1709
|
-
const unguarded = unguardedUnproducibleReads(comp, n);
|
|
1710
|
-
if (unguarded.length > 0)
|
|
1711
|
-
return `node '${n.id}' reads node '${unguarded[0]}', which can be unproduced when '${n.id}' reads it — the unproduced read is not native-covered`;
|
|
1712
|
-
if ("cond" in n) {
|
|
1713
|
-
// #125: a when(...) control-gate cond (`{if, then:{obj:{ok:true}}, else:null}`) は制御スキップ
|
|
1714
|
-
// マーカーで出力データ型を持たない(A3 の typeless design)— outType を要求しない。gate は `if` を
|
|
1715
|
-
// native bool へコンパイルし produced_<gate> に写すだけで、分岐内ノードは既存の
|
|
1716
|
-
// `parent=gate, bindField:"ok"` skip-gate(run_behavior の null-binding skip)が実行選択する。
|
|
1717
|
-
if (isControlGate(n))
|
|
1718
|
-
continue;
|
|
1719
|
-
// #108: a DATA-JOIN cond node (Φ 合流) is native-covered (its if/then/else compile via the runtime-
|
|
1720
|
-
// free NativeExprCompiler; an uncovered expr fails closed at emit). A data-join cond requires outType
|
|
1721
|
-
// (合流値を de-box する対象だから — control gate だけがこの要求を免除される)。
|
|
1722
|
-
if (n.outType === undefined)
|
|
1723
|
-
return `node '${n.id}' cond has no outType (required to de-box the branch join)`;
|
|
1724
|
-
continue;
|
|
1725
|
-
}
|
|
1726
|
-
if ("fanout" in n) {
|
|
1727
|
-
if (!coveredFanoutNode(n, bodyIds, comp))
|
|
1728
|
-
return `node '${n.id}' is a non-covered fanout shape (over an input array without elemType, or a dynamic element port)`;
|
|
1729
|
-
continue;
|
|
1730
|
-
}
|
|
1731
|
-
if ("map" in n) {
|
|
1732
|
-
if (!coveredMapNode(n, bodyIds, comp))
|
|
1733
|
-
return `node '${n.id}' is a non-covered map shape (guard+into heterogeneous, or over an input array without elemType)`;
|
|
1734
|
-
continue;
|
|
1735
|
-
}
|
|
1736
|
-
if (!("component" in n))
|
|
1737
|
-
return `node '${n.id}' is not a componentRef, map, or cond node (not native-covered)`;
|
|
1738
|
-
const cr = n;
|
|
1739
|
-
// Every Error Policy Kind IS covered on a componentRef (see the go emitter's note): `continue` →
|
|
1740
|
-
// unproduced (produced-aware output), `retry` → `fail`'s control flow with the Kind in the message.
|
|
1741
|
-
// relationKind の閉集合は `connection` の 1 値で、**注記の不在**が「未生成は null」を意味する。ゆえに
|
|
1742
|
-
// bindField 由来 skip は 2 形(connection = 空 connection / 不在 = null)とも produced-aware 出力が
|
|
1743
|
-
// 表現でき、被覆条件は無い(かつての「明示的に single と書け」は既定値の重複綴りの要求だった)。
|
|
1744
|
-
if (cr.relationKind !== undefined && cr.relationKind !== "connection")
|
|
1745
|
-
return `relationKind '${cr.relationKind}' not native-covered (node '${n.id}')`;
|
|
1746
|
-
// #170: a control-gate child's ports may narrow a gate-proven opt ref to non-null (the (a3) gated read).
|
|
1747
|
-
const crNarrowed = nodeNarrowedPaths(comp, cr);
|
|
1748
|
-
for (const p of Object.keys(cr.ports))
|
|
1749
|
-
if (portIsStatic(cr.ports[p], comp, crPlan, crTypedNodes, inputPortTypeRef(cr.portSchemas?.[p], crPlan), undefined, crNarrowed) === false)
|
|
1750
|
-
return `node '${n.id}' port '${p}' is not statically resolvable`;
|
|
1751
|
-
}
|
|
1752
|
-
if (!outputIsNativeLowerable(comp))
|
|
1753
|
-
return "output is not natively lowerable";
|
|
1754
|
-
return null;
|
|
1755
|
-
}
|
|
1756
|
-
function isFullyTyped(comp) {
|
|
1757
|
-
if (comp.outputType === undefined)
|
|
1758
|
-
return false;
|
|
1759
|
-
// #125: a control-gate cond is a typeless skip marker (A3) — it never de-boxes a result, so it is
|
|
1760
|
-
// exempt from the "every node carries outType" de-box requirement (matches type-gate's exemption).
|
|
1761
|
-
for (const n of comp.body)
|
|
1762
|
-
if (!isControlGate(n) && n.outType === undefined)
|
|
1763
|
-
return false;
|
|
1764
|
-
return true;
|
|
1765
|
-
}
|
|
1766
|
-
function isNativeRaw(comp) {
|
|
1767
|
-
return isSequentialComponentRefRead(comp) && isFullyTyped(comp);
|
|
1768
|
-
}
|
|
1769
|
-
function assertTypedCoverage(comp) {
|
|
1770
|
-
if (!isSequentialComponentRefRead(comp))
|
|
1771
|
-
return;
|
|
1772
|
-
if (isFullyTyped(comp))
|
|
1773
|
-
return;
|
|
1774
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust 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 rust-straightline-native (boxed result).`);
|
|
1775
|
-
}
|
|
1776
1369
|
// ── typed input struct (InNR<Comp>) + NATIVE scalar port lowering ────────────────────────────
|
|
1777
1370
|
/** Rust type for an input port's declared type (scalar → concrete; array+elemType → Vec<ElemT>; else Value). */
|
|
1778
1371
|
function inputPortRustType(schema, plan, where = "input port") {
|
|
@@ -1940,12 +1533,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
|
|
|
1940
1533
|
// it starts clean here and is read once the whole body — cond conditions, map guards, port expressions —
|
|
1941
1534
|
// has been lowered.
|
|
1942
1535
|
rustExprUsed.boolAlgebra = false;
|
|
1943
|
-
const typedNodes =
|
|
1944
|
-
// #125: control-gate は typeless(typedNodes に載せない)。map ノードは produced-array ref に正規化
|
|
1945
|
-
// (recorder SoT の element outType を {arr:element} へラップ / legacy {arr} はそのまま)。
|
|
1946
|
-
for (const n of comp.body)
|
|
1947
|
-
if (!isControlGate(n))
|
|
1948
|
-
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan));
|
|
1536
|
+
const typedNodes = buildTypedNodes(comp, plan);
|
|
1949
1537
|
// A result is handed on by MOVE at its LAST read (movableRefs) — every earlier reader copies, because the
|
|
1950
1538
|
// cell still has to hold the value for the ones after it. The lookup is BY SITE: node k's ports get the
|
|
1951
1539
|
// heads whose last read is k, the output assembly the heads whose last read is the output.
|
|
@@ -2541,7 +2129,7 @@ isAsync = false, policy = "fail") {
|
|
|
2541
2129
|
// each element is de-boxed strictly INLINE: the handler returns the per-element WIRE and the arm decodes
|
|
2542
2130
|
// it against the element ref (the `into` field's type for map...into, else the element type). A de-box
|
|
2543
2131
|
// mismatch fails closed regardless of elementPolicy (matching the interpreter's whole-node outType throw).
|
|
2544
|
-
const elemDeBoxRef = mapElemRowRef(node, elemArrRef, plan);
|
|
2132
|
+
const elemDeBoxRef = mapElemRowRef("rust", node, elemArrRef, plan);
|
|
2545
2133
|
const renderElemDeBox = (il) => renderResultDeBox(elemDeBoxRef, `er_${s}`, node.id, plan, il, returnErrFail, nodeWirePassthrough(node));
|
|
2546
2134
|
// #177/#182 keep-with-skip-value: the into value for a guard-skipped element is driven by relationKind,
|
|
2547
2135
|
// NOT by opt-ness (matching run_behavior applyInto, which fills a connection into with the empty
|
|
@@ -2784,7 +2372,7 @@ isAsync = false, policy = "fail") {
|
|
|
2784
2372
|
* emitFanoutArm (v3, rust twin) — the struct-native exec of a covered FANOUT node: build the per-id
|
|
2785
2373
|
* ports (all over ids), dispatch the batched handler ONCE (aligned per-body rows), then apply THE SAME
|
|
2786
2374
|
* dedupe/drop as run_behavior's fanoutDedupDrop — first-seen dedupe by the elem's dedupeKey field, drop
|
|
2787
|
-
* dangling (
|
|
2375
|
+
* dangling (a non-row body or an absent / null dedupeKey, as fanoutDedupDrop reads it), implicitSource strip (STRUCTURAL:
|
|
2788
2376
|
* the elem type already omits it), wrap into the connection struct { items, cursor: None }.
|
|
2789
2377
|
*/
|
|
2790
2378
|
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, isAsync = false, policy = "fail") {
|
|
@@ -2796,7 +2384,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2796
2384
|
const policyLit = rustStrLit(policy === "retry" ? "retry" : "fail");
|
|
2797
2385
|
const leafSym = resolveLeafSymbol(f.component, leaf, f.leafSymbol);
|
|
2798
2386
|
const connRef = typedNodes.get(node.id);
|
|
2799
|
-
const elemRef = fanoutItemsElemRef(node, connRef, plan);
|
|
2387
|
+
const elemRef = fanoutItemsElemRef("rust", node, connRef, plan);
|
|
2800
2388
|
const elemName = renderTypeRef(elemRef);
|
|
2801
2389
|
const { elemRef: overElemRef, over } = fanoutOverElemInfo(comp, node, typedNodes, plan);
|
|
2802
2390
|
const ov = over(isAsync);
|
|
@@ -2850,24 +2438,24 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2850
2438
|
lines.push(`${indent} };`);
|
|
2851
2439
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2852
2440
|
// each present body is de-boxed strictly INLINE (a de-box mismatch fails closed). A DANGLING id is a
|
|
2853
|
-
// WireValue::Null
|
|
2441
|
+
// WireValue::Null (or an absent / null dedupeKey) — dropped under drop:dangling, kept and failed under drop:none.
|
|
2854
2442
|
lines.push(`${indent} if rows_${s}.len() != want_${s} {`);
|
|
2855
2443
|
lines.push(`${indent} return Err(BehaviorError::new("FANOUT_BATCH_RESULT_MISMATCH", format!("fanout '{}': batched handler must return a list aligned to the deduped id list (want {})", ${rustStrLit(node.id)}, want_${s})));`);
|
|
2856
2444
|
lines.push(`${indent} }`);
|
|
2857
2445
|
// ── THE ONE dedupe/drop (mirrors fanoutDedupDrop verbatim): first-seen dedupe by dedupeKey field;
|
|
2858
|
-
// drop dangling (
|
|
2446
|
+
// drop dangling (non-row body / absent or null dedupeKey); implicitSource strip is
|
|
2859
2447
|
// structural (the elem type already omits it). cursor is always None (connection wrap).
|
|
2860
2448
|
lines.push(`${indent} let mut seen_${s}: std::collections::HashSet<String> = std::collections::HashSet::new();`);
|
|
2861
2449
|
lines.push(`${indent} for er_${s} in rows_${s}.into_iter() {`);
|
|
2862
|
-
lines.push(`${indent} let el_${s}: ${elemName} = if matches!(er_${s}, WireValue::Null) {`);
|
|
2863
|
-
lines.push(`${indent} Default::default()`);
|
|
2864
|
-
lines.push(`${indent} } else {`);
|
|
2865
|
-
lines.push(`${indent} ${renderResultDeBox(elemRef, `er_${s}`, node.id, plan, `${indent} `, returnErrFail, nodeWirePassthrough(node))}`);
|
|
2866
|
-
lines.push(`${indent} };`);
|
|
2867
|
-
lines.push(`${indent} let key_${s} = el_${s}.${dkRust}.clone();`);
|
|
2868
2450
|
if (f.drop === "dangling") {
|
|
2869
|
-
|
|
2451
|
+
// dangling ≡ fanoutDedupDrop: a body that is not a row, or whose dedupeKey is absent / null, is dropped.
|
|
2452
|
+
// A present key — the empty string included — is a real row and is kept (de-boxed and deduped below).
|
|
2453
|
+
lines.push(`${indent} if !matches!(&er_${s}, WireValue::Row(r) if r.entries.iter().find(|(k, _)| k == ${rustStrLit(f.dedupeKey)}).is_some_and(|(_, v)| !matches!(v, WireValue::Null))) { continue; }`);
|
|
2870
2454
|
}
|
|
2455
|
+
// every kept body is de-boxed strictly: under drop:none a dangling body (null) is kept as-is by
|
|
2456
|
+
// fanoutDedupDrop and fails the element type exactly as run_behavior's outType check does.
|
|
2457
|
+
lines.push(`${indent} let el_${s}: ${elemName} = ${renderResultDeBox(elemRef, `er_${s}`, node.id, plan, `${indent} `, returnErrFail, nodeWirePassthrough(node))};`);
|
|
2458
|
+
lines.push(`${indent} let key_${s} = el_${s}.${dkRust}.clone();`);
|
|
2871
2459
|
lines.push(`${indent} if seen_${s}.contains(&key_${s}) { continue; }`);
|
|
2872
2460
|
lines.push(`${indent} seen_${s}.insert(key_${s});`);
|
|
2873
2461
|
lines.push(`${indent} built_${s}.push(el_${s});`);
|
|
@@ -3067,23 +2655,10 @@ function emit(ctx) {
|
|
|
3067
2655
|
// rust CONSUMES this annotation (async fn + .await where derived); go ignores it. per-node granularity
|
|
3068
2656
|
// is a strict generalization of increment-1's uniform ioModel:'async' (= every terminal async).
|
|
3069
2657
|
const asyncPlans = buildAsyncPlans(ctx.ir, ctx.ioModel);
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
const
|
|
3074
|
-
// FAIL CLOSED (bc#86/#89): the --typed-native (native codegen) surface is native-only. Previously a
|
|
3075
|
-
// non-covered component was SILENTLY DROPPED (emitted only as a comment note), concealing that it
|
|
3076
|
-
// never got native codegen. We now throw a LOUD GeneratorFailure naming every uncovered component +
|
|
3077
|
-
// its specific reject reason. A fully-covered module is unchanged.
|
|
3078
|
-
if (nonNative.length > 0) {
|
|
3079
|
-
const rejects = nonNative
|
|
3080
|
-
.map((c) => ` - component '${c.name}': ${coverageRejectReason(c) ?? "not a covered native read"}`)
|
|
3081
|
-
.join("\n");
|
|
3082
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust typed-native (native codegen) surface: ${nonNative.length} component(s) are NOT a covered native read:\n${rejects}\n\n` +
|
|
3083
|
-
`The --typed-native (native codegen) surface is native-only and fail-closed: it does not silently ` +
|
|
3084
|
-
`box uncovered shapes. Implement native coverage for this shape, fix the spec if the shape is ` +
|
|
3085
|
-
`genuinely runtime-dynamic, or generate this component on the --ir dynamic interpreter surface.`);
|
|
3086
|
-
}
|
|
2658
|
+
// FAIL CLOSED (bc#86/#89): the native codegen surface is native-only — every component must be a covered,
|
|
2659
|
+
// fully typed native read (the ONE coverage rule, native-coverage.ts), or generation fails LOUDLY naming
|
|
2660
|
+
// each uncovered component and its specific reason (never a silently dropped / boxed component).
|
|
2661
|
+
const native = rustCoverage.assertCovered(ctx.ir.components);
|
|
3087
2662
|
if (native.length === 0) {
|
|
3088
2663
|
// an empty native surface (no covered read) carries no runner and no failure — nothing references
|
|
3089
2664
|
// bc-runtime, so it stays runtime-free (bc#90) with only the component-names const.
|
|
@@ -3116,11 +2691,8 @@ ${withRustfmtSkip(emitStructSurface([]))}
|
|
|
3116
2691
|
// in-crate (byte-identical to before). resolveRustWire is the SSoT for this decision.
|
|
3117
2692
|
const crossPackage = ctx.sharedTypesImport !== undefined;
|
|
3118
2693
|
for (const c of native) {
|
|
3119
|
-
const typedNodes = new Map();
|
|
3120
2694
|
// build the full typed-node map FIRST so a map's over-element resolution can see every node.
|
|
3121
|
-
|
|
3122
|
-
if (!isControlGate(n))
|
|
3123
|
-
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
|
|
2695
|
+
const typedNodes = buildTypedNodes(c, plan);
|
|
3124
2696
|
// #183: a covered node's ports cross the transport boundary as ONE op-agnostic `WireRow` payload built
|
|
3125
2697
|
// inline at the call site — there are NO per-node ports structs on the covered plane or the shared crate.
|
|
3126
2698
|
// #192: no `InNR_<comp>` input box — the entry takes positional params.
|