Skip to content
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

Stop SRoA'ing DynMetadata in MIR #125508

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_mir_transform/src/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ fn escaping_locals<'tcx>(
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
return true;
}
if Some(def.did()) == tcx.lang_items().dyn_metadata() {
// codegen wants to see the `DynMetadata<T>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually think it's about time to investigate remove the layout special casing from dynmetadata and seeing what happens if you just let it be repr(transparent) :3

Copy link
Member Author

@scottmcm scottmcm May 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it out; #125532 (comment)

Looks like the hardest part might be dealing with whether the reference actually has AM memory behind it, and I have no idea how to solve that, so I'll stick with this change for now.

// not the inner reference-to-opaque-type.
return true;
}
// We already excluded unions and enums, so this ADT must have one variant
let variant = def.variant(FIRST_VARIANT);
if variant.fields.len() > 1 {
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/mir/dyn_metadata_sroa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ run-pass
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir

#![feature(ptr_metadata)]

// Regression for <https://github.com/rust-lang/rust/issues/125506>,
// which failed because of SRoA would project into `DynMetadata`.

trait Foo {}

struct Bar;

impl Foo for Bar {}

fn main() {
let a: *mut dyn Foo = &mut Bar;

let _d = a.to_raw_parts().0 as usize;
}
Loading