![]() I’m actually not sure where it’s getting 12% from? Īs far as I can tell that paper only tests the cost of adding runtime checks to detect signed integer overflow. I’d definitely bet against the median Rust program getting a 12% boost, or even 5%, from making signed integer overflow undefined. (So does C++20, btw.) Most of the weird per-architecture stuff is stuff you can't do in safe Rust, anyway - it's oddball pointers, or weird machine registers, etc. If you compile to a machine that doesn't do two's complement, Rust has to emulate two's complement. Rust is not doing different things on different hardware, except for a handful of types which are not available on some architectures. Undefined behaviour is stuff that your program is never supposed to do, on any implementation - often because there are optimisations the compiler writers want to perform that depend on the UB never happening. No, C++ has implementation-defined behaviour for stuff that is meant to be different per implementation. There is no such thing as a program which is accepted but where the compiler is expected to produce nonsense.Ī lot of the UB sections, I feel, shouldn't be thought of as pure UB (code may summon a demon), but rather were originally intended to be "different hardware requires different solutions, so this section is compiler defined" any accepted safe Rust program is either valid, or there is a compiler bug that needs to be fixed. One of the things they have written down is that safe Rust doesn't have UB - i.e. When the spec doesn't say something, whether in C++ or Rust, you still have to go ask about it. When you think the compiler is doing something wrong, you ask the people who sit around deciding what the compiler should do.Īll a spec does is shortcut the "asking the people defining the language what they think" part, because they've already written down what they think. It has a compiler, and it has a bunch of people who sit around deciding what the compiler should do. Maybe it would have been cool to have "Unsafe signed integer" types w/ undefined overflow behavior (at the expense of requiring unsafe).Īnyways! Would anyone have historical references to the discussions that led to this outcome? In a language like Rust, surely having SIO be UB would force signed integer operations to require unsafe blocks - and that sounds like an ergonomic burden. This enables powerful optimizations (and footguns galore). Instead, if overflow occurs, Rust performs two’s complement wrapping.Ĭ++, in staunch contrast, specifies SIO to be undefined behavior (UB). When you’re compiling in release mode with the -release flag, Rust does not include checks for integer overflow that cause panics. ![]() The Rust Book states that Rust has well-defined semantics for signed integer overflow (SIO): When you’re compiling in debug mode, Rust includes checks for integer overflow that cause your program to panic at runtime if this behavior occurs. We'll do our best to keep these links up to date, but if we fall behind please don't hesitate to shoot us a modmail.įoreword: I'm sure there are mistakes in my conception of things, please provide corrections. This is not an official Rust forum, and cannot fulfill feature requests. Err on the side of giving others the benefit of the doubt.Īvoid re-treading topics that have been long-settled or utterly exhausted. Please create a read-only mirror and link that instead.Ī programming language is rarely worth getting worked up over.īe charitable in intent. If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Post titles should include useful context.įor Rust questions, use the stickied Q&A thread.Īrts-and-crafts posts are permitted on weekends.Ĭriticism is encouraged, though it must be constructive, useful and actionable. ![]() For content that does not, use a text post to explain its relevance. Posts must reference Rust or relate to things using Rust. We observe the Rust Project Code of Conduct. ![]() Strive to treat others with respect, patience, kindness, and empathy. Currently, basic arith operations can overflow during folding.Please read The Rust Community Code of Conduct The Rust Programming LanguageĪ place for all things related to the Rust programming language-an open-source systems language that emphasizes performance, reliability, and productivity. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |