7.5 Source, Binary, and Behavioral Compatibility

ABI AND FFISTATUS: DEVELOPINGLEVEL: DEEPREVIEWED: 2026-11-18

7.5.1 Motivation

Compatibility is three separate properties. When a system moves from version A to version B, source code can keep compiling, compiled binaries can keep running, and programs can keep producing the same output, and any one of these can hold while another fails.

Which of them hold determines what an R implementation can change and what it must freeze.

7.5.2 Three kinds of compatibility

Source compatibility

Source compatibility means existing source code compiles against the new version without modification.

An R package with C code includes headers from R. It calls functions from the R C API. If the headers change and new calls are required, the source no longer compiles. Source compatibility is broken.

Example: adding a required parameter to a function breaks source compatibility.

// Old API
SEXP allocVector(SEXPTYPE type, R_len_t length);

// New API (requires new parameter)
SEXP allocVector(SEXPTYPE type, R_len_t length, int flags);

// Old code does not compile because it passes only 2 arguments

Source compatibility is cheap to maintain. You rarely need to change the API. You can add new functions without touching old ones. C has no default arguments, so a new parameter usually means a new function next to the old one.

Binary compatibility

Binary compatibility means compiled binaries run on the new version without recompilation.

A compiled .so or .dll is machine code carrying unresolved references: the names of the functions it calls, the argument shapes it pushes, and the values of any public constant it compiled in. If you rename an exported symbol, change its signature, or change the width of a public type, those binaries break.

What they do not carry is R’s internal layout, because the header never showed it to them. The exception is a package that reached past the API, by defining USE_RINTERNALS before R 4.2.0 or by copying R’s internal headers. It traded the protection for direct access and breaks when the layout moves. “Conforming” below means a package that did not make that trade.

A package compiled for version A does not run on version B when the exported surface has moved underneath it. The binary is frozen to the interface it saw.

Binary compatibility is expensive to maintain. You must freeze the ABI: the exported symbol surface, function signatures, calling conventions, public constants and types, and documented behavior. Fields behind an opaque pointer can move freely. You cannot remove a symbol or rename it. You cannot change a function signature. You cannot alter the meaning of a public constant.

Behavioral compatibility

Behavioral compatibility means existing programs produce the same output on the new version.

A function can have the same signature and the same calling convention, but different behavior. If you change how it computes results, the behavior is incompatible.

Example: a sorting function that changes from ascending to descending order breaks behavioral compatibility.

Behavioral compatibility is often implicit. A script depends on what a function returns, and nothing in the script records that dependence. If the function’s behavior changes, the script’s output changes, while its source and any compiled code stay compatible.

7.5.3 A matrix of compatibility

A change can affect these three dimensions independently.

Change Source Binary Behavioral
Add new function Preserved Preserved Preserved
Add a defaulted parameter (C++) Preserved Broken Sometimes breaks
Change parameter order Broken Broken Sometimes breaks
Rename function Broken Broken Preserved (code does not call it)
Change an opaque struct’s layout Fine Fine for conforming packages Fine
Change a public type’s width Fine after rebuild Broken Sometimes breaks
Change return type Broken Broken Sometimes breaks
Change algorithm (same output) Preserved Preserved Preserved
Change algorithm (different output) Preserved Preserved Broken

7.5.4 Examples: breaking each while preserving others

Breaking source compatibility while preserving binary and behavioral

Suppose you change the name of a function from Rf_allocVector to allocVector:

// Old
SEXP Rf_allocVector(SEXPTYPE type, R_len_t length);

// New
SEXP allocVector(SEXPTYPE type, R_len_t length);
SEXP Rf_allocVector(SEXPTYPE type, R_len_t length) {
  return allocVector(type, length);  // Wrapper maintains binary compatibility
}

New source code calls allocVector. The new header no longer declares Rf_allocVector, so old source that calls it does not compile until you update the call.

But old compiled binaries still work. The linker finds Rf_allocVector in the symbol table. The wrapper function calls the new implementation. Binary and behavioral compatibility are intact.

Breaking binary compatibility while preserving source and behavioral

Suppose you widen a public integer type:

// Old
typedef int R_len_t;

// New
typedef ptrdiff_t R_xlen_t;   // and the API now takes this instead

A package compiled against the old header passes a 32-bit value. The new function reads 64 bits from the same register or stack slot, and nothing obliged the old caller to set the upper 32. Nothing in the loader notices, because the symbol name did not change, so the call resolves and then misbehaves. That is the shape of a binary break: same name, same source, different machine-level agreement.

R made this change for real in 3.0.0, when long vectors arrived: Rf_allocVector() went from taking R_len_t to taking R_xlen_t, and the release notes said packages “need to be (re-)installed under this version”. library() still refuses a package built before R 3.0.0.

one argument slot, two header versions what the package binary writes, built against R_len_t 32 bits: the argument not written what R reads, built against R_xlen_t 32 bits: the argument 32 bits: whatever was there R reads all 64 bits as one value low byte high byte

The symbol name matched and the call resolved, but the caller set 32 bits where the callee reads 64.

Source compatibility survives it. Recompile the package against the new header and the compiler emits the right width. Behavior survives it too, for anything newly compiled. Only binaries built against the older signature break.

Note what is not an example. Adding a field to SEXPREC would not break a conforming package’s code, because SEXPREC is opaque to extensions and VECTOR_ELT is a function call, not pointer arithmetic. The breaks that matter live in the declarations packages compile against.

Breaking behavioral compatibility while preserving source and binary

R 4.0.0 changed the default of stringsAsFactors in data.frame() and read.table() from TRUE to FALSE:

d <- data.frame(x = c("b", "a"))
class(d$x)   # "character" in R 4.0.0 and later, "factor" before

The function names and their arguments did not change; only a default did. A script written for R 3.6 still runs on R 4.0 without modification.

But the output is different. Code that expected a factor now gets a character vector, and anything that relied on factor levels or their integer codes computes something else. The R 4.0.0 release notes said so: “A large number of packages relied on the previous behaviour and so have needed/will need updating.”

This is the most dangerous kind of break, because it can be silent: no compilation error, no runtime error, only different output.

7.5.5 The three-way constraint

Here is the constraint that shapes R implementation strategy:

CRAN holds thousands of packages with compiled code: 5,569 of 25,474 had NeedsCompilation set to yes in tools::CRAN_package_db() on 2026-10-21. Each binary was compiled for a specific version of R and the R C API. For those packages to work on a new R implementation, the implementation must choose which compatibility level to promise.

GNU R promises source compatibility for its documented API. “Writing R Extensions” says the entry points it documents “will only be changed with considerable notice”. Binary compatibility is narrower. R asked for packages to be reinstalled at 3.0.0, at 3.5.0 (those with compiled code) and at 4.0.0, and loadNamespace() refuses a compiled package built under different internals. Behavior changes too, with notice, as stringsAsFactors showed. Internal layout is the part R kept free, which is why sxpinfo could widen in 3.5.0 without any conforming package changing its source.

threaded-r keeps source and behavioral compatibility, not binary. It is a patch to GNU R and the documented API does not change, so a package that sticks to the documented API compiles against it unchanged. A binary built for stock R is refused at load: threaded-r carries its own R_INTERNALS_UUID, because some exported variables, such as R_GlobalEnv, now find the current interpreter through macros.

r-in-rust reaches source compatibility from the other side. It is written from scratch, with no SEXPREC in it at all. What it exports is the same symbols, with the same signatures, behind headers in the same function-accessor style, which is the whole interface a conforming package’s C code uses. That is why CRAN mime compiles from its own source against those headers, installs and loads, and why Rcpp builds and links. There is no layout to translate, because a conforming package never depended on one.

So this is not a translation layer bolted onto a foreign runtime. It is an implementation of the same interface, and C code written to R’s documented API compiles against it and, for the packages tested, runs. What it costs is a function call at the boundary where GNU R might have inlined one internally, not a conversion on every value.

7.5.6 Compatibility options for an alternative R runtime

If you build an alternative R runtime and want real-world users to use it, you must decide on a compatibility stance.

Option 1: Full compatibility. Promise all three: source, binary, and behavioral. This means you cannot rename symbols or change their signatures, and cannot optimize algorithms if they change output. You are locked to GNU R’s design. You gain users with CRAN packages but lose freedom to innovate.

Option 2: Source and behavioral, not binary. Users recompile their C code against your implementation. This costs package maintainers effort, but you gain freedom to change signatures and public types, and that freedom is what the recompile pays for. Users of pure R packages see no impact.

Option 3: Behavioral only. Package authors must change their C code before it compiles against your implementation. Some C API functions are hard to implement without significant overhead. This is faster to implement but locks out packages nobody will port (proprietary packages, packages whose authors have moved on).

Option 4: Compatibility layer. Wrap a foreign representation and convert at every crossing. C code runs, and pays for it on each call. Nobody has made this cheap, which is why r-in-rust took Option 2 instead: answering the same interface directly is available precisely because the interface never promised a layout.

Option 5: No compatibility. Do not support native packages at all. This is fastest to implement and frees you from all constraints. But real-world R use runs on several thousand compiled packages. You lose almost all users.

GNU R keeps source compatibility for its documented API and asks for rebuilds when its internals change. threaded-r and r-in-rust both take Option 2: a package that sticks to the documented API compiles against them unchanged, and its compiled code has to be built for them. threaded-r refuses a binary built for stock R. r-in-rust reaches this from a new implementation, by exporting the same surface over a different implementation.

7.5.7 Earlier reimplementations

Of the five other implementations (Renjin, FastR, Rho, pqR, Riposte), two kept GNU R’s own C code and with it the C API. pqR is a fork of R 2.15.0, and Rho was a C++ refactor of GNU R, so packages written to the API compiled against both; what hurt pqR was keeping up with upstream R, and what hurt Rho was that it could not load packages whose native code defined USE_RINTERNALS. Riposte, a research virtual machine, was close to Option 5: it implemented a subset of R and no C API.

Renjin and FastR are the other two reimplementations, and both took Option 4. Renjin compiles a package’s C and Fortran code to JVM bytecode, and FastR runs native code against its own implementation of much of the C API, paying at each crossing between native and managed code. Both shipped and found users.

An R alternative has to pick a position. Option 1 keeps every existing binary working. Option 2 accepts a recompile, which is what most language ecosystems ask of their users. Option 4 buys compatibility with a conversion on every crossing, and nobody has made that cheap.

Option 2 means implementing a large interface faithfully and keeping it that way. Option 4 means paying for a conversion forever. Neither is free, and the reason a reimplemented runtime can take Option 2 at all is the opacity of SEXP.

Further reading

  • Writing R Extensions <https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-R-API>, chapter 6 (The R API), on which entry points are stable, and its section on moving into C API compliance <https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Moving-into-C-API-compliance>.
  • ABI Policy and Guidelines <https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html>, the GNU C++ library’s account of how it keeps binary compatibility across releases.
  • Semantic Versioning <https://semver.org/>, a framework for reasoning about compatibility across versions.

Where this appears

  • threaded-r Keeps source and behavioral compatibility for CRAN packages, and refuses binaries built for stock R.
  • r-in-rust (rrs) Packages compile from source against headers that present the same accessor functions, not the same layout.

Where to go next

Back to top