-
-
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
Changes from all commits
464dc07
1162bdc
0569574
3459964
75015f4
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 |
|---|---|---|
|
|
@@ -1953,7 +1953,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>>, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -2319,3 +2319,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(StableHash))] | ||
| 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.