Back
Roc's Rust-to-Zig compiler rewrite reaches feature parity after 487 days
SiTech AI Team3 წთ. საკითხავი

Roc's Rust-to-Zig compiler rewrite reaches feature parity after 487 days

The team behind the Roc language has finished rewriting its 300,000-line compiler from Rust to Zig, reaching feature parity with the original after 487 days. The write-up compares build times, memory safety and ecosystem fit.

The team behind the Roc programming language has spent the past year and a half rewriting roughly 300,000 lines of Rust into Zig, and has now reached feature parity with the original compiler. It is not a formal release — version 0.1.0, Roc's first numbered release, is planned for later this year — but the new compiler can already build and run real programs.

One early test was Rocci Bird, a WASM-4 game written in under a thousand lines of Roc. Built with the new compiler, roc build --opt=size produces a 31KB WebAssembly binary, less than half the size the original produced. Getting the game to run at all required landing a large number of compiler features.

A 487-day rewrite

The rewrite took 487 days, against 11 days for Bun's port in the opposite direction, which moved some 500,000 lines of Zig into Rust. The author calls that comparison misleading: Bun's work was a direct port, while Roc chose a scratch rewrite because so much of the compiler was going to change. The decision followed an architectural problem in Roc's lambda set specialization system that spanned several compiler phases.

Why Zig, and what happened to memory safety

Four considerations drove the choice: build times, memory control — Roc relies on arenas and struct-of-arrays layouts, while Zig's ecosystem passes allocators around instead of assuming one global allocator — ecosystem relevance, and help with memory-unsafe code. The Rust compiler held about 1,200 uses of unsafe across 300,000 lines, and the team expected to keep writing such code, since compilers that emit machine code do a lot of it.

In practice the switch has not hurt. Bug reports classified by Claude Opus 4.8 show 2,596 bugs in the Rust compiler, 21 of them involving memory corruption, against 431 in the Zig compiler, 10 involving memory corruption. Eight of the ten were miscompilations; the other two were use-after-free errors in error reporting that made filenames render as replacement characters in roc check and roc bundle.

Build times and what's next

On an Intel desktop running Ubuntu 26, the Rust compiler at 354K lines took 25.4 seconds for a cold build and 3.4 seconds incremental. The Zig rewrite, at 464K lines, takes 32.1 seconds cold and about 35 milliseconds incremental — but only on Zig 0.17.0, because a bug in stable 0.16.0 breaks incremental builds on this code base. Rather than depend on a nightly compiler, the team is waiting for the next stable release.

The compiler also caches work on disk using zero-parse deserialization: its data structures are arrays of 32-bit indices rather than pointers, so cached results load straight into memory without parsing. Running roc check twice reuses the previous run's outputs at roughly memcpy speed.

SSiTech

SiTech — AI-powered web development

We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.