-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Vec's calloc optimization for Option<NonZero> #85737
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This looks fine to me. It just makes me wonder if there's a better way we could do this for all types. Some kind of @bors r+ |
📌 Commit 04d34a9 has been approved by |
☀️ Test successful - checks-actions |
// `Option<num::NonZeroU32>` and similar have a representation guarantee that | ||
// they're the same size as the corresponding `u32` type, as well as a guarantee | ||
// that transmuting between `NonZeroU32` and `Option<num::NonZeroU32>` works. | ||
// While the documentation officially makes in UB to transmute from `None`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be "makes it ub"?
Edit: I see this was already merged, I assume I was wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right. Feel free to send a PR if you want ^^'. But this doesn't appear in any public documentation/interface, so it doesn't matter that much.
@m-ou-se I guess it depends on how much this wants to care about types with padding. Supporting |
Very strange spike (https://perf.rust-lang.org/index.html), perhaps problems with perf runner? |
Yeah, this was a runner hiccup I believe. |
Is there any logs, as part of benches isn't run at all (or not saved info about it, check lower part of bench list)? |
There's some discussion on the rustc-perf repository, but there's really no need to investigate further in my opinion. |
Fix a typo See also: rust-lang#85737
Fix a typo See also: rust-lang#85737
Ideally, it should work for things with padding too. As long as an all-zero-bits value is an identical value, ignoring padding bits, it shoud return true. So a |
Someone on discord noticed that
vec![None::<NonZeroU32>; N]
wasn't getting the optimization, so here's a PR 🙃We can certainly do this in the standard library because we know for sure this is ok, but I think it's also a necessary consequence of documented guarantees like those in https://doc.rust-lang.org/std/option/#representation and https://doc.rust-lang.org/core/num/struct.NonZeroU32.html
It feels weird to do this without adding a test, but I wasn't sure where that would belong. Is it worth adding codegen tests for these?