Repository navigation
don't inhibit random field reordering on repr(packed(1)) - #125360
Conversation
commented
May 21, 2024
ea7545b to
1fcce90
Compare
| pub fn can_randomize_type_layout(&self) -> bool { | ||
| !self.inhibit_struct_field_reordering_opt() | ||
| && self.flags.contains(ReprFlags::RANDOMIZE_LAYOUT) | ||
| !self.inhibit_struct_field_reordering() && self.flags.contains(ReprFlags::RANDOMIZE_LAYOUT) |
There was a problem hiding this comment.
This is still a bit silly, the only place where can_randomize_type_layout is called is effectively inside an if !self.inhibit_struct_field_reordering()... but I didn't want to do a larger refactoring here, not sure what even would be the better structure.
commented
May 21, 2024
|
Note that this does not only affect |
This comment has been minimized.
This comment has been minimized.
1fcce90 to
a53f3ed
Compare
commented
May 21, 2024
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
| continue; | ||
| } | ||
| if def.repr().inhibit_struct_field_reordering_opt() { | ||
| if def.repr().inhibit_struct_field_reordering() { |
There was a problem hiding this comment.
FWIW clippy already used to assume inhibit_struct_field_reordering_opt means that the field order is guaranteed, which was not the case before this PR.
This comment has been minimized.
This comment has been minimized.
a53f3ed to
823f5bb
Compare
This comment has been minimized.
This comment has been minimized.
823f5bb to
f707e61
Compare
This comment has been minimized.
This comment has been minimized.
f707e61 to
37aeb75
Compare
commented
May 21, 2024
|
The Miri subtree was changed cc @rust-lang/miri |
commented
May 29, 2024
|
@bors r+ |
commented
May 29, 2024
commented
May 29, 2024
commented
May 29, 2024
|
☀️ Test successful - checks-actions |
commented
Jun 4, 2024
@rustbot label: +perf-regression-triaged |
|
This broke ICU4X. It's our fault: we assumed So while I wouldn't go as far as to say it's a breaking change, I wonder if this should be done more carefully, perhaps requiring Or even having (The fix for ICU4X is unicode-org/icu4x#5049) |
commented
Jun 13, 2024
|
Some crates getting broken is expected, it also happened the last time we changed field ordering (#102750) which is why i added the relnotes label. Also note that If the beta crater run shows a bigger impact then a more careful approach would make sense. |
commented
Jun 13, 2024
Right, but I think in this case, while the nomicon and reference seem to be clear that So while the docs are clear, I wonder if the ecosystem's impression of how things work is going to be a problem for this change. That's not as much the case for I'm also not sure if this will show up much on crater since it may require specific kinds of test failures. |
commented
Jun 18, 2024
|
If this is a common source of confusion, maybe there should be a lint that encourages people to use an explicit representation with |
commented
Jun 19, 2024
The |
inhibit_struct_field_reordering_optbeing false means we exclude this type from random field shuffling. However,packed(1)types can still be shuffled! The logic was added in #48528 since it's pointless to reorder fields in packed(1) types (there's no padding that could be saved) -- but that shouldn't inhibit-Zrandomize-layout(which did not exist at the time).We could add an optimization elsewhere to not bother sorting the fields for
repr(packed)types, but I don't think that's worth the effort.This does change the behavior in that we may now reorder fields of
packed(1)structs (e.g. if there are niches, we'll try to move them to the start/end, according toNicheBias). We were always allowed to do that but so far we didn't. Quoting the reference: