behavior-contracts 0.11.8 → 0.11.9

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.
@@ -2,7 +2,7 @@ import { entryPortOrder, GeneratorFailure } from "./core.js";
2
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
- import { buildTypePlan, deriveTypeRef, findDecl, guardedMapIntoIsCoverable, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
5
+ import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
6
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";
@@ -1233,15 +1233,13 @@ function coveredMapNode(n, bodyIds, comp) {
1233
1233
  if (n === null || typeof n !== "object" || !("map" in n))
1234
1234
  return false;
1235
1235
  const m = n.map;
1236
- // #108 (rust twin of the go predicate): a guarded map (`when`) IS covered with NO `into`. #177/#182: a
1237
- // guarded map WITH `into` is covered when the guard-skipped element has a well-defined skip value — the
1238
- // into field is OPT (skip → None, #177) OR relationKind:connection (skip → the empty connection
1239
- // {items:[],cursor:null}, #182). Byte-equal to run_behavior applyInto (opt-into → null / connection-into
1240
- // → unproducedValue("connection")). A REQUIRED non-connection into → run_behavior FAILS MISSING_PROP on a
1241
- // skipped element, so fail-close is byte-equal. over element type must be statically resolvable: prior-node
1242
- // arr field, or an input array port carrying `elemType` (BC does not infer — consumer-interface C3).
1243
- if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsCoverable(n, comp))
1244
- return false;
1236
+ // #108 (rust twin of the go predicate): a guarded map (`when`) IS covered with NO `into`. #177/#182/#232:
1237
+ // a `map...into` ALWAYS has a well-defined unproduced value for the into field — OPT (unproduced → None,
1238
+ // #177) OR relationKind:connection (unproduced → the empty connection {items:[],cursor:null}, #182).
1239
+ // Byte-equal to run_behavior applyInto. The type gate (`mapIntoHoldsUnproduced`, run for every component
1240
+ // at the codegen entry) rejects anything else BEFORE any emitter sees it (#232). over element type must be
1241
+ // statically resolvable: prior-node arr field, or an input array port carrying `elemType` (BC does not
1242
+ // infer — consumer-interface C3).
1245
1243
  if (m.relationKind !== undefined && m.relationKind !== "connection")
1246
1244
  return false;
1247
1245
  // A map node must carry an outType (its ELEMENT type per the recorder SoT — authoring.ts recordMap
@@ -1555,19 +1553,8 @@ function movableRefs(comp) {
1555
1553
  function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
1556
1554
  const ep = execPlan(comp);
1557
1555
  const order = ep.order;
1558
- const hasConcurrency = ep.parallelStageOf.size > 0;
1559
1556
  const fn = sanitize(comp.name);
1560
1557
  const isAsync = ap.runnerIsAsync;
1561
- // bc#97: the async runner awaits each async handler at its call site (derived per-node). A real-
1562
- // concurrency stage (bc#87) dispatches handlers from scoped std threads — that mechanism cannot host
1563
- // `.await` (a std thread is not an async task). Fail closed LOUDLY (rather than emit code that won't
1564
- // compile) iff the runner is async AND has a concurrency stage. NOTE: with per-node granularity a
1565
- // consumer CAN keep a concurrency-stage component sync (declare only its OTHER terminals async) — only
1566
- // a component that both concurrency-stages AND awaits is rejected. Async + concurrent-stage (issuing
1567
- // the stage's futures with join!) is a documented follow-up.
1568
- if (isAsync && hasConcurrency) {
1569
- throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust typed-native async (bc#97): component '${comp.name}' has a bc#87 real-concurrency stage AND an async terminal handler, but a scoped-std-thread stage cannot host \`.await\`. Async + concurrent-stage (join! over the stage's futures) is a follow-up — declare this component's terminals sync, or split the concurrency stage.`);
1570
- }
1571
1558
  const typedNodes = new Map();
1572
1559
  // #125: control-gate は typeless(typedNodes に載せない)。map ノードは produced-array ref に正規化
1573
1560
  // (recorder SoT の element outType を {arr:element} へラップ / legacy {arr} はそのまま)。
@@ -1608,7 +1595,11 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
1608
1595
  lines.push(`// results are typed struct cells; a relation child reads the parent's REAL struct result via`);
1609
1596
  lines.push(`// direct field access (child-present decision from the real parent value — relation /`);
1610
1597
  lines.push(`// connection converge). A real-concurrency stage (bc#87) is static parallel orchestration —`);
1611
- lines.push(`// scoped worker threads (bounded by the static plan.concurrency) call the transport; preflight +`);
1598
+ // #231: the dispatch MECHANISM a stage uses is derived from its members' async-ness (a std thread cannot
1599
+ // host `.await`), so the banner names the one this component actually emits.
1600
+ lines.push([...new Set(ep.parallelStageOf.values())].some((s) => stageAwaits(comp, s, ap))
1601
+ ? `// the stage's futures joined (bounded by the static plan.concurrency) call the transport; preflight +`
1602
+ : `// scoped worker threads (bounded by the static plan.concurrency) call the transport; preflight +`);
1612
1603
  lines.push(`// interpret are committed in ascending index order so the value / op multiset / failure`);
1613
1604
  lines.push(`// precedence byte-match run_behavior. The output is a typed struct/value assembled by struct`);
1614
1605
  lines.push(`// literal + field access — the consumer keeps it native.`);
@@ -1643,7 +1634,7 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
1643
1634
  const i = order[k];
1644
1635
  const stage = ep.parallelStageOf.get(i);
1645
1636
  if (stage !== undefined && stage[0] === i) {
1646
- lines.push(emitParallelStageArm(comp, stage, k, ep.concurrency, metas, typedNodes, plan, priorNodeAt, leaf));
1637
+ lines.push(emitParallelStageArm(comp, stage, k, ep.concurrency, metas, typedNodes, plan, priorNodeAt, leaf, ap));
1647
1638
  k += stage.length - 1;
1648
1639
  continue;
1649
1640
  }
@@ -1762,21 +1753,36 @@ function emitNativeRawRunner(comp, plan, ap, leaf, declared) {
1762
1753
  return lines.join("\n");
1763
1754
  }
1764
1755
  /**
1765
- * emitParallelStageArm (bc#87/#94, rust CONCRETE) — EXPLICIT static parallel orchestration for a real-
1766
- * concurrency stage. Reproduces run_plan_parallel's deterministic protocol so the observed value / op
1756
+ * stageAwaits (#231) — the ONE derivation of a real-concurrency stage's dispatch MECHANISM: a std thread
1757
+ * cannot host `.await`, so a stage dispatches by joining its members' futures iff ANY member awaits, and
1758
+ * by scoped std threads otherwise. Read per-node from the SHARED language-agnostic async propagation pass
1759
+ * (async-plan.ts) — the same SSoT the sequential arms consume. A no-dispatch member (cond / pure-expression
1760
+ * map) has no catalog component, so `nodeIsAsync` is false for it and it never flips the mechanism.
1761
+ */
1762
+ function stageAwaits(comp, stage, ap) {
1763
+ return stage.some((i) => ap.nodeIsAsync(comp.body[i].id));
1764
+ }
1765
+ /**
1766
+ * emitParallelStageArm (bc#87/#94/#231, rust CONCRETE) — EXPLICIT static parallel orchestration for a
1767
+ * real-concurrency stage. Reproduces run_plan_parallel's deterministic protocol so the observed value / op
1767
1768
  * multiset / failure precedence byte-match run_behavior:
1768
1769
  * 1. PREFLIGHT (ascending): parent-produced gate + build each member's CONCRETE ports struct.
1769
- * 2. DISPATCH (bounded scoped threads): share `&H` (the concrete trait; `H: Sync`), pull runnable
1770
- * members from a shared atomic cursor in ascending order, call the concrete node_* method. Each
1771
- * concrete row lands in a per-member Mutex slot (None = unknown component).
1770
+ * 2. DISPATCH (bounded — ONE phase, two mechanisms picked by the members' derived async-ness):
1771
+ * - SYNC members: scoped std threads pull runnable members from a shared atomic cursor in ascending
1772
+ * order and call the leaf transport. Each result wire lands in a per-member Mutex slot.
1773
+ * - ASYNC members (#231): a std thread cannot host `.await`, so the stage's FUTURES are joined
1774
+ * instead — one lazily-built future per RUNNABLE member (a skipped member gets no future at all),
1775
+ * driven by a `std::future::poll_fn` scheduler that admits members in ascending order and keeps at
1776
+ * most `workers` of them in flight. A future that is never polled has never started, so "in flight"
1777
+ * IS "admitted and unsettled" — that is how the static bound is enforced without a runtime, without
1778
+ * the `futures` crate and without boxing. Each result lands in a per-member plain Option slot (the
1779
+ * scheduler is one task on one thread — no lock to take).
1772
1780
  * 3. COMMIT (ascending index): interpret policy + move the concrete row into the outType cell —
1773
- * lowest-index failure wins.
1781
+ * lowest-index failure wins. IDENTICAL for both mechanisms (only the slot read differs).
1774
1782
  */
1775
- function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes, plan, priorNodeAt, leaf) {
1783
+ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes, plan, priorNodeAt, leaf, ap) {
1776
1784
  const lines = [];
1777
1785
  const ids = stage.map((i) => comp.body[i].id);
1778
- lines.push(` // ── bc#87 real-concurrency stage {${ids.map((x) => rustStrLit(x)).join(", ")}} — static parallel`);
1779
- lines.push(` // orchestration (scoped threads, bound=${concurrency}); preflight+commit in ascending index order.`);
1780
1786
  // #125/#108: a stage member may be a cond node — a pure Expression (NO handler/dispatch). The scoped-
1781
1787
  // thread orchestration governs only the componentRef fan-out members; a cond is settled in ascending
1782
1788
  // preflight order — BEFORE any dispatch — via the SAME emitCondArm the sequential path uses (no forked
@@ -1790,6 +1796,9 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1790
1796
  const noDispatch = (i) => "cond" in comp.body[i] || ("map" in comp.body[i] && mapTransformExpr(comp.body[i].map) !== undefined);
1791
1797
  const condMembers = stage.filter(noDispatch);
1792
1798
  const refMembers = stage.filter((i) => !noDispatch(i));
1799
+ const stageIsAsync = stageAwaits(comp, stage, ap);
1800
+ lines.push(` // ── bc#87 real-concurrency stage {${ids.map((x) => rustStrLit(x)).join(", ")}} — static parallel`);
1801
+ lines.push(` // orchestration (${stageIsAsync ? "joined futures" : "scoped threads"}, bound=${concurrency}); preflight+commit in ascending index order.`);
1793
1802
  for (const i of condMembers) {
1794
1803
  const n = comp.body[i];
1795
1804
  lines.push("cond" in n
@@ -1797,9 +1806,9 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1797
1806
  : // 純式 map は leaf を呼ばないので async 性を持たない(sync 既定)。
1798
1807
  emitMapArm(comp, n, atPos + stage.indexOf(i), typedNodes, plan, priorNodeAt, leaf, false, metas[i].policy));
1799
1808
  }
1800
- // A cond-ONLY stage carries no handler fan-out — the conds above ARE the whole stage. Skip the scoped-
1801
- // thread orchestration block entirely (an empty one is dead scaffolding clippy rejects: never_loop /
1802
- // match_single_binding on a zero-job scope).
1809
+ // A cond-ONLY stage carries no handler fan-out — the conds above ARE the whole stage. Skip the dispatch
1810
+ // block entirely (an empty one is dead scaffolding clippy rejects: never_loop / match_single_binding on
1811
+ // a zero-job scope, and a zero-member poll_fn scheduler is likewise dead).
1803
1812
  if (refMembers.length === 0)
1804
1813
  return lines.join("\n");
1805
1814
  lines.push(` {`);
@@ -1853,63 +1862,137 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1853
1862
  for (const c of closers)
1854
1863
  lines.push(c);
1855
1864
  }
1856
- // 2) DISPATCH (bounded scoped threads). Each worker calls the leaf TRANSPORT directly for its member's
1857
- // CONCRETE ports and stores the returned wire in its slot. #125: the fan-out (slots / jobs / workers)
1858
- // spans the COMPONENTREF members only — a control gate dispatches no handler (committed in preflight
1859
- // above), so it is not a scoped-thread job. The wire's concrete type is inferred from the transport's
1860
- // return (Result<_, BehaviorError>); it impls Send so it crosses the scoped threads.
1865
+ // 2) DISPATCH (bounded). Each runnable member calls the leaf TRANSPORT directly for its CONCRETE ports
1866
+ // and stores the returned wire in its slot; the ascending COMMIT phase de-boxes it (so the WIRE — not
1867
+ // the decode — is what crosses the dispatch). #125: the fan-out (slots / jobs / workers) spans the
1868
+ // COMPONENTREF members only — a control gate dispatches no handler (committed in preflight above), so it
1869
+ // is not a job. The wire's concrete type is inferred from the transport's return
1870
+ // (Result<_, BehaviorError>).
1861
1871
  const nMembers = refMembers.length;
1862
1872
  const boundN = Math.min(concurrency, nMembers);
1863
1873
  const jobsVar = `jobs_${sanitize(comp.name)}`;
1864
- for (const i of refMembers) {
1865
- const s = sanitize(comp.body[i].id);
1866
- // every member's thread returns the result WIRE; the ascending COMMIT phase de-boxes it (so the wire —
1867
- // not the decode — is what crosses the scoped threads).
1868
- lines.push(` let slot_${s}: std::sync::Mutex<Option<Result<_, BehaviorError>>> = std::sync::Mutex::new(None);`);
1869
- }
1870
- lines.push(` let mut ${jobsVar}: Vec<usize> = Vec::new();`);
1871
- refMembers.forEach((i, slot) => {
1872
- const s = sanitize(comp.body[i].id);
1873
- lines.push(` if payload_${s}.lock().unwrap().is_some() { ${jobsVar}.push(${slot}); }`);
1874
- });
1875
- lines.push(` let cursor = std::sync::atomic::AtomicUsize::new(0);`);
1876
- lines.push(` let workers = ${boundN}usize.min(${jobsVar}.len());`);
1877
- lines.push(` std::thread::scope(|scope| {`);
1878
- lines.push(` for _ in 0..workers {`);
1879
- lines.push(` scope.spawn(|| loop {`);
1880
- lines.push(` let j = cursor.fetch_add(1, std::sync::atomic::Ordering::SeqCst);`);
1881
- lines.push(` if j >= ${jobsVar}.len() { break; }`);
1882
- lines.push(` let slot = ${jobsVar}[j];`);
1883
- lines.push(` match slot {`);
1884
- refMembers.forEach((i, slot) => {
1874
+ // the RUNNABLE-member job list + the static bound are mechanism-independent: both dispatch forms pull
1875
+ // jobs in ascending order and hold at most `workers` of them at a time. It is built BEFORE any payload is
1876
+ // taken — TAKING the payload is what dispatch does, so the list has to be read off the intact payloads.
1877
+ const emitJobList = () => {
1878
+ lines.push(` let mut ${jobsVar}: Vec<usize> = Vec::new();`);
1879
+ refMembers.forEach((i, slot) => {
1880
+ lines.push(` if payload_${sanitize(comp.body[i].id)}.lock().unwrap().is_some() { ${jobsVar}.push(${slot}); }`);
1881
+ });
1882
+ };
1883
+ const leafSym = (i) => {
1885
1884
  const node = comp.body[i];
1886
- const s = sanitize(node.id);
1887
- // DIRECT leaf transport call — ONE op-agnostic symbol, ONE WireRow payload (the preflight-built ports,
1888
- // MOVED into the owned-arg call — the worker that wins the slot takes it). No `bound` (BC's internal
1889
- // produced/skip gate is already applied in preflight — the leaf never sees it).
1890
- const call = `${resolveLeafSymbol(node.component, leaf, node.leafSymbol)}(payload)`;
1891
- lines.push(` ${slot} => {`);
1892
- lines.push(` let payload = payload_${s}.lock().unwrap().take().expect("runnable member has ports");`);
1893
- lines.push(` let row = ${call};`);
1894
- lines.push(` *slot_${s}.lock().unwrap() = Some(row);`);
1895
- lines.push(` }`);
1896
- });
1897
- lines.push(` _ => unreachable!(),`);
1898
- lines.push(` };`);
1899
- lines.push(` });`);
1900
- lines.push(` }`);
1901
- lines.push(` });`);
1902
- // 3) COMMIT (ascending index): interpret + move the concrete row into the outType cell.
1885
+ return resolveLeafSymbol(node.component, leaf, node.leafSymbol);
1886
+ };
1887
+ if (stageIsAsync) {
1888
+ // #231 ASYNC dispatch: one future per RUNNABLE member (a skipped member's `payload_<s>` is None, so
1889
+ // `Option::map` yields NO future — it is never constructed and never polled), pinned on the stack. An
1890
+ // async member's future IS the transport call; a SYNC member in the same stage is wrapped in an async
1891
+ // block so it starts when the scheduler admits it (calling it eagerly would ignore the bound). The
1892
+ // scheduler below is the join: it admits members in ASCENDING order, keeps at most `workers` in flight
1893
+ // (a future that has not been polled has not started), and settles each into a plain Option slot — one
1894
+ // task on one thread, so no lock. No `futures` crate, no boxing: every future is a concrete stack type.
1895
+ // The future MOVES the payload out of its slot (same take-not-clone as the scoped-thread arm).
1896
+ emitJobList();
1897
+ for (const i of refMembers) {
1898
+ const s = sanitize(comp.body[i].id);
1899
+ const taken = `payload_${s}.lock().unwrap().take()`;
1900
+ const fut = ap.nodeIsAsync(comp.body[i].id)
1901
+ ? `${taken}.map(${leafSym(i)})`
1902
+ : `${taken}.map(|payload| async move { ${leafSym(i)}(payload) })`;
1903
+ lines.push(` let mut fut_${s} = std::pin::pin!(${fut});`);
1904
+ lines.push(` let mut slot_${s}: Option<Result<_, BehaviorError>> = None;`);
1905
+ }
1906
+ lines.push(` let workers = ${boundN}usize.min(${jobsVar}.len());`);
1907
+ lines.push(` let mut settled = [false; ${nMembers}];`);
1908
+ lines.push(` let mut admitted = 0usize;`);
1909
+ lines.push(` let mut in_flight = 0usize;`);
1910
+ lines.push(` std::future::poll_fn(|cx| {`);
1911
+ lines.push(` loop {`);
1912
+ lines.push(` while in_flight < workers && admitted < ${jobsVar}.len() {`);
1913
+ lines.push(` admitted += 1;`);
1914
+ lines.push(` in_flight += 1;`);
1915
+ lines.push(` }`);
1916
+ lines.push(` let mut progressed = false;`);
1917
+ lines.push(` for (j, slot) in ${jobsVar}.iter().copied().enumerate().take(admitted) {`);
1918
+ lines.push(` if settled[j] { continue; }`);
1919
+ lines.push(` let ready = match slot {`);
1920
+ refMembers.forEach((i, slot) => {
1921
+ const s = sanitize(comp.body[i].id);
1922
+ lines.push(` ${slot} => {`);
1923
+ lines.push(` let f = fut_${s}.as_mut().as_pin_mut().expect("runnable member has a future");`);
1924
+ lines.push(` match std::future::Future::poll(f, cx) {`);
1925
+ lines.push(` std::task::Poll::Ready(r) => {`);
1926
+ lines.push(` slot_${s} = Some(r);`);
1927
+ lines.push(` true`);
1928
+ lines.push(` }`);
1929
+ lines.push(` std::task::Poll::Pending => false,`);
1930
+ lines.push(` }`);
1931
+ lines.push(` }`);
1932
+ });
1933
+ lines.push(` _ => unreachable!(),`);
1934
+ lines.push(` };`);
1935
+ lines.push(` if ready {`);
1936
+ lines.push(` settled[j] = true;`);
1937
+ lines.push(` in_flight -= 1;`);
1938
+ lines.push(` progressed = true;`);
1939
+ lines.push(` }`);
1940
+ lines.push(` }`);
1941
+ lines.push(` if admitted == ${jobsVar}.len() && in_flight == 0 {`);
1942
+ lines.push(` return std::task::Poll::Ready(());`);
1943
+ lines.push(` }`);
1944
+ lines.push(` if !progressed { return std::task::Poll::Pending; }`);
1945
+ lines.push(` }`);
1946
+ lines.push(` })`);
1947
+ lines.push(` .await;`);
1948
+ }
1949
+ else {
1950
+ // SYNC dispatch: bounded scoped std threads pulling from a shared atomic cursor in ascending order.
1951
+ // The result wire impls Send so it crosses the scoped threads.
1952
+ for (const i of refMembers) {
1953
+ lines.push(` let slot_${sanitize(comp.body[i].id)}: std::sync::Mutex<Option<Result<_, BehaviorError>>> = std::sync::Mutex::new(None);`);
1954
+ }
1955
+ emitJobList();
1956
+ lines.push(` let cursor = std::sync::atomic::AtomicUsize::new(0);`);
1957
+ lines.push(` let workers = ${boundN}usize.min(${jobsVar}.len());`);
1958
+ lines.push(` std::thread::scope(|scope| {`);
1959
+ lines.push(` for _ in 0..workers {`);
1960
+ lines.push(` scope.spawn(|| loop {`);
1961
+ lines.push(` let j = cursor.fetch_add(1, std::sync::atomic::Ordering::SeqCst);`);
1962
+ lines.push(` if j >= ${jobsVar}.len() { break; }`);
1963
+ lines.push(` let slot = ${jobsVar}[j];`);
1964
+ lines.push(` match slot {`);
1965
+ refMembers.forEach((i, slot) => {
1966
+ const s = sanitize(comp.body[i].id);
1967
+ // DIRECT leaf transport call — ONE op-agnostic symbol, ONE WireRow payload (the preflight-built ports,
1968
+ // MOVED into the owned-arg call — the worker that wins the slot takes it). No `bound` (BC's internal
1969
+ // produced/skip gate is already applied in preflight — the leaf never sees it).
1970
+ lines.push(` ${slot} => {`);
1971
+ lines.push(` let payload = payload_${s}.lock().unwrap().take().expect("runnable member has ports");`);
1972
+ lines.push(` let row = ${leafSym(i)}(payload);`);
1973
+ lines.push(` *slot_${s}.lock().unwrap() = Some(row);`);
1974
+ lines.push(` }`);
1975
+ });
1976
+ lines.push(` _ => unreachable!(),`);
1977
+ lines.push(` };`);
1978
+ lines.push(` });`);
1979
+ lines.push(` }`);
1980
+ lines.push(` });`);
1981
+ }
1982
+ // 3) COMMIT (ascending index): interpret + move the concrete row into the outType cell. IDENTICAL for
1983
+ // both dispatch mechanisms — only the slot read differs (a joined-futures slot needs no lock).
1903
1984
  refMembers.forEach((i) => {
1904
1985
  const node = comp.body[i];
1905
1986
  const meta = metas[i];
1906
1987
  const s = sanitize(node.id);
1907
1988
  const ref = typedNodes.get(node.id);
1908
1989
  // A member that ran wrote its slot; taking it is both the "did it run" test and the move of the wire
1909
- // out of the stage (the payload was already taken by the worker, so it can no longer answer that).
1990
+ // out of the stage (the payload was already taken at dispatch, so it can no longer answer that).
1910
1991
  // bind first: an `if let` scrutinee keeps its temporaries — including the MutexGuard — alive for the
1911
- // whole body, which outlives the borrow the body needs.
1912
- lines.push(` let taken_${s} = slot_${s}.lock().unwrap().take();`);
1992
+ // whole body, which outlives the borrow the body needs. A joined-futures slot is a plain Option (one
1993
+ // task on one thread), so it takes without a lock.
1994
+ const takeSlot = stageIsAsync ? `slot_${s}.take()` : `slot_${s}.lock().unwrap().take()`;
1995
+ lines.push(` let taken_${s} = ${takeSlot};`);
1913
1996
  lines.push(` if let Some(out_${s}) = taken_${s} {`);
1914
1997
  if (meta.policy === "continue") {
1915
1998
  // continue: a member whose COMPONENT failed commits no Port. A de-box mismatch still propagates —