Rollup merge of #109390 - cbeuw:aggregate-lit, r=oli-obk
Custom MIR: Support aggregate expressions Add support for tuple, array and ADT expressions in custom mir r? `````@oli-obk````` or `````@tmiasko````` or `````@JakobDegen`````
This commit is contained in:
commit
b2e48edded
6 changed files with 135 additions and 1 deletions
|
@ -1165,7 +1165,7 @@ pub enum AggregateKind<'tcx> {
|
|||
Tuple,
|
||||
|
||||
/// The second field is the variant index. It's equal to 0 for struct
|
||||
/// and union expressions. The fourth field is
|
||||
/// and union expressions. The last field is the
|
||||
/// active field number and is present only for union expressions
|
||||
/// -- e.g., for a union expression `SomeUnion { c: .. }`, the
|
||||
/// active field index would identity the field `c`
|
||||
|
|
|
@ -166,6 +166,28 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||
let cast_kind = mir_cast_kind(source_ty, expr.ty);
|
||||
Ok(Rvalue::Cast(cast_kind, source, expr.ty))
|
||||
},
|
||||
ExprKind::Tuple { fields } => Ok(
|
||||
Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Tuple),
|
||||
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
|
||||
)
|
||||
),
|
||||
ExprKind::Array { fields } => {
|
||||
let elem_ty = expr.ty.builtin_index().expect("ty must be an array");
|
||||
Ok(Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Array(elem_ty)),
|
||||
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
|
||||
))
|
||||
},
|
||||
ExprKind::Adt(box AdtExpr{ adt_def, variant_index, substs, fields, .. }) => {
|
||||
let is_union = adt_def.is_union();
|
||||
let active_field_index = is_union.then(|| fields[0].name.index());
|
||||
|
||||
Ok(Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Adt(adt_def.did(), *variant_index, substs, None, active_field_index)),
|
||||
fields.iter().map(|f| self.parse_operand(f.expr)).collect::<Result<_, _>>()?
|
||||
))
|
||||
},
|
||||
_ => self.parse_operand(expr_id).map(Rvalue::Use),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue