Skip to content

Commit

Permalink
move ignoring condition out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jun 14, 2024
1 parent 7246da3 commit b375e33
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,19 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
.collect::<Option<Vec<&OpTy<'_>>>>()?;
let ty = match kind {
AggregateTy::Array => {
assert!(fields.len() > 0);
Ty::new_array(self.tcx, fields[0].layout.ty, fields.len() as u64)
let [field, ..] = fields.as_slice() else {
bug!("fields.len() == 0");
};
let field_ty = field.layout.ty;
// Ignore nested array
if field_ty.is_array() {
trace!(
"ignoring nested array of type: [{field_ty}; {len}]",
len = fields.len(),
);
return None;
}
Ty::new_array(self.tcx, field_ty, fields.len() as u64)
}
AggregateTy::Tuple => {
Ty::new_tup_from_iter(self.tcx, fields.iter().map(|f| f.layout.ty))
Expand Down Expand Up @@ -424,10 +435,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
.ecx
.intern_with_temp_alloc(ty, |ecx, dest| {
for (field_index, op) in fields.iter().copied().enumerate() {
// ignore nested arrays
if let Either::Left(_) = op.as_mplace_or_imm() {
interpret::throw_inval!(TooGeneric);
}
let field_dest = ecx.project_field(dest, field_index)?;
ecx.copy_op(op, &field_dest)?;
}
Expand Down

0 comments on commit b375e33

Please sign in to comment.