Roc 编译器:从 Rust 到 Zig 的重生之路

How Our Rust-to-Zig Rewrite Is Going

过去一年半,我们团队将 Roc 编译器从 30 万行 Rust 代码重写为 Zig,终于实现了功能对等!这次重写不仅让 Rocci Bird 游戏的二进制体积减半,还带来了热代码加载和零堆内存分配的字符串插值模式匹配等特性。虽然耗时 487 天远超 Bun 项目的 11 天,但这次彻底重构解决了原有架构的深层缺陷,为 Roc 语言的性能和开发体验打开了新大门。

编译器领域有个奇特现象:从头重写往往是成功项目的常态,这通常是实现自托管的唯一途径。
  • High-performance throughput-optimized systems require latency hiding at the 1µs granularity, making standard GC pauses of 1ms unacceptable and effectively ruling out GC for such architectures.
  • Rust's syntax complexity and ecosystem characteristics currently result in lower efficiency and correctness scores for LLM code generation compared to other languages, contrary to popular belief.
  • The `unsafe` keyword in Rust should be conceptualized as a 'hard hat required' sign rather than an escape hatch, where the code semantics remain identical but the compiler cannot guarantee safety.
  • Zig's strategy of never reusing memory addresses helps detect dangling pointers by preventing exploitable use-after-free scenarios, even if the underlying mechanism remains opaque to some.
  • Critics argue that changing core language features every few months undermines consistency, while proponents counter that production-readiness relies on consistent long-term vision rather than static code.

同日更多故事

2026-07-16