rue: A programming language that is a minimal subset of Rust
47 points by robinhundt
47 points by robinhundt
Hi there!
Yeah robinhundt is correct, this isn’t really intended to be public, it just is. I make no claim that any of this is good, or high quality, or anything else, just yet. It’s something to screw around with in my spare time.
Right now the language itself is very boring, I have i32/i64, bools, and (heap allocated for now) struct/tuple/arrays, functions, if/else/while. That’s it.
I’m more interested in the compiler itself than the language at this stage, though I do have some ideas of where I want the language to go: higher level than Rust, lower level than Go. Memory safe by default. But at the moment, I’m not adding any more higher level language stuff until I have the compiler shaped into something good first. Right now I’m in the middle of re-writing the runtime in Rust, which involves writing a basic linker and all sorts of other stuff. I recently re-did one of the IRs to go from a more traditional design to a more data-oriented one.
It is also an experiment in working with Claude, which is one reason I make no quality claims here. I am taking a more liberal attitude with this project than I do in my professional work, to test the boundaries. Basically, I am more willing to merge things at a lower quality bar and refactor it later. But since this is a spare time thing, the time between “an initial implementation that works” and “okay maybe this is up to snuff” may be a while.
Anyway that’s a rough summary of what’s going on here.
I got excited by the repository and the code I saw and only afterwards, after reading the callout in the README again, realized that you might not like this being posted yet. I’m very sorry if that is the case.
But what is currently there will likely already help me with a compiler I’m currently working on where the language is similarly simple :) I’m very much looking forward to reading about your plans with the language once they’re more fleshed out, or about your experience with Claude.
It’s okay! I did briefly see if it got posted anywhere else so I could make sure to respond there too, but it seems like it’s just here. It’s fine :)
I’ve been meaning to update the README to be a bit more accurate with regards to the current state of things, maybe I’ll bump that up the priority list :)
: higher level than Rust, lower level than Go.
I’m curious what you mean by this. For me, rust is absolutely a higher level language than go, it’s strictly more expressive thanks to macros and expressive power of its generics, on the same ballpark than C++ with some caveats (e.g. in C++ you can parametrize at compile-time on arbitrary values nowadays, not just types but C++ has less on the macro side than rust until C++26 & esp. C++29. So they hit somewhat different corners of the “high-level-language” hypercube)
I find the “high level vs low level” thing kind of weird myself. What I mean here more specifically is something like “no GC, but also no explicit control over memory layouts, and not trying to compete with C/C++/Rust on speed” or thereabouts.
Like I said, still figuring out a bunch of details, so we’ll see how it ends up.
… and yet your README is better than that of some projects with 10 contributors over 10 years.
Thank you! That’s a weird part about LLMs, they make it a lot easier to do better than average, but you still have to be careful with letting stuff get out of date.
Note the disclaimer that this is mainly public to have access to GitHub actions.
From a language feature standpoint there doesn’t seem to be anything particularly exciting. However, from a cursory glance at the source, it seems that this is a compiler that goes beyond many hobby compilers I’ve seen implemented in Rust, and even handles e.g. incremental compilation (via salsa) and IDE integration, while staying fairly small, nicely structured and easily digestible. I’m currently working on a DSL compiler implemented in Rust for my job, and I’ll definitely take some inspiration from this. Maybe this helps someone else as well, even in its unfinished state :)
Note that while I did some initial incremental compilation work I didn’t end up threading it super far through the compiler yet; I haven’t fully decided the exact compilation model and so I decided to leave it be for a bit first.
I do have some (I hope) interesting language ideas but I haven’t written them down yet, and they’re mostly just combining some already existing ideas in a hopefully interesting way. We’ll see!
The compiler uses Buck2 exclusively as its build system.
Curious about why this is. Unlike many popular languages Rust already has good build tooling. Additionally, this is a single-language project.
I originally had both Cargo and Buck. I wanted to improve my understanding of Buck and knew Cargo, so that made sense.
I moved to exclusively buck in preparation for some work I have locally that’s unfinished: re-writing the runtime in rust. With that, I want the runtime crate compiled as a staticlib no matter what, even in the test configuration. I could not figure out how to twist Cargo into doing this, but it’s pretty trivial in Buck.
If Rue ever becomes bootstrapped (and I’m not sure I ever will do that, it’s a big if) that’s also easier in Buck than with Cargo. The port of rustc to use Buck compiles far faster than the official rustc build system, which is layered on top of cargo.
There are some downsides, mainly that I implemented my own snapshot testing rather than being able to use cargo-insta, but I still get rust analyzer and clippy and rustfmt and everything.
What about just using the Rust compiler and enforcing the subset before compilation? Somewhat like SPARK, the Ada subset.
If the GOAL of the project is to:
serve as a testbed for modern compiler implementation techniques
…then wouldn’t using Rust’s compiler undermine that?
It’s syntactically a subset but that’s not a hard requirement in the future; I mostly just want to build a compiler for a language and so the syntax isn’t the interesting part, so I’m keeping it a subset of rust’s syntax until I feel like not doing so.