3 ms·
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
by neilv 1y 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.
- Smaug123 1y agoIs mrustc "simple" enough? Its purpose is as you describe, and it can bootstrap rustc to version 1.74.0. https://github.com/thepowersgang/mrustc https://github.com/thepowersgang/mrustc
- neilv 1y ago`mrustc` might be exactly what I wanted. Thank you.
- stevefolta 1y agoNo it can't. Not for RISC-V/musl, so I'm sure that must be true for other platforms too.
- yjftsjthsd-h 1y agoSo.... It can, just not for a particular target platform? Or am I missing your point?
- JoshTriplett 1y agoOnce 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.
- alganet 1y agoIdeally, 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.
- deleted 1y ago[deleted]
- charcircuit 1y agoRust can selfbootstrap by compiling the rust code for the compiler.
- yjftsjthsd-h 1y ago> 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.
- charcircuit 1y ago>The whole point is that we don't have rustc. This is a made up restriction.
- yjftsjthsd-h 1y agoOkay, yes, if you declare the exercise pointless then you can skip it. That's not very interesting, though.
- neilv 1y agoI 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 https://dl.acm.org/doi/10.1145/358198.358210
- colonial 1y agoTo 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.