7 ms·
'Book' seems a grand title for what could essentially fit in a long blog post? One thing I've been wondering recently is in relation to Rust's overhead for dyna
by anonymousDan 6y ago
'Book' seems a grand title for what could essentially fit in a long blog post? One thing I've been wondering recently is in relation to Rust's overhead for dynamic bounds checks. I know in many cases these can be avoided/elided (e.g. using iterators), but are there any common cases where this isn't possible? Or alternatively where convincing the compiler to remove them introduces a significant amount of complexity?
- gameswithgo 6y agowhen iterators can’t be used and llvm can’t elide you can use unsafe to elide by hand. the scenarios where the performance matters and iterators can’t be used are thankfully pretty rare so not much unsafe has to be used for this reason.
- vbezhenar 6y agoIs there any way to treat bounds check as a warning to eliminate it early?
- gameswithgo 6y agonot globally no. isolating that kind of behavior to unsafe blocks is a priority to make it easier to audit. if you wanted globally unsafe memory C or Zig would be a more sensible choice
- staticassertion 6y agoA nice method I've found (and seems popular) is to use unsafe but use a debug_assert!. That way your tests will fail loudly if you hit the assertion, but you won't take a hit in production.
- __s 6y agoBook is what this site layout is called in the community, see also: Rust Book: https://doc.rust-lang.org/book https://doc.rust-lang.org/book Rust Rand Book: https://rust-random.github.io/book https://rust-random.github.io/book Rust WebAssembly Book: https://rustwasm.github.io/book https://rustwasm.github.io/book Rust Unstable Book: https://doc.rust-lang.org/beta/unstable-book/index.html https://doc.rust-lang.org/beta/unstable-book/index.html Rustonomicon: https://doc.rust-lang.org/beta/nomicon/index.html https://doc.rust-lang.org/beta/nomicon/index.html Cargo Book: https://doc.rust-lang.org/cargo https://doc.rust-lang.org/cargo Which seems to be generated by https://github.com/rust-lang/mdBook https://github.com/rust-lang/mdBook Now, I don't see why "book" should seem so grand. Remember when reference books would come out as a "bible"? As for bounds check, here's a relevant issue raised on rand crate: https://github.com/rust-random/rand/issues/592 https://github.com/rust-random/rand/issues/592 One can dig for a kind of "unsafe assertions" with https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.... (so the random code, for example, could have before returning value 'if x >= upper { unsafe { unreachable_unchecked() } }')
- trevyn 6y agoYep. I'll also add that "books" are typically used for higher-level, more narrative pieces of documentation, vs the API-level `rustdoc`-generated documentation.
- anonymousDan 6y agoThanks for the links. If the intention is to expand over time then I agree it makes sense.
- nicoburns 6y agoIf you're really convinced that it's safe to elide them and you can't get it to work using iterators or asserts then you can use `unsafe` to bypass the checks. But I don't think this is necessary in most cases.
- rkangel 6y agoThe expectation for a blog post is that it captures things at a single moment in time. To me, "book" implies something that will be continually updated and maybe expanded.
- staticassertion 6y agoStrange, I feel the opposite, just because of the medium that books tend to be written in - ink. To me a book has chapters, sequence, etc.
- rkangel 6y agoYes, it you get multiple editions of books over multiple years, whereas blog posts don't get continuously revised.