Skip to content
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

Define the properties of Padding #882

Open
Havvy opened this issue Sep 1, 2020 · 3 comments · May be fixed by #935
Open

Define the properties of Padding #882

Havvy opened this issue Sep 1, 2020 · 3 comments · May be fixed by #935
Labels
A-type-layout Area: type layout New Content Missing features or aspects of language not currently documented.

Comments

@Havvy
Copy link
Contributor

Havvy commented Sep 1, 2020

We don't have a good explanation of the properties of padding. Currently we talk about it in two places:

  1. Type layout; It's pointed out that a type can have alignment padding that adds to the size.
  2. Added in clarify when reading uninititalized memory is allowed #852, it's pointed out that it can be set as uninitialized.

I think padding should probably be described in the type layout chapter.

My question though, other than being an unnameable psuedo-field that can theoretically have any value, does it have any other properties? E.g., can they be repurposed by enums to do niche optimizations (making it unsafe to set the value)? Other restrictions?

@RalfJung
Copy link
Member

RalfJung commented Sep 2, 2020

My question though, other than being an unnameable psuedo-field that can theoretically have any value, does it have any other properties?

Yes, a very crucial one: padding content is lost on "typed copies" (assignment, function argument/return passing). The content of the padding is not guaranteed to be preserved by such actions.

That's also why it can not be used for niche optimizations.

@Havvy
Copy link
Contributor Author

Havvy commented Jan 16, 2021

Is there a difference between a "typed copy" and a move?

@RalfJung
Copy link
Member

I am not sure what you mean by "move". ;) Both the MIR Operand::Copy and Operand::Move are "typed copies". There might be a difference between them, that is discussed at rust-lang/unsafe-code-guidelines#188.

@Havvy Havvy added the A-type-layout Area: type layout label Jan 17, 2021
@Havvy Havvy linked a pull request Jan 17, 2021 that will close this issue
@Havvy Havvy added the New Content Missing features or aspects of language not currently documented. label Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-layout Area: type layout New Content Missing features or aspects of language not currently documented.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants