News for hackers. Stuff that matters.
Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @01:49PM (#31054380)
And as we know from C, every developer is quite capable of taking care of use after free possible bugs.
Re:Zig self hosted compiler is now capable of building itself by Comevius on Saturday April 16, 2022 @02:50PM (#31054985)
The point of C and Zig is that you can solve any kind of problems with them. In particular there is much more to memory reclamation than garbage collectors or Rust's borrow checker. Some of the reclamation schemes offer wait-freedom, or efficiently support linearizable operations.
Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @03:02PM (#31055099)
Any kind of problem?

So how do you solve SIMD with C, without language extensions?

C is not a special snowflake.

Re:Zig self hosted compiler is now capable of building itself by Comevius on Saturday April 16, 2022 @04:01PM (#31055613)
SIMD is not a problem, it's hardware. Compilers tend to take advantage of the CPU-specific SIMD registers and instructions, or you can use them explicitly.

Writing generic SIMD code is more portable. C has libraries, and Zig also has vector primitives available through built-in functions.

Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @04:14PM (#31055716)
Any language can have libraries, C is not special here, nor is Zig.

In fact, a few GC enabled languages have explicit SIMD support.

Re:Zig self hosted compiler is now capable of building itself by turminal on Saturday April 16, 2022 @03:15PM (#31055193)
Are there languages that "solve" SIMD?
Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @04:13PM (#31055704)
Re:Zig self hosted compiler is now capable of building itself by sitkack on Sunday April 17, 2022 @06:06PM (#31064932)
Re:Zig self hosted compiler is now capable of building itself by maleldil on Saturday April 16, 2022 @04:29PM (#31055823)
What can C and Zig do that Rust can't?
Re:Zig self hosted compiler is now capable of building itself by Comevius on Saturday April 16, 2022 @04:49PM (#31055979)
Nothing if unsafe Rust is considered, though Zig does not require you to fight the language nearly as much. This is especially obvious with embedded. Zig's philosophy of no hidden control flow or allocation makes things simple. Simplicity is power.

For certain problems you would want a TLA+ specification for safety and especially liveness either way. It's not like Rust absolutely guarantees correctness in all cases.

Rust sits in a sweet spot between C/Zig and languages like Java, but it's not an appropriate replacement for either of them.

Re:Zig self hosted compiler is now capable of building itself by 3a2d29 on Saturday April 16, 2022 @11:24PM (#31058188)
Certainly Rust sits where C++ is. Zig and Rust are definitely best used for different things, but I think sweating rust off as in between C and Java is inaccurate.
Re:Zig self hosted compiler is now capable of building itself by politician on Saturday April 16, 2022 @05:53PM (#31056428)
This is kind of a trick question because they are all Turing Complete, but so is Assembly. The best way to interpret your question, then, is not “what is possible” but rather “what is simple to express correctly” and “what is simple to get correct eventually”. Those are questions about how tricky it is to get something to compile in the language and which tools exist to help determine whether a compiled program does what’s expected and does not do what’s not expected.
Re:Zig self hosted compiler is now capable of building itself by maleldil on Monday April 18, 2022 @02:10PM (#31074346)
It wasn't a trick question. I'm not asking it in the same tone as someone would ask 'What can C do that Java can't?'.

I believe that Rust can be as low level as you want. If you have to fight the language to accomplish something, it's because you're probably trying to do something unsafe, and Rust will let you do that if you pay the price.

I was looking for examples of real cases where Zig is a better option than Rust. And while Zig is a lovely language, its main points against Rust are that it lets you do unsafe things more easily, and it's easier to learn.

Re:Zig self hosted compiler is now capable of building itself by messe on Saturday April 16, 2022 @02:20PM (#31054703)
The general purpose allocator in the zig standard library has protections against use after free bugs.
Re:Zig self hosted compiler is now capable of building itself by pcwalton on Saturday April 16, 2022 @04:07PM (#31055660)
By quarantining all memory forever. This is not a scalable solution because keeping one allocation in a 4kB page alive will leak the whole rest of the page. And if you don't quarantine all memory forever then use after free comes back. If it were that easy to solve UAF then C++ would have solved it by now.

There is a scalable solution for UAF that doesn't involve introducing a lifetime/region system: garbage collection. Of course, that comes with its own set of tradeoffs.

Re:Zig self hosted compiler is now capable of building itself by AndyKelley on Saturday April 16, 2022 @04:41PM (#31055915)
The problem of a single allocation keeping a 4 KB page alive is something that you might commonly find with the C++ or Rust way of programming that encourages allocating many individual objects on the heap, but in Zig land this is pretty rare. In fact, compare a Zig implementation of a given application with an equivalent in any other language and you will find there is no contest with respect to the size of the memory footprint.

There are many cool possibilities that C++ has never explored and frankly I find your argument unimaginative.

Re:Zig self hosted compiler is now capable of building itself by pcwalton on Saturday April 16, 2022 @11:15PM (#31058149)
An allocator that can leak (4kB - epsilon) of memory for each allocation is broken. It's not a question of whether the language makes such allocations unusual: free() not actually allowing memory to be freed is a violation of the contract of a memory allocator.

From the man page (which I believe quotes ISO C): "The free() function shall cause the space pointed to by ptr to be deallocated; that is, made available for further allocation." If free doesn't do that because another allocation is pointing into that page, that's a violation of the contract. Standard quarantine doesn't violate the spec because the space will eventually become available no matter what, but perpetual quarantine does.

One way to fix the problem would be to round up all allocations to 4kB, but that's very wasteful and slow due to cache and page table traffic; you'd be better off from a performance point of view with a garbage collector. More promising is ARM MTE, though the tag is currently too small to really be called a solution to UAF as opposed to a mitigation. A 64-bit tag would be enough, but I'm not sure what the performance costs of that would be--I wouldn't be surprised if the increased memory traffic makes it slower than a GC.

Re:Zig self hosted compiler is now capable of building itself by gnuvince on Sunday April 17, 2022 @08:12AM (#31060320)
> way of programming that encourages *allocating many individual objects* on the heap

Quoting and bolding. I think this is the thing that I need to change most about my own style of programming.

Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @02:34PM (#31054834)
Just like C and C++ debugging allocators, so what is the improvement here?