Rust compiler in C

Discussion of chess software programming and technical issues.

Moderator: Ras

syzygy
Posts: 5673
Joined: Tue Feb 28, 2012 11:56 pm

Re: Rust compiler in C

Post by syzygy »

Ras wrote: Tue Dec 17, 2024 10:19 pm
Michel wrote: Tue Dec 17, 2024 2:19 pmJust target a subset of C without undefined behavior.
That is C, i.e. valid C.
OK, you beat me :)
syzygy
Posts: 5673
Joined: Tue Feb 28, 2012 11:56 pm

Re: Rust compiler in C

Post by syzygy »

Ras wrote: Tue Dec 17, 2024 10:19 pmThe problem is that a bug in the code generator may lead to undefined behaviour. The main problem with that is that it may not even manifest with current C compilers, so all tests would pass - and then suddenly, after a C compiler update, the generated code breaks (stuff like that did happen before).
If you write a code generator, you have complete control over the code that you generate. It should not be too hard to avoid generating illegal code (exhibiting undefined behaviour). You just have to get it right once for all small pieces of code that you generate. This is much harder if you write a large program in C yourself.

But I guess it will be still easier to generate LLVM IR.
User avatar
Ras
Posts: 2694
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Rust compiler in C

Post by Ras »

syzygy wrote: Wed Dec 18, 2024 1:38 amYou just have to get it right once for all small pieces of code that you generate.
Yeah, and then rely on the C compiler to somehow optimise such probably pretty awful C code, resulting from the "small pieces" approach and the inherent language mismatch. I think Rust wouldn't be competitive in terms of speed anymore, not to mention that compilation times are already an issue. Also, Rust devs would have to think in terms of C code, which is also not what they want.
But I guess it will be still easier to generate LLVM IR.
Easier and faster. The only minor downside is that you lose targets without LLVM - but if these were popular, they would have LLVM support anyway.
Rasmus Althoff
https://www.ct800.net
syzygy
Posts: 5673
Joined: Tue Feb 28, 2012 11:56 pm

Re: Rust compiler in C

Post by syzygy »

Ras wrote: Wed Dec 18, 2024 2:34 am
syzygy wrote: Wed Dec 18, 2024 1:38 amYou just have to get it right once for all small pieces of code that you generate.
Yeah, and then rely on the C compiler to somehow optimise such probably pretty awful C code, resulting from the "small pieces" approach and the inherent language mismatch.
But that is a separate issue from the "undefined behaviour" objection that I addressed.