behavior-contracts 0.11.4 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring.d.ts +16 -6
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +6 -2
- package/dist/authoring.js.map +1 -1
- package/dist/behavior.d.ts +37 -6
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +62 -13
- package/dist/behavior.js.map +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +21 -8
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +11 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/codegen.d.ts +11 -2
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +11 -14
- package/dist/commands/codegen.js.map +1 -1
- package/dist/commands/ts-compile.d.ts +1 -7
- package/dist/commands/ts-compile.d.ts.map +1 -1
- package/dist/commands/ts-compile.js +45 -14
- package/dist/commands/ts-compile.js.map +1 -1
- package/dist/commands/ts-extract.d.ts +0 -2
- package/dist/commands/ts-extract.d.ts.map +1 -1
- package/dist/commands/ts-extract.js +0 -4
- package/dist/commands/ts-extract.js.map +1 -1
- package/dist/generator/async-plan.d.ts.map +1 -1
- package/dist/generator/async-plan.js +2 -1
- package/dist/generator/async-plan.js.map +1 -1
- package/dist/generator/core.d.ts +35 -2
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js +50 -2
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-php.d.ts.map +1 -1
- package/dist/generator/emit-php.js +4 -3
- package/dist/generator/emit-php.js.map +1 -1
- package/dist/generator/emit-python.d.ts.map +1 -1
- package/dist/generator/emit-python.js +4 -3
- package/dist/generator/emit-python.js.map +1 -1
- package/dist/generator/emit-shared-go.d.ts.map +1 -1
- package/dist/generator/emit-shared-go.js +23 -4
- package/dist/generator/emit-shared-go.js.map +1 -1
- package/dist/generator/emit-shared-rust.d.ts.map +1 -1
- package/dist/generator/emit-shared-rust.js +24 -6
- package/dist/generator/emit-shared-rust.js.map +1 -1
- package/dist/generator/emit-shared-typescript.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript.js +23 -8
- package/dist/generator/emit-shared-typescript.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +2 -2
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +118 -55
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +2 -2
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +119 -70
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +2 -2
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/straightline.d.ts +12 -2
- package/dist/generator/straightline.d.ts.map +1 -1
- package/dist/generator/straightline.js +47 -32
- package/dist/generator/straightline.js.map +1 -1
- package/dist/guard.js +26 -5
- package/dist/guard.js.map +1 -1
- package/dist/lowering.d.ts +47 -3
- package/dist/lowering.d.ts.map +1 -1
- package/dist/lowering.js +113 -8
- package/dist/lowering.js.map +1 -1
- package/dist/provenance.d.ts +26 -24
- package/dist/provenance.d.ts.map +1 -1
- package/dist/provenance.js +30 -59
- package/dist/provenance.js.map +1 -1
- package/dist/type-gate.d.ts.map +1 -1
- package/dist/type-gate.js +3 -1
- package/dist/type-gate.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GeneratorFailure } from "./core.js";
|
|
2
|
-
import { isControlGate, mapNodeElemIsOpaqueWire, nodeWirePassthrough } from "../behavior.js";
|
|
1
|
+
import { entryPortOrder, GeneratorFailure } from "./core.js";
|
|
2
|
+
import { mapTransformExpr, isControlGate, mapNodeElemIsOpaqueWire, 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, guardedMapIntoIsCoverable, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
|
|
6
|
-
import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, nodeNarrowedPaths } from "./straightline.js";
|
|
6
|
+
import { concurrencyPlan, execPlan, analyzeSequentialOps, opsLiteralOf, classifyExpr, nodeNarrowedPaths } from "./straightline.js";
|
|
7
7
|
import { NativeExprCompiler } from "./native-expr.js";
|
|
8
8
|
import { buildAsyncPlans } from "./async-plan.js";
|
|
9
9
|
import { buildDeBoxPlan, buildWirePlan, notationOfRef } from "./emit-shared-debox.js";
|
|
@@ -105,9 +105,12 @@ function emitErrorHelpers() {
|
|
|
105
105
|
// synthesize or re-interpret it).
|
|
106
106
|
#[allow(dead_code)]
|
|
107
107
|
fn op_failed(node: &str, policy: &str, e: BehaviorError) -> BehaviorError {
|
|
108
|
+
// The Kind names itself, and 'retry' says it gave up — the attempts are Runtime-owned (scp-error.md:
|
|
109
|
+
// tuning never enters the IR), so what the plan reports is the exhausted retry.
|
|
110
|
+
let exhausted = if policy == "retry" { " (exhausted)" } else { "" };
|
|
108
111
|
BehaviorError {
|
|
109
112
|
code: "OP_FAILED".to_string(),
|
|
110
|
-
message: format!("operation '{node}' failed under '{policy}' policy: {}", e.message),
|
|
113
|
+
message: format!("operation '{node}' failed under '{policy}' policy{exhausted}: {}", e.message),
|
|
111
114
|
detail: e.detail,
|
|
112
115
|
}
|
|
113
116
|
}
|
|
@@ -1260,8 +1263,6 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
1260
1263
|
// arr field, or an input array port carrying `elemType` (BC does not infer — consumer-interface C3).
|
|
1261
1264
|
if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsCoverable(n, comp))
|
|
1262
1265
|
return false;
|
|
1263
|
-
if (m.policy !== undefined && m.policy !== "fail")
|
|
1264
|
-
return false;
|
|
1265
1266
|
if (m.relationKind !== undefined && m.relationKind !== "single" && m.relationKind !== "connection")
|
|
1266
1267
|
return false;
|
|
1267
1268
|
// A map node must carry an outType (its ELEMENT type per the recorder SoT — authoring.ts recordMap
|
|
@@ -1289,7 +1290,9 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
1289
1290
|
if (schema === undefined || schema.elemType === undefined)
|
|
1290
1291
|
return false;
|
|
1291
1292
|
}
|
|
1292
|
-
|
|
1293
|
+
// 純式 map(#222)は port を持たない: 被覆条件は「要素式が宣言された要素型へ native に materialize
|
|
1294
|
+
// できること」で、それは compilePortNode(宣言型 materializer)が失敗したときに loud に落ちる。
|
|
1295
|
+
const ports = (m.ports ?? {});
|
|
1293
1296
|
const plan = planForComp(comp);
|
|
1294
1297
|
const typedNodes = buildTypedNodes(comp, plan);
|
|
1295
1298
|
const asBinding = mapAsBinding(comp, n, typedNodes, plan);
|
|
@@ -1306,8 +1309,6 @@ function coveredFanoutNode(n, bodyIds, comp) {
|
|
|
1306
1309
|
if (n === null || typeof n !== "object" || !("fanout" in n))
|
|
1307
1310
|
return false;
|
|
1308
1311
|
const f = n.fanout;
|
|
1309
|
-
if (f.policy !== undefined && f.policy !== "fail")
|
|
1310
|
-
return false;
|
|
1311
1312
|
if (f.relationKind !== "connection")
|
|
1312
1313
|
return false;
|
|
1313
1314
|
const overE = classifyExpr(f.over);
|
|
@@ -1421,8 +1422,8 @@ function coverageRejectReason(comp) {
|
|
|
1421
1422
|
if (!("component" in n))
|
|
1422
1423
|
return `node '${n.id}' is not a componentRef, map, or cond node (not native-covered)`;
|
|
1423
1424
|
const cr = n;
|
|
1424
|
-
|
|
1425
|
-
|
|
1425
|
+
// Every Error Policy Kind IS covered on a componentRef (see the go emitter's note): `continue` →
|
|
1426
|
+
// unproduced (produced-aware output), `retry` → `fail`'s control flow with the Kind in the message.
|
|
1426
1427
|
// #125: a when(...) control-gate child (`parent=gate, bindField:"ok"`). Its bindField is the gate's
|
|
1427
1428
|
// skip signal, NOT a relation data key — so the relationKind constraint below (which governs a
|
|
1428
1429
|
// relation bindField into a single|connection parent) does not apply. Its skip is driven by the
|
|
@@ -1518,7 +1519,7 @@ function emitPortWireField(pn, expr, comp, plan, typedNodes, isPrior, expected,
|
|
|
1518
1519
|
function rustScalar(s) {
|
|
1519
1520
|
return s === "string" ? "String" : s === "int" ? "i64" : s === "float" ? "f64" : "bool";
|
|
1520
1521
|
}
|
|
1521
|
-
function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
1522
|
+
function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
|
|
1522
1523
|
const ep = execPlan(comp);
|
|
1523
1524
|
const order = ep.order;
|
|
1524
1525
|
const hasConcurrency = ep.parallelStageOf.size > 0;
|
|
@@ -1540,14 +1541,10 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1540
1541
|
for (const n of comp.body)
|
|
1541
1542
|
if (!isControlGate(n))
|
|
1542
1543
|
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan));
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
const pid = cr.parent;
|
|
1548
|
-
return { id: n.id, parent: pid !== undefined ? idToIndex.get(pid) ?? null : null, policy: cr.policy, bindField: cr.bindField };
|
|
1549
|
-
});
|
|
1550
|
-
const metas = analyzeSequentialOps(opsLiteral, order);
|
|
1544
|
+
// the ops literal comes from the SHARED derivation (opsLiteralOf): a local "read cr.policy / cr.parent"
|
|
1545
|
+
// copy silently drops a MAP's / FANOUT's policy and parent (they live under map./fanout.), which would
|
|
1546
|
+
// make canSkip — and therefore the produced-aware output — disagree with the go surface on the same IR.
|
|
1547
|
+
const metas = analyzeSequentialOps(opsLiteralOf(comp), order);
|
|
1551
1548
|
const idToPos = new Map();
|
|
1552
1549
|
order.forEach((opIdx, k) => idToPos.set(comp.body[opIdx].id, k));
|
|
1553
1550
|
const priorNodeAt = (head, atPos) => {
|
|
@@ -1578,7 +1575,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1578
1575
|
// #192: 1:1 map of the authored method — the entry is the exported fn `<method>` (rustFieldName; no
|
|
1579
1576
|
// `run_native_raw_struct_` prefix) taking POSITIONAL params (one per input port; `In_<comp>` box removed).
|
|
1580
1577
|
lines.push(`${fnKw} ${rustFieldName(comp.name)}(`);
|
|
1581
|
-
for (const p of
|
|
1578
|
+
for (const p of entryPortOrder(comp, declared)) {
|
|
1582
1579
|
lines.push(` ${rustFieldName(p)}: ${inputPortRustType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)},`);
|
|
1583
1580
|
}
|
|
1584
1581
|
lines.push(`) -> Result<${outTy}, BehaviorError> {`);
|
|
@@ -1607,11 +1604,11 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1607
1604
|
continue;
|
|
1608
1605
|
}
|
|
1609
1606
|
if ("fanout" in comp.body[i]) {
|
|
1610
|
-
lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id)));
|
|
1607
|
+
lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id), metas[i].policy));
|
|
1611
1608
|
continue;
|
|
1612
1609
|
}
|
|
1613
1610
|
if ("map" in comp.body[i]) {
|
|
1614
|
-
lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id)));
|
|
1611
|
+
lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id), metas[i].policy));
|
|
1615
1612
|
continue;
|
|
1616
1613
|
}
|
|
1617
1614
|
// #108: a cond node — pure Expression (no handler). Compile via the runtime-free NativeExprCompiler.
|
|
@@ -1676,27 +1673,21 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1676
1673
|
// mismatch (byte-equal codes to run_behavior's outType check, so ≡ holds). The wire's concrete type is
|
|
1677
1674
|
// inferred from the transport's return type (no annotation) — the wire trait methods resolve.
|
|
1678
1675
|
if (meta.policy === "continue") {
|
|
1679
|
-
// continue: a
|
|
1680
|
-
//
|
|
1681
|
-
//
|
|
1682
|
-
//
|
|
1683
|
-
|
|
1684
|
-
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1676
|
+
// continue: a node whose COMPONENT failed produces no Port — the downstream Skip propagation is what
|
|
1677
|
+
// `continue` means (scp-error.md §Dependency rules for continue), so the leaf error leaves
|
|
1678
|
+
// produced_<s> false instead of propagating. A de-box mismatch is NOT a component failure: the
|
|
1679
|
+
// interpreter checks the declared outType in wrappedExec, OUTSIDE the policy interpretation, and
|
|
1680
|
+
// throws — so it must propagate here too, or the two surfaces disagree on the same IR.
|
|
1685
1681
|
lines.push(`${indent}if let Ok(wire_${s}) = ${call} {`);
|
|
1686
|
-
lines.push(`${indent}
|
|
1687
|
-
lines.push(`${indent}
|
|
1688
|
-
lines.push(`${indent} };`);
|
|
1689
|
-
lines.push(`${indent} if let Ok(val_${s}) = decoded_${s} {`);
|
|
1690
|
-
lines.push(`${indent} *${typedCell(node.id)}.borrow_mut() = val_${s};`);
|
|
1691
|
-
lines.push(`${indent} produced_${s}.set(true);`);
|
|
1692
|
-
lines.push(`${indent} }`);
|
|
1682
|
+
lines.push(`${indent} *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, `${indent} `, returnErrFail, nodeWirePassthrough(node))};`);
|
|
1683
|
+
lines.push(`${indent} produced_${s}.set(true);`);
|
|
1693
1684
|
lines.push(`${indent}}`);
|
|
1694
1685
|
}
|
|
1695
1686
|
else {
|
|
1696
|
-
const policyLit = meta.policy === "retry" ? "retry
|
|
1687
|
+
const policyLit = rustStrLit(meta.policy === "retry" ? "retry" : "fail");
|
|
1697
1688
|
lines.push(`${indent}let wire_${s} = match ${call} {`);
|
|
1698
1689
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1699
|
-
lines.push(`${indent} Err(e) => return Err(
|
|
1690
|
+
lines.push(`${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
1700
1691
|
lines.push(`${indent}};`);
|
|
1701
1692
|
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, indent, returnErrFail, nodeWirePassthrough(node))};`);
|
|
1702
1693
|
lines.push(`${indent}produced_${s}.set(true);`);
|
|
@@ -1867,25 +1858,18 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1867
1858
|
lines.push(` if payload_${s}.is_some() {`);
|
|
1868
1859
|
lines.push(` let out_${s} = slot_${s}.lock().unwrap().take().expect("runnable member wrote its slot");`);
|
|
1869
1860
|
if (meta.policy === "continue") {
|
|
1870
|
-
// continue: a failed
|
|
1871
|
-
//
|
|
1872
|
-
const label = `debox_${s}`;
|
|
1873
|
-
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1861
|
+
// continue: a member whose COMPONENT failed commits no Port. A de-box mismatch still propagates —
|
|
1862
|
+
// the interpreter's outType check sits outside the policy interpretation (see the sequential arm).
|
|
1874
1863
|
lines.push(` if let Ok(wire_${s}) = out_${s} {`);
|
|
1875
|
-
lines.push(`
|
|
1876
|
-
lines.push(`
|
|
1877
|
-
lines.push(` };`);
|
|
1878
|
-
lines.push(` if let Ok(val_${s}) = decoded_${s} {`);
|
|
1879
|
-
lines.push(` *${typedCell(node.id)}.borrow_mut() = val_${s};`);
|
|
1880
|
-
lines.push(` produced_${s}.set(true);`);
|
|
1881
|
-
lines.push(` }`);
|
|
1864
|
+
lines.push(` *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", returnErrFail, nodeWirePassthrough(node))};`);
|
|
1865
|
+
lines.push(` produced_${s}.set(true);`);
|
|
1882
1866
|
lines.push(` }`);
|
|
1883
1867
|
}
|
|
1884
1868
|
else {
|
|
1885
|
-
const policyLit = meta.policy === "retry" ? "retry
|
|
1869
|
+
const policyLit = rustStrLit(meta.policy === "retry" ? "retry" : "fail");
|
|
1886
1870
|
lines.push(` let wire_${s} = match out_${s} {`);
|
|
1887
1871
|
lines.push(` Ok(r) => r,`);
|
|
1888
|
-
lines.push(` Err(e) => return Err(
|
|
1872
|
+
lines.push(` Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
1889
1873
|
lines.push(` };`);
|
|
1890
1874
|
lines.push(` *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", returnErrFail, nodeWirePassthrough(node))};`);
|
|
1891
1875
|
lines.push(` produced_${s}.set(true);`);
|
|
@@ -1904,12 +1888,38 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1904
1888
|
* - #93 shape 2: NON-batched map...into — dispatch ONCE PER ELEMENT (N physical requests), into per element.
|
|
1905
1889
|
* - #93 shape 3: BATCHED map NO into — dispatch once, collect each element from the concrete element row.
|
|
1906
1890
|
*/
|
|
1891
|
+
/**
|
|
1892
|
+
* rustPolicyArm — Error Policy Kind を 1 つのノード arm へ適用する共通形(map / fanout が共有。go 側の
|
|
1893
|
+
* `goPolicyArm` の対)。
|
|
1894
|
+
*
|
|
1895
|
+
* `continue` は「Component が失敗 → その Port は未生成 → 下流は Skip」(scp-error.md §Dependency rules
|
|
1896
|
+
* for continue)。失敗した時点でノードの残りを飛ばすため **labeled block** で囲む(`loop { … break }` は
|
|
1897
|
+
* clippy の `never_loop` に `-D warnings` で殺される)。この形なら de-box 不一致 / 整列違反の
|
|
1898
|
+
* `return Err(...)` はそのまま関数を抜ける — interpreter も outType 検査を policy の外で throw する。
|
|
1899
|
+
*/
|
|
1900
|
+
function rustPolicyArm(s, indent, continuePolicy, body) {
|
|
1901
|
+
const produced = `${indent}produced_${s}.set(true);`;
|
|
1902
|
+
if (!continuePolicy)
|
|
1903
|
+
return [...body, produced];
|
|
1904
|
+
return [
|
|
1905
|
+
`${indent}let mut skipped_${s} = false;`,
|
|
1906
|
+
`${indent}'node_${s}: {`,
|
|
1907
|
+
...body.map((l) => ` ${l}`.replace(/\n/g, "\n ")),
|
|
1908
|
+
`${indent}}`,
|
|
1909
|
+
`${indent}if !skipped_${s} {`,
|
|
1910
|
+
` ${produced}`,
|
|
1911
|
+
`${indent}}`,
|
|
1912
|
+
];
|
|
1913
|
+
}
|
|
1907
1914
|
function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf,
|
|
1908
1915
|
// bc#97: whether THIS map node's terminal handler is async (derived per-node) — awaits the batched /
|
|
1909
1916
|
// per-element handler call at its consumption point iff true. Sync map handlers are called directly.
|
|
1910
|
-
isAsync = false) {
|
|
1917
|
+
isAsync = false, policy = "fail") {
|
|
1911
1918
|
const m = node.map;
|
|
1912
1919
|
const awaitSfx = isAsync ? ".await" : "";
|
|
1920
|
+
// Error Policy Kind of the map's Component (resolved by the sequential analysis — never re-derived here).
|
|
1921
|
+
const contPolicy = policy === "continue";
|
|
1922
|
+
const policyLit = rustStrLit(policy === "retry" ? "retry" : "fail");
|
|
1913
1923
|
const batched = m.batched === true;
|
|
1914
1924
|
const hasInto = m.into !== undefined;
|
|
1915
1925
|
const hasGuard = m.when !== undefined;
|
|
@@ -1918,13 +1928,14 @@ isAsync = false) {
|
|
|
1918
1928
|
// skipped elements instead. Byte-equal to run_behavior's applyInto keep-with-null.
|
|
1919
1929
|
const keepWithNull = hasGuard && hasInto;
|
|
1920
1930
|
const s = sanitize(node.id);
|
|
1921
|
-
const
|
|
1931
|
+
const transform = mapTransformExpr(m);
|
|
1932
|
+
const leafSym = transform === undefined ? resolveLeafSymbol(m.component, leaf, m.leafSymbol) : "";
|
|
1922
1933
|
// #108: over element type + the OWNED over-Vec expression (prior-node arr OR input array w/ elemType).
|
|
1923
1934
|
const { elemRef: overElemRef, overExpr, optArr: overOptArr } = mapOverElemInfo(comp, node, typedNodes, plan);
|
|
1924
1935
|
const elemMat = mapElemMaterializerName(comp.name, node.id);
|
|
1925
1936
|
const priorHere = (head) => priorNodeAt(head, atPos);
|
|
1926
1937
|
const asName = m.as;
|
|
1927
|
-
const portNames = Object.keys(m.ports);
|
|
1938
|
+
const portNames = Object.keys(m.ports ?? {});
|
|
1928
1939
|
const elemArrRef = typedNodes.get(node.id);
|
|
1929
1940
|
const elemName = renderTypeRef(elemArrRef.elem);
|
|
1930
1941
|
// each element is de-boxed strictly INLINE: the handler returns the per-element WIRE and the arm decodes
|
|
@@ -1984,15 +1995,37 @@ isAsync = false) {
|
|
|
1984
1995
|
};
|
|
1985
1996
|
const lines = [];
|
|
1986
1997
|
const closers = [];
|
|
1987
|
-
lines.push(` // ── map '${node.id}' (${m.component}, ${batched ? "batched" : "per-element"}, into:${JSON.stringify(m.into ?? null)}${hasGuard ? ", guarded" : ""}${m.relationKind ? ", relationKind:" + m.relationKind : ""}${m.parent ? ", parent:" + m.parent : ""}) ──`);
|
|
1998
|
+
lines.push(` // ── map '${node.id}' (${m.component ?? "pure expression"}, ${batched ? "batched" : "per-element"}, into:${JSON.stringify(m.into ?? null)}${hasGuard ? ", guarded" : ""}${m.relationKind ? ", relationKind:" + m.relationKind : ""}${m.parent ? ", parent:" + m.parent : ""}) ──`);
|
|
1988
1999
|
let indent = " ";
|
|
1989
2000
|
if (m.parent !== undefined && priorNodeAt(m.parent, atPos)) {
|
|
1990
2001
|
lines.push(`${indent}if produced_${sanitize(m.parent)}.get() {`);
|
|
1991
2002
|
closers.unshift(`${indent}}`);
|
|
1992
2003
|
indent += " ";
|
|
1993
2004
|
}
|
|
2005
|
+
// the node's own statements start here (rustPolicyArm wraps THIS range when the Kind is `continue`).
|
|
2006
|
+
const bodyStart = lines.length;
|
|
1994
2007
|
lines.push(`${indent}let over_${s} = ${rustBindOverExpr(overExpr, overOptArr)};`);
|
|
1995
2008
|
lines.push(`${indent}let mut built_${s}: Vec<${elemName}> = Vec::with_capacity(over_${s}.len());`);
|
|
2009
|
+
if (transform !== undefined) {
|
|
2010
|
+
// 純式 map(#222): transport 呼びもワイヤも de-box も無い。要素式を宣言された要素型へ native に
|
|
2011
|
+
// materialize して積む(port 境界と同一の宣言型 materializer を通す)。`when` は同一の keep-gate。
|
|
2012
|
+
lines.push(`${indent}for oel_${s} in over_${s}.iter() {`);
|
|
2013
|
+
for (const l of emitGuard(indent + " "))
|
|
2014
|
+
lines.push(l);
|
|
2015
|
+
const tc = compilePortNode(transform, comp, plan, typedNodes, priorHere, `map '${node.id}' transform`, elemArrRef.elem, {
|
|
2016
|
+
asBinding: { name: asName, ref: overElemRef, plan },
|
|
2017
|
+
asBase: `oel_${s}`,
|
|
2018
|
+
narrowed: nodeNarrowedPaths(comp, node),
|
|
2019
|
+
});
|
|
2020
|
+
for (const st of tc.stmts)
|
|
2021
|
+
lines.push(`${indent} ${st}`);
|
|
2022
|
+
lines.push(`${indent} ${typedCell(node.id)}.borrow_mut().push(${tc.expr});`);
|
|
2023
|
+
lines.push(`${indent}}`);
|
|
2024
|
+
lines.push(...rustPolicyArm(sanitize(node.id), indent, false, lines.splice(bodyStart)));
|
|
2025
|
+
for (const c of closers)
|
|
2026
|
+
lines.push(c);
|
|
2027
|
+
return lines.join("\n");
|
|
2028
|
+
}
|
|
1996
2029
|
if (batched && keepWithNull) {
|
|
1997
2030
|
// #177 BATCHED keep-with-null (guarded map...into, opt into): pass 1 records, per over element, whether
|
|
1998
2031
|
// it is kept (guard true → build ports) or skipped, preserving ORDER. ONE batched dispatch over the
|
|
@@ -2022,7 +2055,9 @@ isAsync = false) {
|
|
|
2022
2055
|
// its aligned per-element wires (byte-equal to run_behavior's aligned batch result).
|
|
2023
2056
|
lines.push(`${indent} let out_${s} = match ${leafSym}(${rustPayloadBatch(`items_${s}`)})${awaitSfx} {`);
|
|
2024
2057
|
lines.push(`${indent} Ok(r) => r,`);
|
|
2025
|
-
lines.push(
|
|
2058
|
+
lines.push(contPolicy
|
|
2059
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2060
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2026
2061
|
lines.push(`${indent} };`);
|
|
2027
2062
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2028
2063
|
lines.push(`${indent} if rows_${s}.len() != want_${s} {`);
|
|
@@ -2062,7 +2097,9 @@ isAsync = false) {
|
|
|
2062
2097
|
// ONE op-agnostic transport call: batch payload WireRow {items:[…]}; result WireList → aligned wires.
|
|
2063
2098
|
lines.push(`${indent} let out_${s} = match ${leafSym}(${rustPayloadBatch(`items_${s}`)})${awaitSfx} {`);
|
|
2064
2099
|
lines.push(`${indent} Ok(r) => r,`);
|
|
2065
|
-
lines.push(
|
|
2100
|
+
lines.push(contPolicy
|
|
2101
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2102
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2066
2103
|
lines.push(`${indent} };`);
|
|
2067
2104
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2068
2105
|
lines.push(`${indent} if rows_${s}.len() != want_${s} {`);
|
|
@@ -2107,7 +2144,9 @@ isAsync = false) {
|
|
|
2107
2144
|
lines.push(`${indent} Err(_) => continue,`);
|
|
2108
2145
|
}
|
|
2109
2146
|
else {
|
|
2110
|
-
lines.push(
|
|
2147
|
+
lines.push(contPolicy
|
|
2148
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2149
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2111
2150
|
}
|
|
2112
2151
|
lines.push(`${indent} };`);
|
|
2113
2152
|
// the element's wire is de-boxed strictly INLINE (fail-closed regardless of elementPolicy).
|
|
@@ -2122,7 +2161,7 @@ isAsync = false) {
|
|
|
2122
2161
|
lines.push(`${indent}}`);
|
|
2123
2162
|
}
|
|
2124
2163
|
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = built_${s};`);
|
|
2125
|
-
lines.push(
|
|
2164
|
+
lines.push(...rustPolicyArm(sanitize(node.id), indent, contPolicy, lines.splice(bodyStart)));
|
|
2126
2165
|
for (const c of closers)
|
|
2127
2166
|
lines.push(c);
|
|
2128
2167
|
return lines.join("\n");
|
|
@@ -2134,10 +2173,13 @@ isAsync = false) {
|
|
|
2134
2173
|
* dangling (empty dedupeKey ≡ the interpreter's null/absent-key body), implicitSource strip (STRUCTURAL:
|
|
2135
2174
|
* the elem type already omits it), wrap into the connection struct { items, cursor: None }.
|
|
2136
2175
|
*/
|
|
2137
|
-
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, isAsync = false) {
|
|
2176
|
+
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, isAsync = false, policy = "fail") {
|
|
2138
2177
|
const f = node.fanout;
|
|
2139
2178
|
const awaitSfx = isAsync ? ".await" : "";
|
|
2140
2179
|
const s = sanitize(node.id);
|
|
2180
|
+
// Error Policy Kind of the fanout's Component (same rule as the map arm — see rustPolicyArm).
|
|
2181
|
+
const contPolicy = policy === "continue";
|
|
2182
|
+
const policyLit = rustStrLit(policy === "retry" ? "retry" : "fail");
|
|
2141
2183
|
const leafSym = resolveLeafSymbol(f.component, leaf, f.leafSymbol);
|
|
2142
2184
|
const connRef = typedNodes.get(node.id);
|
|
2143
2185
|
const elemRef = fanoutItemsElemRef(node, connRef, plan);
|
|
@@ -2168,6 +2210,8 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2168
2210
|
closers.unshift(`${indent}}`);
|
|
2169
2211
|
indent += " ";
|
|
2170
2212
|
}
|
|
2213
|
+
// the node's own statements start here (rustPolicyArm wraps THIS range when the Kind is `continue`).
|
|
2214
|
+
const bodyStart = lines.length;
|
|
2171
2215
|
lines.push(`${indent}let over_${s} = ${rustBindOverExpr(overExpr, overOptArr)};`);
|
|
2172
2216
|
lines.push(`${indent}let mut built_${s}: Vec<${elemName}> = Vec::new();`);
|
|
2173
2217
|
lines.push(`${indent}let mut pi_${s}: Vec<WireValue> = Vec::with_capacity(over_${s}.len());`);
|
|
@@ -2182,7 +2226,9 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2182
2226
|
// per-id element wires (a WireValue::Null element → a DANGLING id). No `bound`.
|
|
2183
2227
|
lines.push(`${indent} let out_${s} = match ${leafSym}(${rustPayloadBatch(`pi_${s}`)})${awaitSfx} {`);
|
|
2184
2228
|
lines.push(`${indent} Ok(r) => r,`);
|
|
2185
|
-
lines.push(
|
|
2229
|
+
lines.push(contPolicy
|
|
2230
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2231
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2186
2232
|
lines.push(`${indent} };`);
|
|
2187
2233
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2188
2234
|
// each present body is de-boxed strictly INLINE (a de-box mismatch fails closed). A DANGLING id is a
|
|
@@ -2210,7 +2256,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2210
2256
|
lines.push(`${indent} }`);
|
|
2211
2257
|
lines.push(`${indent}}`);
|
|
2212
2258
|
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = ${connRef.name} { ${rustFieldName("items")}: built_${s}, ..Default::default() };`);
|
|
2213
|
-
lines.push(
|
|
2259
|
+
lines.push(...rustPolicyArm(sanitize(node.id), indent, contPolicy, lines.splice(bodyStart)));
|
|
2214
2260
|
for (const c of closers)
|
|
2215
2261
|
lines.push(c);
|
|
2216
2262
|
return lines.join("\n");
|
|
@@ -2462,7 +2508,7 @@ ${emitStructSurface([])}
|
|
|
2462
2508
|
// #183: the wire types derive Clone — the covered plane always builds `WireRow` payloads (the transport
|
|
2463
2509
|
// ABI) and the bc#87 parallel stage clones a member's payload into its owned-arg call; the #164 passthrough
|
|
2464
2510
|
// store also clones a `WireValue`. Deriving Clone on the (data-only) wire types is unconditional + harmless.
|
|
2465
|
-
const runners = native.map((c) => emitNativeRawRunner(c, plan, asyncPlans.get(c.name), leaf)).join("\n\n");
|
|
2511
|
+
const runners = native.map((c) => emitNativeRawRunner(c, plan, asyncPlans.get(c.name), leaf, ctx.declaredEntryPortOrder)).join("\n\n");
|
|
2466
2512
|
const structSurface = emitStructSurface(native);
|
|
2467
2513
|
// Leaf transport import (SSoT resolution via resolveLeafSymbol): if the consumer names an import module,
|
|
2468
2514
|
// bring the DISTINCT resolved transport symbols into the covered module's scope. Omitted → the symbols
|
|
@@ -2475,7 +2521,10 @@ ${emitStructSurface([])}
|
|
|
2475
2521
|
for (const n of c.body) {
|
|
2476
2522
|
if ("cond" in n)
|
|
2477
2523
|
continue; // a cond node has no leaf (pure Expression) — no transport symbol.
|
|
2478
|
-
|
|
2524
|
+
// 純式 map は Component を呼ばないので transport シンボルを要らない(cond と同じ扱い)。
|
|
2525
|
+
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
2526
|
+
continue;
|
|
2527
|
+
const component = ("fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component);
|
|
2479
2528
|
const specSym = "fanout" in n ? n.fanout.leafSymbol : "map" in n ? n.map.leafSymbol : n.leafSymbol;
|
|
2480
2529
|
// #176 SSoT: resolve EXACTLY as the call sites do (spec `node.leafSymbol` FIRST, then CLI override,
|
|
2481
2530
|
// then default) so the imported symbol == the called symbol — otherwise cross-crate --from won't compile.
|
|
@@ -2553,7 +2602,7 @@ use std::cell::RefCell;`;
|
|
|
2553
2602
|
* canonical Value for the equivalence pin. Lives OUTSIDE the covered module so the module stays literal
|
|
2554
2603
|
* whole-file zero (the ser_* / decode helpers are test glue, never on the consumer's read hot path).
|
|
2555
2604
|
*/
|
|
2556
|
-
export function rustTypedNativeObserve(ir, ioModel = "sync", leaf) {
|
|
2605
|
+
export function rustTypedNativeObserve(ir, ioModel = "sync", leaf, declared) {
|
|
2557
2606
|
const components = ir.components;
|
|
2558
2607
|
const native = components.filter(isNativeRaw);
|
|
2559
2608
|
const plan = buildTypePlan(ir);
|
|
@@ -2566,7 +2615,7 @@ export function rustTypedNativeObserve(ir, ioModel = "sync", leaf) {
|
|
|
2566
2615
|
const asyncPlans = buildAsyncPlans(ir, ioModel);
|
|
2567
2616
|
const anyAsyncRunner = native.some((c) => asyncPlans.get(c.name).runnerIsAsync);
|
|
2568
2617
|
// ── per-component input decoders: generic &[(String,Value)] -> concrete InNR_<comp> (test glue). ──
|
|
2569
|
-
const inDecoders = native.map((c) => emitInDecoder(c, plan)).join("\n\n");
|
|
2618
|
+
const inDecoders = native.map((c) => emitInDecoder(c, plan, declared)).join("\n\n");
|
|
2570
2619
|
// every covered node returns a WireValue the inline de-box classifies — so the scripted wire adapter is
|
|
2571
2620
|
// needed whenever any component has a handler node.
|
|
2572
2621
|
const anyDeBox = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
@@ -2615,7 +2664,7 @@ fn value_to_wire(v: &Value) -> WireValue {
|
|
|
2615
2664
|
for (const n of c.body) {
|
|
2616
2665
|
if ("cond" in n)
|
|
2617
2666
|
continue; // #108: a cond node has no leaf (pure Expression) — no transport fn.
|
|
2618
|
-
const catalog = "fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component;
|
|
2667
|
+
const catalog = ("fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component);
|
|
2619
2668
|
const specSym = "fanout" in n ? n.fanout.leafSymbol : "map" in n ? n.map.leafSymbol : n.leafSymbol;
|
|
2620
2669
|
const sym = resolveLeafSymbol(catalog, leaf, specSym);
|
|
2621
2670
|
const isAsync = ap.nodeIsAsync(n.id);
|
|
@@ -2695,7 +2744,7 @@ ${echoBlock} Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
|
2695
2744
|
// The scripted async node_* return ready values, so the future needs no real executor / no runtime.
|
|
2696
2745
|
// #192: decode the generic test input into the entry's POSITIONAL args (test glue), then call the
|
|
2697
2746
|
// 1:1 entry positionally (box removed). A no-input entry is called with no args (no decoder).
|
|
2698
|
-
const args =
|
|
2747
|
+
const args = entryPortOrder(c, declared).map((p) => rustFieldName(p));
|
|
2699
2748
|
const runnerCall = `super::${rustFieldName(c.name)}(${args.join(", ")})`;
|
|
2700
2749
|
const driven = asyncPlans.get(c.name).runnerIsAsync ? `bc_block_on(${runnerCall})` : runnerCall;
|
|
2701
2750
|
const decode = args.length === 0 ? "" : ` let (${args.join(", ")},) = decode_${sanitize(c.name)}(input).map_err(to_rt_err)?;\n`;
|
|
@@ -2863,8 +2912,8 @@ ${arms}
|
|
|
2863
2912
|
* param; scalar → typed read; value-typed → the raw wire clone), returned as a tuple the observe companion
|
|
2864
2913
|
* destructures and passes positionally to the 1:1 entry (#192, box removed). A missing key leaves Default
|
|
2865
2914
|
* (every covered input is required + supplied by the corpus). Lives ONLY in the observe companion. */
|
|
2866
|
-
function emitInDecoder(comp, plan) {
|
|
2867
|
-
const ports =
|
|
2915
|
+
function emitInDecoder(comp, plan, declared) {
|
|
2916
|
+
const ports = entryPortOrder(comp, declared);
|
|
2868
2917
|
if (ports.length === 0 || comp.inputPorts === undefined)
|
|
2869
2918
|
return ""; // no input → observe calls the entry with no args.
|
|
2870
2919
|
const args = ports.map((p) => rustFieldName(p));
|