Hacker News new | ask | show | jobs
by _flux 53 days ago
I think the difference is here:

- If a compiled C++ program has unsound behavior, the program needs to be fixed

- If a compiled safe Rust program has unsound behavior, the compiler needs to be fixed

4 comments

> - If a compiled safe Rust program has unsound behavior, the compiler needs to be fixed

Not really: the program still needs to be fixed, but fixing the compiler ensures that this unsound behavior never happens again to anyone. So you have two bugs to solve (vs C++'s one bug) but then you kill an entire class of unsoundness bugs just by recompiling.

That's not completely correct. If the Rust or C++ compiler has a bug in both cases either the compiler has to be fixed or the program can be adjusted to work around said compiler bug If possible. However, It's fair to argue that the Rust compiler makes more assertions and is more complex, which results in a larger error surface.
Which is better, surely? One fix for every program written in Rust vs everyone having to fix it themselves…
> If a compiled safe Rust program has unsound behavior, the compiler needs to be fixed

Can you provide an example of such a program that can’t be fixed at the program level like a C++ example?

Sure, usually the program can be changed to avoid the issue, but the key here is that the Rust compiler is wrong and needs to be fixed. Once fixed, the actual program fix also falls in place, as it cannot be compiled anymore.
That's the same kind of issue like a bug in a C++ compiler.
The average cause of unsoundness in a C++ program is not a C++ compiler bug
This is about an issue in the type checker, which would lead to unsoundness also in a C++ program. And also in Rust most causes of runtime failures are actually things that happen in `unsafe` blocks.
Yes, we're discussing though in safe (non-unsafe/normal) Rust here. There is no safe C++, everything in C++ is unsafe by default. Even more unsafe than Rust unsafe, because Rust unsafe still does a lot of the safety measures of normal Rust, but allows only a handful extra things and doesn't disable the borrow checker:

https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html

But getting back to the point, the C++ compiler doesn't have a borrow checker, so it can't have a bug in it. So it's on you, as the developer, to take care of all unsoundness.

While in Rust an issue is now filed, and with the fix, every future Rust program gets the fix.

That’s not an example, that is you restating your post.
I don't find that anyone made a claim that the program could not be fixed. Why are you suggesting to find a proof of this?

The point of course was not that what you can do, but what you should do. All cases of safe Rust compiler producing unsound code should be fixed, but the same argument is more difficult to make for C++.

Sometimes should might be different of what you must. For example, if your program exhibits unsound behavior in safe Rust (or C++) code, it's probably a lot more practical to just change the program so that it doesn't, instead of updating the compiler, unless you happen to be a Rust compiler developer. But, at the same time, you should file an issue about it.

You can of course find C++ compiler bugs as well, although I expect that to be quite rare nowadays. But the typical case is that if a C++ program exhibits unsound behavior, there is no reasonable compiler fix for it.

Then there's of course Fil-C! This improves the situation greatly by converting most interesting cases of unsound behavior into runtime errors. It seems not everyone is happy with the runtime costs of making this happen, though. And you must compile everything with Fil-C. It doesn't work with Windows or MacOS either.

Your shoulds and musts are nice and all but you said that in these situations, the rust compiler needs to be fixed when the C++ program can be adjusted.

I simply cannot imagine a situation where you can’t find an alternate solution to a problem with the compiler. Even if the compiler would optimize your intended solution away, you can write an asm! macro.

It sounds to me like you have simply decided that one language cannot do what the other can because you personally would not do it, which is very silly.

If this is not the case then I restate my request for an example, for the third time - an example would prove the point you are not making through explanation.

I suggest you point the exact statement where I claimed the corresponding safe Rust program is impossible to fix to avoid unsound behavior.

I hold the argument that if the Rust compiler produces unsound behavior for safe Rust, then the compiler needs to be fixed.