Files
sx/examples/concurrency/1822-concurrency-fiber-context-inherit.sx
agra 959845bd30 style: migrate arrow-block lambdas () => { .. } to () { .. }
The canonical sx block-body lambda is `(params) { stmts }` (and
`(params) -> Ret { stmts }`); the arrow form `=>` is for EXPRESSION bodies
(`(params) => expr`). The arrow-block hybrid `(params) => { .. }` was being
used in 33 files — convert all of them by dropping the `=>`. The two forms are
exactly equivalent (verified: identical IR and identical runtime values — the
block tail is the value with or without a `-> Ret`), so this is a pure source
cleanup: no `.ir` churn, and the only snapshot change is 0923's diagnostic
COLUMN (a negative narrowing test whose error span shifted by the removed `=> `).

Arrow EXPRESSION bodies (`=> expr`, `=> .{..}`, `=> [..]`) and `=>` inside
comments/strings were left untouched. Migrated across examples/concurrency,
examples/{closures,ffi-objc,generics,optionals,types}, issues/, and the stdlib
(io.sx, sched.sx). Suite 855/0.
2026-06-28 16:39:51 +03:00

36 lines
1.4 KiB
Plaintext

// Stream B2/A1 — a fiber INHERITS the dynamic `context` in force when it was
// spawned. Previously a fiber body ran under the static `__sx_default_context`
// (the `abi(.c)` `fib_dispatch` dropped the implicit context), so a
// `push Context { … }` around `spawn` was invisible inside the fiber. Now
// `Scheduler.spawn` snapshots `context` into the fiber and `fib_dispatch`
// re-pushes it around the body — so a capability installed before `spawn`
// (here a marker in `context.data`) is visible to the worker.
//
// This is the foundation for folding a fiber scheduler behind `context.io`: a
// worker's `context.io.*` must resolve to the scheduler that spawned it, not the
// blocking default. Behavior-preserving for fibers spawned under the default
// context (the snapshot just re-pushes that same default).
//
// aarch64-pinned (the scheduler's per-arch asm): runs end-to-end on a matching
// host (macOS + linux), ir-only on a mismatch.
#import "modules/std.sx";
sched :: #import "modules/std/sched.sx";
Marker :: struct { id: i64; }
main :: () -> i64 {
mk := Marker.{ id = 7 };
s := sched.Scheduler.init();
ps := @s;
print("outside: marker id = {}\n", mk.id);
push .{ data = xx @mk } {
ps.spawn(() {
m : *Marker = xx context.data; // inherited from the spawn-time context
print("inside fiber: context.data marker id = {}\n", m.id);
});
ps.run();
}
print("done\n");
return 0;
}