· Mehdi Berel · Announcements · 4 min read
Effect handlers, resumed: what landed after Fid 1.0
Fid 1.0 brings a self-hosted compiler and a zero-dependency toolchain. The weeks since closed the last open pillar (resumable effect handlers) and brought structured concurrency, a verified bootstrap fixpoint, and a public roadmap to 2.0.
With the Fid 1.0 stable release planned for December, the honest line on every page of this site was the same: effect annotations and inference work, handle { } with { } runs handler bodies, but resumable continuations are still in progress. That line is gone now. Here is what replaced it, and what comes next.
do, then resume
An effect handler is only interesting if the handler can hand control back. Fid’s handlers now do exactly that:
fn main() {
handle {
val x = 10;
do IO.print(x); // perform the effect; the block pauses here
println(x + 1); // runs after the handler resumes, prints 11
} with {
IO.print(v) => {
println(v); // prints 10
resume(cont, 0); // continue the block after the `do`
}
}
}The interesting part is how little machinery sits behind it. At lowering time the compiler captures the statements after a do as a continuation closure (lambda-lifted, called through a function pointer), and the handler arm receives it as cont. There is no runtime scheduler, no heap-allocated frame, no state machine rewrite. A do costs what a call costs.
Two consequences fall out of that design for free:
- A handler that does not
resumedrops the rest of the block. That is cooperative cancellation without a cancellation API. - Multiple
dostatements chain. A block with three effects captures three continuations in sequence, so a request handler that reads, computes, and writes reads as straight-line code.
Structured concurrency: spawn scope
Effects gave us the mechanism; spawn scope gives it a shape. Every task spawned inside the block is owned by it and joined at the closing brace:
spawn scope {
spawn task(1);
spawn task(2);
spawn task(3);
} // all three are joined here
println(99); // always prints lastcancel scope; stops every pending task in the enclosing scope, and do Cancel.stop() lets a task bow out cooperatively. Tasks cannot outlive their scope, so the usual bookkeeping (handles, join sets, “did that one finish?”) disappears.
Async I/O is just another effect
With continuations in place, blocking I/O stopped needing its own subsystem. do IO.read(conn) and do Net.accept() perform the operation, the handler decides how (synchronously, on an executor, against a test double), and resume hands the result back. The code doing the I/O never changes shape, and there is still no async fn versus fn split anywhere in the language. Any function is callable from synchronous code, a spawned task, or a handler body.
The fixpoint
One day before the effects work landed, the self-hosted compiler cleared the milestone that defines a self-hosted compiler. Five bootstrap generations were built from the Rust reference, c1 through c5, and the fourth and fifth produce byte-identical C output: 29,763,762 bytes, zero differences. The compiler compiles itself, the result compiles itself again, and the output stops changing.
That compiler is now 54 modules and 104,439 lines of Fid, and it is the release compiler, packaged as fid.exe in the Windows installer. The standard library stands at 129 modules, with arena, template, plot, data, and game added since 1.0. The native backends gained a Chaitin-Briggs graph-coloring register allocator and deterministic PE output.
The road to 2.0
1.0 proved the architecture: every pillar working end to end, from capability security to zero-dependency native emission. The next releases are about depth rather than new pillars, and the plan is public in docs/roadmap/release-roadmap.md:
- 1.1 Semantic depth. Uniform
==on strings and enums,Option<T>andVec<T>with exact layouts for any payload,>>inside nested generics, char literals, and types that cross module boundaries without ceremony. - 1.2 Ergonomics.
?on every fallible call,forloops and iterator adapters everywhere, richer destructuring, auto-deref and inference, fluent string building,HashMap<K, V>as a first-class collection. - 1.3 Hardening. Parity across the interpreter, C, and native backends on the full corpus; deterministic output everywhere; a type system audited against the spec.
- 2.0 Dogfooded. The compiler rewritten in the full language: generics, traits, closures,
?, comptime, and effects used throughout its own 100K lines.
The measure of success for 2.0 is simple: the compiler should look like the code we tell you to write.
Try it
The playground runs the real compiler in your browser. The Windows installer is 2.5 MB. The Concurrency and Errors & Effects pages have the new syntax with runnable examples, and the Feature Status page remains the honest map.
- release
- effects
- concurrency
- roadmap
Mehdi Berel
Engineering notes from the Fid compiler. Everything measured on the real toolchain: nothing on this blog is aspirational.