-
Notifications
You must be signed in to change notification settings - Fork 488
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
Document repr packed(N). #553
Conversation
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.
My overall sense is that the text added here would be more succinctly described in a few equations, but I think this is mostly good for now.
src/type-layout.md
Outdated
It modifies the representation (either the default or `C`) by removing any | ||
padding bytes and forcing the alignment of the type to `1`. | ||
The `packed` representation sets the alignment to the smaller of the specified | ||
packing and the current alignment (either default or `C`). The alignments of |
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.
Here the "default" alignment is referenced but above "primitive alignment" is used... we should pick one phrasing.
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.
Get rid of both "current' and "primitive". Get rid of the parenthetical. Instead spell it out explicitly that if the type has the default or C representation, and the alignment from that representation is smaller, it will use that alignment.
src/type-layout.md
Outdated
It modifies the representation (either the default or `C`) by removing any | ||
padding bytes and forcing the alignment of the type to `1`. | ||
The `packed` representation sets the alignment to the smaller of the specified | ||
packing and the current alignment (either default or `C`). The alignments of |
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.
"or C
" is not super clear wrt. referring to C-the-language
Co-Authored-By: ehuss <[email protected]>
I added an experimental commit to propose a different way of documenting these I do have some concerns and doubts:
|
src/type-layout.md
Outdated
@@ -113,13 +113,12 @@ All user-defined composite types (`struct`s, `enum`s, and `union`s) have a | |||
*representation* that specifies what the layout is for the type. | |||
|
|||
The possible representations for a type are the default representation, `C`, | |||
the primitive representations, `packed`, and `transparent`. Multiple | |||
representations can be applied to a single type. | |||
the primitive representations, and `transparent`. |
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.
Itemize ^
Also make it clear what the "primitive representations" entail (by itemizing all the primitive reprs)
src/type-layout.md
Outdated
`#[repr(align(x))]`. The alignment value must be a power of two from 1 up to | ||
2<sup>29</sup>. | ||
|
||
The `align` modifier raises the type's alignment to the specified alignment. |
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 partial repetition of what you said in the leading paragraph.
src/type-layout.md
Outdated
2<sup>29</sup>. | ||
|
||
The `align` modifier raises the type's alignment to the specified alignment. | ||
If the specified alignment is less than the alignment of the type without the |
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.
I believe this concept of "without the ** modifier" is referred to as the "natural **", for example "natural alignment". I think it would be good to introduce such terms earlier (when we first start to speak about alignment) and then use them.
src/type-layout.md
Outdated
The packing value is specified as an integer parameter in the form of | ||
`#[repr(packed(x))]`. If no value is given, as in `#[repr(packed)]`, then the | ||
packing value is 1. The packing value must be a power of two from 1 up to | ||
2<sup>29</sup>. |
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.
If you extract out the wording about the default it is the same as the paragraph for align
. So extract these two out into a common notion repr_value
or something and then reference that one.
I attempted to reduce some of the duplication. It still seems a little awkward, though. |
I think this is strict improvement for now. Thanks @ehuss. |
Technically it would be more accurate to say |
@retep998 Could you file a clarification PR? |
Update books ## nomicon 1 commits in f1ff93b66844493a7b03101c7df66ac958c62418..c02e0e7754a76886e55b976a3a4fac20100cd35d 2019-02-26 13:37:28 -0500 to 2019-03-25 16:52:56 -0400 - dropck: The drop order is now defined (rust-lang/nomicon#113) ## reference 3 commits in 27ad493..98f90ff 2019-03-26 02:06:15 +0100 to 2019-04-06 09:29:08 -0700 - Document repr packed(N). (rust-lang/reference#553) - Fix broken link in glossary. (rust-lang/reference#558) - Typo fixes (rust-lang/reference#556) ## embedded-book 2 commits in 07fd3880ea0874d82b1d9ed30ad3427ec98b4e8a..7989c723607ef5b13b57208022259e6c771e11d0 2019-03-27 15:40:52 +0000 to 2019-04-04 12:14:37 +0000 - fix rust-embedded/book#182 (rust-embedded/book#183) - Add openocd to list of installable packages (rust-embedded/book#179)
Update books ## nomicon 1 commits in f1ff93b66844493a7b03101c7df66ac958c62418..c02e0e7754a76886e55b976a3a4fac20100cd35d 2019-02-26 13:37:28 -0500 to 2019-03-25 16:52:56 -0400 - dropck: The drop order is now defined (rust-lang/nomicon#113) ## reference 3 commits in 27ad493..98f90ff 2019-03-26 02:06:15 +0100 to 2019-04-06 09:29:08 -0700 - Document repr packed(N). (rust-lang/reference#553) - Fix broken link in glossary. (rust-lang/reference#558) - Typo fixes (rust-lang/reference#556) ## embedded-book 2 commits in 07fd3880ea0874d82b1d9ed30ad3427ec98b4e8a..7989c723607ef5b13b57208022259e6c771e11d0 2019-03-27 15:40:52 +0000 to 2019-04-04 12:14:37 +0000 - fix rust-embedded/book#182 (rust-embedded/book#183) - Add openocd to list of installable packages (rust-embedded/book#179)
Closes #483
I feel like this is lacking, but I'm not sure what else to add.