⏱️ Reading time: 7 min
PyPy didn’t hand-write its JIT compiler: it generated it from an interpreter written in RPython, the restricted Python 2 dialect that Max Bernstein documents in an article published on November 19, 2026 (original source). Knowing what RPython is helps explain that speed: it’s the piece that turns a slow interpreter into compiled C code and, later, into JIT-compiled code, without the language’s author having to hand-write the optimizer.
📑 En este artículo
What RPython Is and Where It Came From
Bernstein writes that the urge to implement a programming language comes back to him every so often, but admits there’s no good language for writing that implementation (source). So he ends up modifying an existing implementation instead of building his own from scratch.
RPython comes from that same problem: it’s a tool for building fast language implementations without hand-writing a full JIT compiler. According to the same source, its flagship success story is PyPy, but it also gave rise to Topaz, a Ruby implementation, and a couple of smaller projects. Truffle and Deegen share that goal, though each solves it with a different method.
How RPython Turns Python Code Into a Fast Machine
To use RPython you have to write the interpreter in a subset of Python 2 that behaves more like Java or Go than Python, without the usual dynamism that lets you mix integers, strings or objects in the same variable (source).
The RPython compiler analyzes that code, infers the types and translates it to C along with its own intermediate representation. That C code can later, at runtime, scale up to JIT-compiled code. For that jump to work, whoever writes the interpreter has to take part in the system’s meta-tracing, explicitly marking where in the main loop each iteration happens, the hint RPython needs to generate the JIT compiler (source).
Bernstein documents the whole process with a minimal example of two functions plus a third one that just tells the compiler where to start translating. According to his account, compiling that program with RPython’s toolchain, cloned from the PyPy repository on GitHub, took about 18 seconds in total. Of that time, half a second went to annotating types, another half second to the internal typing pass, about 10.6 seconds to building the internal database, 1.2 seconds to generating the C source code and 1.5 seconds to compiling it with a conventional C compiler (source).
The Pitfalls of the Restricted Dialect
The same example exposes the cost of that speed. Bernstein modifies his function so the addition operator also concatenates strings, something that works fine in regular Python 2. Under RPython, though, the compiler stops with a type unification error. It can’t decide whether that function returns a character or an integer, and rejects the translation (source).
That underlying rule requires every function in RPython to have a consistent return type, as in a statically typed language, even though it’s written with Python syntax. Bernstein himself warns that RPython is just an implementation detail of PyPy, without the years of polish the rest of the system has, and asks people not to bother its maintainers with those rough edges (source).
Truffle and Deegen: Two Other Bets on the Same Problem
None of the three tools solve the problem the same way. Truffle, the foundation behind TruffleRuby, GraalPython, GraalJS and even Sulong (an LLVM implementation), requires writing an AST or bytecode interpreter in a Java DSL based on annotations. From there it specializes the guest language’s code and generates Graal IR, which applies aggressive partial evaluation to produce optimized code (source).
Deegen, younger, was used to reimplement Lua. It requires writing the bytecode interpreter and type system in a C++ DSL, and from that it generates an interpreter, a baseline JIT and, according to the project’s stated roadmap, eventually an optimizing JIT (source).
| Tool | How the interpreter is written | What it generates | Real-world cases |
|---|---|---|---|
| RPython | Restricted subset of Python 2 | C code and its own IR, then JIT via meta-tracing | PyPy, Topaz |
| Truffle | Java DSL with annotations | Graal IR via partial evaluation | TruffleRuby, GraalPython, GraalJS, Sulong |
| Deegen | C++ DSL | Interpreter and baseline JIT; optimizing JIT still missing | Lua reimplementation |
The biggest practical difference is maturity. Truffle runs in production behind several different languages on top of GraalVM. RPython has been powering PyPy for more than a decade, but it’s still tied to its specific toolchain and to a syntax that looks like Python without behaving like it. Deegen, meanwhile, still has only one public case, Lua, and is missing its most expensive piece, the optimizing JIT.
What the Community Says
The Hacker News thread on the article (discussion) got mixed reactions. A comment from mathisfun123 ironically questions the habit of recommending tools on Hacker News that someone just discovered there, joking that they’re surprised nobody has suggested Mojo yet as an alternative (comment).
More useful for anyone actually weighing options is the contribution from jbloggs777, who responds to Bernstein’s original frustration, the lack of a good implementation language, by pointing to a project the original article doesn’t mention: Nimony, presented as the foundation of Nim 3.0 (comment). That’s a detail that doesn’t come from the original source but from the discussion it sparked, and it serves as a lead for anyone comparing options beyond the three covered here.
Limitations and When Not to Use It
RPython has a high cost of entry. Its own creator documents unclear translation errors, like the type unification one, and warns that the project isn’t built for heavy external support. Adopting it outside the PyPy ecosystem means accepting that friction with no guarantee of help.
Truffle requires buying into the JVM and GraalVM, which is a real cost for teams not already working in that stack. Deegen, because of its youth and the missing optimizing JIT, still isn’t a complete option for anyone who needs top-tier production performance. Today it works better as a design reference than as a ready-to-adopt tool.
What This Means for You
If you’re evaluating building your own language or DSL with serious performance, the choice depends on where you already live as a developer. A team running on the JVM has Truffle as the option with the strongest production track record, since TruffleRuby and GraalJS have been running that way for years.
A developer coming from Python who wants to understand how PyPy achieves its speed, or who’s willing to live with an unpolished tool, can clone the PyPy repository and reproduce the minimal example Bernstein documents to feel the type restriction firsthand before committing to RPython. Anyone who prefers C++ and is willing to bet on a newer project can keep an eye on Deegen, knowing it’s still missing the optimizing JIT.
Frequently Asked Questions
Do I need to know C to use RPython?
Not directly, but the RPython compiler translates the interpreter to C before compiling it, so understanding that intermediate step helps when reading the type errors that come up during translation, like the unification error Bernstein documents (source).
Can RPython be used to write regular applications?
No. It’s a dialect meant only for writing the interpreter that later gets translated. The final program, PyPy for example, still runs regular Python for whoever uses it, not RPython (source).
References
- Inside PyPy: first contact with RPython: Max Bernstein’s original article explaining RPython, the translation example and the type error.
- PyPy repository on GitHub: source code for RPython and PyPy, cloned in the article’s example.
- Hacker News discussion: community thread on Bernstein’s article.
- Comment from jbloggs777: suggests Nimony (Nim 3.0) as an alternative for anyone looking to implement their own language.
Featured image: Foto de Gabriel Heinzer en Unsplash
How each article is made (sources, testing and editorial criteria): How we work.
Did it work for you? Got a different error? Say so below: questions get answered and help the next reader.
Leave a comment
0 Comments