Eagerly convert some ctors to use their specialized ctors

This commit is contained in:
Michael Goulet 2024-03-21 16:50:21 -04:00
parent 24db8eaefd
commit 81e7e80990
12 changed files with 31 additions and 86 deletions

View File

@ -663,11 +663,7 @@ pub(crate) fn codegen_drop<'tcx>(
let arg_value = drop_place.place_ref(
fx,
fx.layout_of(Ty::new_ref(
fx.tcx,
fx.tcx.lifetimes.re_erased,
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
)),
fx.layout_of(Ty::new_mut_ref(fx.tcx, fx.tcx.lifetimes.re_erased, ty)),
);
let arg_value = adjust_arg_for_abi(fx, arg_value, &fn_abi.args[0], true);

View File

@ -414,10 +414,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
calculate_debuginfo_offset(bx, var.projection, base);
// Create a variable which will be a pointer to the actual value
let ptr_ty = Ty::new_ptr(
bx.tcx(),
ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty },
);
let ptr_ty = Ty::new_mut_ptr(bx.tcx(), place.layout.ty);
let ptr_layout = bx.layout_of(ptr_ty);
let alloca = PlaceRef::alloca(bx, ptr_layout);
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));

View File

@ -240,15 +240,9 @@ pub fn check_intrinsic_type(
sym::prefetch_read_data
| sym::prefetch_write_data
| sym::prefetch_read_instruction
| sym::prefetch_write_instruction => (
1,
0,
vec![
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.i32,
],
Ty::new_unit(tcx),
),
| sym::prefetch_write_instruction => {
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.i32], Ty::new_unit(tcx))
}
sym::needs_drop => (1, 0, vec![], tcx.types.bool),
sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)),
@ -257,28 +251,22 @@ pub fn check_intrinsic_type(
sym::arith_offset => (
1,
0,
vec![
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.isize,
],
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.isize],
Ty::new_imm_ptr(tcx, param(0)),
),
sym::ptr_mask => (
1,
0,
vec![
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.usize,
],
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.usize],
Ty::new_imm_ptr(tcx, param(0)),
),
sym::copy | sym::copy_nonoverlapping => (
1,
0,
vec![
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
Ty::new_imm_ptr(tcx, param(0)),
Ty::new_mut_ptr(tcx, param(0)),
tcx.types.usize,
],
Ty::new_unit(tcx),
@ -287,8 +275,8 @@ pub fn check_intrinsic_type(
1,
0,
vec![
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
Ty::new_mut_ptr(tcx, param(0)),
Ty::new_imm_ptr(tcx, param(0)),
tcx.types.usize,
],
Ty::new_unit(tcx),
@ -300,11 +288,7 @@ pub fn check_intrinsic_type(
sym::write_bytes | sym::volatile_set_memory => (
1,
0,
vec![
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
tcx.types.u8,
tcx.types.usize,
],
vec![Ty::new_mut_ptr(tcx, param(0)), tcx.types.u8, tcx.types.usize],
Ty::new_unit(tcx),
),

View File

@ -346,14 +346,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
} else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind()
&& expr_mutbl == Mutability::Not
&& mutbl == Mutability::Mut
&& fcx.can_coerce(
Ty::new_ref(
fcx.tcx,
expr_reg,
TypeAndMut { ty: expr_ty, mutbl: Mutability::Mut },
),
self.cast_ty,
)
&& fcx.can_coerce(Ty::new_mut_ref(fcx.tcx, expr_reg, expr_ty), self.cast_ty)
{
sugg_mutref = true;
}

View File

@ -223,7 +223,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
target = match target.kind() {
&ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
assert!(mutbl.is_mut());
Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty })
Ty::new_imm_ptr(self.tcx, ty)
}
other => panic!("Cannot adjust receiver type {other:?} to const ptr"),
};

View File

@ -1242,8 +1242,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
return None;
};
let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not };
let const_ptr_ty = Ty::new_ptr(self.tcx, const_self_ty);
let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
self.pick_method(const_ptr_ty, unstable_candidates).map(|r| {
r.map(|mut pick| {
pick.autoderefs = step.autoderefs;

View File

@ -1,4 +1,3 @@
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_index::Idx;
use rustc_middle::mir::patch::MirPatch;
@ -629,11 +628,7 @@ where
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
let ty = self.place_ty(self.place);
let ref_ty = Ty::new_ref(
tcx,
tcx.lifetimes.re_erased,
ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut },
);
let ref_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
let ref_place = self.new_temp(ref_ty);
let unit_temp = Place::from(self.new_temp(Ty::new_unit(tcx)));
@ -700,7 +695,7 @@ where
let move_ = |place: Place<'tcx>| Operand::Move(place);
let tcx = self.tcx();
let ptr_ty = Ty::new_ptr(tcx, ty::TypeAndMut { ty: ety, mutbl: hir::Mutability::Mut });
let ptr_ty = Ty::new_mut_ptr(tcx, ety);
let ptr = Place::from(self.new_temp(ptr_ty));
let can_go = Place::from(self.new_temp(tcx.types.bool));
let one = self.constant_usize(1);

View File

@ -5,7 +5,7 @@ use rustc_middle::mir::{
interpret::Scalar,
visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor},
};
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeAndMut};
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
use rustc_session::Session;
pub struct CheckAlignment;
@ -157,7 +157,7 @@ fn insert_alignment_check<'tcx>(
new_block: BasicBlock,
) {
// Cast the pointer to a *const ()
let const_raw_ptr = Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit);
let rvalue = Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(pointer), const_raw_ptr);
let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into();
block_data

View File

@ -570,11 +570,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let coroutine_ty = body.local_decls.raw[1].ty;
let ref_coroutine_ty = Ty::new_ref(
tcx,
tcx.lifetimes.re_erased,
ty::TypeAndMut { ty: coroutine_ty, mutbl: Mutability::Mut },
);
let ref_coroutine_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty);
// Replace the by value coroutine argument
body.local_decls.raw[1].ty = ref_coroutine_ty;
@ -1265,10 +1261,8 @@ fn create_coroutine_drop_shim<'tcx>(
make_coroutine_state_argument_indirect(tcx, &mut body);
// Change the coroutine argument from &mut to *mut
body.local_decls[SELF_ARG] = LocalDecl::with_source_info(
Ty::new_ptr(tcx, ty::TypeAndMut { ty: coroutine_ty, mutbl: hir::Mutability::Mut }),
source_info,
);
body.local_decls[SELF_ARG] =
LocalDecl::with_source_info(Ty::new_mut_ptr(tcx, coroutine_ty), source_info);
// Make sure we remove dead blocks to remove
// unrelated code from the resume part of the function

View File

@ -539,14 +539,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
const_: Const::zero_sized(func_ty),
}));
let ref_loc = self.make_place(
Mutability::Not,
Ty::new_ref(
tcx,
tcx.lifetimes.re_erased,
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
),
);
let ref_loc =
self.make_place(Mutability::Not, Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty));
// `let ref_loc: &ty = &src;`
let statement = self.make_statement(StatementKind::Assign(Box::new((
@ -771,11 +765,7 @@ fn build_call_shim<'tcx>(
// let rcvr = &mut rcvr;
let ref_rcvr = local_decls.push(
LocalDecl::new(
Ty::new_ref(
tcx,
tcx.lifetimes.re_erased,
ty::TypeAndMut { ty: sig.inputs()[0], mutbl: hir::Mutability::Mut },
),
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, sig.inputs()[0]),
span,
)
.immutable(),

View File

@ -336,12 +336,9 @@ fn check_other_call_arg<'tcx>(
&& let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) {
Some((n_refs, receiver_ty))
} else if trait_predicate.def_id() != deref_trait_id {
Some((1, Ty::new_ref(cx.tcx,
Some((1, Ty::new_imm_ref(cx.tcx,
cx.tcx.lifetimes.re_erased,
ty::TypeAndMut {
ty: receiver_ty,
mutbl: Mutability::Not,
},
receiver_ty,
)))
} else {
None

View File

@ -374,9 +374,9 @@ impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, &'tcx LayoutError<'tcx>> {
let tcx = layout_cx.tcx;
let mut_raw_ptr =
Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Mut });
Ty::new_mut_ptr(tcx, tcx.types.unit);
let const_raw_ptr =
Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
Ty::new_imm_ptr(tcx, tcx.types.unit);
Ok(Self {
unit: layout_cx.layout_of(Ty::new_unit(tcx))?,
i8: layout_cx.layout_of(tcx.types.i8)?,