behavior-contracts 0.8.14 → 0.8.16
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/README.md +12 -6
- package/cli-contract.yaml +16 -12
- package/dist/behavior.d.ts +28 -1
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +34 -9
- package/dist/behavior.js.map +1 -1
- 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 +2 -2
- package/dist/generated/program.js.map +1 -1
- package/dist/generator/emit-shared-debox.d.ts +51 -13
- package/dist/generator/emit-shared-debox.d.ts.map +1 -1
- package/dist/generator/emit-shared-debox.js +53 -18
- package/dist/generator/emit-shared-debox.js.map +1 -1
- package/dist/generator/emit-shared-go-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-go-typed.js +6 -0
- package/dist/generator/emit-shared-go-typed.js.map +1 -1
- package/dist/generator/emit-shared-typescript.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript.js +15 -4
- package/dist/generator/emit-shared-typescript.js.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.d.ts.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js +4 -0
- package/dist/generator/emit-straightline-typed-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 +58 -10
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +12 -0
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +162 -20
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +1 -1
- 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/native-expr.d.ts +10 -2
- package/dist/generator/native-expr.d.ts.map +1 -1
- package/dist/generator/native-expr.js +21 -15
- package/dist/generator/native-expr.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +8 -0
- package/dist/guard.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { GeneratorFailure } from "./core.js";
|
|
2
|
-
import { isControlGate } from "../behavior.js";
|
|
2
|
+
import { 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 } from "./typed.js";
|
|
6
6
|
import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr } from "./straightline.js";
|
|
7
7
|
import { NativeExprCompiler } from "./native-expr.js";
|
|
8
8
|
import { buildAsyncPlans } from "./async-plan.js";
|
|
9
|
-
import { buildDeBoxPlan, notationOfRef } from "./emit-shared-debox.js";
|
|
9
|
+
import { buildDeBoxPlan, buildWirePlan, notationOfRef } from "./emit-shared-debox.js";
|
|
10
10
|
const { sanitize, rustStrLit } = rustStraightlineInternals;
|
|
11
11
|
const { typeRefIsCopy, rustFieldName, renderTypeRef, typedCell, typedFieldAccess, serializeTyped, emitTypeDecls, emitDefaults, emitSerializers, emitTypedValue, checkOutputFieldType, emitMarshallers, emitMarshalHelpers, materializeExpr, } = rustTypedInternals;
|
|
12
12
|
/** rustErr — build the LOCAL concrete error value for a behavior/plan failure on the covered read
|
|
@@ -17,10 +17,11 @@ const { typeRefIsCopy, rustFieldName, renderTypeRef, typedCell, typedFieldAccess
|
|
|
17
17
|
function rustErr(code, msgExpr) {
|
|
18
18
|
return `BehaviorError::new(${JSON.stringify(code)}, ${msgExpr})`;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
20
|
+
/** emitErrorTypeDefs — the LOCAL concrete error TYPE (ErrorKind + ErrorDetail + BehaviorError + impls),
|
|
21
|
+
* runtime-free. Baked into the covered module (no --shared-types-import) OR into the shared crate (#165,
|
|
22
|
+
* --shared-types-import) so a cross-crate transport can return `Result<WireValue, BehaviorError>`. Codes
|
|
23
|
+
* match run_behavior verbatim (byte-equal). */
|
|
24
|
+
function emitErrorTypeDefs() {
|
|
24
25
|
return `// ErrorKind — what went wrong (the closed set of scp-error.md). A concrete enum: the covered plane
|
|
25
26
|
// carries no strings-as-tags and no dynamic kind lookup.
|
|
26
27
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
@@ -93,9 +94,13 @@ impl std::fmt::Display for BehaviorError {
|
|
|
93
94
|
write!(f, "{}: {}", self.code, self.message)
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
impl std::error::Error for BehaviorError {}
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
impl std::error::Error for BehaviorError {}`;
|
|
98
|
+
}
|
|
99
|
+
/** emitErrorHelpers — the de-box mismatch + op-failure CONSTRUCTORS (each PRODUCES a BehaviorError). They
|
|
100
|
+
* live in the COVERED module always (they are called by the inline de-box / runner); under
|
|
101
|
+
* --shared-types-import (#165) the TYPE they build is imported from the shared crate (`use <path>::*;`). */
|
|
102
|
+
function emitErrorHelpers() {
|
|
103
|
+
return `// op_failed — wrap a leaf failure as the node's Failure under its Error Policy Kind, carrying the
|
|
99
104
|
// leaf's structured detail through unchanged (the runner transports the Error Value; it does not
|
|
100
105
|
// synthesize or re-interpret it).
|
|
101
106
|
#[allow(dead_code)]
|
|
@@ -163,6 +168,12 @@ fn de_overflow(model: &str, field: &str, expected: &str, actual_wire: String, ra
|
|
|
163
168
|
)
|
|
164
169
|
}`;
|
|
165
170
|
}
|
|
171
|
+
/** emitBehaviorErrorType — the FULL local error layer (type defs THEN constructors) baked into the covered
|
|
172
|
+
* module when NOT cross-package. Byte-identical to the pre-#165 single block (type defs + "\n\n" + helpers),
|
|
173
|
+
* so a no-flag rust module is unchanged. */
|
|
174
|
+
function emitBehaviorErrorType() {
|
|
175
|
+
return `${emitErrorTypeDefs()}\n\n${emitErrorHelpers()}`;
|
|
176
|
+
}
|
|
166
177
|
function portFieldName(wire) {
|
|
167
178
|
const safe = wire.replace(/[^A-Za-z0-9_]/g, "_").toLowerCase();
|
|
168
179
|
return `f_${safe}`;
|
|
@@ -487,6 +498,23 @@ ${I1}}`)},
|
|
|
487
498
|
${probeArms}
|
|
488
499
|
${I}}`;
|
|
489
500
|
}
|
|
501
|
+
if (plan.k === "list" && plan.elem.k === "value") {
|
|
502
|
+
// bc#164: `{arr:"value"}` output-passthrough — the result wire is a list of OPAQUE values; validate the
|
|
503
|
+
// container is a list, then take its items AS-IS (clone, no per-element de-box / no re-box). The elements
|
|
504
|
+
// stay `WireValue` so a downstream op-agnostic leaf consumes them with no per-op `typed→Value` re-box.
|
|
505
|
+
return `match ${probe("list")} {
|
|
506
|
+
${I1}Probe::Got(l${id}) => ${wrapSome(`l${id}.items.clone()`)},
|
|
507
|
+
${probeArms}
|
|
508
|
+
${I}}`;
|
|
509
|
+
}
|
|
510
|
+
if (plan.k === "value") {
|
|
511
|
+
// bc#164: a bare `value` output-passthrough (top position) — the whole result wire crosses UNCHANGED
|
|
512
|
+
// (clone), no probe, no de-box. (elem-position `value` is handled by the list branch above; field/mapval
|
|
513
|
+
// never carry `value` — buildWirePlan does not relax those positions.)
|
|
514
|
+
if (plan.access.from !== "top")
|
|
515
|
+
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust de-box: a 'value' node at a non-top position (${plan.access.from}) is not a legal passthrough shape`);
|
|
516
|
+
return `${srcExpr}.clone()`;
|
|
517
|
+
}
|
|
490
518
|
if (plan.k === "list") {
|
|
491
519
|
const elemExpr = renderRustDeBox(plan.elem, `l${id}`, ctr, `${I1} `, fail, `i${id}`);
|
|
492
520
|
return `match ${probe("list")} {
|
|
@@ -514,6 +542,33 @@ ${I1}}`)},
|
|
|
514
542
|
${probeArms}
|
|
515
543
|
${I}}`;
|
|
516
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* renderRustWireBox — the ONE inline BOX renderer (typed→wire), the mirror of renderRustDeBox. Folds a
|
|
547
|
+
* language-neutral {@link WirePlan} (the SAME SSoT walk, `dir:"in"`) into a Rust EXPRESSION evaluating to an
|
|
548
|
+
* owned `WireValue` built from `srcExpr` (an OWNED native typed value of the plan's type). `value` is
|
|
549
|
+
* identity (already the opaque wire); a native scalar wraps in its wire ctor. A `value[]` bound-value list
|
|
550
|
+
* carries scalar / opaque elements, so those are the covered element shapes; a nested opt / collection /
|
|
551
|
+
* record element is fail-closed here (C1 — the compound box lands with the batched WireRow contract).
|
|
552
|
+
*/
|
|
553
|
+
function renderRustWireBox(plan, srcExpr) {
|
|
554
|
+
if (plan.optDepth === 0) {
|
|
555
|
+
if (plan.k === "value")
|
|
556
|
+
return srcExpr; // identity — already the opaque BC wire.
|
|
557
|
+
if (plan.k === "scalar") {
|
|
558
|
+
switch (plan.scalar) {
|
|
559
|
+
case "string":
|
|
560
|
+
return `WireValue::Str(${srcExpr})`;
|
|
561
|
+
case "int":
|
|
562
|
+
return `WireValue::int(${srcExpr})`;
|
|
563
|
+
case "float":
|
|
564
|
+
return `WireValue::float(${srcExpr})`;
|
|
565
|
+
case "bool":
|
|
566
|
+
return `WireValue::Bool(${srcExpr})`;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust wire box: a value[] element of type '${plan.expectedType}' is not a scalar / opaque value (a nested opt/collection/record bound-value is not native-covered)`);
|
|
571
|
+
}
|
|
517
572
|
/** returnErrFail — the default de-box mismatch control flow: propagate the structured Error Value out of
|
|
518
573
|
* the enclosing runner (fail/retry componentRef results + map/fanout element de-box, which fails closed
|
|
519
574
|
* regardless of elementPolicy — matching the interpreter's whole-node outType throw). */
|
|
@@ -522,8 +577,8 @@ const returnErrFail = (errValueExpr) => `return Err(${errValueExpr})`;
|
|
|
522
577
|
* native value, from the TOTAL SSoT plan for `ref` at the top position. `fail` selects the mismatch
|
|
523
578
|
* control flow. This is the ONE de-box call the runner arms share (componentRef result + map/fanout
|
|
524
579
|
* element) — no per-position predicate, no helper decode fn. */
|
|
525
|
-
function renderResultDeBox(ref, srcExpr, nodeId, plan, indent, fail = returnErrFail) {
|
|
526
|
-
return renderRustDeBox(buildDeBoxPlan(ref, { from: "top" }, { model: nodeId, field: nodeId, plan }), srcExpr, { n: 0 }, indent, fail);
|
|
580
|
+
function renderResultDeBox(ref, srcExpr, nodeId, plan, indent, fail = returnErrFail, passthrough = false) {
|
|
581
|
+
return renderRustDeBox(buildDeBoxPlan(ref, { from: "top" }, { model: nodeId, field: nodeId, plan }, passthrough), srcExpr, { n: 0 }, indent, fail);
|
|
527
582
|
}
|
|
528
583
|
/** mapFanoutElemRef — the element ROW TypeRef a map/fanout node decodes (the per-element record). */
|
|
529
584
|
function mapFanoutElemRef(node, typedNodes, plan) {
|
|
@@ -704,6 +759,9 @@ function makeRustExprBackend(resolveHead, plan) {
|
|
|
704
759
|
lang: "rust",
|
|
705
760
|
freshTemp: () => `ex_${rustExprTempSeq++}`,
|
|
706
761
|
renderType: (ref) => renderTypeRef(ref),
|
|
762
|
+
wireType: () => renderTypeRef({ kind: "value" }),
|
|
763
|
+
// bc#156/#160: box a value[] element into the opaque BC wire via the ONE box SSoT (owned element expr).
|
|
764
|
+
wireBox: (item) => renderRustWireBox(buildWirePlan(item.ref, { from: "top" }, { model: "port", field: "port", plan }, "in"), item.expr),
|
|
707
765
|
scalarType: (s) => rustScalar(s),
|
|
708
766
|
strLit: (s) => `${rustStrLit(s)}.to_string()`,
|
|
709
767
|
boolLit: (b) => (b ? "true" : "false"),
|
|
@@ -1549,7 +1607,12 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1549
1607
|
// #125: a control-gate cond has no typed data cell — only a produced_<gate> flag (its `if` result),
|
|
1550
1608
|
// which its gated children read via the existing `if produced_<parent>.get()` skip-gate.
|
|
1551
1609
|
if (!isControlGate(nd)) {
|
|
1552
|
-
|
|
1610
|
+
const cellRef = typedNodes.get(id);
|
|
1611
|
+
// bc#164: a bare `value` passthrough cell holds a `WireValue`, which has no derived Default (the wire
|
|
1612
|
+
// enum is a self-contained runtime-free type — no Default derive so goldens stay byte-identical); seed
|
|
1613
|
+
// it with the null wire. Every other cell (concrete struct / Vec<WireValue> / scalar) is Defaultable.
|
|
1614
|
+
const cellInit = cellRef.kind === "value" ? "WireValue::Null" : "Default::default()";
|
|
1615
|
+
lines.push(` let ${typedCell(id)}: RefCell<${renderTypeRef(cellRef)}> = RefCell::new(${cellInit});`);
|
|
1553
1616
|
}
|
|
1554
1617
|
lines.push(` let produced_${sanitize(id)} = std::cell::Cell::new(false);`);
|
|
1555
1618
|
lines.push(` let _ = &produced_${sanitize(id)};`);
|
|
@@ -1643,7 +1706,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1643
1706
|
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1644
1707
|
lines.push(`${indent}if let Ok(wire_${s}) = ${call} {`);
|
|
1645
1708
|
lines.push(`${indent} let decoded_${s}: Result<${renderTypeRef(ref)}, BehaviorError> = '${label}: {`);
|
|
1646
|
-
lines.push(`${indent} Ok(${renderResultDeBox(ref, `wire_${s}`, node.id, plan, `${indent} `, contFail)})`);
|
|
1709
|
+
lines.push(`${indent} Ok(${renderResultDeBox(ref, `wire_${s}`, node.id, plan, `${indent} `, contFail, nodeWirePassthrough(node))})`);
|
|
1647
1710
|
lines.push(`${indent} };`);
|
|
1648
1711
|
lines.push(`${indent} if let Ok(val_${s}) = decoded_${s} {`);
|
|
1649
1712
|
lines.push(`${indent} *${typedCell(node.id)}.borrow_mut() = val_${s};`);
|
|
@@ -1657,7 +1720,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1657
1720
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1658
1721
|
lines.push(`${indent} Err(e) => return Err(BehaviorError { code: "OP_FAILED".to_string(), message: format!("operation '{}' failed under '${policyLit}: {}", ${rustStrLit(node.id)}, e.message), detail: e.detail }),`);
|
|
1659
1722
|
lines.push(`${indent}};`);
|
|
1660
|
-
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, indent)};`);
|
|
1723
|
+
lines.push(`${indent}*${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, indent, returnErrFail, nodeWirePassthrough(node))};`);
|
|
1661
1724
|
lines.push(`${indent}produced_${s}.set(true);`);
|
|
1662
1725
|
}
|
|
1663
1726
|
for (const c of closers)
|
|
@@ -1834,7 +1897,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1834
1897
|
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1835
1898
|
lines.push(` if let Ok(wire_${s}) = out_${s} {`);
|
|
1836
1899
|
lines.push(` let decoded_${s}: Result<${renderTypeRef(ref)}, BehaviorError> = '${label}: {`);
|
|
1837
|
-
lines.push(` Ok(${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", contFail)})`);
|
|
1900
|
+
lines.push(` Ok(${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", contFail, nodeWirePassthrough(node))})`);
|
|
1838
1901
|
lines.push(` };`);
|
|
1839
1902
|
lines.push(` if let Ok(val_${s}) = decoded_${s} {`);
|
|
1840
1903
|
lines.push(` *${typedCell(node.id)}.borrow_mut() = val_${s};`);
|
|
@@ -1848,7 +1911,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1848
1911
|
lines.push(` Ok(r) => r,`);
|
|
1849
1912
|
lines.push(` Err(e) => return Err(BehaviorError { code: "OP_FAILED".to_string(), message: format!("operation '{}' failed under '${policyLit}: {}", ${rustStrLit(node.id)}, e.message), detail: e.detail }),`);
|
|
1850
1913
|
lines.push(` };`);
|
|
1851
|
-
lines.push(` *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ")};`);
|
|
1914
|
+
lines.push(` *${typedCell(node.id)}.borrow_mut() = ${renderResultDeBox(ref, `wire_${s}`, node.id, plan, " ", returnErrFail, nodeWirePassthrough(node))};`);
|
|
1852
1915
|
lines.push(` produced_${s}.set(true);`);
|
|
1853
1916
|
}
|
|
1854
1917
|
lines.push(` }`);
|
|
@@ -1890,7 +1953,7 @@ isAsync = false) {
|
|
|
1890
1953
|
// it against the element ref (the `into` field's type for map...into, else the element type). A de-box
|
|
1891
1954
|
// mismatch fails closed regardless of elementPolicy (matching the interpreter's whole-node outType throw).
|
|
1892
1955
|
const elemDeBoxRef = mapElemRowRef(node, elemArrRef, plan);
|
|
1893
|
-
const renderElemDeBox = (il) => renderResultDeBox(elemDeBoxRef, `er_${s}`, node.id, plan, il);
|
|
1956
|
+
const renderElemDeBox = (il) => renderResultDeBox(elemDeBoxRef, `er_${s}`, node.id, plan, il, returnErrFail, nodeWirePassthrough(node));
|
|
1894
1957
|
// build the per-element CONCRETE native ports struct. `il` = indent inside the element loop.
|
|
1895
1958
|
const buildPorts = (il) => {
|
|
1896
1959
|
const out = [];
|
|
@@ -2087,7 +2150,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2087
2150
|
lines.push(`${indent} let mut seen_${s}: std::collections::HashSet<String> = std::collections::HashSet::new();`);
|
|
2088
2151
|
lines.push(`${indent} for opt_er_${s} in row_${s}.into_iter() {`);
|
|
2089
2152
|
lines.push(`${indent} let el_${s}: ${elemName} = match opt_er_${s} {`);
|
|
2090
|
-
lines.push(`${indent} Some(wire_${s}) => ${renderResultDeBox(elemRef, `wire_${s}`, node.id, plan, `${indent}
|
|
2153
|
+
lines.push(`${indent} Some(wire_${s}) => ${renderResultDeBox(elemRef, `wire_${s}`, node.id, plan, `${indent} `, returnErrFail, nodeWirePassthrough(node))},`);
|
|
2091
2154
|
lines.push(`${indent} None => Default::default(),`);
|
|
2092
2155
|
lines.push(`${indent} };`);
|
|
2093
2156
|
lines.push(`${indent} let key_${s} = el_${s}.${dkRust}.clone();`);
|
|
@@ -2257,6 +2320,58 @@ fn leaf_failure(message: impl Into<String>) -> BehaviorError {
|
|
|
2257
2320
|
BehaviorError::new("LEAF_FAILURE", message)
|
|
2258
2321
|
}`;
|
|
2259
2322
|
// ── module assembly ──────────────────────────────────────────────────────────────────
|
|
2323
|
+
/** isCrossPackageSharedNode (#165, rust twin of the go predicate) — a node whose ports struct CROSSES the
|
|
2324
|
+
* leaf-transport boundary as a whole value (the batch ports struct passed to the transport), so under
|
|
2325
|
+
* --shared-types-import it must live in the SHARED crate/module (else the transport crate → covered crate
|
|
2326
|
+
* import cycle). Batched maps + fanouts pass a batch struct; every other node passes only primitive port
|
|
2327
|
+
* fields, so its ports struct stays local. The SINGLE predicate emit() (skip-local) and
|
|
2328
|
+
* {@link rustSharedWireTypesModule} (emit-there) both use — they never disagree (SSoT). */
|
|
2329
|
+
function isCrossPackageSharedNode(n) {
|
|
2330
|
+
return "fanout" in n || ("map" in n && n.map.batched === true);
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* rustSharedWireTypesModule (#165, rust twin of goSharedWireTypesPackage) — the BC-GENERATED shared module
|
|
2334
|
+
* content emitted when the covered module is generated with --shared-types-import. Carries the SAME wire seam
|
|
2335
|
+
* the covered module emits in-crate when the flag is absent (Probe/NumProbe + WireValue/WireRow/WireList +
|
|
2336
|
+
* the probe classifiers) so a separate leaf-transport crate can build+return `WireValue` (and the covered
|
|
2337
|
+
* module reference it) without an import cycle. When `ir` is given, ALSO emits the batched-map / fanout batch
|
|
2338
|
+
* ports structs (the ONLY covered-module types that cross the transport boundary as a whole value) — same
|
|
2339
|
+
* emitMapPortsStructs / emitFanoutPortsStructs + same {@link isCrossPackageSharedNode} predicate emit()
|
|
2340
|
+
* skip-local uses, so the two never disagree (SSoT). The wire types derive Clone (a cross-crate transport +
|
|
2341
|
+
* the #164 passthrough store clone them). Self-contained + runtime-free — drop it in the shared crate's
|
|
2342
|
+
* lib.rs (a separate crate) or a module. `pub use` re-exports keep every name reachable unqualified. */
|
|
2343
|
+
export function rustSharedWireTypesModule(ir) {
|
|
2344
|
+
const portsStructs = [];
|
|
2345
|
+
if (ir !== undefined) {
|
|
2346
|
+
const components = ir.components;
|
|
2347
|
+
const plan = buildTypePlan(ir);
|
|
2348
|
+
for (const c of components.filter(isNativeRaw)) {
|
|
2349
|
+
const typedNodes = buildTypedNodes(c, plan);
|
|
2350
|
+
for (const n of c.body) {
|
|
2351
|
+
if (!isCrossPackageSharedNode(n))
|
|
2352
|
+
continue;
|
|
2353
|
+
portsStructs.push("fanout" in n ? emitFanoutPortsStructs(c, n, typedNodes, plan) : emitMapPortsStructs(c, n, typedNodes, plan));
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
const portsSection = portsStructs.length
|
|
2358
|
+
? `\n\n// #165 cross-crate batched/fanout ports structs — the batch ports the covered module's runner passes\n// to the leaf transport as a whole value. Here (not the covered module) so the transport crate can name\n// them without importing the covered crate (cycle-free). Native fields — no boxed Value.\n${portsStructs.filter((s) => s.trim().length > 0).join("\n\n")}`
|
|
2359
|
+
: "";
|
|
2360
|
+
return `#![allow(dead_code, unused_imports, non_snake_case)]
|
|
2361
|
+
// GENERATED by behavior-contracts (rust-typed-native) — the BC-OWNED shared wire types (#165). A covered
|
|
2362
|
+
// module generated with --shared-types-import imports these (\`use <path>::*;\`); a separate leaf-transport
|
|
2363
|
+
// crate builds + returns the SAME \`WireValue\` (and, on failure, the SAME \`BehaviorError\`). The concrete
|
|
2364
|
+
// failure type lives here too so the transport crate returns \`Result<WireValue, BehaviorError>\` WITHOUT
|
|
2365
|
+
// importing the covered crate (unlike go's \`error\` interface, rust's runner reads the concrete
|
|
2366
|
+
// \`.detail\`/\`.message\`, so the type must be shared). Self-contained + runtime-free.
|
|
2367
|
+
|
|
2368
|
+
// Local concrete failure type (runtime-free) — the covered runner + the transport crate share it. Only the
|
|
2369
|
+
// TYPE lives here; the de-box/op-failure CONSTRUCTORS stay in the covered module (they are called there).
|
|
2370
|
+
${emitErrorTypeDefs()}
|
|
2371
|
+
|
|
2372
|
+
${emitRustProbeWireTypes(true)}${portsSection}
|
|
2373
|
+
`;
|
|
2374
|
+
}
|
|
2260
2375
|
function emit(ctx) {
|
|
2261
2376
|
// bc#97 (increment 2): the SSoT language-agnostic propagation pass derives, PER COMPONENT + PER NODE,
|
|
2262
2377
|
// which handler-call boundaries must be awaited (bottom-up over the declared async terminal handlers).
|
|
@@ -2306,6 +2421,13 @@ ${emitStructSurface([])}
|
|
|
2306
2421
|
// every covered node returns a WireValue the inline de-box classifies — the wire seam (probe enums +
|
|
2307
2422
|
// WireValue/WireRow/WireList traits) is emitted once whenever any handler node exists.
|
|
2308
2423
|
const anyWire = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
2424
|
+
// #165: --shared-types-import parity with go. When set, the BC-OWNED wire types (WireValue/WireRow/
|
|
2425
|
+
// WireList + Probe/NumProbe) AND the batched-map/fanout batch ports structs (the ONLY structs that cross
|
|
2426
|
+
// the leaf-transport boundary as a whole value) live in the SHARED crate/module at that path; the covered
|
|
2427
|
+
// module IMPORTS them (`use <path>::*;`) instead of defining them locally — so a separate transport crate
|
|
2428
|
+
// can return the shared WireValue with NO import cycle (covered → tx → shared, no back-edge). Absent →
|
|
2429
|
+
// in-crate (byte-identical to before). resolveRustWire is the SSoT for this decision.
|
|
2430
|
+
const crossPackage = ctx.sharedTypesImport !== undefined;
|
|
2309
2431
|
for (const c of native) {
|
|
2310
2432
|
const typedNodes = new Map();
|
|
2311
2433
|
// build the full typed-node map FIRST so a map's over-element resolution can see every node.
|
|
@@ -2313,6 +2435,10 @@ ${emitStructSurface([])}
|
|
|
2313
2435
|
if (!isControlGate(n))
|
|
2314
2436
|
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
|
|
2315
2437
|
for (const n of c.body) {
|
|
2438
|
+
// #165: a cross-package batch ports struct (batched map / fanout) is emitted in the SHARED module
|
|
2439
|
+
// instead (rustSharedWireTypesModule), referenced here via the `use <path>::*;` glob — skip local.
|
|
2440
|
+
if (crossPackage && isCrossPackageSharedNode(n))
|
|
2441
|
+
continue;
|
|
2316
2442
|
if ("fanout" in n)
|
|
2317
2443
|
structs.push(emitFanoutPortsStructs(c, n, typedNodes, plan));
|
|
2318
2444
|
else if ("map" in n)
|
|
@@ -2354,6 +2480,15 @@ ${emitStructSurface([])}
|
|
|
2354
2480
|
return undefined;
|
|
2355
2481
|
return `// op-agnostic leaf transport symbols (consumer-supplied) — called directly at each covered node.\nuse ${leaf.import}::{${[...syms].sort().join(", ")}};`;
|
|
2356
2482
|
})();
|
|
2483
|
+
// #165: --shared-types-import — bring the BC-OWNED wire types (WireValue/WireRow/WireList + Probe/NumProbe)
|
|
2484
|
+
// and the batched/fanout batch ports structs into scope from the shared crate/module (a glob `use`, so no
|
|
2485
|
+
// reference site is qualified). The covered module defines NONE of them locally; a separate transport crate
|
|
2486
|
+
// returns the SAME shared WireValue with no import cycle. Absent → in-crate (byte-identical to before).
|
|
2487
|
+
const sharedImportBlock = crossPackage
|
|
2488
|
+
? `// #165 --shared-types-import: the BC-OWNED wire seam lives in the shared crate/module — import it.\nuse ${ctx.sharedTypesImport}::*;`
|
|
2489
|
+
: undefined;
|
|
2490
|
+
// the wire seam is emitted LOCALLY only when NOT cross-package (else it lives in the shared module).
|
|
2491
|
+
const emitsWireTypes = anyWire && !crossPackage;
|
|
2357
2492
|
// (nonNative.length === 0 is guaranteed here — the fail-closed guard above threw otherwise.)
|
|
2358
2493
|
const banner = `#![allow(dead_code, unused_imports, non_snake_case)]
|
|
2359
2494
|
// GENERATED by behavior-contracts (bc#90, rust-typed-native — the RUNTIME-FREE read de-box; STRUCT-ONLY,
|
|
@@ -2376,7 +2511,14 @@ use std::cell::RefCell;`;
|
|
|
2376
2511
|
const sections = [
|
|
2377
2512
|
banner,
|
|
2378
2513
|
importBlock,
|
|
2379
|
-
|
|
2514
|
+
sharedImportBlock,
|
|
2515
|
+
// #165: cross-package puts the concrete failure TYPE in the shared crate (imported via the glob above),
|
|
2516
|
+
// so the transport crate returns `Result<WireValue, BehaviorError>` without importing the covered crate;
|
|
2517
|
+
// the covered module keeps only the de-box/op-failure CONSTRUCTORS (they build the shared type). Absent →
|
|
2518
|
+
// the full local error layer (type + constructors), byte-identical to before.
|
|
2519
|
+
crossPackage
|
|
2520
|
+
? `// De-box / op-failure constructors (produce the shared BehaviorError, imported above). Runtime-free.\n${emitErrorHelpers()}`
|
|
2521
|
+
: `// Local concrete failure type (runtime-free) — a covered runner returns Result<T, BehaviorError> over\n// THIS local type instead of a bc-runtime failure, so the fully-covered module imports ZERO bc runtime.\n${emitBehaviorErrorType()}`,
|
|
2380
2522
|
decls || undefined,
|
|
2381
2523
|
defaults || undefined,
|
|
2382
2524
|
UNKNOWN_COMPONENT_HELPER,
|
|
@@ -2387,7 +2529,7 @@ use std::cell::RefCell;`;
|
|
|
2387
2529
|
? `// Native ports structs (one per componentRef node; typed per the static port type — CONCRETE).\n${structs.filter((r) => r.trim().length > 0).join("\n\n")}`
|
|
2388
2530
|
: undefined,
|
|
2389
2531
|
`// CONCRETE per-component input structs (fields = inputPorts).\n${inStructs.join("\n\n")}`,
|
|
2390
|
-
|
|
2532
|
+
emitsWireTypes
|
|
2391
2533
|
? `// strict de-box wire seam — the BC-OWNED, BC-GENERATED concrete WireValue (+ WireRow/WireList): the\n// consumer's single transport builds + returns it, implements NOTHING over it. The generated INLINE de-box\n// classifies it against the STATICALLY declared type and owns strictness (required/optional, present/absent,\n// error assembly, fail-closed). Self-contained concrete types — no trait, no boxed runtime value.\n${emitRustProbeWireTypes(hasValuePort)}`
|
|
2392
2534
|
: undefined,
|
|
2393
2535
|
elemMaterializers.length
|