How (memory) safe is Zig? (2021)
scattered-thoughts.net
How (memory) safe is Zig? (2021)
1–10 of 88 posts
Re: How (memory) safe is Zig? (2021)
#2Unless I gravely misunderstood Zig when I learned it, the Zig approach to memory safety is to just write a ton of tests fully exercising your functions and let the test allocators find and log all your bugs for you. Not my favorite approach, but your article doesn't seem to take into account this entirely different mechanism.
Re: How (memory) safe is Zig? (2021)
#3Kani is a model checker for Rust, and CBMC is a model checker for C. I'm not aware of one (yet!) for Zig, but it would not be difficult to build a port. Both Kani and CBMC compile down to goto-c, which is then converted to formulas in an SMT solver.
Re: How (memory) safe is Zig? (2021)
#4> But it does not nearly approach the level of systematic prevention of memory unsafety that rust achieves. Unless I gravely misunderstood Zig when I learned it, the Zig approach to memory safety is to just write a ton of tests fully exercising your functions and let the test allocators find and log all your bugs for you. Not my favorite approach, but your article doesn't seem to take into account this entirely diffe…
Not a great approach for critical software, but may be much better than what C++ normally offers for e.g. game software, where the development speed definitely trumps correctness.
Re: How (memory) safe is Zig? (2021)
#5False. Fil-C secures C and C++. It’s more comprehensively safe than Rust (Fil-C has no escape hatches). And it’s compatible enough with C/C++ that you can think of it as an alternate clang target.
Re: How (memory) safe is Zig? (2021)
#6> But it does not nearly approach the level of systematic prevention of memory unsafety that rust achieves. Unless I gravely misunderstood Zig when I learned it, the Zig approach to memory safety is to just write a ton of tests fully exercising your functions and let the test allocators find and log all your bugs for you. Not my favorite approach, but your article doesn't seem to take into account this entirely diffe…
Re: How (memory) safe is Zig? (2021)
#7> it seems impossible to secure c or c++ False. Fil-C secures C and C++. It’s more comprehensively safe than Rust (Fil-C has no escape hatches). And it’s compatible enough with C/C++ that you can think of it as an alternate clang target.
Fil-C is in the cards for my next project.
Re: How (memory) safe is Zig? (2021)
#8> it seems impossible to secure c or c++ False. Fil-C secures C and C++. It’s more comprehensively safe than Rust (Fil-C has no escape hatches). And it’s compatible enough with C/C++ that you can think of it as an alternate clang target.
I love this shameless self-promotion. ;) Fil-C is in the cards for my next project.
Hit me up if you have questions or issues. I’m easy to find
Re: How (memory) safe is Zig? (2021)
#9Earlier quoted context omitted.
I love this shameless self-promotion. ;) Fil-C is in the cards for my next project.
Thank you for considering it :-) Hit me up if you have questions or issues. I’m easy to find
Re: How (memory) safe is Zig? (2021)
#10There is a third category of memory and other software safety mechanisms: model checking. While it does involve compiling software to a different target -- typically an SMT solver -- it is not a compile-time mechanism like in Rust. Kani is a model checker for Rust, and CBMC is a model checker for C. I'm not aware of one (yet!) for Zig, but it would not be difficult to build a port. Both Kani and CBMC compile down to…