4 ms·
This is one of my favorite attempts at better programming language safety, because it compiles down to C that can then be shipped like normal C, so you don't ge
by yjftsjthsd-h 2y ago
This is one of my favorite attempts at better programming language safety, because it compiles down to C that can then be shipped like normal C, so you don't get the ecosystem friction like with ex. Rust.
- vlovich123 2y agoIt’s an interesting idea for sure but it isn’t a general purpose language, so the problem domains it can solve is very very different vs what Rust is trying to do.
- tialaramex 2y agoNigel has said that emitting "unsafe" Rust is a reasonable thing for a hypothetical WUFFS 1.0 to be able to do as an alternative to C. As with good "unsafe" Rust written by humans WUFFS would know exactly why what it's doing is fine, it's just that the Rust compiler can't necessarily see that, hence the need to label it "unsafe". Today C makes most sense given the WUFFS language is still in flux. [Edited to fix a serious typo]
- nequo 2y agoWhat would be the primary benefit of emitting Rust rather than C? Both would be considered safe (assuming Wuffs generates correct code), and Rust could access the C code via FFI. Is there something I’m missing?
- vlovich123 2y agoNominally it can safely elide bounds checks via unsafe that it has proved are actually safe within the constraints of Wuffs, which is what it does for C (+ the language is built for more easy translation to vectorizated than something like llvm is able to do for general purpose languages). So basically higher performance. FFI nominally has a runtime and compile time cost - whether that matters for you in particular will depend on your needs, but being able to publish a very simple crate without a build.rs to manage can have an attraction.
- tialaramex 2y agoI expect that the Rust emitted by a hypothetical future WUFFS transpiler would be much easier to just drop into an existing Rust project than some C via a C FFI. It's common for C libraries that do get wrapped today (e.g. openssl) to have a two phase wrapping, a -sys crate which turns the C into Rust C FFI and then another crate to turn the Rust C FFI into something actually palatable to ordinary people.
- jcranmer 2y agoThe C abstract machine is slightly funkier than unsafe Rust (things like C lacking a way to do signed integer overflow without UB or needing to adhere to strict aliasing in C), so I would expect that lowering to unsafe Rust would be slightly more likely to be correct.
- IshKebab 2y agoProbably not too much from a "final product" point of view, but using a pure Rust library is a whole lot easier than C from a faff point of view. Especially for cross-compilation.
- pcwalton 2y agoOne benefit would be that Rust users could use Wuffs code without having to install a C compiler. Pure-Rust solutions are much more convenient in the Cargo ecosystem than wrangling -sys crates.
- edflsafoiewq 2y agoYou could also use c2rust.
- vlovich123 2y agoI’m responding to this: > that can then be shipped like normal C, so you don't get the ecosystem friction like with ex. Rust. Emitting Rust doesn’t help with this.
- tomjakubowski 2y agoit helps in the other direction: less friction to use from rust
- fiddlerwoaroof 2y agoBut more friction to use from just about every other language.
- andrepd 2y agoWhat's the difference vs compiling down to machine code and linking it with your program?
- pornel 2y agoYou reuse optimizer and machine code generator of the C compiler, and you're not tied to a single backend like LLVM.
- pcwalton 2y agoC has a lot of problems as a compilation target as well, from surprising UB (e.g. signed integer overflow) to debugging problems (e.g. #line is woefully inadequate compared to the ability to emit DWARF DIEs) to the inconvenience of setting up a toolchain for end users. To its credit, Wuffs is one of the better projects that compiles to C, because it targets a very restricted domain. But, in general, don't write programming languages that compile to C.
- yjftsjthsd-h 2y agoOf course C sucks, but since everything under the sun uses it, there's unique value in being able to make it safer without putting a whole new compiler in the process for users. Remember that time the cryptography library in Python decided to add rust? We could have avoided all that pain with wuffs.
- bobajeff 2y agoFor many of us making a compile to c language is many times more feasible than using something like llvm. I'm not saying it's great mind you but it's probably the best thing available without a runtime. For debugging i believe you can generate your own source maps and use gdb as a backend to talk with your custom debugger.