3 ms·
Modern compilers generally have a language-specific front and that generates an intermediate representation of the program logic, which is then transformed into
by bregma 7y ago
Modern compilers generally have a language-specific front and that generates an intermediate representation of the program logic, which is then transformed into an abstract representation (such as a single static analysis tree) for optimization. That is then transformed into an abstract machine description language, which gets further transformed by the back end into concrete machine instructions or assembly code.
Outside of the language-specific front end, compilers generally have no knowledge of the programming language itself. There is no technical advantage to transforming Rust into C when it comes to the middle and back ends, which form the bulk of the compiler.
There are no language-specific optimization opportunities. There are, of course, restrictions on what you can do in some languages that eliminate optimization opportunities, but you're not suddenly going to be able to take advantage of those opportunities by transforming your code into a langue that lacks the restrictions, because then you change the semantics of your code.
- jfkebwjsbx 7y ago> There is no technical advantage to transforming Rust into C There is a key one: the ability to use any C compiler out there (including proprietary ones). This allows you to target all platforms out there.
- pjmlp 7y agoA dumb interpreter for the IR as bootstraping stage is a better alternative. Plus very few platforms have only support for C and nothing else, unless we are speaking about esoteric embedded CPUs.
- jfkebwjsbx 7y agoOf course we are talking about embedded CPUs. And no, they are not "esoteric". They are everywhere around you. Then you can also add custom CPUs and systems, FPGAs, etc. Those are way more rare, but still something people use daily in some industries.
- steveklabnik 7y agoWe have an interpreter for MIR. It isn't fast enough.
- pjmlp 7y agoI clearly mentioned "as bootstraping stage", for nothing else.
- steveklabnik 7y agoI see, I think I misinterpreted you. Sorry!