6 ms·
Would someone kindly ELI5 what is GCC Rust ?
by pjerem 5y ago
Would someone kindly ELI5 what is GCC Rust ?
- gostsamo 5y agoUsing GCC for Rust backend compilation instead of LLVM.
- jeltz 5y agoNo, this is writing a new frontend for compiling Rust which uses GCC as a backend.
- Blikkentrekker 5y agoWas it actually done tabulā rasā?, why? Certainly quite a bit of rustc could be cannibalized? Surely the parsing, type, and borrow checking stage or perhaps all the way to the m.i.r. could have been shared.
- steveklabnik 5y agoPart of the point is that you won’t need a Rust compiler to compile this. If you did that, you would. There is another project pursuing that approach. Both are valid strategies with different pros and cons.
- IshKebab 5y agoDidn't that recent critique of this project say that they've already imported some Rust code, so that wouldn't be true.
- steveklabnik 5y agoI don’t know what you’re referring to, exactly. I’m pretty sure you’re talking about the post linked above but I don’t remember reading that in it. It’s possible I missed it!
- raphlinus 5y agoI believe gcc-rs has a dependency on Polonius, the new(ish) experimental Rust borrow checker.
- steveklabnik 5y agoGotcha, thanks. I wonder about the details here; you could imagine that as either a temporary step until things are further along, or possibly a thing only introduced later in the bootstrap process after you’ve built a stage1 compiler, which you could use to build this without an external rustc.
- qzw 5y agoPolonius is an awesome name for a borrow checker! Just hope there’s a —no-verbose flag.
- karatinversion 5y agoPhilosophically, I think the view is that two independent implementations will give the language more long term stability by helping it avoid the trap of a single implementation, with its bugs, being the definitive version of the language. On the practical level, rustc is written in rust and self-hosting, so reusing code from it in gcc would mean that you needed a rust compiler as well as a c compiler to compile gcc. Also, rustc and gcc have incompatible licenses.
- raphlinus 5y agoI am not a licensing lawyer, but the license for rustc (and its standard library, and a great many infrastructural crates in the ecosystem) is dual MIT + Apache 2, which was explicitly chosen so that it would be compatible with both GPL v2 and GPL v3.
- estebank 5y agoI think that the biggest barrier to having GCC use the rustc frontend isn't technical, it's the requirement of copyright assignment to the FSF.
- pjmlp 5y agoThat wasn't a problem when GCC was a requirement to keep free beer UNIX alive, how quickly people forget.
- estebank 5y agoIt is a problem when trying to bring code from an existing codebase that has no such copyright assignment clauses. Bringing the rustc frontend code into gcc would be unlikely because getting a copyright release to GNU from everyone that contributed to rustc would be unlikely.
- nextaccountic 5y agoDo you know whether the GCC Ada, Fortran, Go, D and Java frontends also assign full copyright to the FSF? Are the copyright of all dependencies likewise assigned to them?
- raphlinus 5y agoThere is a different project that grafts the existing rustc frontend to the gcc backend: rustc_codegen_gcc. The existence of both projects is currently very contentious, as there are concerns about duplicated effort and possible fragmentation of the community. Some of the goals, like the ability to target more architectures, are equally supported by both projects, but for other goals (mostly more organizational and less technical, to my ears) they're pretty different.
- hyperman1 5y agoA third implementation of the rust compiler. The official compiler has an LLVM backend. GNU also wants to provide rust, and is adding a rust front to their gcc compiler. These monthly reports document the progress until the gcc compiler reaches feature parity with the LLVM-based compiler
- up6w6 5y agoI always thought Rust and other PLs generate LLVM IR and leave the optimizations to LLVM while GCC has something more complex to deal with, doesnt it make things much complicated ?
- steveklabnik 5y agoThis has largely been true for Rust, however, there are some optimizations that the compiler does before generating LLVM IR. * Compiler docs: https://rustc-dev-guide.rust-lang.org/mir/optimizations.html https://rustc-dev-guide.rust-lang.org/mir/optimizations.html * Working Group: https://rust-lang.github.io/compiler-team/working-groups/mir-opt/ https://rust-lang.github.io/compiler-team/working-groups/mir... * Example of one such optimization, "constant propagation" https://blog.rust-lang.org/inside-rust/2019/12/02/const-prop-on-by-default.html https://blog.rust-lang.org/inside-rust/2019/12/02/const-prop...
- gostsamo 5y agoIt is complicated, but GCC has more target platforms.
- mhh__ 5y agoAnd generates faster code depending on which benchmarks matter to you
- astrange 5y agoGCC and LLVM have very similar structures, as do all compilers. LLVM IR is only special because it has a defined serialization. GCC has an IR called GIMPLE that’s fine.