Live data from Hacker News

GCC Rust: GCC Front-End for Rust

github.com

11–20 of 179 posts

Re: GCC Rust: GCC Front-End for Rust

#11
post #7

Earlier quoted context omitted.

As far as I can tell, this is written in C++ like the rest of GCC, so they don't need a rust compiler to bootstrap.

I see, so it’s written in C++. Would it remain that way, though? AFAIK the LLVM Rust is, itself, written in Rust, right? I imagine that it would be a goal to do the same for gcc.

There is absolutely no reason why the GCC front-end needs to be written in Rust. The reason the LLVM front-end was written in Rust initially was so they could immediately test and use new features in what was at the time also the largest program in Rust. Re-writing the GCC front-end in Rust would just prolong an already rather unfortunate bootstrap problem with the language and it should be strongly discouraged.

As it stands, the way to bootstrap the official Rust compiler from source with just a C/C++ compiler is a few options:

* Compile OCaml (implemented in C), use it to build the original Rust front-end in OCaml and then build each successive version of the language until you hit 1.49. This option is not fun.

* Compile mrustc, which is a C++ implemented compiler that supports Rust 1.29. Use that to build the actual Rust 1.29 and then iterate building your way all the way to 1.49. That is less bad, but still not fun.

* Compile the 1.49 compiler to WASM and run it via a C/C++ implemented runtime in order to compile itself on the target system. This would also mean packaging and distributing the WASM generated code, which some distributions would refuse. I also am not sure if it's even currently feasible, as I don't follow the WASM situation closely.

A compliant, independent C++ implementation that could be built in the ten minutes it takes to build GCC itself would be a very good thing to have and would be more friendly to distribution maintainers.

Re: GCC Rust: GCC Front-End for Rust

#12
What I really hope is that the Rust community doesn’t go out of its way to make this easier. Communicate and let value come back but there’s an significant amount of value in keeping a single backend relies on. CPython has done the Python community a lot of good by keeping one official compiler/tool chain (despite the great work done by projects like JPython/PyPy).

The only way to do this properly, if desirable, is to make GCC an official backend of the main frontend. That will defocus some progress that happens with LLVM (every feature has to be implemented on both backends) and can make dev lives hard (eg “oh this problem comes up with GCC so use the LLVM backend “). The value would be if the majority of bugs/features are in the shared frontend.

This project though seems like a parallel implementation of Rust. That’s valuable for the community and inevitable as a part of successful growth. I don’t believe it’s beneficial to the community though if this grows beyond a toy, niche project.

Re: GCC Rust: GCC Front-End for Rust

#13
post #2

This is very cool, maybe this could push the rust community to have a formal specification and a stable ABI in the future.

The work on a spec is already going as fast as it reasonably can be. A stable ABI is unclear.

Glad you're going slow on the stable ABI and resisting the pressure to put out something half-baked. The C++ ABI is horribly fragile and complex. Unless the pitfalls of C++ can be avoided, making no ABI promises is better.

Re: GCC Rust: GCC Front-End for Rust

#14

I'm not sure if what I'm asking makes sense, but since it's written for a new backend, would the authors have to bootstrap it using a different toolchain? I guess what I'm asking is, could they use the LLVM Rust to build the GCC frontend or do they have to start all over with a different base language to get a first working version of a rust compiler?

The LLVM-based Rust compiler uses a lot of unstable/nightly-only Rust features internally. So even if this project got to the point where it could compile all stable Rust programs, I think it would take quite a bit more work than that to be able to compile `rustc` itself. (It might be that the unstable stuff is mostly in the standard library and not the compiler itself? Does it make a difference?)

Re: GCC Rust: GCC Front-End for Rust

#16
post #6

I'm not sure if what I'm asking makes sense, but since it's written for a new backend, would the authors have to bootstrap it using a different toolchain? I guess what I'm asking is, could they use the LLVM Rust to build the GCC frontend or do they have to start all over with a different base language to get a first working version of a rust compiler?

It's not written in rust; gcc is written in c. There is no bootstrapping involved.

C++ but yes.

Re: GCC Rust: GCC Front-End for Rust

#17
post #6

I'm not sure if what I'm asking makes sense, but since it's written for a new backend, would the authors have to bootstrap it using a different toolchain? I guess what I'm asking is, could they use the LLVM Rust to build the GCC frontend or do they have to start all over with a different base language to get a first working version of a rust compiler?

It's not written in rust; gcc is written in c. There is no bootstrapping involved.

GCC is no longer written in C, but in C++. They switched after GCC 4.7.

Re: GCC Rust: GCC Front-End for Rust

#18

I'm not sure if what I'm asking makes sense, but since it's written for a new backend, would the authors have to bootstrap it using a different toolchain? I guess what I'm asking is, could they use the LLVM Rust to build the GCC frontend or do they have to start all over with a different base language to get a first working version of a rust compiler?

If it was written in rust, there's no reason they couldn't use LLVM rust to start development until it became self-hosting. (Same as you can develop a self-hosting C compiler by starting with gcc)

Re: GCC Rust: GCC Front-End for Rust

#19
post #6

Earlier quoted context omitted.

It's not written in rust; gcc is written in c. There is no bootstrapping involved.

Do gcc languages - even low level ones - remain written in c?

The GCC Ada frontend is written in Ada:

https://gcc.gnu.org/wiki/GNAT

There is also a port of the Ada frontend to LLVM backend:

https://github.com/AdaCore/gnat-llvm

Re: GCC Rust: GCC Front-End for Rust

#20
Is a great deal of actual Rust behavior not fairly intimately tied to LLVM? As far as I know it leaks various LLVM details and much of the documentation about various functions documents them as being little more than a thin wrapper to various LLVM internals.
Post reply on HN