4 ms·
If I were to try bootstrapping rust, I think I would write a proto-rust in C that has fewer features than full rust, and then write a full rust compiler in prot
by Someone 2y ago
If I were to try bootstrapping rust, I think I would write a proto-rust in C that has fewer features than full rust, and then write a full rust compiler in proto-rust.
‘proto-rust’ might, for example, not have a borrow checker, may have limited or no macro support, may never free memory (freeing memory isn’t strictly needed in a compiler whose only goal in life is to compile a better compiler), and definitely need not create good code.
That proto-rust would basically be C with rust syntax, but for rust aficionados, I think that’s better than writing a rust compiler in “C with C syntax” that this project aims for.
Anybody know why this path wasn’t taken?
- sjrd 2y agoThis is what we did for Mozart/Oz [1]. We have a compiler for "proto-Oz" written in Scala. We use it to compile the real compiler, which is written in Oz. Since the Scala compiler produces inefficient code, we then recompile the real compiler with itself. This way we finally have an efficient real compiler producing good code. This is all part of the standard build of the language. [1] https://github.com/mozart/mozart2 https://github.com/mozart/mozart2
- TwentyPosts 2y agoSo now you're writing two compilers. What did you actually gain from this, outside of more work?
- Etheryte 2y agoTwo simpler pieces of work as opposed to one complex one. Even if the two parts might be more volume, they're both easier to write and debug.
- returningfory2 2y agoWriting a small compiler in C and a big compiler in Rust is simpler than writing a big compiler in C.
- getmenta 2y ago[flagged]
- antirez 2y agoWriting programs in Rust is not simpler then writing programs in C.
- tux3 2y agoFor compilers specifically, I think plenty of people would disagree. It's not that it's exceedingly hard in C, but programming languages have evolved in the last millenium, and there are indeed language features that make writing compilers easier than it used to be I have the most fun when I write x86 MASM assembly. It's a pretty simple language all in all, even with the macro system. Much simpler than C. But a simple language doesn't always make it simple to write complex programs like compilers.
- ZoomZoomZoom 2y agoSure, for you it isn't. It is for me. Especially if we're talking "working roughly as intended" programs.
- kstrauser 2y agoWriting programs that compile is much easier in C. It lets me accidentally do all sorts of ill-advised things that the Rust compiler will correctly yell at me about. I don't remember it being any easier to write C that passes through a static analyzer like Coverity etc. than it is to write Rust. Think of rustc like a built-in static analyzer that won't let you ignore it. Sometimes that means it's harder to sneak bad ideas past the compiler.
- School-Cotton 2y agoFWIW mrustc, the existing state of the art non-rust rust compiler, already doesn’t have a borrow checker. Removing the borrow checker doesn’t break any correct programs — it just makes it so a huge amount of incorrect programs can be compiled. This is fine, since we mainly want to use mrustc to compile rustc, and we already know rustc can compile itself with no borrow checker errors.
- mikepurvis 2y agoAnd once you have yourself bootstrapped, you can presumably turn around and compile the compiler again, now with borrow-checking and optimizations. In the very special case of proto-rust bootstrapping, the cost of not having borrow-checking can be paid back basically right away.
- 1vuio0pswjnm7 2y ago"Removing the borrow checker doesn't break any correct programs - it just makes it so a huge amount of incorrect programs can be compiled." Not a user of Rust programs myself but am curious how users determine whether a Rust binary was compiled with mrustc or rustc.
- School-Cotton 2y agoYou can assume that unless you have some specific information to the contrary, any Rust binary you encounter in real life was built with rustc. mrustc is not used for any mainstream purpose other than in the bootstrap chain of rustc in distros like Guix that care about reproducibility, and even then, the build of rustc they distribute to users will be re-built from the bootstrapped rustc, it won’t be one compiled by mrustc directly.
- 1vuio0pswjnm7 2y agoHypothetical: A computer program is distributed in binary form with the description "written in Rust" or some similar indication it is a Rust binary. A computer user who neither compiles their own programs nor reads source code downloads and runs the program under the belief that because the program is "written in Rust" it offers memory safety. Unbeknownst to the computer user, the program has been compiled without memory safety.