Hacker News new | ask | show | jobs
by neilv 364 days ago
Is there, or could there be, a simple implementation of a compiler for the latest full Rust language (in C, Python, Scheme/Racket, or anything except Rust) that is greatly simplified because, although it accepts the latest full Rust language as input, it assumes the input is correct?

Could this simple non-checking Rust implementation transliterate the real Rust compiler's code, to unchecked C, that is good enough for that minimal-steps, sustainable bootstrapping?

This simple non-checking compiler only has to be able to compile one program, and only under controlled conditions, possibly only on hardware with a ton of memory.

3 comments

Is mrustc "simple" enough? Its purpose is as you describe, and it can bootstrap rustc to version 1.74.0. https://github.com/thepowersgang/mrustc
No it can't. Not for RISC-V/musl, so I'm sure that must be true for other platforms too.
Once you've compiled it for one platform, you've re-bootstrapped it, at which point you can use the real compiler to cross-compile for another platform.
Ideally, you want more than one bootstrapped platform. Platforms eventually die, and you don't want to rely on an emulator for bootstrapping.

Some time from now x86_64 will fade away, and there's a large chance rust will still be around. I know that this will probably take a long time, but it's better and easier to do it now than later.

So.... It can, just not for a particular target platform? Or am I missing your point?
`mrustc` might be exactly what I wanted. Thank you.
To some extent, sure - but Rust leans heavily on static analysis even for "simple" code. Something as fundamental as File::open is still generic over "types that can be coerced into a &Path" - which is obviously useful, but it probably means you would need to implement a lot of the type system (+ stubbed out borrow/reference semantics?) just to get rustc's parser bootstrapped.

This is actually tenable for C, though - so maybe you could cook up some sort of C -> C++ -> LLVM -> rustc bootstrap.

Rust can selfbootstrap by compiling the rust code for the compiler.
> Rust can selfbootstrap by compiling the rust code for the compiler.

Compiling the rust code for the compiler how? The whole point is that we don't have rustc.

>The whole point is that we don't have rustc.

This is a made up restriction.

I think one of the reasons that we sometimes think about different ways of compiler bootstrapping is that someone decided to spend their Turing Award lecture on the topic.

Ken Thompson, "Reflections on Trusting Trust". https://dl.acm.org/doi/10.1145/358198.358210

Okay, yes, if you declare the exercise pointless then you can skip it. That's not very interesting, though.