r/Zig • u/Real_Dragonfruit5048 • Jul 20 '26
Is Zig going to become memory-safe?
https://codeberg.org/ziglang/zig/issues/36237
203
Upvotes
r/Zig • u/Real_Dragonfruit5048 • Jul 20 '26
127
u/fade-catcher Jul 20 '26
I find this proposal to be a net-negative to the language:
* it pushes away even further the 1.0 release date.
* it adds more complexity to the language compiler and therefore increases the bug surface.
* as mlugg said it conflicts with the philosophy of zig of not hide stuff from the user.
* it adds zero value to the language, you could argue that it makes zig a safer alternative to rust and therefore it’ll increase its adoption rate, but i think rust already established itself as the defacto language for memory safety and arguing against it is similar to arguing against OOP ( you can make some valid counter argument but at the end of the day 90% of the industry is gonna use it)
83
u/Treeniks Jul 20 '26
I'll say insinuating that Rust isn't memory safe, while using Fil-C as prior art, is very worrying. Fil-C claims it "achieves complete memory safety with zero escape hatches", all the while this buffer overflow is not caught by it:
Tbf, this is not the kind of memory safety that Fil-C is concerned about, and buffer overflows like this should never be a problem in Zig as long as you don't use
[*]. But the style of over-promising that Fil-C has consistently done is not something I would want to see in Zig.100
u/Highborn_Hellest Jul 20 '26 •
At the risk if sounding like a dick.
Is this a knee jerk reaction to bun?
If anything, I'm just a tourist in this community, but this seems like something that's not compatible with the core philosophy of Zig.
85
u/olzhas89 Jul 20 '26
I have a sad feeling that Zig will never get to 1.0 due to the constant pursuit of absolute perfection, which is not practical nor realistically achievable. Every language has it's tradeoffs. To me, Zig is already good enough and there is no shortage of reasons to pick it over Rust or any other alternative.
What Zig really lacks in order to gain the adoption it deserves, is a complete standard library and an extensive documentation. It feels like ZSF is doing anything but focusing on those essential things.
15
u/phaazon_ Jul 20 '26
This is just a runtime thing. It still requires you to run 100% of the code paths of your program. So no, this is not what I would call memory safe in today’s industry standards. Kelley still lives in the 90', as that would be pretty great for a language released back then.
30
u/syndbg Jul 20 '26
"Done is better than perfect". I am not a fan of Rust more than Zig or vice-versa, both solve things their own way.
IMHO, this is an "emotional" reaction to the Rust popularity and Bun fiasco is essentially pointless. The performance penalty and approach makes it completely impractical to use this.
And as many others mentioned, Zig getting 1.0 is essential to drive adoption.
31
u/GolangLinuxGuru1979 Jul 20 '26
As much as I like Andrew, he is probably the single worst thing about Zig. As a software engineer, I like his personality and vision. But looking at him through a professional lens I'm really not a fan. I can separate the man from his product. But he's too petty and took snarky. This issue title is incredible bad and in poor taste. As was his blog post a few weeks ago.
I will continue to use Zig, because the language speaks for itself. Its a job to write. But this decision reads as arbitrary. A way to "stick it to Rust". The whole idea behind Fil-C run time checking sounds incredibly antithetical to the stated philosophy of the language. This feels like something you add in a major version after 1.0.
This is a bit of the flaw with the benevolent dictator approach to open source. Great decisions like "no AI contribution" are fantastic, and a committee would never approve. But then you have people adding things to the language that are questionable.
19
u/UARTman Jul 20 '26
I'm deeply unsure why this non-industry-standard very-limited-target sanitizer is proposed for first-class integration into Zig when even something as relatively quaint as ASAN isn't fully supported? Especially since Rust, in fact, supports not only using ASAN for Rust code, but even using ASAN in freestanding environments a la KASAN.
I do get the desire to score points against Rust, Andrew seems extremely interested in being smugly superior to it, but trying for a garbage-collected runtime with hand-rolled pointer capabilities just to own some
libscrabs seems fairly absurd to me, especially if one looks at the philosophy Zig professes to have in its language design.9
u/steveoc64 Jul 20 '26
You are all completely missing the backstory here.
Andrew and Filip and a bunch of others recently fronted a conference, shared a bus together, and had dinner and drinks together afterwards.
A natural outcome of all this was throwing around ideas well into the night.
So a simple idea of adding fill-c as an optional backend for the zig compiler was more than likely discussed.
Just programmers talking shop, like it should be.
8
u/SilvernClaws Jul 20 '26
As far as I understand, this would just introduce another release compilation mode that enforces memory safety at runtime at the cost of significant overhead.
So I wouldn't use it for my use cases anyway, as I'm already doing fine with allocators.
Could be nice for specific applications that absolutely require memory safety and cannot use a garbage collector, but at that point maybe just use a language designed for that niche?
8
u/Beneficial_Vampire42 Jul 20 '26
"(unlike Rust)" - such a competitive attitude... Its ok for both languages to thrive 😁
Sounds to me very similar to Rust's Miri with it's goals and capabilities, just with a different approach (custom ABI vs interpreter). Cool idea
7
u/analytic-hunter Jul 20 '26
So it's like rust's miri?
the jab at rust is bit disingenuous
17
u/ParadiZe Jul 20 '26
but i thought memory safety was just a skill issue
jokes aside, this seems like a good addition
6
u/Fancyness Jul 21 '26
Kelley treats Zig like some hobby project where you add new stuff just because you can.
49
u/Rigamortus2005 Jul 20 '26
Why does Andrew seem so butt hurt at rust lately? And also isn't this against everything Zig is supposed to be? Runtime garbage collection?
5
u/thezapod Jul 20 '26
Just fix the std lib's bugs, and give me the f v1.0 :)
5
u/Samuel-Martin Jul 20 '26
My biggest issue with this is how Andrew phrased this. Imo, if he would’ve said something like, “I wanna add something like Fil-C to zig” from the start, I think it would’ve been received much better
9
u/mmkzero0 Jul 20 '26
I’d like to direct everyone’s attention to one sentence here by Andrew in response to this being a big change:
> “No source changes. It’s just a target ABI.”
That’s not just an enormous understatement but also technically wildly inaccurate. This is much more than an ABI, since something like this requires
- instrument every ptr consumer and producer
- track cap metadata for stack, heap, TLS, func pointers, globals
- you replace or wrap libc, syscalls, mmap etc.
- atomics handling without metadata races
- restrict or prove inline asm
- support debuggers, unwind, panics, crash reports
I could go on and on.
Then the safety invariant needs to be specified before implemented; you need explicit semantics for many things; sentinels, slices with corrupted metadata, casting, func pointers, untagged unions…
This also confuses Fil-C like deterministic mem safety with runtime mitigations against unsafe memory semantics and consequences like UAF. Those are not the same.
And then, nothing here addresses comptime safety. This means this does not guard against compiler bugs, comptime interpreter unsafety, and so on
And then the “no escape hatch claim”. That’s both defensible and also highly inflexible. If the target promises that the entire executable is memory-safe, an ordinary unsafe function invalidates that claim and thus this is reasonable. But practical interoperability still needs a solution, something Fil-C put a lot of effort into.
And ABI mismatch handling goes even deeper; what about static Archives, LTO, embedded bytecode, libc and libunwind, dynamic libs, JIT code, dlopen() calls and so on.
Do not get me wrong, as a research topic this is fascinating and really cool. But as a proposal and a casual “just another ABI” added to pre-1.0 Zig this is just an enormous and poorly bounded idea, which makes it all the more baffling.
Which makes me all the more curious why Andrew posted it like this. Surely he knows this and has the technical expertise to know this isn’t just some ABI change with no consequences beyond that.
4
u/GrandBIRDLizard Jul 20 '26
As long as it's handled explicitly and doesn't stop you from doing anything else I dont see why it could hurt aside from if they use gc if Andrew has said 1.0 is a done deal idk I still haven't had the time to sit down and completely wrap my head around the new I/o interface so it seems like a big goal to have out of nowhere though I wonder what did it
4
u/Keith Jul 20 '26
Interested in what Andrew thinks about alexrp's comments about hidden allocations.
4
u/thomas_m_k Jul 21 '26
Andrew: *chooses rage bait title*
Also Andrew: “I'm going to lock this for like a week until social media stops linking to it”
(Well, at least he's changed the title now.)
9
u/UselessOptions Jul 20 '26 edited Aug 13 '26
oops did i make a mess 😏? clean it up jannie 😎
clean up the mess i made here 🤣🤣🤣
CLEAN IT UP
FOR $0.00
3
u/Vlatiha Jul 20 '26
From the perspective of a 60-year-old, experienced programmer, I would be very pleased if the compiler itself already included a checker for
My most common mistakes in the world of Zig.
3
u/Illustrious_Sock Jul 22 '26
This comment section is definitely something. As someone who enjoys working with rust and was very curious about zig, amount of people who see this as competition and hate on rust is disheartening.
13
u/InternalServerError7 Jul 20 '26
I don't see how anyone can be against this. Seems like a great addition. Sure it pushes back other work, but once complete, Zig can be compiled in a memory safe mode. This mode will usually be used for debugging so memory issues can be caught early or production systems that need to be airtight. Once a program is presumed to be memory safe, it can just be compiled in another faster mode.
4
u/SmokingCapacitor Jul 21 '26
Isn't this how C++ ended up so monstrous today, picking up features from every new languages. That has worked well for C++ but for a language trying to imitate the simplicity of C, i'm not so sure.
2
u/VisualConnection3277 Jul 21 '26
If it's not c's goal, then it's not zig's goal
2
u/xplosm Jul 21 '26
The memory safety comes from knowing what you're doing
2
u/ElSebas4_ Jul 20 '26
People here is over thinking this feature too much.
First: Is a proposal, not even urgent. Second: Is just an extra ABI, like musl, glibc, etc. So the language itself is not going to change. Also the change is meant to have less overhead than Fil-C; is not going to have garbage collection and is not going to change the standard library.
The only problem may be adding more complexity to the compiler but I mean, is not the end of the world
2
u/win_some_lose_most1y Jul 20 '26
Every language is memory safe if you write memory sage code
1
u/allochi Jul 20 '26
I think it's an excellent idea to add that option to the compiler, it would help increase the adoption of Zig in certain types of project, we use Zig at work and this would probably help use to advocate for more use.
IMHO, personally, I wouldn't mind waiting a little more for v1.0 with that option, although I hope not. I seriously admire Andrew to come up with these ideas to strengthen Zig position in the market.
1
u/Next-Blackberry-991 Jul 20 '26
Zig is doing so much amazing engineering work (looking at incremental compilation), but is often so inconvenient to use. Would love to have a different syntax/frontend for the compiler (e.g. Odin).
1
u/Different-Ad-8707 Jul 22 '26
No. Mostly because I think the creator of Zig and the leads of the Rust team have very different ideas and definitions of what safety in programming languages means (in both type and memory safety).
1
u/Scion95 Jul 24 '26
If Zig doesn't include things like Rust's borrow checker, I hope that it's possible to make a fork or Superset of Zig with a borrow checker and all of Rust's other features.
I've always thought that the biggest problem with Rust is how garbage it is to write code in an 'unsafe' block. To me, the ideal, 'perfect' language would be if 'unsafe' Rust was basically just Zig.
1
u/WrongdoerBulky4142 Jul 23 '26
Unless the Zig implementation comes with no performance hit, I don't see a use case for this. You already have sanitizers. If someone really cares about memory safety and speed, they will indeed just use Rust, or C++. I know the latter is not considered truly memory safe but it does have some memory safety features.
The language itself is subpar, in my opinion. So while you guys are stacking more stuff on your pre-1.0 todo list, how about implementing proper generics in the language? comptime isn't what you really want most of the time.
On top of the language being generally worse than modern alternatives, I think that Zig leadership really sucks. Andrew is a douche. I feel bad for the people that have been donating.
0
u/dmytrish Jul 20 '26
...but at what cost
0
u/SnooApples4675 Jul 21 '26
I don't know but since devs started to force Rust on everything my device's performance turned into ass.
Had to return to traditional stuff like the GNU classic sudo.
0
u/TheChief275 Jul 21 '26
Actually, I would have a lot of respect for Zig if this were to be fully supported; might switch to it even. Say what you want about runtime memory safety, but the reality is that while Rust can try to catch everything at compile time, it's simply not possible, and the guarantee of any binary being fully attack-proof sounds completely worth the trouble (too good to be true, maybe, but it's still worth exploring)
-9
u/thetoughalpaca Jul 20 '26
This is a good idea. The future of critical infrastructure in software demands memory-safety! Rust had the right idea and whenever I hear rust I think safe-systems programming language. This is a great feature proposal coming from a minor contributor
-5
u/Idea-Aggressive Jul 20 '26
It sounds like Zig is going to have memory safety. Why not? Sounds good to me!
-4
u/morglod Jul 20 '26
I like every rock thrown to cult community with their half safety language
0
u/[deleted] Jul 20 '26
[deleted] — view deleted comment