Live data from Hacker News

GCC Rust Approved by GCC Steering Committee

gcc.gnu.org

11–20 of 300 posts

Re: GCC Rust Approved by GCC Steering Committee

#12

What does a "front-end" mean exactly, in this context?

The part of a compiler that handles tokenization, parsing, AST generation and IR emission, as opposed to the backend which is responsible for conversion of IR to a target-compatible executable.

Re: GCC Rust Approved by GCC Steering Committee

#13

What does a "front-end" mean exactly, in this context?

At a high level, GCC and LLVM are divided into two ends: the front and the back. The front end takes the source code and turns it into some form that's language agnostic (e.g. LLVM bitcode). The back end takes those structures and turns it into machine code. This allows the compiler to be modular.

Old compilers didn't use this concept. So a C->x86 compiler and a Fortran->x86 one couldn't share code as easily. And if you wanted to expand to, say, ARM, Alpha, etc. targets, it gets worse. You end up needing O(l*t) compilers[a] to be homogenous. It gets even worse if you want to add optimization. With this model, the whole system is working on an AST, and therefore, the optimizers are tailored to the individual compiler varient, so they end up being just as unportable.

However, with a modular design (front and back end), you can have C->IR and Fortran->IR front ends, then a single back end for each target: IR->x86 and IR->ARM. If you want to add, say, Ada support, you only need to write an Ada->IR module, and the back ends handle the rest. In the end, you only need O(l+t) modules. You also get the benefit of agnostic optimizers as they only need to support your internal IR.

[a]: 'l' is languages and 't' is targets

Re: GCC Rust Approved by GCC Steering Committee

#15

What does a "front-end" mean exactly, in this context?

Compilers are often implemented as a front-end/back-end split.

The front-end compiles your input language (C, C++, Rust, etc) down to a low-level language called an Intermediate Representation. Then the back-end of the compiler optimizes the IR and compiles it into object code. A family of compilers will usually share the back-end.

This kind of split allows for deduplication across different compilers in the same family, and also makes it easier to design a new language without having to fully re-implement everything about the compiler yourself.

In GCC, these are bundled together as a common project afaik. In Clang/LLVM, these are split into the front-end (clang) and the back-end (LLVM).

Re: GCC Rust Approved by GCC Steering Committee

#17
post #9

Why would someone want this? (Honest question)

GCC already has compiler front ends for Fortran, Ada, Go, and formerly Java. Adding another language, especially one as popular as Rust, couldn't hurt.

Huh, I didn't realize that

Re: GCC Rust Approved by GCC Steering Committee

#18
post #6

Earlier quoted context omitted.

Multiple implementations of a standard help shine light into dark corners.

Indeed, but I think they should first create a standard?

If not a standard, then at least a specification. This discussion is from 2020, so I'm not sure if it's still up to date:

https://users.rust-lang.org/t/where-is-the-rust-language-spe...

"For the most part though, rustc itself is the spec" - so, for implementing the GCC frontend, read the current LLVM frontend really carefully and do everything the same way? And try to keep up with all the changes which will inevitably happen in the LLVM frontend while you are implementing the GCC frontend?

Re: GCC Rust Approved by GCC Steering Committee

#20
post #6

Earlier quoted context omitted.

Multiple implementations of a standard help shine light into dark corners.

Indeed, but I think they should first create a standard?

Rust already has stable standards. There's Rust editions 2015 (1.0), 2018 (1.31.0), and 2021 (1.56.0).
Post reply on HN