Skip to content

Commit

Permalink
Change enum->int casts to not go through MIR casts.
Browse files Browse the repository at this point in the history
Instead we generate a discriminant rvalue and cast the result of that.
  • Loading branch information
oli-obk committed Jun 30, 2022
1 parent 92749f0 commit 846eecb
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,29 +635,6 @@ fn codegen_stmt<'tcx>(
let (ptr, _extra) = operand.load_scalar_pair(fx);
lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
}
} else if let ty::Adt(adt_def, _substs) = from_ty.kind() {
// enum -> discriminant value
assert!(adt_def.is_enum());
match to_ty.kind() {
ty::Uint(_) | ty::Int(_) => {}
_ => unreachable!("cast adt {} -> {}", from_ty, to_ty),
}
let to_clif_ty = fx.clif_type(to_ty).unwrap();

let discriminant = crate::discriminant::codegen_get_discriminant(
fx,
operand,
fx.layout_of(operand.layout().ty.discriminant_ty(fx.tcx)),
)
.load_scalar(fx);

let res = crate::cast::clif_intcast(
fx,
discriminant,
to_clif_ty,
to_ty.is_signed(),
);
lval.write_cvalue(fx, CValue::by_val(res, dest_layout));
} else {
let to_clif_ty = fx.clif_type(to_ty).unwrap();
let from = operand.load_scalar(fx);
Expand Down

0 comments on commit 846eecb

Please sign in to comment.