fibers B1.2: UNBLOCKED — remove invalid issue 0151, correct the async idiom

The B1.2 "blockers" were not real:
- Issue 0151 was INVALID: its repro used the non-idiomatic `($A) -> $R`
  bare-fn-ptr form. The canonical higher-order pack idiom
  `Closure(..$args) -> $R` + `..$args` (see examples/0543-packs-canonical-map)
  infers $R fine and runs today with no compiler change. Removed 0151.
- The correct async idiom is verified working live (42 42 for homo + hetero
  args): async :: (io, worker: Closure(..$args) -> $R, ..$args) -> Future($R)
  with a lambda worker (annotated params) + a `result = ---; result.v = ...`
  build form. No compiler change needed.

Issue 0150 (void struct field -> SIGTRAP exit 133) IS a real bug but is only
reached via Future(void) (void-returning worker / timeout) — deferred to B1.4;
B1.2 supports non-void workers.

Updates the PLAN/CHECKPOINT B1.2 status to UNBLOCKED with the corrected idiom
and the resume plan. No compiler/library code changed in this commit.
This commit is contained in:
agra
2026-06-20 20:00:36 +03:00
parent f0a918f3c8
commit 7bf65565bd
3 changed files with 48 additions and 131 deletions

View File

@@ -59,13 +59,21 @@ body); closed + locked. The review's `.naked`-lambda CRITICAL was a false positi
(unparseable — `isLambda` breaks on the `abi` keyword).
## Current state
**B1.2 is BLOCKED on two newly-filed compiler bugs (issues 0150 + 0151). Master is GREEN
(726/0); all B1.2 working changes were REVERTED so the installed `zig-out/bin/sx` is clean.**
See the "B1.2 attempt (BLOCKED)" subsection below + "Known issues" for the full story. The
B1.2 *design* is validated end-to-end (the `Io` protocol on `Context`, the blocking
`CBlockingIo` default, and `context.io.now_ms()` all WORK — verified live); only the two
generic/void compiler gaps stop the `async`/`await`/`timeout` ergonomic layer. WIP saved at
`.sx-tmp/b12-wip/` (io.sx + the compiler+lib diff + the 1805 example) for a fast resume.
**B1.2 is UNBLOCKED.** Master GREEN (726/0), installed `sx` clean. The earlier "blockers"
were NOT real: issue **0151 was INVALID** (its repro used the non-idiomatic `($A)->$R`
bare-fn-ptr form) — **removed**. The correct `async` idiom **works today with no compiler
change** (verified live): `spawn :: (worker: Closure(..$args) -> $R, ..$args) -> Wrap($R)`
with a **lambda worker** + the `w : Wrap($R) = ---; w.v = worker(..args);` build form —
mirrors the canonical `examples/0543-packs-canonical-map.sx`. Ran `42 42` for homogeneous +
heterogeneous args. Caveats (work within them, not "bugs"): lambda params must be annotated
(`(a: i64, b: i64) -> i64 => …`); a bare *named* fn passed as the worker is non-idiomatic —
use a lambda; build the result struct with `= ---` + field-assign, not a struct-literal in
`return`. Issue **0150** (`void` struct field → SIGTRAP exit 133) is a **real** bug but only
reached via `Future(void)` (void-returning worker / `timeout`) — **DEFERRED**: B1.2 supports
non-void workers; revisit `Future(void)` in B1.4 (or fix 0150 standalone). The B1.2 *design*
(Io protocol on Context, blocking `CBlockingIo`, `context.io.now_ms()`) was validated live;
WIP at `.sx-tmp/b12-wip/` has the working Io/Context/materializer parts — reuse those, rewrite
the async layer to the pack-lambda idiom above.
### B1.2 attempt (BLOCKED — design proven, two compiler bugs filed)
What was built + verified WORKING (then reverted to keep master green):
@@ -132,27 +140,29 @@ fibers/Io/scheduler code yet. Grounded floor facts:
boundary; a sharper sx diagnostic for it is a candidate polish, not a blocker.
## Next step
**B1.2 is BLOCKED — resume only AFTER issues 0150 + 0151 are fixed.** Then re-land B1.2 from
the saved WIP (`.sx-tmp/b12-wip/`): the `Io` protocol + `Context.io` + both materializers +
the push-inherit fix + the `!`-impl-warning fix all WORK as-is; restore `timeout ->
Future(void)` (needs 0150) and `async`/`await` (needs 0151), add `examples/1805-concurrency-
io-blocking-async.sx` (lock→green) + `1806-concurrency-io-cancel.sx` (cancel→`await` raises
`.canceled`). Regen `.ir` snapshots ONLY after green (`-Dupdate-goldens`) — adding `Io` to the
prelude shifts many `.ir` type tables; confirm the diff is ONLY layout/numbering + the new
vtable, NO error text. The `Context` layout decision is settled: `{ allocator; data; io; }`
(allocator index 0 fixed by `call.zig:1229`, `io` last).
**B1.2 — resume now (UNBLOCKED, no compiler fix needed).** Re-land from the saved WIP
(`.sx-tmp/b12-wip/`): keep the verified-working parts — the `Io` protocol on `Context`, both
`__sx_default_context` materializers (protocol.zig + comptime_vm.zig), the push-inherit-omitted
fix (stmt.zig `lowerPush` — omitted `push Context.{...}` fields inherit the ambient ctx; the
correct fix, NOT per-site `io = context.io` edits across the 17 sites), and the
`!`-impl-warning fix. **Rewrite the async/await layer to the CORRECT idiom** (verified live):
**API CORRECTION (user, 2026-06-20):** `async`'s args are a **variadic heterogeneous
comptime pack** `..$args: []Type` ([specs.md:1383](../specs.md#L1383)), NOT a single `$A`.
Shape: `async(io, worker, ..args)` forwards a per-position-typed pack to `worker` (so
`context.io.async(fn, a, b, c)` works at any arity). The WIP's single-`arg: $A` form is
superseded — re-land async with the pack. This is ORTHOGONAL to issue 0151 (which is about
the *return* type-var `$R` not binding in the body — needed regardless of arg shape); also
verify packs-in-fn-pointer-param-signatures work when re-landing (surface a new issue if not).
async :: (io: Io, worker: Closure(..$args) -> $R, ..$args) -> Future($R) {
f : Future($R) = ---; // `= ---` + field-assign, NOT a struct-literal return
f.value = worker(..args); // blocking impl: run to completion
f.state = .ready;
return f;
}
NOTE for the resume: do NOT add `io = context.io` to the 17 partial `push Context.{...}` sites
— the push-inherit-omitted fix (in the WIP diff) makes omitted fields inherit from the ambient
context, which is the correct fix and was verified to compile. Use that, not per-site edits.
Worker is a **lambda** with **annotated params** (`(a: i64, b: i64) -> i64 => …`); name it
`async` (NOT `run` — `run` collides with `process.run` re-exported by std.sx and is silently
shadowed). `Future($R)` is a parameterized `struct($T)` (so the bare-`-> $R`-return inference
gap is auto-avoided). **Avoid `Future(void)`** (issue 0150 SIGTRAP) — B1.2 supports non-void
workers; `timeout`/`Future(void)` defer to B1.4. Add `examples/1805-concurrency-io-blocking-
async.sx` (lock→green) + `1806-concurrency-io-cancel.sx`. Regen `.ir` ONLY after green
(`-Dupdate-goldens`) — adding `Io` to the prelude shifts many `.ir` type tables; confirm the
diff is ONLY layout/numbering + the new vtable, NO error text. `Context` layout settled:
`{ allocator; data; io; }` (allocator index 0 fixed by `call.zig:1229`, `io` last).
## Known issues / capability gaps
- **🔴 B1.2 BLOCKERS (both filed, both standalone-reproducible, both independent of the Io

View File

@@ -1,12 +1,17 @@
# PLAN-FIBERS — Stream B1 (fibers + Io + M:1 scheduler)
> **STATUS: 🚧 in progress.** B1.0 (`abi(.naked)` codegen) ✅ + B1.1 (per-fiber `context`
> root — zero compiler change, library convention) ✅ complete. **B1.2** (`Io` interface +
> `context.io` + `Future` + `cancel()`) is **🔴 BLOCKED on compiler issues 0150 (`void`
> struct field SIGTRAP) + 0151 (type-var from a fn-ptr-return not bound in body)** — the Io
> design is proven (the protocol-on-`Context` + blocking default + `context.io.now_ms()` work
> live), but `Future(void)`/`timeout` and the `async`/`await` generics hit those two bugs.
> Resume B1.2 after both land (WIP saved at `.sx-tmp/b12-wip/`); see `CHECKPOINT-FIBERS.md`.
> **STATUS: 🚧 in progress.** B1.0 (`abi(.naked)`) ✅ + B1.1 (per-fiber `context`) ✅. **B1.2**
> (`Io` interface) is **UNBLOCKED** — the earlier "blockers" were artifacts of non-idiomatic
> syntax + a worker's dirty binary. Issue **0151 was INVALID** (the `($A)->$R` bare-fn-ptr
> form is not idiomatic sx) and is **removed**. The correct `async` idiom **works today, no
> compiler change**: `async :: (io, worker: Closure(..$args) -> $R, ..$args) -> Future($R)`
> with a **lambda worker** + the `result : Future($R) = ---; result.v = worker(..args);` build
> form (mirrors the canonical `examples/0543-packs-canonical-map.sx`). Caveats: lambda params
> must be annotated; passing a bare *named* fn as the worker is non-idiomatic (use a lambda).
> Issue **0150** (`void` struct field SIGTRAP, exit 133) is a **real** bug but only hit by
> `Future(void)`/`timeout` — **deferred** (avoid void Futures in B1.2; revisit in B1.4). Resume
> B1.2 with the corrected idiom (the WIP at `.sx-tmp/b12-wip/` has the Io-protocol/Context/
> materializer parts that WORK; rewrite the async layer to the pack-lambda form above).
Carved from [PLAN-POST-METATYPE.md](PLAN-POST-METATYPE.md) Stream B (§B1) + the
design-of-record [../design/execution-evolution-roadmap.md](../design/execution-evolution-roadmap.md)