4 ms·
Interesting how instead of embracing Rust as a required toolchain for APT, the conversation quickly devolved into "why don't we just build a tool that can tran
by petcat 11mo ago
Interesting how instead of embracing Rust as a required toolchain for APT, the conversation quickly devolved into
"why don't we just build a tool that can translate memory-safe Rust code into memory-unsafe C code? Then we don't have to do anything."
This feels like swimming upstream just for spite.
- sidewndr46 11mo agoAll compilers do anyways is translate from one language specification to another. There's nothing magical about Rust or any specific architecture target. The compiler of a "memory safe" language like Rust could easily output assembly with severe issues in the presence of a compiler bug. There's no difference between compiling to assembly vs. C in that regard.
- simonask 11mo agoThe assumption here is that there exists an unambiguous C representation for all LLVM IR bitcode emitted by the Rust compiler. To my knowledge, this isn’t the case.
- andsoitis 11mo ago> The assumption here is that there exists an unambiguous C representation for all LLVM IR bitcode emitted by the Rust compiler. > To my knowledge, this isn’t the case. Tell us more?
- adwn 11mo agoFor one, signed integer overflow is allowed and well-defined in Rust (the result simply wraps around in release builds), while it's Undefined Behavior in C. This means that the LLVM IR emitted by the Rust compiler for signed integer arithmetic can't be directly translated into the analogous C code, because that would change the semantics of the program. There are ways around this and other issues, but they aren't necessarily simple, efficient, and portable all at once.
- pengaru 11mo agoYou guys seem to be assuming transpiling to C means it must produce C that DTRT on any random C compiler invoked any which way on the other side, where UB is some huge possibility space. There's nothing preventing it from being some specific invocation of a narrow set of compilers like gcc-only of some specific version range with a set of flags configuring the UB to match what's required. UB doesn't mean non-deterministic, it's simply undefined by the standard and generally defined by the implementation (and often something you can influence w/cli flags).
- adwn 11mo ago> You guys seem to be assuming transpiling to C means it must produce C that DTRT on any random C compiler invoked any which way on the other side, where UB is some huge possibility space. Yes, that's exactly what "translating to C" means – as opposed to "translating to the very specific C-dialect spoken by gcc 10.9.3 with patches X, Y, and Z, running on an AMD Zen 4 under Debian 12.1 with glibc 2.38, invoked with flags -O0 -g1 -no-X -with-Y -foo -blah -blub...", and may the gods have mercy if you change any of this! Do you see the problem?
- simonask 11mo agoSource-to-source translation will be very hard to get right, because lots of things are UB in C that aren’t in Rust, and obviously vice versa. Rust has unwinding (panics), C doesn’t.
- thesz 11mo agoOne can do a direct translation from Rust AST/IR to C. Many functional languages do that, C++ started as a compiler to C.
- tsimionescu 11mo agoThe gigantic difference is that assembly language has extremely simple semantics, while C has very complex semantics. Similarly, assembler output is quite predictable, while C compilers are anything but. So the level of match between the Rust code and the machine code you'll get from a Rust-to-assembly compiler will be much, much easier to understand than the match you'll get between the Rust code and the machine code produced by a C compiler compiling C code output by a Rust-to-C transpiler.
- epolanski 11mo agoThe problem is that rust is being shoved in pointless places with a rewrite-everything-in-rust mentality. There's lunatics that want to replace basic Unix tools like sudo, etc, that are battle tested since ages which has been a mess of bugs till now. Instead Rust should find it's niches beyond rewriting what works, but tackling what doesn't.
- VWWHFSfQ 11mo agoIs the apt package manager a pointless place? It seems like a pretty foundational piece of supply chain software with a large surface area.
- metalforever 11mo agoThe author of the rust software did not solve the platform problem, as a result it is not a solution. Since it is not a solution, it should be reverted. It's really that simple.
- genewitch 11mo agoWe need lisp, cobol, and java in apt, too. and firefox.
- sidewndr46 11mo agoI seem to remember going through this with systemD in Ubuntu. Lots of lessons learned seemed to come back as "didn't we fix this bug 3 years ago?"
- dralley 11mo agoConverting parsers to Rust is not "pointless". Doing string manipulation in C is both an awful experience and also extremely fertile ground for serious issues.
- donkeybeer 11mo agoapt is C++
- 11mo ago
- forgotpwd16 11mo ago>tool that can translate memory-safe Rust code into memory-unsafe C code Fwiw, there're two such ongoing efforts. One[1] being an, written in C++, alternative Rust compiler that emits C (aka, in project's words, high-level assembly), the other[2] being a Rust compiler backend/plugin (as an extra goal to its initial being to compile Rust to CLR asm). Last one apparently is[3] quite modular and could be adapted for other targets too. Other options are continuing/improve GCC front-end for Rust and a recent attempt to make a Rust compiler in C[4] that compiles to QBE IR which can then be compiled with QBE/cc. [1]: https://github.com/thepowersgang/mrustc https://github.com/thepowersgang/mrustc [2]: https://github.com/FractalFir/rustc_codegen_clr https://github.com/FractalFir/rustc_codegen_clr [3]: https://old.reddit.com/r/rust/comments/1bhajzp/ https://old.reddit.com/r/rust/comments/1bhajzp/ [4]: https://codeberg.org/notgull/dozer https://codeberg.org/notgull/dozer
- pabs3 11mo agoAlso there is a rustc codegen backend that uses GCC, so you can just skip the C part: https://github.com/rust-lang/rustc_codegen_gcc https://github.com/rust-lang/rustc_codegen_gcc
- pbohun 11mo agoThat's not what the comment said. It said, "How about a Rust to C converter?..." The idea was that using a converter could eliminate the problem of not having a rust compiler for certain platforms.