Skip to content
Open
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
19 changes: 18 additions & 1 deletion compiler/rustc_public/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,27 @@ pub enum VariantsShape {
tag: Scalar,
tag_encoding: TagEncoding,
tag_field: usize,
variants: Vec<LayoutShape>,
variants: Vec<VariantFields>,
},
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct VariantFields {
/// Offsets for the first byte of each field,
/// ordered to match the source definition order.
/// I.e.: It follows the same order as [super::ty::VariantDef::fields()].
/// This vector does not go in increasing order.
pub offsets: Vec<Size>,
}

impl VariantFields {
pub fn fields_by_offset_order(&self) -> Vec<FieldIdx> {
let mut indices = (0..self.offsets.len()).collect::<Vec<_>>();
indices.sort_by_key(|idx| self.offsets[*idx]);
indices
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub enum TagEncoding {
/// The tag directly stores the discriminant, but possibly with a smaller layout
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_public/src/unstable/convert/stable/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_target::callconv;
use crate::abi::{
AddressSpace, ArgAbi, CallConvention, FieldsShape, FloatLength, FnAbi, IntegerLength,
IntegerType, Layout, LayoutShape, PassMode, Primitive, ReprFlags, ReprOptions, Scalar,
TagEncoding, TyAndLayout, ValueAbi, VariantsShape, WrappingRange,
TagEncoding, TyAndLayout, ValueAbi, VariantFields, VariantsShape, WrappingRange,
};
use crate::compiler_interface::BridgeTys;
use crate::target::MachineSize as Size;
Expand Down Expand Up @@ -212,7 +212,15 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Variants<rustc_abi::FieldIdx, rustc_abi::
tag: tag.stable(tables, cx),
tag_encoding: tag_encoding.stable(tables, cx),
tag_field: tag_field.stable(tables, cx),
variants: variants.iter().as_slice().stable(tables, cx),
variants: variants
.iter()
.map(|v| match &v.fields {
rustc_abi::FieldsShape::Arbitrary { offsets, .. } => VariantFields {
offsets: offsets.iter().as_slice().stable(tables, cx),
},
_ => panic!("variant layout should be Arbitrary"),
})
.collect(),
}
}
}
Expand Down
Loading