HeadlinesBriefing favicon HeadlinesBriefing.com

Roc Compiler Reaches Feature Parity in Rust-to-Zig Rewrite

Hacker News •
×

For the past year and a half, the team building Roc's compiler has been rewriting 300,000 lines of Rust code into Zig, recently reaching feature parity. The milestone allowed updating Brendan Hansknecht's Rocci Bird game (art by Luke De Vault) to the new compiler, producing a 31KB WebAssembly binary—half the original size. The 487-day rewrite took 476 days longer than Bun's 11-day Zig-to-Rust port, though the projects differ significantly.

Key contributors include Anthony Bullard and Sam Mohr (parser), Jared Ramirez (type-checker), Ayaz Hafiz (lambda set resolution), Aurélien Geron (108 Exercism exercises), and Anton-4 and Luke Boswell for extensive compiler work. Sponsors like rwx, Lambda Class, and Vendr supported the effort.

The new compiler unlocks hot code loading during development—automatically applying code changes to running servers—and cross-compilation via `roc build --target=x64musl`. Pattern matching now supports string interpolation (e.g., `"/users/${id}"`) with zero heap allocations and compile-time type safety. These features stem from Roc's polymorphic defunctionalization through lambda set specialization, a runtime optimization that proved architecturally difficult in Rust, prompting the rewrite after Ayaz Hafiz prototyped a solution in OCaml.