behavior-contracts 0.11.5 → 0.11.7
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 +12 -3
- 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 +46 -10
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +98 -20
- package/dist/behavior.js.map +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +23 -10
- package/dist/builder.js.map +1 -1
- package/dist/commands/ts-compile.d.ts.map +1 -1
- package/dist/commands/ts-compile.js +32 -7
- package/dist/commands/ts-compile.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/emit-shared-go.d.ts.map +1 -1
- package/dist/generator/emit-shared-go.js +40 -7
- 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 +46 -12
- 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 +43 -13
- package/dist/generator/emit-shared-typescript.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +4 -4
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +162 -71
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +145 -78
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/straightline.d.ts +16 -4
- package/dist/generator/straightline.d.ts.map +1 -1
- package/dist/generator/straightline.js +51 -32
- package/dist/generator/straightline.js.map +1 -1
- package/dist/guard.js +32 -15
- 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 +121 -24
- package/dist/lowering.js.map +1 -1
- package/dist/plan.d.ts +9 -2
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +9 -2
- package/dist/plan.js.map +1 -1
- package/dist/primitives.d.ts +0 -2
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +0 -4
- package/dist/primitives.js.map +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/type-gate.d.ts.map +1 -1
- package/dist/type-gate.js +35 -6
- package/dist/type-gate.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { entryPortOrder, GeneratorFailure } from "./core.js";
|
|
2
|
-
import { isControlGate, mapNodeElemIsOpaqueWire, nodeWirePassthrough } from "../behavior.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,9 +1263,7 @@ 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.
|
|
1264
|
-
return false;
|
|
1265
|
-
if (m.relationKind !== undefined && m.relationKind !== "single" && m.relationKind !== "connection")
|
|
1266
|
+
if (m.relationKind !== undefined && 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
|
|
1268
1269
|
// holds `node.outType = mapElem`, the PRE-array-wrap element; the emitter synthesizes the produced
|
|
@@ -1273,7 +1274,13 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
1273
1274
|
// per-op re-box), exactly as the componentRef path treats a passthrough result. Any other non-compound
|
|
1274
1275
|
// element type stays uncovered (loud), as before.
|
|
1275
1276
|
const outT = n.outType;
|
|
1276
|
-
|
|
1277
|
+
// #225: 純式 map(`transform`)の要素は**式から native に組む**(ワイヤも de-box も無い)ので、要素型が
|
|
1278
|
+
// スカラでも被覆される — 宣言型 materializer が組めれば良く、組めなければそこで loud に落ちる。
|
|
1279
|
+
// Component map は要素 wire を de-box するので従来どおり compound / opaque wire に限る。
|
|
1280
|
+
const isTransformMap = mapTransformExpr(m) !== undefined;
|
|
1281
|
+
if (outT === undefined)
|
|
1282
|
+
return false;
|
|
1283
|
+
if (!isTransformMap && typeof outT !== "object" && !mapNodeElemIsOpaqueWire(n))
|
|
1277
1284
|
return false;
|
|
1278
1285
|
const overE = classifyExpr(m.over);
|
|
1279
1286
|
if (overE.kind !== "ref")
|
|
@@ -1289,7 +1296,9 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
1289
1296
|
if (schema === undefined || schema.elemType === undefined)
|
|
1290
1297
|
return false;
|
|
1291
1298
|
}
|
|
1292
|
-
|
|
1299
|
+
// 純式 map(#222)は port を持たない: 被覆条件は「要素式が宣言された要素型へ native に materialize
|
|
1300
|
+
// できること」で、それは compilePortNode(宣言型 materializer)が失敗したときに loud に落ちる。
|
|
1301
|
+
const ports = (m.ports ?? {});
|
|
1293
1302
|
const plan = planForComp(comp);
|
|
1294
1303
|
const typedNodes = buildTypedNodes(comp, plan);
|
|
1295
1304
|
const asBinding = mapAsBinding(comp, n, typedNodes, plan);
|
|
@@ -1306,8 +1315,6 @@ function coveredFanoutNode(n, bodyIds, comp) {
|
|
|
1306
1315
|
if (n === null || typeof n !== "object" || !("fanout" in n))
|
|
1307
1316
|
return false;
|
|
1308
1317
|
const f = n.fanout;
|
|
1309
|
-
if (f.policy !== undefined && f.policy !== "fail")
|
|
1310
|
-
return false;
|
|
1311
1318
|
if (f.relationKind !== "connection")
|
|
1312
1319
|
return false;
|
|
1313
1320
|
const overE = classifyExpr(f.over);
|
|
@@ -1387,8 +1394,12 @@ function coverageRejectReason(comp) {
|
|
|
1387
1394
|
// {ok}/null skip marker) AND the Φ-merge VALUE cond (#108, has outType — the sibling Φ-join). A
|
|
1388
1395
|
// value cond's outType requirement is enforced by the per-node cond check below, so a parallel
|
|
1389
1396
|
// value cond without outType still loud-rejects there.
|
|
1397
|
+
// #225: 純式 map(`map.transform`)も cond と同じ性質(handler も boxed result も無い変換)なので、
|
|
1398
|
+
// 昇順 preflight で確定させれば error-precedence 協定を乱さない。免除根拠は go 側と同一。
|
|
1390
1399
|
if ("cond" in n)
|
|
1391
1400
|
continue;
|
|
1401
|
+
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
1402
|
+
continue;
|
|
1392
1403
|
if (!("component" in n))
|
|
1393
1404
|
return `node '${n.id}' is a non-componentRef member of a parallel stage (not native-covered)`;
|
|
1394
1405
|
}
|
|
@@ -1421,16 +1432,12 @@ function coverageRejectReason(comp) {
|
|
|
1421
1432
|
if (!("component" in n))
|
|
1422
1433
|
return `node '${n.id}' is not a componentRef, map, or cond node (not native-covered)`;
|
|
1423
1434
|
const cr = n;
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
//
|
|
1427
|
-
//
|
|
1428
|
-
//
|
|
1429
|
-
|
|
1430
|
-
const childOfGate = cr.parent !== undefined && isControlGate(comp.body.find((b) => b.id === cr.parent));
|
|
1431
|
-
if (!childOfGate && cr.bindField !== undefined && cr.relationKind !== "single" && cr.relationKind !== "connection")
|
|
1432
|
-
return `node '${n.id}' relationKind '${cr.relationKind ?? "point"}' not native-covered (bindField only supports single|connection)`;
|
|
1433
|
-
if (cr.relationKind !== undefined && cr.relationKind !== "single" && cr.relationKind !== "connection")
|
|
1435
|
+
// Every Error Policy Kind IS covered on a componentRef (see the go emitter's note): `continue` →
|
|
1436
|
+
// unproduced (produced-aware output), `retry` → `fail`'s control flow with the Kind in the message.
|
|
1437
|
+
// relationKind の閉集合は `connection` の 1 値で、**注記の不在**が「未生成は null」を意味する。ゆえに
|
|
1438
|
+
// bindField 由来 skip は 2 形(connection = 空 connection / 不在 = null)とも produced-aware 出力が
|
|
1439
|
+
// 表現でき、被覆条件は無い(かつての「明示的に single と書け」は既定値の重複綴りの要求だった)。
|
|
1440
|
+
if (cr.relationKind !== undefined && cr.relationKind !== "connection")
|
|
1434
1441
|
return `relationKind '${cr.relationKind}' not native-covered (node '${n.id}')`;
|
|
1435
1442
|
// #170: a control-gate child's ports may narrow a gate-proven opt ref to non-null (the (a3) gated read).
|
|
1436
1443
|
const crNarrowed = nodeNarrowedPaths(comp, cr);
|
|
@@ -1540,14 +1547,10 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
|
|
|
1540
1547
|
for (const n of comp.body)
|
|
1541
1548
|
if (!isControlGate(n))
|
|
1542
1549
|
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);
|
|
1550
|
+
// the ops literal comes from the SHARED derivation (opsLiteralOf): a local "read cr.policy / cr.parent"
|
|
1551
|
+
// copy silently drops a MAP's / FANOUT's policy and parent (they live under map./fanout.), which would
|
|
1552
|
+
// make canSkip — and therefore the produced-aware output — disagree with the go surface on the same IR.
|
|
1553
|
+
const metas = analyzeSequentialOps(opsLiteralOf(comp), order);
|
|
1551
1554
|
const idToPos = new Map();
|
|
1552
1555
|
order.forEach((opIdx, k) => idToPos.set(comp.body[opIdx].id, k));
|
|
1553
1556
|
const priorNodeAt = (head, atPos) => {
|
|
@@ -1565,7 +1568,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
|
|
|
1565
1568
|
lines.push(`// de-boxes the returned wire INLINE (match wire.as_*() { … } fully unrolled — no decode helper) into`);
|
|
1566
1569
|
lines.push(`// the node's outType struct cell — no boxed handler result, no generic enum crossing, no dispatch on a dynamic value on the covered plane. Node`);
|
|
1567
1570
|
lines.push(`// results are typed struct cells; a relation child reads the parent's REAL struct result via`);
|
|
1568
|
-
lines.push(`// direct field access (child-present decision from the real parent value —
|
|
1571
|
+
lines.push(`// direct field access (child-present decision from the real parent value — relation /`);
|
|
1569
1572
|
lines.push(`// connection converge). A real-concurrency stage (bc#87) is static parallel orchestration —`);
|
|
1570
1573
|
lines.push(`// scoped worker threads (bounded by the static plan.concurrency) call the transport; preflight +`);
|
|
1571
1574
|
lines.push(`// interpret are committed in ascending index order so the value / op multiset / failure`);
|
|
@@ -1607,11 +1610,11 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
|
|
|
1607
1610
|
continue;
|
|
1608
1611
|
}
|
|
1609
1612
|
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)));
|
|
1613
|
+
lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id), metas[i].policy));
|
|
1611
1614
|
continue;
|
|
1612
1615
|
}
|
|
1613
1616
|
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)));
|
|
1617
|
+
lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, leaf, ap.nodeIsAsync(comp.body[i].id), metas[i].policy));
|
|
1615
1618
|
continue;
|
|
1616
1619
|
}
|
|
1617
1620
|
// #108: a cond node — pure Expression (no handler). Compile via the runtime-free NativeExprCompiler.
|
|
@@ -1676,27 +1679,21 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
|
|
|
1676
1679
|
// mismatch (byte-equal codes to run_behavior's outType check, so ≡ holds). The wire's concrete type is
|
|
1677
1680
|
// inferred from the transport's return type (no annotation) — the wire trait methods resolve.
|
|
1678
1681
|
if (meta.policy === "continue") {
|
|
1679
|
-
// continue: a
|
|
1680
|
-
//
|
|
1681
|
-
//
|
|
1682
|
-
//
|
|
1683
|
-
|
|
1684
|
-
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1682
|
+
// continue: a node whose COMPONENT failed produces no Port — the downstream Skip propagation is what
|
|
1683
|
+
// `continue` means (scp-error.md §Dependency rules for continue), so the leaf error leaves
|
|
1684
|
+
// produced_<s> false instead of propagating. A de-box mismatch is NOT a component failure: the
|
|
1685
|
+
// interpreter checks the declared outType in wrappedExec, OUTSIDE the policy interpretation, and
|
|
1686
|
+
// throws — so it must propagate here too, or the two surfaces disagree on the same IR.
|
|
1685
1687
|
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} }`);
|
|
1688
|
+
lines.push(`${indent} *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, `${indent} `, returnErrFail, nodeWirePassthrough(node))};`);
|
|
1689
|
+
lines.push(`${indent} produced_${s}.set(true);`);
|
|
1693
1690
|
lines.push(`${indent}}`);
|
|
1694
1691
|
}
|
|
1695
1692
|
else {
|
|
1696
|
-
const policyLit = meta.policy === "retry" ? "retry
|
|
1693
|
+
const policyLit = rustStrLit(meta.policy === "retry" ? "retry" : "fail");
|
|
1697
1694
|
lines.push(`${indent}let wire_${s} = match ${call} {`);
|
|
1698
1695
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1699
|
-
lines.push(`${indent} Err(e) => return Err(
|
|
1696
|
+
lines.push(`${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
1700
1697
|
lines.push(`${indent}};`);
|
|
1701
1698
|
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, indent, returnErrFail, nodeWirePassthrough(node))};`);
|
|
1702
1699
|
lines.push(`${indent}produced_${s}.set(true);`);
|
|
@@ -1751,10 +1748,16 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1751
1748
|
// when-gated connection relations each folding to `ref | emptyConn`). Both are mutually independent
|
|
1752
1749
|
// (§1), so ascending-at-head is byte-equal to run_behavior. A cond never shares a stage with a node
|
|
1753
1750
|
// that depends on it (an intra-stage parent/child dep is rejected by concurrencyPlan).
|
|
1754
|
-
|
|
1755
|
-
const
|
|
1751
|
+
// #225: dispatch を持たないメンバ = cond + 純式 map。昇順に、**逐次パスと同じ arm** で emit する。
|
|
1752
|
+
const noDispatch = (i) => "cond" in comp.body[i] || ("map" in comp.body[i] && mapTransformExpr(comp.body[i].map) !== undefined);
|
|
1753
|
+
const condMembers = stage.filter(noDispatch);
|
|
1754
|
+
const refMembers = stage.filter((i) => !noDispatch(i));
|
|
1756
1755
|
for (const i of condMembers) {
|
|
1757
|
-
|
|
1756
|
+
const n = comp.body[i];
|
|
1757
|
+
lines.push("cond" in n
|
|
1758
|
+
? emitCondArm(comp, n, atPos + stage.indexOf(i), typedNodes, plan, priorNodeAt)
|
|
1759
|
+
: // 純式 map は leaf を呼ばないので async 性を持たない(sync 既定)。
|
|
1760
|
+
emitMapArm(comp, n, atPos + stage.indexOf(i), typedNodes, plan, priorNodeAt, leaf, false, metas[i].policy));
|
|
1758
1761
|
}
|
|
1759
1762
|
// A cond-ONLY stage carries no handler fan-out — the conds above ARE the whole stage. Skip the scoped-
|
|
1760
1763
|
// thread orchestration block entirely (an empty one is dead scaffolding clippy rejects: never_loop /
|
|
@@ -1867,25 +1870,18 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1867
1870
|
lines.push(` if payload_${s}.is_some() {`);
|
|
1868
1871
|
lines.push(` let out_${s} = slot_${s}.lock().unwrap().take().expect("runnable member wrote its slot");`);
|
|
1869
1872
|
if (meta.policy === "continue") {
|
|
1870
|
-
// continue: a failed
|
|
1871
|
-
//
|
|
1872
|
-
const label = `debox_${s}`;
|
|
1873
|
-
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1873
|
+
// continue: a member whose COMPONENT failed commits no Port. A de-box mismatch still propagates —
|
|
1874
|
+
// the interpreter's outType check sits outside the policy interpretation (see the sequential arm).
|
|
1874
1875
|
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(` }`);
|
|
1876
|
+
lines.push(` *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", returnErrFail, nodeWirePassthrough(node))};`);
|
|
1877
|
+
lines.push(` produced_${s}.set(true);`);
|
|
1882
1878
|
lines.push(` }`);
|
|
1883
1879
|
}
|
|
1884
1880
|
else {
|
|
1885
|
-
const policyLit = meta.policy === "retry" ? "retry
|
|
1881
|
+
const policyLit = rustStrLit(meta.policy === "retry" ? "retry" : "fail");
|
|
1886
1882
|
lines.push(` let wire_${s} = match out_${s} {`);
|
|
1887
1883
|
lines.push(` Ok(r) => r,`);
|
|
1888
|
-
lines.push(` Err(e) => return Err(
|
|
1884
|
+
lines.push(` Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
1889
1885
|
lines.push(` };`);
|
|
1890
1886
|
lines.push(` *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", returnErrFail, nodeWirePassthrough(node))};`);
|
|
1891
1887
|
lines.push(` produced_${s}.set(true);`);
|
|
@@ -1904,12 +1900,38 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1904
1900
|
* - #93 shape 2: NON-batched map...into — dispatch ONCE PER ELEMENT (N physical requests), into per element.
|
|
1905
1901
|
* - #93 shape 3: BATCHED map NO into — dispatch once, collect each element from the concrete element row.
|
|
1906
1902
|
*/
|
|
1903
|
+
/**
|
|
1904
|
+
* rustPolicyArm — Error Policy Kind を 1 つのノード arm へ適用する共通形(map / fanout が共有。go 側の
|
|
1905
|
+
* `goPolicyArm` の対)。
|
|
1906
|
+
*
|
|
1907
|
+
* `continue` は「Component が失敗 → その Port は未生成 → 下流は Skip」(scp-error.md §Dependency rules
|
|
1908
|
+
* for continue)。失敗した時点でノードの残りを飛ばすため **labeled block** で囲む(`loop { … break }` は
|
|
1909
|
+
* clippy の `never_loop` に `-D warnings` で殺される)。この形なら de-box 不一致 / 整列違反の
|
|
1910
|
+
* `return Err(...)` はそのまま関数を抜ける — interpreter も outType 検査を policy の外で throw する。
|
|
1911
|
+
*/
|
|
1912
|
+
function rustPolicyArm(s, indent, continuePolicy, body) {
|
|
1913
|
+
const produced = `${indent}produced_${s}.set(true);`;
|
|
1914
|
+
if (!continuePolicy)
|
|
1915
|
+
return [...body, produced];
|
|
1916
|
+
return [
|
|
1917
|
+
`${indent}let mut skipped_${s} = false;`,
|
|
1918
|
+
`${indent}'node_${s}: {`,
|
|
1919
|
+
...body.map((l) => ` ${l}`.replace(/\n/g, "\n ")),
|
|
1920
|
+
`${indent}}`,
|
|
1921
|
+
`${indent}if !skipped_${s} {`,
|
|
1922
|
+
` ${produced}`,
|
|
1923
|
+
`${indent}}`,
|
|
1924
|
+
];
|
|
1925
|
+
}
|
|
1907
1926
|
function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf,
|
|
1908
1927
|
// bc#97: whether THIS map node's terminal handler is async (derived per-node) — awaits the batched /
|
|
1909
1928
|
// per-element handler call at its consumption point iff true. Sync map handlers are called directly.
|
|
1910
|
-
isAsync = false) {
|
|
1929
|
+
isAsync = false, policy = "fail") {
|
|
1911
1930
|
const m = node.map;
|
|
1912
1931
|
const awaitSfx = isAsync ? ".await" : "";
|
|
1932
|
+
// Error Policy Kind of the map's Component (resolved by the sequential analysis — never re-derived here).
|
|
1933
|
+
const contPolicy = policy === "continue";
|
|
1934
|
+
const policyLit = rustStrLit(policy === "retry" ? "retry" : "fail");
|
|
1913
1935
|
const batched = m.batched === true;
|
|
1914
1936
|
const hasInto = m.into !== undefined;
|
|
1915
1937
|
const hasGuard = m.when !== undefined;
|
|
@@ -1918,13 +1940,14 @@ isAsync = false) {
|
|
|
1918
1940
|
// skipped elements instead. Byte-equal to run_behavior's applyInto keep-with-null.
|
|
1919
1941
|
const keepWithNull = hasGuard && hasInto;
|
|
1920
1942
|
const s = sanitize(node.id);
|
|
1921
|
-
const
|
|
1943
|
+
const transform = mapTransformExpr(m);
|
|
1944
|
+
const leafSym = transform === undefined ? resolveLeafSymbol(m.component, leaf, m.leafSymbol) : "";
|
|
1922
1945
|
// #108: over element type + the OWNED over-Vec expression (prior-node arr OR input array w/ elemType).
|
|
1923
1946
|
const { elemRef: overElemRef, overExpr, optArr: overOptArr } = mapOverElemInfo(comp, node, typedNodes, plan);
|
|
1924
1947
|
const elemMat = mapElemMaterializerName(comp.name, node.id);
|
|
1925
1948
|
const priorHere = (head) => priorNodeAt(head, atPos);
|
|
1926
1949
|
const asName = m.as;
|
|
1927
|
-
const portNames = Object.keys(m.ports);
|
|
1950
|
+
const portNames = Object.keys(m.ports ?? {});
|
|
1928
1951
|
const elemArrRef = typedNodes.get(node.id);
|
|
1929
1952
|
const elemName = renderTypeRef(elemArrRef.elem);
|
|
1930
1953
|
// each element is de-boxed strictly INLINE: the handler returns the per-element WIRE and the arm decodes
|
|
@@ -1984,15 +2007,40 @@ isAsync = false) {
|
|
|
1984
2007
|
};
|
|
1985
2008
|
const lines = [];
|
|
1986
2009
|
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 : ""}) ──`);
|
|
2010
|
+
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
2011
|
let indent = " ";
|
|
1989
2012
|
if (m.parent !== undefined && priorNodeAt(m.parent, atPos)) {
|
|
1990
2013
|
lines.push(`${indent}if produced_${sanitize(m.parent)}.get() {`);
|
|
1991
2014
|
closers.unshift(`${indent}}`);
|
|
1992
2015
|
indent += " ";
|
|
1993
2016
|
}
|
|
2017
|
+
// the node's own statements start here (rustPolicyArm wraps THIS range when the Kind is `continue`).
|
|
2018
|
+
const bodyStart = lines.length;
|
|
1994
2019
|
lines.push(`${indent}let over_${s} = ${rustBindOverExpr(overExpr, overOptArr)};`);
|
|
1995
|
-
|
|
2020
|
+
// `built_<s>` は Component 経路の集積ローカル。純式 map は typed cell へ直接積むので出さない
|
|
2021
|
+
// (生成物は clippy -D warnings を通るので未使用/不要 mut は出せない)。
|
|
2022
|
+
if (transform === undefined)
|
|
2023
|
+
lines.push(`${indent}let mut built_${s}: Vec<${elemName}> = Vec::with_capacity(over_${s}.len());`);
|
|
2024
|
+
if (transform !== undefined) {
|
|
2025
|
+
// 純式 map(#222): transport 呼びもワイヤも de-box も無い。要素式を宣言された要素型へ native に
|
|
2026
|
+
// materialize して積む(port 境界と同一の宣言型 materializer を通す)。`when` は同一の keep-gate。
|
|
2027
|
+
lines.push(`${indent}for oel_${s} in over_${s}.iter() {`);
|
|
2028
|
+
for (const l of emitGuard(indent + " "))
|
|
2029
|
+
lines.push(l);
|
|
2030
|
+
const tc = compilePortNode(transform, comp, plan, typedNodes, priorHere, `map '${node.id}' transform`, elemArrRef.elem, {
|
|
2031
|
+
asBinding: { name: asName, ref: overElemRef, plan },
|
|
2032
|
+
asBase: `oel_${s}`,
|
|
2033
|
+
narrowed: nodeNarrowedPaths(comp, node),
|
|
2034
|
+
});
|
|
2035
|
+
for (const st of tc.stmts)
|
|
2036
|
+
lines.push(`${indent} ${st}`);
|
|
2037
|
+
lines.push(`${indent} ${typedCell(node.id)}.borrow_mut().push(${tc.expr});`);
|
|
2038
|
+
lines.push(`${indent}}`);
|
|
2039
|
+
lines.push(...rustPolicyArm(sanitize(node.id), indent, false, lines.splice(bodyStart)));
|
|
2040
|
+
for (const c of closers)
|
|
2041
|
+
lines.push(c);
|
|
2042
|
+
return lines.join("\n");
|
|
2043
|
+
}
|
|
1996
2044
|
if (batched && keepWithNull) {
|
|
1997
2045
|
// #177 BATCHED keep-with-null (guarded map...into, opt into): pass 1 records, per over element, whether
|
|
1998
2046
|
// it is kept (guard true → build ports) or skipped, preserving ORDER. ONE batched dispatch over the
|
|
@@ -2022,7 +2070,9 @@ isAsync = false) {
|
|
|
2022
2070
|
// its aligned per-element wires (byte-equal to run_behavior's aligned batch result).
|
|
2023
2071
|
lines.push(`${indent} let out_${s} = match ${leafSym}(${rustPayloadBatch(`items_${s}`)})${awaitSfx} {`);
|
|
2024
2072
|
lines.push(`${indent} Ok(r) => r,`);
|
|
2025
|
-
lines.push(
|
|
2073
|
+
lines.push(contPolicy
|
|
2074
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2075
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2026
2076
|
lines.push(`${indent} };`);
|
|
2027
2077
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2028
2078
|
lines.push(`${indent} if rows_${s}.len() != want_${s} {`);
|
|
@@ -2062,7 +2112,9 @@ isAsync = false) {
|
|
|
2062
2112
|
// ONE op-agnostic transport call: batch payload WireRow {items:[…]}; result WireList → aligned wires.
|
|
2063
2113
|
lines.push(`${indent} let out_${s} = match ${leafSym}(${rustPayloadBatch(`items_${s}`)})${awaitSfx} {`);
|
|
2064
2114
|
lines.push(`${indent} Ok(r) => r,`);
|
|
2065
|
-
lines.push(
|
|
2115
|
+
lines.push(contPolicy
|
|
2116
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2117
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2066
2118
|
lines.push(`${indent} };`);
|
|
2067
2119
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2068
2120
|
lines.push(`${indent} if rows_${s}.len() != want_${s} {`);
|
|
@@ -2107,7 +2159,9 @@ isAsync = false) {
|
|
|
2107
2159
|
lines.push(`${indent} Err(_) => continue,`);
|
|
2108
2160
|
}
|
|
2109
2161
|
else {
|
|
2110
|
-
lines.push(
|
|
2162
|
+
lines.push(contPolicy
|
|
2163
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2164
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2111
2165
|
}
|
|
2112
2166
|
lines.push(`${indent} };`);
|
|
2113
2167
|
// the element's wire is de-boxed strictly INLINE (fail-closed regardless of elementPolicy).
|
|
@@ -2122,7 +2176,7 @@ isAsync = false) {
|
|
|
2122
2176
|
lines.push(`${indent}}`);
|
|
2123
2177
|
}
|
|
2124
2178
|
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = built_${s};`);
|
|
2125
|
-
lines.push(
|
|
2179
|
+
lines.push(...rustPolicyArm(sanitize(node.id), indent, contPolicy, lines.splice(bodyStart)));
|
|
2126
2180
|
for (const c of closers)
|
|
2127
2181
|
lines.push(c);
|
|
2128
2182
|
return lines.join("\n");
|
|
@@ -2134,10 +2188,13 @@ isAsync = false) {
|
|
|
2134
2188
|
* dangling (empty dedupeKey ≡ the interpreter's null/absent-key body), implicitSource strip (STRUCTURAL:
|
|
2135
2189
|
* the elem type already omits it), wrap into the connection struct { items, cursor: None }.
|
|
2136
2190
|
*/
|
|
2137
|
-
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, isAsync = false) {
|
|
2191
|
+
function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, isAsync = false, policy = "fail") {
|
|
2138
2192
|
const f = node.fanout;
|
|
2139
2193
|
const awaitSfx = isAsync ? ".await" : "";
|
|
2140
2194
|
const s = sanitize(node.id);
|
|
2195
|
+
// Error Policy Kind of the fanout's Component (same rule as the map arm — see rustPolicyArm).
|
|
2196
|
+
const contPolicy = policy === "continue";
|
|
2197
|
+
const policyLit = rustStrLit(policy === "retry" ? "retry" : "fail");
|
|
2141
2198
|
const leafSym = resolveLeafSymbol(f.component, leaf, f.leafSymbol);
|
|
2142
2199
|
const connRef = typedNodes.get(node.id);
|
|
2143
2200
|
const elemRef = fanoutItemsElemRef(node, connRef, plan);
|
|
@@ -2168,6 +2225,8 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2168
2225
|
closers.unshift(`${indent}}`);
|
|
2169
2226
|
indent += " ";
|
|
2170
2227
|
}
|
|
2228
|
+
// the node's own statements start here (rustPolicyArm wraps THIS range when the Kind is `continue`).
|
|
2229
|
+
const bodyStart = lines.length;
|
|
2171
2230
|
lines.push(`${indent}let over_${s} = ${rustBindOverExpr(overExpr, overOptArr)};`);
|
|
2172
2231
|
lines.push(`${indent}let mut built_${s}: Vec<${elemName}> = Vec::new();`);
|
|
2173
2232
|
lines.push(`${indent}let mut pi_${s}: Vec<WireValue> = Vec::with_capacity(over_${s}.len());`);
|
|
@@ -2182,7 +2241,9 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2182
2241
|
// per-id element wires (a WireValue::Null element → a DANGLING id). No `bound`.
|
|
2183
2242
|
lines.push(`${indent} let out_${s} = match ${leafSym}(${rustPayloadBatch(`pi_${s}`)})${awaitSfx} {`);
|
|
2184
2243
|
lines.push(`${indent} Ok(r) => r,`);
|
|
2185
|
-
lines.push(
|
|
2244
|
+
lines.push(contPolicy
|
|
2245
|
+
? `${indent} Err(_) => { skipped_${s} = true; break 'node_${s}; }`
|
|
2246
|
+
: `${indent} Err(e) => return Err(op_failed(${rustStrLit(node.id)}, ${policyLit}, e)),`);
|
|
2186
2247
|
lines.push(`${indent} };`);
|
|
2187
2248
|
lines.push(`${indent} let rows_${s}: Vec<WireValue> = ${rustListItems(`out_${s}`)};`);
|
|
2188
2249
|
// each present body is de-boxed strictly INLINE (a de-box mismatch fails closed). A DANGLING id is a
|
|
@@ -2210,7 +2271,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2210
2271
|
lines.push(`${indent} }`);
|
|
2211
2272
|
lines.push(`${indent}}`);
|
|
2212
2273
|
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = ${connRef.name} { ${rustFieldName("items")}: built_${s}, ..Default::default() };`);
|
|
2213
|
-
lines.push(
|
|
2274
|
+
lines.push(...rustPolicyArm(sanitize(node.id), indent, contPolicy, lines.splice(bodyStart)));
|
|
2214
2275
|
for (const c of closers)
|
|
2215
2276
|
lines.push(c);
|
|
2216
2277
|
return lines.join("\n");
|
|
@@ -2475,7 +2536,10 @@ ${emitStructSurface([])}
|
|
|
2475
2536
|
for (const n of c.body) {
|
|
2476
2537
|
if ("cond" in n)
|
|
2477
2538
|
continue; // a cond node has no leaf (pure Expression) — no transport symbol.
|
|
2478
|
-
|
|
2539
|
+
// 純式 map は Component を呼ばないので transport シンボルを要らない(cond と同じ扱い)。
|
|
2540
|
+
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
2541
|
+
continue;
|
|
2542
|
+
const component = ("fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component);
|
|
2479
2543
|
const specSym = "fanout" in n ? n.fanout.leafSymbol : "map" in n ? n.map.leafSymbol : n.leafSymbol;
|
|
2480
2544
|
// #176 SSoT: resolve EXACTLY as the call sites do (spec `node.leafSymbol` FIRST, then CLI override,
|
|
2481
2545
|
// then default) so the imported symbol == the called symbol — otherwise cross-crate --from won't compile.
|
|
@@ -2498,7 +2562,7 @@ ${emitStructSurface([])}
|
|
|
2498
2562
|
const banner = `#![allow(dead_code, unused_imports, unused_variables, non_snake_case)]
|
|
2499
2563
|
// GENERATED by behavior-contracts (bc#90, rust-typed-native — the RUNTIME-FREE read de-box; STRUCT-ONLY,
|
|
2500
2564
|
// FULLY-NATIVE). A covered read is a strictly-sequential typed componentRef chain (point reads +
|
|
2501
|
-
//
|
|
2565
|
+
// relation children), emitted ONLY as a STRUCT-returning runner that calls the op-agnostic leaf
|
|
2502
2566
|
// TRANSPORT symbol DIRECTLY at each covered node's execution point: native ports struct IN (direct
|
|
2503
2567
|
// construction — every port is a CONCRETE Rust value: String / bool / Vec<&str> projection / i64 limit —
|
|
2504
2568
|
// NO boxed Value, NO by-name accessor); the transport is called with the node's port fields spread and
|
|
@@ -2508,7 +2572,7 @@ ${emitStructSurface([])}
|
|
|
2508
2572
|
// The covered plane carries NO bc-runtime reference at all — failures use the LOCAL BehaviorError (same
|
|
2509
2573
|
// codes, byte-equal to run_behavior). INLINE sequential (no plan driver) so a relation child reads the
|
|
2510
2574
|
// parent's REAL struct result via direct field access and the child-present decision is made from the real
|
|
2511
|
-
// parent value —
|
|
2575
|
+
// parent value — relation / connection converge with run_behavior (fixes #323/#74). The exposed API
|
|
2512
2576
|
// is the 1:1 entry <method>(<positional params>) -> Result<T, BehaviorError> (the InNR_<comp> box removed);
|
|
2513
2577
|
// the consumer supplies the leaf transport symbols (default in-scope names leaf_<comp>, or a leafTransport
|
|
2514
2578
|
// import). This module
|
|
@@ -2615,7 +2679,10 @@ fn value_to_wire(v: &Value) -> WireValue {
|
|
|
2615
2679
|
for (const n of c.body) {
|
|
2616
2680
|
if ("cond" in n)
|
|
2617
2681
|
continue; // #108: a cond node has no leaf (pure Expression) — no transport fn.
|
|
2618
|
-
|
|
2682
|
+
// #225: 純式 map も Component を呼ばないので transport fn を持たない(cond と同じ)。
|
|
2683
|
+
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
2684
|
+
continue;
|
|
2685
|
+
const catalog = ("fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component);
|
|
2619
2686
|
const specSym = "fanout" in n ? n.fanout.leafSymbol : "map" in n ? n.map.leafSymbol : n.leafSymbol;
|
|
2620
2687
|
const sym = resolveLeafSymbol(catalog, leaf, specSym);
|
|
2621
2688
|
const isAsync = ap.nodeIsAsync(n.id);
|