1
Fork 0

Auto merge of #135753 - compiler-errors:from-ty-const, r=oli-obk

Get rid of `mir::Const::from_ty_const`

This function is strange, because it turns valtrees into `mir::Const::Value`, but the rest of the const variants stay as type system consts.

All of the callsites except for one in `instsimplify` (array length simplification of `ptr_metadata` call) just go through the valtree arm of the function, so it's easier to just create a `mir::Const` directly for those.

For the instsimplify case, if we have a type system const we should *keep* having a type system const, rather than turning it into a `mir::Const::Value`; it doesn't really matter in practice, though, bc `usize` has no padding, but it feels more principled.
This commit is contained in:
bors 2025-01-26 09:26:34 +00:00
commit d9b4598d7e
10 changed files with 21 additions and 98 deletions

View file

@ -1178,11 +1178,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
) if let ty::Slice(..) = to.builtin_deref(true).unwrap().kind()
&& let ty::Array(_, len) = from.builtin_deref(true).unwrap().kind() =>
{
return self.insert_constant(Const::from_ty_const(
*len,
self.tcx.types.usize,
self.tcx,
));
return self.insert_constant(Const::Ty(self.tcx.types.usize, *len));
}
_ => Value::UnaryOp(op, arg_index),
};
@ -1492,11 +1488,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
// Trivial case: we are fetching a statically known length.
let place_ty = place.ty(self.local_decls, self.tcx).ty;
if let ty::Array(_, len) = place_ty.kind() {
return self.insert_constant(Const::from_ty_const(
*len,
self.tcx.types.usize,
self.tcx,
));
return self.insert_constant(Const::Ty(self.tcx.types.usize, *len));
}
let mut inner = self.simplify_place_value(place, location)?;
@ -1518,11 +1510,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
&& let Some(to) = to.builtin_deref(true)
&& let ty::Slice(..) = to.kind()
{
return self.insert_constant(Const::from_ty_const(
*len,
self.tcx.types.usize,
self.tcx,
));
return self.insert_constant(Const::Ty(self.tcx.types.usize, *len));
}
// Fallback: a symbolic `Len`.

View file

@ -171,7 +171,7 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
if let Rvalue::Len(ref place) = *rvalue {
let place_ty = place.ty(self.local_decls, self.tcx).ty;
if let ty::Array(_, len) = *place_ty.kind() {
let const_ = Const::from_ty_const(len, self.tcx.types.usize, self.tcx);
let const_ = Const::Ty(self.tcx.types.usize, len);
let constant = ConstOperand { span: DUMMY_SP, const_, user_ty: None };
*rvalue = Rvalue::Use(Operand::Constant(Box::new(constant)));
}