-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Attach range metadata to alignment loads from vtables #91569
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
Conversation
...because alignment is always nonzero. This helps eliminate redundant runtime alignment checks, when a DST is a field of a struct whose remaining fields have alignment 1.
(rust-highfive has picked a reviewer for you, use r? to override) |
Since the range metadata is only being applied to the actual load from the vtable, I believe that this is fine. Regardless of what other decisions we make about pointer metadata/vtable validity invariants, the vtable clearly needs to be valid at the point where we actually read from it. cc @rust-lang/wg-unsafe-code-guidelines |
Yeah, this sounds like a reasonable requirement to impose on vtables. Miri already considers invalid alignments to be UB:
|
r? @cuviper (or maybe someone else from @rust-lang/wg-llvm) |
Looks reasonable to me. I guess we could instead special case alignment 1 instead (in which case we can always pick the other), but using range metadata does seem more elegant/general. @bors r+ rollup=never (may have optimization effect) |
📌 Commit 2ff5a3e has been approved by |
⌛ Testing commit 2ff5a3e with merge 8323fd5e21e152f70d521ca877edcf143a05df74... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors r+ |
📌 Commit 94f0833 has been approved by |
⌛ Testing commit 94f0833 with merge 5099869c742d325347de01576a17fbe708a534d3... |
💔 Test failed - checks-actions |
Not really clear what happened here, but probably spurious... @bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4a7fb97): comparison url. Summary: This change led to large relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Add 0..=isize::MAX range metadata to size loads from vtables This is the (much belated) size counterpart to rust-lang#91569. Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often. Miri detects this UB already: https://github.com/rust-lang/rust/blob/b7cc99142ad0cfe47e2fe9f7a82eaf5b672c0573/compiler/rustc_const_eval/src/interpret/traits.rs#L119-L121 (In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](https://github.com/rust-lang/rust/blob/9db224fc908059986c179fc6ec433944e9cfce50/compiler/rustc_abi/src/lib.rs#L312-L331), but I don't think we can assume that in an optimization.)
Add 0..=isize::MAX range metadata to size loads from vtables This is the (much belated) size counterpart to rust-lang#91569. Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often. Miri detects this UB already: https://github.com/rust-lang/rust/blob/b7cc99142ad0cfe47e2fe9f7a82eaf5b672c0573/compiler/rustc_const_eval/src/interpret/traits.rs#L119-L121 (In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](https://github.com/rust-lang/rust/blob/9db224fc908059986c179fc6ec433944e9cfce50/compiler/rustc_abi/src/lib.rs#L312-L331), but I don't think we can assume that in an optimization.)
...because alignment is always nonzero[0].
This helps eliminate redundant runtime alignment checks, when a DST
is a field of a struct whose remaining fields have alignment 1.
Fixes #91438.
[0]:
The reference says that alignment must be at least 1.
And in practice, the alignment field for all vtables is generated here:
rust/compiler/rustc_middle/src/ty/vtable.rs
Lines 68 to 90 in 772d51f
Align::bytes()
is always nonzero.