-
Notifications
You must be signed in to change notification settings - Fork 2k
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
doc: What is movability in types #17826
base: master
Are you sure you want to change the base?
Conversation
(The IPv6 example may be more relevant than I realized initially, for if the struct were considered opaque and 1-2 functions were different, the implementation might easily flip from having addresses copied around everywhere to storing an 8-bit index into a refcounting NIB that ensures that addresses are cheaper on the stack. We don't do that, and I don't think it pays off with 16 byte addresses, but it could be done that way and then all of a a sudden properties would change. Not on movability mind you but copyability, which is not covered here, but still close enough to be a not-totally-off example.) |
Co-authored-by: Kaspar Schleiser <[email protected]>
Co-authored-by: Kaspar Schleiser <[email protected]>
|
||
Movability | ||
---------- | ||
|
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.
This is a nice explanation, but also slightly verbose and might be missing the "why do we care?".
Something along the lines of:
The C compiler in general doesn't move around data that has been allocated on stack or on the heap by itself, so movability is usually not something that ideomatic C needs to deal with.
The Rust compiler does move data around, if it deems it beneficial for optimization.
As most of RIOT's C APIs are being used by Rust through wrappers, movability of a type needs to be specified in order to no force Rust to assume *may never move* on *all* types.
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.
Thanks, taken in and modified (because Rust doesn't just move data around either).
doc/doxygen/src/move-semantics.md
Outdated
|
||
This is being documented for consistency within RIOT, | ||
and for the benefit of users who use RIOT | ||
from other languages (such as @rust using-rust "Rust" ) |
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.
Is there some rust documentation on movability that this could link to?
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.
It's not like Rust does anything "special" that'd be documented; neither does C strictly forbid moving around values. In particular, the Rust compiler will not willy-nilly move data around, but the ways things are used (RAII without guaranteed return placement, destruction by value) that lead to things being moved.
The Pin<>
documentation is obviously related, I've linked it as "verbose and complicated" in the latest version. The proposal for guaranteed copy elision is related as well, but it's not clear enough yet whether it even suffices to link it in here.
…RIOT into doc-move-semantics
ivp6_addr_t needs no dedicated docs
Thanks for your input, I've pulled in changes and made adjustments. In particular, I found that the IPv6 example doesn't need more docs (because it is returned by value), and that the lack of a destructor can be a good hint (but no more: not having a destructor / close function / timer clearing function means that the struct is not part of a linked list, but it could still have internal references.) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This adds text explaining what it means for a type to be movable in the context of C, and gives examples.
It does not (yet) declare any type as movable, but contains a TBD note that
ipv6_addr_t
probably should be as it is already used as that -- given that it's probably already used that way.I've asked for reviews from people who participated earlier in discussion on this; I don't expect the current state to go through immediately given that with the "used in functions" criterion it diverges a bit from what was previously discussed, but would appreciate your feedback to check the direction.
See-Also: #17817