-
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
Validate the special layout restriction on DynMetadata
#125479
Conversation
rustbot has assigned @workingjubilee. Use |
Library changes look fine to me but I think I want to ask r? compiler |
@bors r+ rollup |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4649877): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (secondary -3.4%)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.
CyclesResults (primary 2.4%, secondary 4.9%)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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 673.551s -> 673.01s (-0.08%) |
ptr::metadata: avoid references to extern types References to `extern types` are somewhat dubious entities, since generally we say that references must be dereferenceable for their size as determined via `size_of_val`, but with `extern type` that is an ill-defined statement. I'd like to make Miri warn for such cases since it interacts poorly with Stacked Borrows. To avoid warnings people can't fix, this requires not using references to `extern type` in the standard library, and I think `DynMetadata` is the only currently remaining use. so this changes `DynMetadata` to use a NonNull raw pointer instead. Given that the alignment was 1, this shouldn't really change anything meaningful. I also updated a comment added by `@scottmcm` in rust-lang#125479, since I think the old comment is wrong. The `DynMetadata` type itself is not special, it is a normal aggregate. But computing field types for wide pointers (including references) is special.
Rollup merge of rust-lang#127859 - RalfJung:ptr-dyn-metadata, r=scottmcm ptr::metadata: avoid references to extern types References to `extern types` are somewhat dubious entities, since generally we say that references must be dereferenceable for their size as determined via `size_of_val`, but with `extern type` that is an ill-defined statement. I'd like to make Miri warn for such cases since it interacts poorly with Stacked Borrows. To avoid warnings people can't fix, this requires not using references to `extern type` in the standard library, and I think `DynMetadata` is the only currently remaining use. so this changes `DynMetadata` to use a NonNull raw pointer instead. Given that the alignment was 1, this shouldn't really change anything meaningful. I also updated a comment added by `@scottmcm` in rust-lang#125479, since I think the old comment is wrong. The `DynMetadata` type itself is not special, it is a normal aggregate. But computing field types for wide pointers (including references) is special.
If you look at https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/std/ptr/struct.DynMetadata.html, you'd think that
DynMetadata
is a struct with fields.But it's actually not, because the lang item is special-cased in rustc_middle layout:
rust/compiler/rustc_middle/src/ty/layout.rs
Lines 861 to 864 in 7601adc
That explains the very confusing codegen ICEs I was getting in #124251 (comment)
because there was a
Field
projection despite the layout clearly saying it'sPrimitive
.Thus this PR updates the MIR validator to check for such a projection, and changes
libcore
to not ever emit any projections intoDynMetadata
, just to transmute the whole thing when it wants a pointer.