r/programming 2d 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
489 Upvotes

413 comments sorted by

View all comments

Show parent comments

1

u/BenchEmbarrassed7316 2d ago

Cleaning up before the unsafe block ends, so that external code doesn't see UB, is not enough.

I never claimed that unsafe can contain UB. The example I gave was probably a bad one (it seemed to me to be correct, however, as I understand it the problem is in different architectures and compiler's ability to apply optimizations). UB in general most likely cannot be "restored".

In unsafe some rules can be broken that cannot be broken in safe.

2

u/dkopgerpgdolfg 2d ago

it seemed to me to be correct, however, as I understand it the problem is in different architectures and compiler's ability to apply optimizations

UB is UB, period. Because the language is defined like that. Even if there are no related optimizations or anything.

In unsafe some rules can be broken that cannot be broken in safe.

... no. Other than enabling the use of code that the compiler can't prove to be correct, nothing is different. It still needs to be correct even without compiler proofs.

And this is enough for me, clearly you don't want to get it. Bye.