-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
-Zrandomize-layout
harder. Foo<T> != Foo<U>
#133088
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @petrochenkov. Use |
This comment has been minimized.
This comment has been minimized.
c91c222
to
119ccc4
Compare
This comment has been minimized.
This comment has been minimized.
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
This comment has been minimized.
This comment has been minimized.
r? compiler |
bb177bb
to
8cf5cd2
Compare
This comment has been minimized.
This comment has been minimized.
8cf5cd2
to
c53f89c
Compare
This comment has been minimized.
This comment has been minimized.
c53f89c
to
e536d05
Compare
This comment has been minimized.
This comment has been minimized.
e536d05
to
c276116
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
`-Zrandomize-layout` harder. `Foo<T> != Foo<U>` Tracking issue: rust-lang#106764 Previously randomize-layout only used a deterministic shuffle based on the seed stored in an Adt's ReprOptions, meaning that `Foo<T>` and `Foo<U>` were shuffled by the same seed. This change adds a similar seed to each calculated LayoutData so that a struct can be randomized both based on the layout of its fields and its per-type seed. Primitives start with simple seed derived from some of their properties. Though some types can no longer be distinguished at that point, e.g. usize and u64 will still be treated the same.
@@ -119,6 +119,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { | |||
.chain(Niche::from_scalar(dl, Size::ZERO, a)) | |||
.max_by_key(|niche| niche.available(dl)); | |||
|
|||
let combined_seed = a.size(&self.cx).bytes().wrapping_add(b.size(&self.cx).bytes()); |
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.
Why do we need to do any of this seed computation if -Zrandomize-layout
is not set?
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.
Because if -Zrandomize-layout
is not set, then keeping this set to 0 means we should also be able to avoid all that //@ normalize-stderr-test:
below.
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.
Because randomization is toggled on a per-crate basis, so we want types from non-randomized crates still contribute a seed to randomized crates.
Additionally one CI job builds with randomization enabled, which includes std, so it wouldn't actually help the tests.
compiler/rustc_abi/src/layout.rs
Outdated
@@ -1043,10 +1067,12 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> { | |||
{ | |||
use rand::SeedableRng; | |||
use rand::seq::SliceRandom; | |||
//let field_entropy = fields_excluding_tail.iter().map(|f| f.).sum(); |
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.
remove commented out code
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.
done
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (0e4cbcd): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (secondary 3.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 797.356s -> 796.07s (-0.16%) |
previously field ordering was using the same seed for all instances of Foo, now we pass seed values through the layout tree so that not only the struct itself affects layout but also its fields
c276116
to
1775c91
Compare
I have also changed some comments at the request of Ralf to explain places where randomization explicitly does not randomize is not a guarantee but instead a conservative approach until the UCG questions are settled. |
Tracking issue: #106764
Previously randomize-layout only used a deterministic shuffle based on the seed stored in an Adt's ReprOptions, meaning that
Foo<T>
andFoo<U>
were shuffled by the same seed. This change adds a similar seed to each calculated LayoutData so that a struct can be randomized both based on the layout of its fields and its per-type seed.Primitives start with simple seed derived from some of their properties. Though some types can no longer be distinguished at that point, e.g. usize and u64 will still be treated the same.