flowchart TD parser["layer 1: parser<br/>surface syntax"] runtime["layer 2: runtime<br/>heap, GC, environments"] stdlib["layer 3: base library<br/>~1,400 functions"] native["layer 4: native<br/>interface, the C API"] wall["compatibility wall:<br/>compiled CRAN packages"] parser --> runtime --> stdlib --> native --> wall
What Rewriting R in Rust Actually Means
“Rewrite R in Rust” sounds like one job. It is four separable layers, each a different problem, and every earlier reimplementation of R that wanted CRAN’s compiled packages had to build its own answer to the last one, the native interface.
Four layers
The first layer is the language surface. R has syntax. x <- 1 assigns. f(x) calls a function. The parser must understand this syntax and build an AST. Semantics must be correct: when you reference x, you get what you assigned.
The second layer is the runtime. Code runs on a machine with memory. The runtime allocates objects on a heap, tracks references, runs garbage collection, manages environments. This layer answers “where does data live” and “who manages its lifetime.”
The third layer is the standard library. In R 4.6.1 the base package alone holds 1,412 objects, 1,367 of them functions, written in R, in C, or in both, and the other packages that ship with R add many more: sum and paste live in base, lm in stats. A rewrite must implement all of them, and that is work measured in years.
The fourth layer is the native interface: R’s C API and the ABI that compiled code is built against. On 2026-10-21, 5,569 of the 25,474 packages on CRAN needed compilation (NeedsCompilation: yes in tools::CRAN_package_db()). Their compiled code reaches R through the C API. It calls functions like REAL() to get at the doubles in a vector, allocates objects with allocVector(), and protects them from garbage collection with PROTECT().
Earlier reimplementations
Three implementations written from scratch handled layer four in three different ways. Renjin <https://www.renjin.org/>, on the JVM, compiled packages’ C and Fortran code to JVM bytecode with its own GCC-Bridge <https://www.renjin.org/blog/2016-01-31-introducing-gcc-bridge.html> and mapped calls into the R API onto Java methods. FastR <https://github.com/oracle/fastr>, on GraalVM, implemented the C API so that packages built for GNU R could run, and its README warns that the crossing between native and managed code is slow. Riposte <https://justintalbot.com/research/riposte.pdf>, a research VM for vector code, implemented a subset of R and no C API. Two other projects, pqR and CXXR (later Rho <https://github.com/rho-devel/rho>), modified GNU R’s own source, so they started from its C API and changed what sat behind it; Rho could not load packages whose native code used USE_RINTERNALS, Rcpp and data.table among them.
As of October 2026: Renjin’s site says it was developed between 2010 and 2021 and is no longer actively maintained. Oracle’s GraalVM documentation <https://docs.oracle.com/en/graalvm/jdk/23/docs/reference-manual/r/> says FastR is in maintenance mode, with 22.3.1 as its last release. Rho’s repository says development is suspended. pqR’s last release is dated 2020-07-23, and Riposte’s repository has had no commit since 2015.
To run CRAN’s compiled packages, a new implementation has to answer R’s exported C interface exactly: the symbol names, the signatures, the calling conventions, and the documented behavior behind them. It does not have to match GNU R’s memory layout. The public header declares SEXP as a pointer to a SEXPREC it never defines, so a package that uses only the API never sees that layout, and that opacity is what makes layer four possible at all.
Changes Rust brings
Rust brings three things to runtime engineering. The first is memory safety. In safe Rust the compiler rules out use-after-free and double free, and every index is bounds-checked, so an out-of-range write stops the program with a panic instead of corrupting memory. In C, the same guarantees come only from discipline and testing.
The second is data-race rejection at compile time. Safe Rust code in which two threads could mutate the same memory without synchronization does not compile; the borrow checker and the Send and Sync traits enforce this together. In C, catching the same bug takes code review and tools such as ThreadSanitizer.
The third is the absence of a second collector. Rust frees memory when its owner goes out of scope, and counts references only where the code asks for it with Rc or Arc. An R interpreter written in Rust still needs a garbage collector for R objects, but it can design that collector for R, where an implementation on the JVM inherits the JVM’s.
Limits of Rust
Rust does not eliminate the compatibility wall. To run CRAN packages you still have to implement the exported C API, function by function, and get the calling conventions right, even though the heap layout behind it is yours to choose. The question moves from “is this C code safe” to “does this Rust code answer the same interface”.
Rust does not reduce the surface of base R. Whether base R is C or Rust, every one of those functions still has to exist, along with data frames, factors, attributes, and S4 classes.
A different language does not make the rewrite cheaper. What it buys is a compiler that rejects whole classes of memory and threading bugs before the code runs.
Four layers of a rewrite, each a separate problem.
The rrs approach
The r-in-rust project (rrs) built layers one and two and part of three first and left layer four for later, on the assumption that compatibility would be the hardest part.
rrs is differential-tested byte for byte against a pinned GNU R 4.6.1: the same input must give the same output. A gate check that runs before every commit keeps global mutable state out of the interpreter. Only the C API crates may use unsafe code, and only they may hold thread-local state or process-wide statics; each file that does is listed with its reason in an allowlist.
That assumption turned out to be wrong. The ABI layer landed, and it was not the wall it looked like: rrs exports R’s C API over its own representation, and CRAN mime now compiles from source, installs and loads, while Rcpp links against the same headers. In the census of 2026-08-18, twenty-eight of the thirty most downloaded compiled packages installed and all twenty-eight loaded, and the ledger gives no sign that either failure was at the C boundary. The larger job left is base R coverage, which is layer three, the part that looked easy.
Compatibility came cheaper than expected once the opacity of SEXP became something to build on instead of something to work around. Breadth of base R is what takes the years.
Read next: why Rust explains the language choice. What is an ABI covers layer four in detail. Ownership teaches the Rust concept behind those memory-safety guarantees.
Further reading
- r-in-rust, my R interpreter in Rust, including how it is tested against GNU R. Its repository is not public yet.
- Renjin project: renjin.org <https://www.renjin.org/>
- FastR project: github.com/oracle/fastr <https://github.com/oracle/fastr>
- Talbot, J., DeVito, Z., & Hanrahan, P. (2012). Riposte: A trace-driven compiler and parallel VM for vector code in R <https://justintalbot.com/research/riposte.pdf>. PACT 2012, 43-52.
Where this appears
- r-in-rust (rrs) Reimplements four separable layers. The ABI layer landed earlier and cheaper than planned, because SEXP is opaque.