Submitted by joshadel t3_zaqbwr in MachineLearning
Desperate-Whereas50 t1_iyqiqqi wrote
Reply to comment by Craksy in [D] PyTorch 2.0 Announcement by joshadel
>However, using unsafe does not necessarily mean UB. You preferably want to avoid that regardless.
>Unsafe code simply means that you are responsible for memory safety, not that it should be ignored.
Maybe I am wrong but I think you misunderstand UB. Of course you want to avoid UB and have memory safety in your code/executable because otherwise you can not argue about the program anymore. But you want UB (at least in C/C++ the language I work with) in your standard. UB is more like a promise of the programmer to not do specific things. The compiler assumes the code contains no UB and optimizies like that. See for example signed integer overflow. Because the compiler knows this is UB and the programmer promised to not allow it he can use better optimizations. Rust does not have this "feature" in safe blocks and produces less optimal code.
>And UB is not the only way a compiler can optimize.
I would not disagree about that. But if you want the last .x% of performance increase than you need it too. Especially if you want your language to work on different systems. Because even Hardware can have UB.
The only other option (as far as I know) you have to get some comperable (with UB assumption) performance is to rely on other assumptions like functions have no side effects etc.
>I don't know, you're talking about UB as if it was a feature and not an unfortunate development of compilers over the years.
As language specification it is like a feature. In the binary it is a bug. I have read enough discussions of UB in C++ threads to know that a lot of C++ developers dont see UB as unfortunate development of compilers.
>In fact, Rust made it very clear that if you rely on UB that's your pain.
By the way this is the sentence why I think you that you misunderstand UB. As mentioned: You should never rely on UB you promised the compiler to avoid it. And by avoiding it the compiler can work better.
Viewing a single comment thread. View all comments