2 ms·
This seems pretty contrary to the purpose of Rust, since the generated code is full of non-idiomatic unsafe and possibly situationally unsound pointer manipulat
by dodobirdlord 7y ago
This seems pretty contrary to the purpose of Rust, since the generated code is full of non-idiomatic unsafe and possibly situationally unsound pointer manipulations that could definitely be done in idiomatic safe code. No reason I can see not to just write this sort of thing in Rust to begin with and expose it to other languages via the C ABI to call with FFI or even co-compile with other LLVM languages.
- flohofwoe 7y agoYeah theoretically, but then you have the same problem as using C libraries from Rust, the build process for those other languages suddenly becomes much more complicated because they must integrate with another language toolchain. Lets say I want to expose a Zig library to Rust or vice versa, now I must call the Zig compiler from Cargo, or Cargo from the Zig build process. With a transpiled library such a project is "clean", it only needs the Rust or Zig toolchain. The transpiling process only needs to happen once, and this can happen automatically on a CI service when the base library is updated and then made available automatically through the language's package repository. Rust probably won't get the ability to transpile to Zig, and Zig probably won't be able to transpile to Rust. Some sort of Lingua Franca makes sense in a multi-language world, and C (or even a subset of C) makes sense for that because it already is the Lingua France, and has a very small feature set to consider. I'm aware that this is a controversial opinion though ;)
- dodobirdlord 7y agoControversial indeed ;) If we were going to create a Lingua Franca for such a purpose from scratch, it would probably look very little like C. It would probably look like a much reduced subset of Some compiler IR, or Haskell. We would want something that is typesafe and lowers trivially to an AST. As the barest of table stakes, a language with any undefined or implementation defined behavior whatsoever is obviously unsuitable for this purpose. After all, we need a wide variety of compilers to be able to easily generate their own IR from it, and for them all to guarantee exactly the same behavior when they do. C seems close to the worst choice possible. Edit: Haha, I realized I invented WASM again. This happens frequently...
- masklinn 7y agoThe point of c2rust is to be a transitional tool, once the system is done in Rust, compiles with Rust tooling and works as it used to it's assumed it'll be much easier to manage and iterate on.