-
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
Add an unstable conversion from thread ID to u64 #67566
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
It is intended for this to close #52780, though it is not mutually exclusive with it. I am against adding a direct Display impl for ThreadId (there is not "one true way" that I would expect it to be formatted); this allows an easy way to get the "just a number" formatting for ThreadId that seems to be commonly wanted. |
I have wished for a method like this, 👍 |
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.
Looks good to me! Want to open a tracking issue, set it up here, and then r=me?
We see multiple cases inside rustc and ecosystem code where ThreadId is transmuted to u64, exploiting the underlying detail. This is suboptimal (can break unexpectedly if we change things in std). It is unlikely that ThreadId will ever need to be larger than u64 -- creating even 2^32 threads over the course of a program is quite hard, 2^64 is even harder. As such, we do not choose to return a larger sized type (e.g. u128). If we choose to shrink ThreadId in the future, or otherwise change its internals, it is likely that a mapping to u64 will still be applicable (though may become more complex).
4e7a541
to
d9a7db9
Compare
Updated with a tracking issue and also added a bit of text even further warning against using the returned value for non-equality (specifically, ordering not being defined). @bors r=alexcrichton |
📌 Commit d9a7db9 has been approved by |
…excrichton Add an unstable conversion from thread ID to u64 We see multiple cases inside rustc and ecosystem code where ThreadId is transmuted to u64, exploiting the underlying detail. This is suboptimal (can break unexpectedly if we change things in std). It is unlikely that ThreadId will ever need to be larger than u64 -- creating even 2^32 threads over the course of a program is quite hard, 2^64 is even harder. As such, we do not choose to return a larger sized type (e.g. u128). If we choose to shrink ThreadId in the future, or otherwise change its internals, it is likely that a mapping to u64 will still be applicable (though may become more complex). I will file a tracking issue as soon as this is loosely approved.
…excrichton Add an unstable conversion from thread ID to u64 We see multiple cases inside rustc and ecosystem code where ThreadId is transmuted to u64, exploiting the underlying detail. This is suboptimal (can break unexpectedly if we change things in std). It is unlikely that ThreadId will ever need to be larger than u64 -- creating even 2^32 threads over the course of a program is quite hard, 2^64 is even harder. As such, we do not choose to return a larger sized type (e.g. u128). If we choose to shrink ThreadId in the future, or otherwise change its internals, it is likely that a mapping to u64 will still be applicable (though may become more complex). I will file a tracking issue as soon as this is loosely approved.
Rollup of 13 pull requests Successful merges: - #67566 (Add an unstable conversion from thread ID to u64) - #67671 (Account for `type X = impl Trait;` in lifetime suggestion) - #67727 (Stabilise vec::remove_item) - #67877 (Omit underscore constants from rustdoc) - #67880 (Handle multiple error fix suggestions carefuly) - #67898 (Improve hygiene of `newtype_index`) - #67908 (rustdoc: HTML escape const values) - #67909 (Fix ICE in const pretty printing and resolve FIXME) - #67929 (Formatting an example for method Vec.retain) - #67934 (Clean up E0178 explanation) - #67936 (fire "non_camel_case_types" for associated types) - #67943 (Missing module std in example.) - #67962 (Update books) Failed merges: r? @ghost
We see multiple cases inside rustc and ecosystem code where ThreadId is
transmuted to u64, exploiting the underlying detail. This is suboptimal
(can break unexpectedly if we change things in std).
It is unlikely that ThreadId will ever need to be larger than u64 --
creating even 2^32 threads over the course of a program is quite hard,
2^64 is even harder. As such, we do not choose to return a larger sized
type (e.g. u128). If we choose to shrink ThreadId in the future, or
otherwise change its internals, it is likely that a mapping to u64 will
still be applicable (though may become more complex).
I will file a tracking issue as soon as this is loosely approved.