5 ms·
> What does "undefined behavior" mean without a spec? While not as formalized as C/C++, Rust's "spec" exists in the reference, nomicon, RFCs and documentation.
by mmastrac 2y ago
> What does "undefined behavior" mean without a spec?
While not as formalized as C/C++, Rust's "spec" exists in the reference, nomicon, RFCs and documentation. I believe that there is a desire for a spec, but enough resources exist that the community can continue without one with no major negative side-effects (unless you want to re-implement the compiler from scratch, I suppose).
The compiler may exploit "lack of UB" for optimizations, e.g., using a known-invalid value as a niche, optimizing away safety checks, etc.
> Wouldn't the behavior rustc produces today be de-facto defined behavior?
Absolutely not. Bugs are fixed and the behaviour changes. Not often, but it happens.
This post probably answers a lot of your reply as well: https://jacko.io/safety_and_soundness.html https://jacko.io/safety_and_soundness.html
- NoTeslaThrow 2y agoEDIT: > While not as formalized as C/C++, Rust's "spec" exists in the reference, nomicon, RFCs and documentation. I believe that there is a desire for a spec, but enough resources exist that the community can continue without one with no major negative side-effects (unless you want to re-implement the compiler from scratch, I suppose). Thank you, I was unaware that this is a thing. > This post probably answers a lot of your reply as well: https://jacko.io/safety_and_soundness.html https://jacko.io/safety_and_soundness.html This appears to also rely on "undefined behavior" as a meaningful term.
- mmastrac 2y ago> This appears to also rely on "undefined behavior" as a meaningful term. I assure you it is a meaningful term: https://llvm.org/docs/UndefinedBehavior.html https://llvm.org/docs/UndefinedBehavior.html
- NoTeslaThrow 2y agoOk, but in the context of the language at hand? Presumably the IR has distinct semantics from the language that generates the IR. Does UB just strictly resolve to LLVM UB? That's very reasonable!
- fc417fc802 2y agoNo. UB is a term of art here. Consider a hypothetical non-LLVM full reimplementation of the compiler. If it optimizes and there are invalid assumptions then there is likely UB. LLVM isn't involved in that case though.
- NoTeslaThrow 2y ago> If it optimizes and there are invalid assumptions then there is likely UB. It's the distinguishing from bugs that concerns me.
- lmm 2y agoAnything a compiler does with code which is UB is not a bug in the compiler. That's pretty much the definition of UB.
- fc417fc802 2y agoI don't follow. Isn't UB a subset of bugs or alternatively a follow on consequence that causes observable behavior to further deviate?
- NoTeslaThrow 2y ago> Isn't UB a subset of bugs No, not at all. UB can still produce correct and expected results for the entire input domain.
- fc417fc802 2y agoIf I have a bug that only triggers between 9 and 10 am EST on Mondays that is still a bug, no? Now extend that to "rand(1.0) < 0.01". Now extend that to a check using __TIME__ that goes off at compile time instead of runtime (some binaries are buggy, some aren't). Now extend that to UB.
- deleted 2y ago[deleted]