-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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, | ||
| 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 | ||
| } | ||
| } | ||
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.
Can't be removed, as it is used by the
variant_size_differenceslint.