9 ms·
Announcing Rust 1.28
- azhenley 8y agoA summary of what is new: - Global allocators - Improved error message for formatting: provides a specific reason why it is invalid - Library stabilizations: NonZero number types - Changes to Cargo: src directory can not be modified
- egnehots 8y agoGlobal allocators are nice, but what would be really helpful in some performance intensive applications is to specify an allocator for a collection.
- steveklabnik 8y agoThat work relies on this work; that's coming!
- masklinn 8y agoGlobal allocators is the first step to instance-wise allocator selection.
- doctor_stopsign 8y agoI have to say, the Rust compiler's commitment to nice error messages makes it a pleasure to work with. It is also cool to hear about the GlobalAllocator trait stabilization. I'll have to check out what the embedded-Rust space has been doing in this area!
- k__ 8y agoYes, it's nice to see improvemed error messages. I read many people loathed what the borrow checker threw at them.
- steveklabnik 8y agoI'd like to mention that along those lines specifically, a lot of people have talked about NLL in terms of "the borrow checker accepts more of my code", but it also produces way better errors. See the "Diagnostics" section of http://smallcultfollowing.com/babysteps/blog/2018/06/15/mir-based-borrow-check-nll-status-update/ http://smallcultfollowing.com/babysteps/blog/2018/06/15/mir-... for an example that I ran into in real code. (It's niko's blog but I supplied him with this example)
- k__ 8y agoI think pouring more time and money into the error messages will pay out in the long run. Messages like that make coding low-level stuff fun again.
- ronjouch 8y agoGood times! And to those that like me enjoy a good dead trees-based book to learn a language, the Rust Book (from NoStarch publishing) arrived yesterday at my door :) https://nostarch.com/Rust https://nostarch.com/Rust
- wyldfire 8y agoI've been reading the O'Reilly book but I'll look at TRPL next. BTW I'm read this on Safari: Steve, do you know how publishers/authors get compensated for Safari books? Are there just normal royalties or is it somehow negotiated in a bulk rate? EDIT: Steve answers a semi-related question in [1] [1] https://www.reddit.com/r/rust/comments/8u0ggw/trpl_is_releasing_on_amazon_without_customer/e1bwffl/ https://www.reddit.com/r/rust/comments/8u0ggw/trpl_is_releas...
- steveklabnik 8y agoYeah, I don't happen to know, as I'm not being paid for this book :) None of the other books I've worked on have been on Safari, or at least, if they are, I've never seen a breakdown of the (not large, mind you) payments that described that.
- clumsysmurf 8y agoThanks for not using Safari — I cannot afford it ;)
- cschmidt 8y agoI don't know how far in you are, but I would suggest reading TRPL first. I read the Programming Rust book first, but I found TRPL a much better introduction. I wish I had done them in the other order. Maybe read TRPL first, and then go back to PR.
- artificial 8y agoI completely agree and I did the same thing. I own dead tree variants of both and TRPL approach immensely helped grokking the language whereas the Programming Rust book feels more like a reference book for dives into concepts.
- ainar-g 8y agoI wonder, why is it NonZeroU8, NonZeroU16, etc instead of something like NonZero<u8>, NonZero<u16>, etc? In theory, in the future, when Rust supports constants as template arguments, one might even add a const argument, the value that should be used as "null". E.g. if my u8 never reaches 255, I could use something like Never<u8, 255>.
- Arnavion 8y ago>I wonder, why is it NonZeroU8, NonZeroU16, etc instead of something like NonZero<u8>, NonZero<u16>, etc? The RFC covers this. https://github.com/rust-lang/rfcs/blob/master/text/2307-concrete-nonzero-types.md https://github.com/rust-lang/rfcs/blob/master/text/2307-conc... Also see the RFC discussion at https://github.com/rust-lang/rfcs/pull/2307 https://github.com/rust-lang/rfcs/pull/2307 Basically the generic NonZero already existed, but it's hard to express safely when used with arbitrary user types. >In theory, in the future, when Rust supports constants as template arguments, one might even add a const argument, the value that should be used as "null". E.g. if my u8 never reaches 255, I could use something like Never<u8, 255>. This requires const generics, so it could happen when they're implemented. (This is also mentioned in the RFC discussion.)
- lmm 8y agoDoes "const generics" essentially mean singleton types?
- steveklabnik 8y agoThere are so many "slightly different but mostly the same" things in this space. In Rust, this is const generics: https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md https://github.com/rust-lang/rfcs/blob/master/text/2000-cons... struct RectangularArray<T, const WIDTH: usize, const HEIGHT: usize> { array: [[T; WIDTH]; HEIGHT], } const X: usize = 7; fn main() { let x: RectangularArray<i32, 2, 4>; let y: RectangularArray<i32, X, {2 * 2}>; } I haven't read enough about singleton types to know the exact details about their similarities, so I'm not sure.
- syn_rst 8y agoI'm pretty happy about the GlobalAllocator stabilization. Now you can run Massif and Heaptrack on rust code without switching to unstable!
- kibwen 8y agoNow that users can switch out the global allocator, the next step may be to change the default allocator for Rust programs from jemalloc (which, note, is only the default on some platforms) to the system allocator. This has been blocked on stable global allocator support in order to make sure that users who find that jemalloc is superior for their program have a recourse to avoid performance regressions; ideally switching to jemalloc (or tcmalloc, etc.) should be well-facilitated by Crates.io. As for the rationale behind moving away from jemalloc as a default, the tracking issue is here: https://github.com/rust-lang/rust/issues/36963 https://github.com/rust-lang/rust/issues/36963 (TL;DR: lower maintenance burden, easier cross-compilation, smaller binaries, better system integration (including packaging), and the ability to use Valgrind).
- nathell 8y agoWill it also shave off fifty-odd KB from executable size?
- steveklabnik 8y agoIt depends; for example, on Windows, we already do not use jemalloc, so you won't see any change there. I don't have a Linux box handy to find the exact size of the binary there, but it will be smaller, yes.
- sudeepj 8y agoIn case of FFI, if C & Rust are using the same allocator (say the system allocator), does it mean that memory allocated by C can be freed by Rust and vice-versa?
- sanxiyn 8y agoYes.
- dikaiosune 8y agoMany types in the standard library do not consider it sound behavior to have their allocations freed by functions other than their own destructors: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.into_raw https://doc.rust-lang.org/std/boxed/struct.Box.html#method.i... After calling this function, the caller is responsible for the memory previously managed by the Box. In particular, the caller should properly destroy T and release the memory. The proper way to do so is to convert the NonNull<T> pointer into a raw pointer and back into a Box with the Box::from_raw function. I would guess that this might become a fun latent footgun in crates.io code -- everyone writes their unsafe code in a way that Just Works under the default allocator, but then things break down in confusing ways when enabling alternative allocators, which should be safe to do even when using external crates.
- pedrocr 8y agoAfter two versions where performance has been unchanged I once again see a little bit of performance improvement with this version in my pet photo camera raw decoding benchmark. 1.28 is ~1% faster than 1.27 and nightly seems to be ~1% faster than 1.28 again. Don't know if there have been LLVM updates or if work on the rust compiler itself has helped. In total, since version 1.17 I'm measuring almost a 25% improvement in CPU intensive code. I need to make a more comprehensive benchmark easy to run by everyone (many different kinds of files, fully automatic running, etc).
- steveklabnik 8y agoDue to an upstream LLVM bug, we had to remove some information about aliasing; that bug was fixed and this was re-enabled in this release. That may be what you’re seeing.
- ChrisSD 8y agoThe NonZero type reminds me of something else I'd like to see in Rust; ranged integers. By which I mean integers that can only represent a specified range of numbers. This is not so much for optimization but for type safety (i.e. avoiding bugs).
- steveklabnik 8y agoWe'd like that too; it's likely to fall out of const generics, which are looking likely to hit stable sometime early next year.
- henrikeh 8y agoWith const generics ranged integers would be implemented as a user specified check. How viable would it be to implement an optimization step which seeks to minimize the number of these checks?
- steveklabnik 8y agoI'm not entirely sure what you mean, exactly. As far as I know, all of the usual optimization passes would already be working to minimize them.
- sanxiyn 8y agoRust could emit LLVM range metadata for ranged integers. IIRC, it already does so for enum discriminants.
- steveklabnik 8y agoThat seems quite good!
- masklinn 8y agoThat's probably down the line from const generics, as it has the additional constraint of defining the workings of those (API, over/underflow behaviour), how they'd interact with regular integral types (in terms of conversions back and forth), literals, …
- giovannibajo1 8y agoI've been studying Rust on and off in the past 3 months. There are a few things that I find annoying, they are somehow discussed in the issue tracker, but it's not clear to me what the priorities are to land them: * Partial borrow. I can't borrow a field of a structure and then reference another field. I can't cite how many times in a few weeks I've been forced to rethink and split my structures just to work around this, making my code harder to read and write for no good reason than working around this limit of the borrow checker. * The Rc/RefCell/Box dance is very verbose, when you just want to share a reference to some long-living object within other long-living objects. Worse than verbose, it also causes a runtime overhead because of the RefCell. * No simple way to declare non-const global objects, like something as easy as a global HashMap of constants strings to constant integers. I'm a little spoiled from Go's excellent support of init functions (both compiler-generated and manually written), but this is something I really miss in Rust. lazy_static! is a workaround which is harder to use and forces the code to be thread-safe even if no threading support is necessary (that is, I can't use my non-thread-safe classes in a lazy_static). * In generic code, there is no simple way to represent integer types. You need to use the "num" trait which breaks the "as" operator causing big pain and less readable code (as it's normal to covert between integer types). * No integer generic parameters. We have to use the "typenum" crate which ends up causing less readable code and generates C++-like error messages. * PhantomData is awkward, it absolutely sounds like something the compiler should handle, not the programmer. * "Wrapping<u32> + 1" doesn't compile, but is there a good reason why it does not? I really wish Rust added wuNN/wiNN native wrapping types, or evolved in a way that I can write the same code with "u32" and "Wrapping<u32>" (another example: "as" doesn't work). Right now, it seems like the solution is half-baked: it tries to use the generic to avoid adding a native type, but the code that users must write is more bloated compared to native types.
- sanxiyn 8y agoPartial borrow works for me. Yes, if it didn't work it would be very annoying.
- CUViper 8y agoIt works when you access fields directly. Where I've seen people get frustrated is that calling a method on `&self` or `&mut self` is always a full borrow, even if it only really accesses and returns something partial. The borrow checker doesn't look to see what that method really uses in its implementation, just that the signature would allow full access.
- sbjs 8y agoI want to expand my knowledge but don't know whether to invest in learning C++ or Rust. Both look like they have interesting concepts, but Rust is new and not yet widely used, and I hear C++ is easy to break in confusing ways. (I have cut Go out of the picture because copying and pasting code is the first thing you learn not to do in school, but all the Go leaders say you have to do this since they don't want to implement generics, so I don't trust their judgment on language design.)
- deleted 8y ago[deleted]
- always_good 8y agoIf you're trying to expand your knowledge, then waffling over which thing to learn is just procrastination.
- AnimalMuppet 8y agoWell... to learn a language moderately well takes weeks. To learn it really well takes months. To learn it at an expert level takes years. It might be worth a day or two of thought before that kind of investment. Eventually, sure, it becomes procrastination. But just randomly choosing isn't really the optimal approach either.
- adwn 8y agoNo. By that logic, you could as well open a random page on Wikipedia and start learning new stuff. Choosing to study a certain technology in depth carries with it a high opportunity cost in the form of your time.
- imtringued 8y agoThey are almost equivalent choices in terms of return of investment. C++ is used almost everywhere. Rust will allow you to write programs with less bugs and similar performance to C++. The opportunity cost of figuring out which one is better can often be higher than just trying out both choices. [1] [1] https://xkcd.com/1445/ https://xkcd.com/1445/
- ghrifter 8y agoHow exciting! How exciting!