Conversation
|
I like this. Having unused bits in a pointer is really useful.
Would it be reasonable to add a basic example of this? It would be great for docs to not just provide the guarantee but give a real example where it's useful. |
|
@BurntSushi I'm afraid the example would be far too long and too subtle for the docs on this. |
|
Maybe we can shorten it so that it just hows how to (correctly) use those lower bits in the pointer to store something? It can be a pretty subtle thing to get correct in my experience. I know I've toiled over it. It would be a real gem to have something like that in the docs precisely where a guarantee affording such chicanery is written. |
|
@BurntSushi I mean feel free to take a look: https://gist.github.com/orlp/de53ae21e357f92f705052d8760e9517. Ultimately I don't think the |
|
@rfcbot fcp merge libs-api |
|
@BurntSushi has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
@orlp Thanks! I actually don't think that example is too big for std's docs personally. It seems rather useful and could be an awesome addition to the docs. It "just" needs to be broken down into pieces and explained with some exposition. (I think this could be hard to do.) As for pointer tagging more broadly, probably the provenance APIs are the place for that. And at least there is an unstable API that has a lightweight example of it: https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.mask |
|
cc @adamgreig & @therealprof on behalf of wg-embedded - is this change likely to impact you negatively? otherwise we'd be happy to accept this PR ^^ |
|
I expect the impact on embedded to be negligible. Waker vtables are const statics; an application will not have more than a handful of them, and increasing the alignment shouldn't make much of a difference as there are plenty of things the compiler/linker can use to fill the space (especially on a 32-bit platform where you have tons of 4-byte variables). I built a moderately-sized Embassy project on the latest main: Latest main + this patch: The code size increased by four bytes (the |
This comment has been minimized.
This comment has been minimized.
904ecef to
fd4d2e6
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
No objections from wg-embedded, we don't expect a meaningful impact. |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
@bors r+ rollup |
…fonthey Guarantee 8 bytes of alignment of RawWakerVTable This is similar to an earlier PR I made for `Thread::into_raw`: rust-lang#143859. When using `AtomicPtr` for synchronization it's incredibly useful when you've got a couple bits you can stuff metadata in. By guaranteeing that `RawWakerVTable` is aligned to 8 bytes everyone can use the bottom 3 bits to signal other things, such as a critical section, etc. In particular, this can be used to portably implement an `AtomicWaker` which is always two pointers in size, no more. On almost all platforms the align is already 8 bytes, and on other platforms it might cause an infinitesimal increase in size. This guarantee is thus very useful and costs us essentially nothing. --- r? libs-api Like last time since this adds a guarantee this probably needs a FCP.
…fonthey Guarantee 8 bytes of alignment of RawWakerVTable This is similar to an earlier PR I made for `Thread::into_raw`: rust-lang#143859. When using `AtomicPtr` for synchronization it's incredibly useful when you've got a couple bits you can stuff metadata in. By guaranteeing that `RawWakerVTable` is aligned to 8 bytes everyone can use the bottom 3 bits to signal other things, such as a critical section, etc. In particular, this can be used to portably implement an `AtomicWaker` which is always two pointers in size, no more. On almost all platforms the align is already 8 bytes, and on other platforms it might cause an infinitesimal increase in size. This guarantee is thus very useful and costs us essentially nothing. --- r? libs-api Like last time since this adds a guarantee this probably needs a FCP.
…uwer Rollup of 8 pull requests Successful merges: - #162796 (libtest: do not early exit from test runners) - #162844 (Add loan reachability traces to polonius MIR dumps) - #158186 (Guarantee 8 bytes of alignment of RawWakerVTable) - #160108 (Stabilize `windows_process_extensions_main_thread_handle`) - #161305 (Use the entire type of a dropped local to compute variance (edge direction) for Polonius alpha) - #161838 (tests: accept LLVM 24 optimization in this test) - #162825 (core: Add examples for `debug_closure_helpers`) - #162856 (Stabilize CommandExt::show_window)
…fonthey Guarantee 8 bytes of alignment of RawWakerVTable This is similar to an earlier PR I made for `Thread::into_raw`: rust-lang#143859. When using `AtomicPtr` for synchronization it's incredibly useful when you've got a couple bits you can stuff metadata in. By guaranteeing that `RawWakerVTable` is aligned to 8 bytes everyone can use the bottom 3 bits to signal other things, such as a critical section, etc. In particular, this can be used to portably implement an `AtomicWaker` which is always two pointers in size, no more. On almost all platforms the align is already 8 bytes, and on other platforms it might cause an infinitesimal increase in size. This guarantee is thus very useful and costs us essentially nothing. --- r? libs-api Like last time since this adds a guarantee this probably needs a FCP.
Rollup of 12 pull requests Successful merges: - #161596 (coretests: Add more pattern tests.) - #162796 (libtest: do not early exit from test runners) - #162844 (Add loan reachability traces to polonius MIR dumps) - #158186 (Guarantee 8 bytes of alignment of RawWakerVTable) - #160108 (Stabilize `windows_process_extensions_main_thread_handle`) - #160212 (traits: Fix rigid alias liveness matching) - #160544 (Stabilize `feature(trim_prefix_suffix)` (`{str, [T], Path}::trim_prefix` and `{str, [T]}::trim_suffix`)) - #161305 (Use the entire type of a dropped local to compute variance (edge direction) for Polonius alpha) - #161838 (tests: accept LLVM 24 optimization in this test) - #162805 (Add `must_use` lint to `ExitCode`) - #162825 (core: Add examples for `debug_closure_helpers`) - #162856 (Stabilize CommandExt::show_window)
|
This change (predictably) fails semver checks in CI: #162877 (comment) I assume it needs some special directive to skip those checks for a deliberate “breaking” change, though I don’t know offhand what that is. IIRC there’s some relevant discussion on Zulip somewhere. @bors r- |
|
This pull request was unapproved. This PR was contained in the following rollups:
|
This is similar to an earlier PR I made for
Thread::into_raw: #143859.When using
AtomicPtrfor synchronization it's incredibly useful when you've got a couple bits you can stuff metadata in. By guaranteeing thatRawWakerVTableis aligned to 8 bytes everyone can use the bottom 3 bits to signal other things, such as a critical section, etc. In particular, this can be used to portably implement anAtomicWakerwhich is always two pointers in size, no more.On almost all platforms the align is already 8 bytes, and on other platforms it might cause an infinitesimal increase in size. This guarantee is thus very useful and costs us essentially nothing.
r? libs-api
Like last time since this adds a guarantee this probably needs a FCP.