-
Notifications
You must be signed in to change notification settings - Fork 59
Effect of packed
and align
on representation
#17
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
Comments
To note for the future validity discussion: This creates an invalid reference, which briefly exists even if we cast to raw pointer immediately. How to handle that is not part of the current discussion area, but we should remember adding it for the next :) |
@RalfJung yes, I was reminded of that while writing this comment. I remember @arielb1 proposing that we have some kind of MIR operation for "borrowing as a raw pointer" -- this would perhaps be written in Rust syntax as |
I worry about how would we teach this, and whether we can lint against people splitting this into two operations (e.g. I still think that this is the best solution we've got, andI don't think it is worth it to add a new sigil for it. But if we introduce this subtlety doing the wrong thing should ideally produce a hard error (e.g. can't do |
Yes, please -- a new lint, first warn-by-default and then when crater permits, err-by-default. For uninitailized memory, we will likely not have immediate UB when creating a reference, but that is something the next discussion area will show. |
I cannot think of a good reason for the compiler to do so. The possibility of trying to align individual fields at some alignment higher than their natural alignment but lower than the struct's alignment seems extremely esoteric. That said, I do not know in what circumstances PGO might actually make this valuable. The one thing I do think that we should guarantee is that a newtype with As for For newtypes, a similar guarantee should hold as above: a In fact, I think that if we go with that definition, we could define
|
It seems surprising to me that |
That said, I feel like there is probably more work to be done than your comment might suggest. In particular, I think that the interaction with |
I meant that, theoretically, we could have But in general I think that's kinda silly and pointless. |
See https://oroboro.com/short-enum/, in particular its mention of the use of |
I believe this is basically addressed by #31, so I've marked this as final-comment-period as well. |
@briansmith I'm not entirely sure what points you meant to convey with those links, though I didn't read them yet. The purpose of this issue was to kind of describe how align/transparent work; are those links talking about details of things we should document? Perhaps take a look at #31, which has some (fairly short and not super detailed, admittedly) text on this topic, and make some suggested edits? |
Discussion topic for the effect of
#[repr(packed)]
and#[repr(align)]
on memory layout.Both of these attributes have RFCs. We should document what current behavior is, what gotchas to watch out for (e.g.,
&x.foo
wherefoo
is a field of a packed struct may not be aligned), and what we can guarantee going forward.The text was updated successfully, but these errors were encountered: