fibers B1.2: Io capability + context.io + blocking impl + Future/async/await/cancel

Threads an `Io` capability onto `Context` exactly like `Allocator`: a
`protocol #inline` whose process-wide default is a stateless `CBlockingIo`
(the mirror of `CAllocator`), installed in `__sx_default_context`.

Library (library/modules/std):
- core.sx: `Io` protocol (spawn_raw / suspend_raw / ready / poll / now_ms /
  arm_timer) + `SpawnOpts` / `PinTarget` / `ParkToken`; `Context` gains an
  `io: Io` field LAST (allocator stays index 0, data stays index 1).
- io.sx (new): `CBlockingIo` + `impl Io` (blocking M:1 semantics — now_ms is
  a real monotonic clock, the rest are no-ops/0; suspend never called);
  `Future($R)` { value; state: FutureState; err: IoErr; park; task; canceled:
  Atomic(bool) } with `Value :: R`; the async ergonomic layer
  `async` / `async_void` / `await` (value-carrying `(R, !IoErr)`) / `cancel`.
  Built with the verified `= ---` + field-assign + `Closure(..$args) -> $R` +
  `..$args` idiom (NON-void $R only — Future(void) is deferred per issue 0150).
- std.sx: re-export the Io surface + the io.sx tail.

Compiler (src/ir):
- protocol.zig `emitDefaultContextGlobal` + comptime_vm.zig
  `materializeDefaultContext`: both materializers of `__sx_default_context`
  now build the inline CBlockingIo->Io vtable (7 words) at the new field.
- stmt.zig `lowerPush`: `push Context.{...}` now INHERITS omitted fields from
  the ambient context (seed the slot from current_ctx_ref, overwrite only the
  literal's named fields) — correct capability-bag semantics, so the partial
  `push Context.{ allocator = X }` sites don't zero a null `io` vtable.
- protocols.zig + lower.zig + error_analysis.zig: record protocol-impl method
  names so the "declared `!` but never errors" lint skips a conforming impl
  whose `!` is dictated by the protocol contract (e.g. Io.suspend_raw).

37 `.ir` snapshots regenerated: layout-only (the Context type now carries the
Io field, shifting type-table numbering); no stdout/stderr/exit changes.

The blocking Io + now_ms + Future/async work when `async` is called with the
receiver passed explicitly; the user-facing UFCS form `context.io.async(...)`
is blocked on a separate UFCS generic-inference bug (filed next).

Suite: 726 ran, 0 failed.
This commit is contained in:
agra
2026-06-20 22:21:27 +03:00
parent a1b14f0c0f
commit 45d869da41
48 changed files with 213273 additions and 180506 deletions

View File

@@ -1,35 +0,0 @@
// Stream B1 (fibers) — the `Io` capability + the blocking-`Io` default
// (step B1.2). `Io` is threaded on `Context` exactly like `Allocator`: a
// `protocol #inline` at a fixed field, whose process-wide default is a
// stateless `CBlockingIo` (the mirror of `CAllocator`).
//
// In the blocking M:1 model there is no scheduler and no suspension:
// `async(worker, ..args)` runs the worker to COMPLETION synchronously, so
// the returned `Future` is born `.ready` and `await` yields the stored
// result immediately. This locks the B1.2 surface — `context.io.async(...)`
// with a lambda worker (annotated params) + `f.await()`.
//
// Worker form: a lambda `(a: i64, b: i64) -> i64 => ...` whose params are
// annotated. Named-fn workers need a `::` callable-param feature that does
// not exist yet and are DEFERRED.
#import "modules/std.sx";
main :: () -> i32 {
// Single-arg lambda worker.
f1 := context.io.async((n: i64) -> i64 => n * 2, 21);
v1, e1 := f1.await();
if !e1 { print("double: {}\n", v1); } // → 42
// Two-arg lambda worker — exercises the `..$args` variadic forward.
f2 := context.io.async((a: i64, b: i64) -> i64 => a + b, 40, 2);
v2, e2 := f2.await();
if !e2 { print("sum: {}\n", v2); } // → 42
// `now_ms` is a protocol method (a deterministic-sim Io [B1.4] can
// override it); the blocking Io returns a real monotonic clock, so we
// only assert it is non-negative, not an exact value.
t := context.io.now_ms();
if t >= 0 { print("clock ok\n"); }
return 0;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long