-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Remove redundant information in rustc_abi::Variants
#151742
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
base: main
Are you sure you want to change the base?
Changes from all commits
1c613d1
4118daa
f4e8f99
89e3bd3
93db272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1974,7 +1974,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> { | |
| tag: Scalar, | ||
| tag_encoding: TagEncoding<VariantIdx>, | ||
| tag_field: FieldIdx, | ||
| variants: IndexVec<VariantIdx, LayoutData<FieldIdx, VariantIdx>>, | ||
| variants: IndexVec<VariantIdx, VariantLayout<FieldIdx>>, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -2339,3 +2339,40 @@ pub enum AbiFromStrErr { | |
| /// no "-unwind" variant can be used here | ||
| NoExplicitUnwind, | ||
| } | ||
|
|
||
| // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. | ||
| #[derive(PartialEq, Eq, Hash, Clone, Debug)] | ||
| #[cfg_attr(feature = "nightly", derive(HashStable_Generic))] | ||
| pub struct VariantLayout<FieldIdx: Idx> { | ||
| pub size: Size, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't be removed, as it is used by the |
||
| pub backend_repr: BackendRepr, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know enough about codegen to confidently say if it requires accurate reprs for enum variants, so I've left this field for now.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enum variants should not need their own BackendRepr, but it is probably a good idea to leave this cleanup for a future PR. |
||
| pub field_offsets: IndexVec<FieldIdx, Size>, | ||
| fields_in_memory_order: IndexVec<u32, FieldIdx>, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this field could be removed and recomputed from the field offsets in |
||
| largest_niche: Option<Niche>, | ||
| uninhabited: bool, | ||
| } | ||
|
|
||
| impl<FieldIdx: Idx> VariantLayout<FieldIdx> { | ||
| pub fn from_layout(layout: LayoutData<FieldIdx, impl Idx>) -> Self { | ||
| let FieldsShape::Arbitrary { offsets, in_memory_order } = layout.fields else { | ||
| panic!("Layout of fields should be Arbitrary for variants"); | ||
| }; | ||
|
|
||
| Self { | ||
| size: layout.size, | ||
| backend_repr: layout.backend_repr, | ||
| field_offsets: offsets, | ||
| fields_in_memory_order: in_memory_order, | ||
| largest_niche: layout.largest_niche, | ||
| uninhabited: layout.uninhabited, | ||
| } | ||
| } | ||
|
|
||
| pub fn is_uninhabited(&self) -> bool { | ||
| self.uninhabited | ||
| } | ||
|
|
||
| pub fn has_fields(&self) -> bool { | ||
| self.field_offsets.len() > 0 | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
I do not have context about this new variant layout stuff, but calculating a zero seed for variants with fields seems like a bad idea for randomization, this
LayoutDatanever gets looked at by types that contain one of these.If it's never used then there should be a comment here.
View changes since the review
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.
These layouts never flow into actual layout calculations; they're "fake" layouts that get re-synthesized after-the-fact, mostly for use by codegen backends for field projections. So the only thing that really matters here is the field offsets, everything else can be more-or-less dummy values.
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.
Ok, then I think a comment saying that would be good.