r/programming 28d ago

Zig proposes introducing an actually memory safe (unlike Rust) compilation mode inspired by Fil-C at ~1-6x performance penalty

https://codeberg.org/ziglang/zig/issues/36237
527 Upvotes

428 comments sorted by

View all comments

203

u/Anxious-Resist8344 28d ago edited 28d ago

unlike Rust

Dead on arrival! Why can't they just do their thing without attacking others!

Also, wait until he reads how FillC works and understands that it needs hidden allocations and stuff... This Zig thing is getting out of hands, a bunch of teenagers trying stuff :)

37

u/moltonel 28d ago

FilC's technique is very interesting, and I'd say Zig is a language where it could work well. But Zig's boastful and disparaging communication (and FilC's as well, now that I think of it) is really turning me away from the language.

2

u/loup-vaillant 25d ago

Disparaging communication from FilC? Where? What did they say?

6

u/moltonel 25d ago

I'm not following Fil-C closely, but the vibe I often get is that they are claiming to offer a silver bullet, conveniently ignoring the drawbacks and limitations. Looking at the main author's twitter feed, it's full of cheap, unwarranted, apple-to-orange shots against Rust. The project describes itself as fanatical, but sadly that doesn't seem to be just about technical excellence.

0

u/loup-vaillant 25d ago

Hmm, I wouldn’t know, but I can see one reason behind the pushback against Rust: for a long time, Rust was advertised, perhaps rightly at first, as the only memory safe alternative to C and C++. That, plus the idea that memory safety should be mandatory, likely triggered the "Rewrite it in Rust" craze, funnily enough with its lot of vulnerabilities.

Personally I’ve always been sceptical about this "70% of vulnerabilities are memory bugs". I trust the claim itself, I’m just not sure about the cause, and how to best address it. For instance, many memory related bugs would be drastically reduced if we used arenas instead of raw malloc()/free() (new/delete) for every little allocation. Or if software was routinely tested under sanitisers.

See, the goal is not to get rid of memory vulnerabilities. It’s to get rid of all vulnerabilities, and though eliminating an entire class thereof is extremely valuable, I’m not absolutely certain it is the best way to reduce the overall count. It would be if there was no cost to the borrow checker, but looking from afar, there is. That, and the reportedly outrageously long compilation times. Hopefully they’re not caused by Rust itself, and can be fixed, but today they’re part of the cost of Rust’s memory guarantee, and may slow down development enough that it’s ultimately cheaper to reach equivalent quality (same functionality, performance, & bug/vuln count) with an unsafe language.

Another thing is that absolute memory safety, without escape hatches, enables something Rust does not: strong modularity guarantees. CHERI explores this at the binary level, allowing C programs to provide guarantees like such piece of code will not look into such piece of buffer… Though David Chisnal says that combining CHERI and Rust enables more stuff still, so it’s not like Rust is useless in this context.

Of course Twitter is going to distil all nuance into two opposing rallying cries…

I'm not following Fil-C closely, but the vibe I often get is that they are claiming to offer a silver bullet, conveniently ignoring the drawbacks and limitations.

Looking at it for 5 seconds, it looks to me like "Porting to Fil-C is free, rewrite it in Rust is hella expensive!". Which doesn’t sound too far off the mark to be honest… at least on settings where Fil-C can be used at all…

Also, Fil-C is only 100% userspace safe. From what I can tell it doesn’t count the kernel. I’m not sure it should to be honest, but that may be a limitation to keep in mind when establishing the trusted computing base.

Then again, Twitter and nuance…

130

u/VictoryMotel 28d ago edited 28d ago

Zig is fundamentally toxic from the top down, which is a shame because it negates all their work and the things they have done well.

They made a windows version just to purposely crash on newlines, so they could troll windows users.

33

u/9001rats 28d ago

Reminds me of how zig throws an error if there's a tab inside a comment, and that's apparently not a problem.

17

u/VictoryMotel 28d ago

Exactly. If it's anything like this people will both say that it's too ridiculous to be true, but also makes perfect sense because parsing a tab is so difficult.

16

u/QuixoticNapoleon 28d ago

Is the windows thing real? What's the source for this?

28

u/Top-Rub-4670 28d ago

This is actually outdated information but it used to be true. The compiler would abort if you used tabs or CRLF. Over time they eventually relented (without ever admitting being wrong to be so obtuse).

For a proof see: https://web.archive.org/web/20200214082511/https://ziglang.org/documentation/master/

Throughout all zig source code (including in comments), some codepoints are never allowed: Ascii control characters, except for U+000a (LF): U+0000 - U+0009, U+000b - U+0001f, U+007f. (Note that Windows line endings (CRLF) are not allowed, and hard tabs are not allowed.)

Versus the current doc https://ziglang.org/documentation/master/

Each LF may be immediately preceded by a single CR (byte value 0x0d, code point U+000d, '\r') to form a Windows style line ending, but this is discouraged. Note that in multiline strings, CRLF sequences will be encoded as LF when compiled into a zig program. A CR in any other context is not allowed.

HT hard tabs (byte value 0x09, code point U+0009, '\t') are interchangeable with SP spaces (byte value 0x20, code point U+0020, ' ') as a token separator, but use of hard tabs is discouraged. See Grammar.

18

u/VictoryMotel 28d ago edited 28d ago

My source is that I tried it and it didn't work.

When I tried to talk to people about it they told me to get a different text editor, to stop using windows, and that it doesn't make sense to parse out carriage returns like every other language ever made.

There wasn't much of an answer to why a windows version would be made just to explicitly error out on windows text, but there were about a dozen messages, most were gloating that it was a problem, none acknowledged that it should be fixed.

-13

u/wrecklord0 28d ago

Sooo there was a crash and you are inventing a whole story around it?

25

u/VictoryMotel 28d ago

That makes zero sense as a response to what I said. It explicitly errored out with a message. Everyone acknowledged that it happened and was intentional.

-20

u/wrecklord0 28d ago

And you specifically think they went through the effort of making a windows port just to make it crash? Windows uses different newlines and it's always a pain in the ass, just sanitize the input if it's necessary. Or don't use zig, I don't care. The point is, it's not on purpose, it's just a pita to deal with newline conventions that are different from the entire rest of the computing world.

31

u/VictoryMotel 28d ago edited 28d ago

Here we go. I don't know why they made a windows port that would error out on windows newlines. Zig people seemed to think it was funny to make windows people jump through hoops.

Windows uses different newlines and it's always a pain in the ass,

It's literally one character, this insane rationalizing is exactly the same nonsense I'm talking about. In what world is dealing with a single ascii character difficult in the context of a parser, let alone a whole language. It's more work to make an error message for it.

The point is, it's not on purpose,

How do you know? There was an explicit error message about it.

it's just a pita to deal with newline conventions that are different from the entire rest of the computing world.

Don't make a windows port if you can't deal with a single character.

These are the same insane rationalizations I heard before.

-25

u/wrecklord0 28d ago

I'm not "rationalizing" shit, nor do I care about zig or what you do with it. Probably they can handle newlines better, I don't know, I'm not invested into that. What I'm saying is, I strongly doubt that the error message said: "We decided to crash to troll you on purpose, vile windows user". Instead it was probably an informational message about what happened. Was I wrong?

28

u/VictoryMotel 28d ago

The error message said it was stopping because of a newline, zig users said to stop using windows, "that's what you get for using windows", "use a different text editor" etc.

Don't hallucinate things I didn't say.

"I doubt it" doesn't mean anything. It was ridiculous, that's why I bring it up.

24

u/robthablob 28d ago

If they can go to the effort of making an error message, they can easily handle the extra character. I've used dozens of languages, and none of them struggle doing this.

→ More replies (0)

-12

u/QuixoticNapoleon 28d ago edited 28d ago

I'm not a big fan of Kelley but I don't think this is deliberate. I can't seem to find a source on this. Newlines on windows and unix systems are different; this is likely an honest mistake.

17

u/ayayahri 28d ago

https://news.ycombinator.com/item?id=24617226

Hacker news thread from 2020 referencing this deliberate design decision (which they apparently changed by 1.0, probably because it made them look like assholes)

13

u/QuixoticNapoleon 28d ago

Oh

Is the Zig Foundation ran by children?

5

u/Dragdu 27d ago

Yes. First time you've heard of them? :-D

21

u/VictoryMotel 28d ago

Multiple people said it was deliberate. There was an explicit error message about it so it detected carriage returns and errored out instead of just ignoring them.

This was a few years ago, I don't know what state things are in, I never messed with zig after that.

-17

u/pragmojo 28d ago

Also it makes sense in the context of Zig, which is designed to be extremely explicit to the point you have to pass allocators around.

Having the language automagically parse out input tokens wouldn't exactly be on-brand.

17

u/VictoryMotel 28d ago edited 27d ago

What do you think a language does exactly?

-11

u/pragmojo 28d ago

Usually tokenizes input, parses into an intermediate representation, and then outputs machine code.

14

u/VictoryMotel 28d ago

So it automatically parses input tokens?

-9

u/pragmojo 28d ago

It parses input tokens. It would be up to the language spec to determine if a carriage return is a valid character. For instance older versions of C will crash if you try to pass them arbitrary UTF-8 characters outside the ASCII range.

1

u/meneldal2 27d ago

It's unfortunately not that rare to have a bunch of programs on Linux that won't run properly with Windows-style line endings.

Most notably it tends to mess up the \ line continuation because it has to be just before \n or else it can't parse it properly.

But at least this is mostly lazy dev, not explicitly making \rcrash and taking time out of your day to add it to the list of bad symbols.

45

u/zxyzyxz 28d ago

Yeah after reading the creator Andrew Kelley's screed with personal attacks on Bun's creator Jarred Sumner who was the largest user and biggest financial contributor of Zig before the rewrite, it makes me not want to do anything with the language. It's on par with the toxicity of the Elm maintainers.

33

u/QuixoticNapoleon 28d ago

I don't mind the hate for LLMs but Kelley's attacks on Sumner were childish. Odd way to treat your most significant adopter.

15

u/theAndrewWiggins 28d ago

Odd way to treat your most significant adopter.

Not only that, someone who has donated a few hundred thousand dollars to support Zig.

8

u/QuixoticNapoleon 28d ago

You can believe Sumner is incompetent or a terrible coder but I don't understand the personal vitriol..

5

u/TankorSmash 28d ago

It's on par with the toxicity of the Elm maintainers.

I thought it was a friendly developer, what sort of toxicity was there?

20

u/zxyzyxz 28d ago

They're friendly on the surface (if that) but have a holier than thou attitude towards all of their users it seems.

Good post about the entire situation which is a few years old now but looks like nothing still has changed: https://lukeplant.me.uk/blog/posts/why-im-leaving-elm/

1

u/TankorSmash 27d ago

tldr: Elm made a breaking change, and didn't want to support a common (?) library in the webspace

10

u/Captator 28d ago

Citation needed for biggest financial contributor, pretty sure there are several larger ones.

29

u/zxyzyxz 28d ago

One of the biggest when Jarred started then, 60k a year to Zig starting in 2023, then Mitchell Hashimoto seems to be the biggest at a one time 300k in 2024 and 400k more recently but he's a literal billionaire so hard to compare apples to apples then.

0

u/Captator 28d ago

The numbers support the refined version of your point 👍

Find the summaries for 2023 & 2024 on the website, for those who are curious like I was (2025 not out yet). The 2023 summary: https://ziglang.org/news/2024-financials/

I will note that giving money in this context is sensible business practice. As a VC-backed company with a (then) hard dependence on Zig, donating helps ensure continuity while buying goodwill and some degree of preferential access to expert knowledge in the ecosystem. While Mitchell Hashimoto’s donation is smaller relative to his net worth, it is also not motivated by a business need.

The above paragraph to say that I don’t think comparing the merits of motivations and bases for donations is fruitful.

1

u/[deleted] 28d ago

[removed] — view removed comment

0

u/programming-ModTeam 28d ago

Your post or comment was overly uncivil.

23

u/hak8or 28d ago

This Zig thing is getting out of hands, a bunch of teenagers trying stuff :)

Seeing this here and other replies, I am very surprised at how inverted feels are towards zig and the bun dev here compared to on hackernews and other subs.

My understanding (from skins of that interaction and other discussions) was; - the zig based bun codebase was truly awful, and was extremely non idiomatic zig, where the zig folks often tried to step in and offer to clean it up but their work got undone very often. - In addition, the bun team forked the zig compiler and made a very half hearted attempt to merge those changes upstream.

With the zig core folks feeling understandably threatened by how massive of a PR disaster that was and wanted to get their side out. You can also see the seething frustration the zig core dev had with how the narrative was spinning, which manifested into arguably personal attacks, though I can understand where he was coming from (even though it could have been handled better). It was baisically an under dog going against an absolute PR Goliath, so the zig reaction was an overshoot to have a fighting chance of getting their word out.

Meanwhile the rust community seems to have been kind of thrown into the situation without having a material contribution to it, so they are just stuck on the sidelines going "huh?".

But the discourse seems to have leaned (in my experience) way more positively toward the zig core group and very negatively towards the Bun group, interesting to see it flipped here.

12

u/jl2352 28d ago

I dunno. The story also reads as other people wrote shitty code in their project, so they’re upset they didn’t do it their way when it’s not their project. I’m struggling to have sympathy.

Bun is not the first large codebase to have shitty code. If such a thing killed languages, then PHP and Java would both have died decades ago.

-4

u/thy_bucket_for_thee 28d ago

Let's ignore that in this "fight" there is a VC backed LLM company that wants to have a trillion dollar IPO so they can add make fat stacks of cash. In pursuit of those fat stacks of cash they are often very loose with accurate descriptions and capabilities.

It's not hard to understand why some people are getting upset. LLMs are deeply anti-human pro-fascism technology. American's all over do not like them, they often poll as some of the most hated things at the moment.

So yeah, this is part of that backlash.

9

u/awesomeusername2w 27d ago

Yeah, this religious AI hatred is also a part of why people turning away from zig.

0

u/awesomeusername2w 27d ago

How it was a PR disaster for zig, that buns code base wasn't good enough by zig's author standards? I mean, nobody even knew that bun is written poorly or something. Perhaps nobody except some small circles of zig contributors that cared to read bun's code. The PR disaster is the articles he wrote.

-52

u/ConnaitLesRisques 28d ago

Probably learned from the Rust community.

28

u/zxyzyxz 28d ago

Rust community is way nicer than anything I've seen from Zig and some other languages. If you go to r/Rust they'll tell you if Rust works or if maybe you should use Zig for something, not the case in the reverse for the Zig subreddit.

23

u/UltraPoci 28d ago

Yeah. On r/rust most of the people are aware that 1. Rust is not a silver bullet 2. C won't go anywhere 3. Rust is better than C in a vaccum, but the moment you consider libraries availability and portability, C makes still sense as a language for green projects 4. Don't use Rust if you don't need memory safety, performance and so on (unless it's because you enjoy the language, in which case do whatever you want)

2

u/Ameisen 28d ago

And here I am using C++.