Make index_by_increasing_offset
return one item for primitives
This commit is contained in:
parent
dcab06d7d2
commit
99213ae164
@ -1271,7 +1271,12 @@ pub fn index_by_increasing_offset(&self) -> impl ExactSizeIterator<Item = usize>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(0..self.count()).map(move |i| match *self {
|
// Primitives don't really have fields in the way that structs do,
|
||||||
|
// but having this return an empty iterator for them is unhelpful
|
||||||
|
// since that makes them look kinda like ZSTs, which they're not.
|
||||||
|
let pseudofield_count = if let FieldsShape::Primitive = self { 1 } else { self.count() };
|
||||||
|
|
||||||
|
(0..pseudofield_count).map(move |i| match *self {
|
||||||
FieldsShape::Primitive | FieldsShape::Union(_) | FieldsShape::Array { .. } => i,
|
FieldsShape::Primitive | FieldsShape::Union(_) | FieldsShape::Array { .. } => i,
|
||||||
FieldsShape::Arbitrary { .. } => {
|
FieldsShape::Arbitrary { .. } => {
|
||||||
if use_small {
|
if use_small {
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
use rustc_target::abi::{self, FieldIdx, FIRST_VARIANT};
|
use rustc_target::abi::{self, FieldIdx, FIRST_VARIANT};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use either::Either;
|
|
||||||
|
|
||||||
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
#[instrument(level = "trace", skip(self, bx))]
|
#[instrument(level = "trace", skip(self, bx))]
|
||||||
@ -698,24 +697,16 @@ pub fn codegen_rvalue_operand(
|
|||||||
}
|
}
|
||||||
mir::Rvalue::Use(ref operand) => self.codegen_operand(bx, operand),
|
mir::Rvalue::Use(ref operand) => self.codegen_operand(bx, operand),
|
||||||
mir::Rvalue::Repeat(..) => bug!("{rvalue:?} in codegen_rvalue_operand"),
|
mir::Rvalue::Repeat(..) => bug!("{rvalue:?} in codegen_rvalue_operand"),
|
||||||
mir::Rvalue::Aggregate(ref kind, ref fields) => {
|
mir::Rvalue::Aggregate(_, ref fields) => {
|
||||||
let ty = rvalue.ty(self.mir, self.cx.tcx());
|
let ty = rvalue.ty(self.mir, self.cx.tcx());
|
||||||
let ty = self.monomorphize(ty);
|
let ty = self.monomorphize(ty);
|
||||||
let layout = self.cx.layout_of(ty);
|
let layout = self.cx.layout_of(ty);
|
||||||
|
|
||||||
let field_indices = if let mir::AggregateKind::RawPtr(..) = **kind {
|
|
||||||
// `index_by_increasing_offset` gives an empty iterator for primitives
|
|
||||||
Either::Left([0_usize, 1_usize].iter().copied())
|
|
||||||
} else {
|
|
||||||
Either::Right(layout.fields.index_by_increasing_offset())
|
|
||||||
};
|
|
||||||
debug_assert_eq!(field_indices.len(), fields.len());
|
|
||||||
|
|
||||||
// `rvalue_creates_operand` has arranged that we only get here if
|
// `rvalue_creates_operand` has arranged that we only get here if
|
||||||
// we can build the aggregate immediate from the field immediates.
|
// we can build the aggregate immediate from the field immediates.
|
||||||
let mut inputs = ArrayVec::<Bx::Value, 2>::new();
|
let mut inputs = ArrayVec::<Bx::Value, 2>::new();
|
||||||
let mut input_scalars = ArrayVec::<abi::Scalar, 2>::new();
|
let mut input_scalars = ArrayVec::<abi::Scalar, 2>::new();
|
||||||
for field_idx in field_indices {
|
for field_idx in layout.fields.index_by_increasing_offset() {
|
||||||
let field_idx = FieldIdx::from_usize(field_idx);
|
let field_idx = FieldIdx::from_usize(field_idx);
|
||||||
let op = self.codegen_operand(bx, &fields[field_idx]);
|
let op = self.codegen_operand(bx, &fields[field_idx]);
|
||||||
let values = op.val.immediates_or_place().left_or_else(|p| {
|
let values = op.val.immediates_or_place().left_or_else(|p| {
|
||||||
|
Loading…
Reference in New Issue
Block a user