RC RANDOM CHAOS

Roc Compiler Hits Feature Parity After 487-Day Rust-to-Zig Rewrite

· via Hacker News

Original source

How Our Rust-to-Zig Rewrite Is Going

Hacker News →

The team behind the Roc programming language has spent about 18 months rewriting its 300,000-line compiler from Rust to Zig, and just reached feature parity with the original. The proof point was porting a small WASM-4 game, Rocci Bird, to the new toolchain, where an optimized build now produces a 31KB WebAssembly binary — less than half the size the old compiler emitted. This is a milestone, not a release; the team is targeting version 0.1.0 later this year.

Unlike Bun’s recent 11-day Zig-to-Rust port, Roc’s effort was a ground-up rewrite rather than a direct translation, which explains the 476-day gap in timelines. The motivation was architectural, not language preference: Roc’s lambda set specialization system — the polymorphic defunctionalization that lets closures avoid heap allocation — had root-cause bugs spanning multiple compiler phases. Only after a fresh OCaml prototype proved out a new design did the team commit to rebuilding most of the compiler to implement it correctly.

The rewrite also shipped capabilities the old compiler lacked: automatic hot code loading during development, reproducible cross-compilation (identical output bytes across host machines for a given target), and string interpolation inside pattern matching that is type-checked at compile time and, in the HTTP routing example shown, performs zero heap allocations. A WebAssembly build of the compiler now runs directly on the Roc homepage so visitors can try the language in the browser.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.