behavior-contracts 0.8.15 → 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 +19 -5
- package/dist/generator/emit-shared-debox.d.ts.map +1 -1
- package/dist/generator/emit-shared-debox.js +30 -10
- 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 +25 -13
- 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 +131 -23
- 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/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,5 +1,5 @@
|
|
|
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";
|
|
@@ -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")} {
|
|
@@ -500,10 +528,6 @@ ${I1}}`)},
|
|
|
500
528
|
${probeArms}
|
|
501
529
|
${I}}`;
|
|
502
530
|
}
|
|
503
|
-
// `value` never appears in a de-box (OUT) plan — buildWirePlan("out") fail-closes it at plan build
|
|
504
|
-
// (input-only). This exhaustiveness guard is unreachable; it keeps the union total for the type checker.
|
|
505
|
-
if (plan.k === "value")
|
|
506
|
-
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust de-box: a 'value' node reached the de-box renderer (unreachable — value is input-only)`);
|
|
507
531
|
// map(V): the wire value is a producer map (a DynamoDB "M"); enumerate its keys, decode each value as V.
|
|
508
532
|
const valExpr = renderRustDeBox(plan.value, `m${id}`, ctr, `${I1} `, fail, `&k${id}`);
|
|
509
533
|
return `match ${probe("row")} {
|
|
@@ -553,8 +577,8 @@ const returnErrFail = (errValueExpr) => `return Err(${errValueExpr})`;
|
|
|
553
577
|
* native value, from the TOTAL SSoT plan for `ref` at the top position. `fail` selects the mismatch
|
|
554
578
|
* control flow. This is the ONE de-box call the runner arms share (componentRef result + map/fanout
|
|
555
579
|
* element) — no per-position predicate, no helper decode fn. */
|
|
556
|
-
function renderResultDeBox(ref, srcExpr, nodeId, plan, indent, fail = returnErrFail) {
|
|
557
|
-
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);
|
|
558
582
|
}
|
|
559
583
|
/** mapFanoutElemRef — the element ROW TypeRef a map/fanout node decodes (the per-element record). */
|
|
560
584
|
function mapFanoutElemRef(node, typedNodes, plan) {
|
|
@@ -1583,7 +1607,12 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1583
1607
|
// #125: a control-gate cond has no typed data cell — only a produced_<gate> flag (its `if` result),
|
|
1584
1608
|
// which its gated children read via the existing `if produced_<parent>.get()` skip-gate.
|
|
1585
1609
|
if (!isControlGate(nd)) {
|
|
1586
|
-
|
|
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});`);
|
|
1587
1616
|
}
|
|
1588
1617
|
lines.push(` let produced_${sanitize(id)} = std::cell::Cell::new(false);`);
|
|
1589
1618
|
lines.push(` let _ = &produced_${sanitize(id)};`);
|
|
@@ -1677,7 +1706,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1677
1706
|
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1678
1707
|
lines.push(`${indent}if let Ok(wire_${s}) = ${call} {`);
|
|
1679
1708
|
lines.push(`${indent} let decoded_${s}: Result<${renderTypeRef(ref)}, BehaviorError> = '${label}: {`);
|
|
1680
|
-
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))})`);
|
|
1681
1710
|
lines.push(`${indent} };`);
|
|
1682
1711
|
lines.push(`${indent} if let Ok(val_${s}) = decoded_${s} {`);
|
|
1683
1712
|
lines.push(`${indent} *${typedCell(node.id)}.borrow_mut() = val_${s};`);
|
|
@@ -1691,7 +1720,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1691
1720
|
lines.push(`${indent} Ok(r) => r,`);
|
|
1692
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 }),`);
|
|
1693
1722
|
lines.push(`${indent}};`);
|
|
1694
|
-
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))};`);
|
|
1695
1724
|
lines.push(`${indent}produced_${s}.set(true);`);
|
|
1696
1725
|
}
|
|
1697
1726
|
for (const c of closers)
|
|
@@ -1868,7 +1897,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1868
1897
|
const contFail = (e) => `break '${label} Err(${e})`;
|
|
1869
1898
|
lines.push(` if let Ok(wire_${s}) = out_${s} {`);
|
|
1870
1899
|
lines.push(` let decoded_${s}: Result<${renderTypeRef(ref)}, BehaviorError> = '${label}: {`);
|
|
1871
|
-
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))})`);
|
|
1872
1901
|
lines.push(` };`);
|
|
1873
1902
|
lines.push(` if let Ok(val_${s}) = decoded_${s} {`);
|
|
1874
1903
|
lines.push(` *${typedCell(node.id)}.borrow_mut() = val_${s};`);
|
|
@@ -1882,7 +1911,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
|
|
|
1882
1911
|
lines.push(` Ok(r) => r,`);
|
|
1883
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 }),`);
|
|
1884
1913
|
lines.push(` };`);
|
|
1885
|
-
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))};`);
|
|
1886
1915
|
lines.push(` produced_${s}.set(true);`);
|
|
1887
1916
|
}
|
|
1888
1917
|
lines.push(` }`);
|
|
@@ -1924,7 +1953,7 @@ isAsync = false) {
|
|
|
1924
1953
|
// it against the element ref (the `into` field's type for map...into, else the element type). A de-box
|
|
1925
1954
|
// mismatch fails closed regardless of elementPolicy (matching the interpreter's whole-node outType throw).
|
|
1926
1955
|
const elemDeBoxRef = mapElemRowRef(node, elemArrRef, plan);
|
|
1927
|
-
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));
|
|
1928
1957
|
// build the per-element CONCRETE native ports struct. `il` = indent inside the element loop.
|
|
1929
1958
|
const buildPorts = (il) => {
|
|
1930
1959
|
const out = [];
|
|
@@ -2121,7 +2150,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, leaf, i
|
|
|
2121
2150
|
lines.push(`${indent} let mut seen_${s}: std::collections::HashSet<String> = std::collections::HashSet::new();`);
|
|
2122
2151
|
lines.push(`${indent} for opt_er_${s} in row_${s}.into_iter() {`);
|
|
2123
2152
|
lines.push(`${indent} let el_${s}: ${elemName} = match opt_er_${s} {`);
|
|
2124
|
-
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))},`);
|
|
2125
2154
|
lines.push(`${indent} None => Default::default(),`);
|
|
2126
2155
|
lines.push(`${indent} };`);
|
|
2127
2156
|
lines.push(`${indent} let key_${s} = el_${s}.${dkRust}.clone();`);
|
|
@@ -2291,6 +2320,58 @@ fn leaf_failure(message: impl Into<String>) -> BehaviorError {
|
|
|
2291
2320
|
BehaviorError::new("LEAF_FAILURE", message)
|
|
2292
2321
|
}`;
|
|
2293
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
|
+
}
|
|
2294
2375
|
function emit(ctx) {
|
|
2295
2376
|
// bc#97 (increment 2): the SSoT language-agnostic propagation pass derives, PER COMPONENT + PER NODE,
|
|
2296
2377
|
// which handler-call boundaries must be awaited (bottom-up over the declared async terminal handlers).
|
|
@@ -2340,6 +2421,13 @@ ${emitStructSurface([])}
|
|
|
2340
2421
|
// every covered node returns a WireValue the inline de-box classifies — the wire seam (probe enums +
|
|
2341
2422
|
// WireValue/WireRow/WireList traits) is emitted once whenever any handler node exists.
|
|
2342
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;
|
|
2343
2431
|
for (const c of native) {
|
|
2344
2432
|
const typedNodes = new Map();
|
|
2345
2433
|
// build the full typed-node map FIRST so a map's over-element resolution can see every node.
|
|
@@ -2347,6 +2435,10 @@ ${emitStructSurface([])}
|
|
|
2347
2435
|
if (!isControlGate(n))
|
|
2348
2436
|
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
|
|
2349
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;
|
|
2350
2442
|
if ("fanout" in n)
|
|
2351
2443
|
structs.push(emitFanoutPortsStructs(c, n, typedNodes, plan));
|
|
2352
2444
|
else if ("map" in n)
|
|
@@ -2388,6 +2480,15 @@ ${emitStructSurface([])}
|
|
|
2388
2480
|
return undefined;
|
|
2389
2481
|
return `// op-agnostic leaf transport symbols (consumer-supplied) — called directly at each covered node.\nuse ${leaf.import}::{${[...syms].sort().join(", ")}};`;
|
|
2390
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;
|
|
2391
2492
|
// (nonNative.length === 0 is guaranteed here — the fail-closed guard above threw otherwise.)
|
|
2392
2493
|
const banner = `#![allow(dead_code, unused_imports, non_snake_case)]
|
|
2393
2494
|
// GENERATED by behavior-contracts (bc#90, rust-typed-native — the RUNTIME-FREE read de-box; STRUCT-ONLY,
|
|
@@ -2410,7 +2511,14 @@ use std::cell::RefCell;`;
|
|
|
2410
2511
|
const sections = [
|
|
2411
2512
|
banner,
|
|
2412
2513
|
importBlock,
|
|
2413
|
-
|
|
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()}`,
|
|
2414
2522
|
decls || undefined,
|
|
2415
2523
|
defaults || undefined,
|
|
2416
2524
|
UNKNOWN_COMPONENT_HELPER,
|
|
@@ -2421,7 +2529,7 @@ use std::cell::RefCell;`;
|
|
|
2421
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")}`
|
|
2422
2530
|
: undefined,
|
|
2423
2531
|
`// CONCRETE per-component input structs (fields = inputPorts).\n${inStructs.join("\n\n")}`,
|
|
2424
|
-
|
|
2532
|
+
emitsWireTypes
|
|
2425
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)}`
|
|
2426
2534
|
: undefined,
|
|
2427
2535
|
elemMaterializers.length
|