-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Collapse trailing padding #17027
Comments
cc @eddyb |
Triage: not aware of any changes. |
Should this be closed in favor of the RFC issue: rust-lang/rfcs#1397? |
Just for record, |
Cc @rust-lang/wg-codegen I'll look at this given I'm having fun in the layout module these days. |
Though I don't think it's something where we can just change the layout to be clever and expect everything else to work. What happens if you have a value coming from a |
I think we should add an attribute for this, something like |
To enable code to handle types with "no trailing padding" correctly, we need to introduce a distinction between "size" and "stride" like Swift has. Theoretically possible but a lot of churn and very hard to ensure all code is updated. |
And also note the downside noted in rust-lang/rfcs#1397 |
Closing this in favour of the rfc listed above: rust-lang/rfcs#1397 |
Since we don't have to worry about FFI interop for types that are not
#[repr(C)]
, this means we can perform certain optimizations with regards to padding. One such optimization is collapsing trailing padding. For examplestd::mem::size_of::<((u16, u8), u8)>()
returns 6, but ideally it would be 4.To implement this size optimization would require keeping track of two separate sizes, one being the actual size not including trailing padding, and the other being the array element size or aligned size. For example
(u16, u8)
would have an actual size of 3, but an array size of 4.As an added benefit, this would allow for enums to use that extra space at the end to store the discriminant.
This likely depends on teaching LLVM to support this sort of stuff.
The text was updated successfully, but these errors were encountered: