mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 11:37:39 +00:00
Eagerly convert some ctors to use their specialized ctors
This commit is contained in:
parent
24db8eaefd
commit
81e7e80990
@ -663,11 +663,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
|||||||
|
|
||||||
let arg_value = drop_place.place_ref(
|
let arg_value = drop_place.place_ref(
|
||||||
fx,
|
fx,
|
||||||
fx.layout_of(Ty::new_ref(
|
fx.layout_of(Ty::new_mut_ref(fx.tcx, fx.tcx.lifetimes.re_erased, ty)),
|
||||||
fx.tcx,
|
|
||||||
fx.tcx.lifetimes.re_erased,
|
|
||||||
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
let arg_value = adjust_arg_for_abi(fx, arg_value, &fn_abi.args[0], true);
|
let arg_value = adjust_arg_for_abi(fx, arg_value, &fn_abi.args[0], true);
|
||||||
|
|
||||||
|
@ -414,10 +414,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||||||
calculate_debuginfo_offset(bx, var.projection, base);
|
calculate_debuginfo_offset(bx, var.projection, base);
|
||||||
|
|
||||||
// Create a variable which will be a pointer to the actual value
|
// Create a variable which will be a pointer to the actual value
|
||||||
let ptr_ty = Ty::new_ptr(
|
let ptr_ty = Ty::new_mut_ptr(bx.tcx(), place.layout.ty);
|
||||||
bx.tcx(),
|
|
||||||
ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty },
|
|
||||||
);
|
|
||||||
let ptr_layout = bx.layout_of(ptr_ty);
|
let ptr_layout = bx.layout_of(ptr_ty);
|
||||||
let alloca = PlaceRef::alloca(bx, ptr_layout);
|
let alloca = PlaceRef::alloca(bx, ptr_layout);
|
||||||
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));
|
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));
|
||||||
|
@ -240,15 +240,9 @@ pub fn check_intrinsic_type(
|
|||||||
sym::prefetch_read_data
|
sym::prefetch_read_data
|
||||||
| sym::prefetch_write_data
|
| sym::prefetch_write_data
|
||||||
| sym::prefetch_read_instruction
|
| sym::prefetch_read_instruction
|
||||||
| sym::prefetch_write_instruction => (
|
| sym::prefetch_write_instruction => {
|
||||||
1,
|
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.i32], Ty::new_unit(tcx))
|
||||||
0,
|
}
|
||||||
vec![
|
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
|
||||||
tcx.types.i32,
|
|
||||||
],
|
|
||||||
Ty::new_unit(tcx),
|
|
||||||
),
|
|
||||||
sym::needs_drop => (1, 0, vec![], tcx.types.bool),
|
sym::needs_drop => (1, 0, vec![], tcx.types.bool),
|
||||||
|
|
||||||
sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)),
|
sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)),
|
||||||
@ -257,28 +251,22 @@ pub fn check_intrinsic_type(
|
|||||||
sym::arith_offset => (
|
sym::arith_offset => (
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
vec![
|
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.isize],
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
Ty::new_imm_ptr(tcx, param(0)),
|
||||||
tcx.types.isize,
|
|
||||||
],
|
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
|
||||||
),
|
),
|
||||||
sym::ptr_mask => (
|
sym::ptr_mask => (
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
vec![
|
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.usize],
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
Ty::new_imm_ptr(tcx, param(0)),
|
||||||
tcx.types.usize,
|
|
||||||
],
|
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
sym::copy | sym::copy_nonoverlapping => (
|
sym::copy | sym::copy_nonoverlapping => (
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
vec![
|
vec![
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
Ty::new_imm_ptr(tcx, param(0)),
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
Ty::new_mut_ptr(tcx, param(0)),
|
||||||
tcx.types.usize,
|
tcx.types.usize,
|
||||||
],
|
],
|
||||||
Ty::new_unit(tcx),
|
Ty::new_unit(tcx),
|
||||||
@ -287,8 +275,8 @@ pub fn check_intrinsic_type(
|
|||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
vec![
|
vec![
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
Ty::new_mut_ptr(tcx, param(0)),
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
Ty::new_imm_ptr(tcx, param(0)),
|
||||||
tcx.types.usize,
|
tcx.types.usize,
|
||||||
],
|
],
|
||||||
Ty::new_unit(tcx),
|
Ty::new_unit(tcx),
|
||||||
@ -300,11 +288,7 @@ pub fn check_intrinsic_type(
|
|||||||
sym::write_bytes | sym::volatile_set_memory => (
|
sym::write_bytes | sym::volatile_set_memory => (
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
vec![
|
vec![Ty::new_mut_ptr(tcx, param(0)), tcx.types.u8, tcx.types.usize],
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
|
||||||
tcx.types.u8,
|
|
||||||
tcx.types.usize,
|
|
||||||
],
|
|
||||||
Ty::new_unit(tcx),
|
Ty::new_unit(tcx),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -346,14 +346,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||||||
} else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind()
|
} else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind()
|
||||||
&& expr_mutbl == Mutability::Not
|
&& expr_mutbl == Mutability::Not
|
||||||
&& mutbl == Mutability::Mut
|
&& mutbl == Mutability::Mut
|
||||||
&& fcx.can_coerce(
|
&& fcx.can_coerce(Ty::new_mut_ref(fcx.tcx, expr_reg, expr_ty), self.cast_ty)
|
||||||
Ty::new_ref(
|
|
||||||
fcx.tcx,
|
|
||||||
expr_reg,
|
|
||||||
TypeAndMut { ty: expr_ty, mutbl: Mutability::Mut },
|
|
||||||
),
|
|
||||||
self.cast_ty,
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
sugg_mutref = true;
|
sugg_mutref = true;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||||||
target = match target.kind() {
|
target = match target.kind() {
|
||||||
&ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
|
&ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
|
||||||
assert!(mutbl.is_mut());
|
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"),
|
other => panic!("Cannot adjust receiver type {other:?} to const ptr"),
|
||||||
};
|
};
|
||||||
|
@ -1242,8 +1242,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not };
|
let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
|
||||||
let const_ptr_ty = Ty::new_ptr(self.tcx, const_self_ty);
|
|
||||||
self.pick_method(const_ptr_ty, unstable_candidates).map(|r| {
|
self.pick_method(const_ptr_ty, unstable_candidates).map(|r| {
|
||||||
r.map(|mut pick| {
|
r.map(|mut pick| {
|
||||||
pick.autoderefs = step.autoderefs;
|
pick.autoderefs = step.autoderefs;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use rustc_hir as hir;
|
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_index::Idx;
|
use rustc_index::Idx;
|
||||||
use rustc_middle::mir::patch::MirPatch;
|
use rustc_middle::mir::patch::MirPatch;
|
||||||
@ -629,11 +628,7 @@ where
|
|||||||
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
|
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
|
||||||
let ty = self.place_ty(self.place);
|
let ty = self.place_ty(self.place);
|
||||||
|
|
||||||
let ref_ty = Ty::new_ref(
|
let ref_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
|
||||||
tcx,
|
|
||||||
tcx.lifetimes.re_erased,
|
|
||||||
ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut },
|
|
||||||
);
|
|
||||||
let ref_place = self.new_temp(ref_ty);
|
let ref_place = self.new_temp(ref_ty);
|
||||||
let unit_temp = Place::from(self.new_temp(Ty::new_unit(tcx)));
|
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 move_ = |place: Place<'tcx>| Operand::Move(place);
|
||||||
let tcx = self.tcx();
|
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 ptr = Place::from(self.new_temp(ptr_ty));
|
||||||
let can_go = Place::from(self.new_temp(tcx.types.bool));
|
let can_go = Place::from(self.new_temp(tcx.types.bool));
|
||||||
let one = self.constant_usize(1);
|
let one = self.constant_usize(1);
|
||||||
|
@ -5,7 +5,7 @@ use rustc_middle::mir::{
|
|||||||
interpret::Scalar,
|
interpret::Scalar,
|
||||||
visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor},
|
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;
|
use rustc_session::Session;
|
||||||
|
|
||||||
pub struct CheckAlignment;
|
pub struct CheckAlignment;
|
||||||
@ -157,7 +157,7 @@ fn insert_alignment_check<'tcx>(
|
|||||||
new_block: BasicBlock,
|
new_block: BasicBlock,
|
||||||
) {
|
) {
|
||||||
// Cast the pointer to a *const ()
|
// 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 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();
|
let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into();
|
||||||
block_data
|
block_data
|
||||||
|
@ -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>) {
|
fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
let coroutine_ty = body.local_decls.raw[1].ty;
|
let coroutine_ty = body.local_decls.raw[1].ty;
|
||||||
|
|
||||||
let ref_coroutine_ty = Ty::new_ref(
|
let ref_coroutine_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty);
|
||||||
tcx,
|
|
||||||
tcx.lifetimes.re_erased,
|
|
||||||
ty::TypeAndMut { ty: coroutine_ty, mutbl: Mutability::Mut },
|
|
||||||
);
|
|
||||||
|
|
||||||
// Replace the by value coroutine argument
|
// Replace the by value coroutine argument
|
||||||
body.local_decls.raw[1].ty = ref_coroutine_ty;
|
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);
|
make_coroutine_state_argument_indirect(tcx, &mut body);
|
||||||
|
|
||||||
// Change the coroutine argument from &mut to *mut
|
// Change the coroutine argument from &mut to *mut
|
||||||
body.local_decls[SELF_ARG] = LocalDecl::with_source_info(
|
body.local_decls[SELF_ARG] =
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: coroutine_ty, mutbl: hir::Mutability::Mut }),
|
LocalDecl::with_source_info(Ty::new_mut_ptr(tcx, coroutine_ty), source_info);
|
||||||
source_info,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Make sure we remove dead blocks to remove
|
// Make sure we remove dead blocks to remove
|
||||||
// unrelated code from the resume part of the function
|
// unrelated code from the resume part of the function
|
||||||
|
@ -539,14 +539,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
|||||||
const_: Const::zero_sized(func_ty),
|
const_: Const::zero_sized(func_ty),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let ref_loc = self.make_place(
|
let ref_loc =
|
||||||
Mutability::Not,
|
self.make_place(Mutability::Not, Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty));
|
||||||
Ty::new_ref(
|
|
||||||
tcx,
|
|
||||||
tcx.lifetimes.re_erased,
|
|
||||||
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// `let ref_loc: &ty = &src;`
|
// `let ref_loc: &ty = &src;`
|
||||||
let statement = self.make_statement(StatementKind::Assign(Box::new((
|
let statement = self.make_statement(StatementKind::Assign(Box::new((
|
||||||
@ -771,11 +765,7 @@ fn build_call_shim<'tcx>(
|
|||||||
// let rcvr = &mut rcvr;
|
// let rcvr = &mut rcvr;
|
||||||
let ref_rcvr = local_decls.push(
|
let ref_rcvr = local_decls.push(
|
||||||
LocalDecl::new(
|
LocalDecl::new(
|
||||||
Ty::new_ref(
|
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, sig.inputs()[0]),
|
||||||
tcx,
|
|
||||||
tcx.lifetimes.re_erased,
|
|
||||||
ty::TypeAndMut { ty: sig.inputs()[0], mutbl: hir::Mutability::Mut },
|
|
||||||
),
|
|
||||||
span,
|
span,
|
||||||
)
|
)
|
||||||
.immutable(),
|
.immutable(),
|
||||||
|
@ -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) {
|
&& let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) {
|
||||||
Some((n_refs, receiver_ty))
|
Some((n_refs, receiver_ty))
|
||||||
} else if trait_predicate.def_id() != deref_trait_id {
|
} 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,
|
cx.tcx.lifetimes.re_erased,
|
||||||
ty::TypeAndMut {
|
receiver_ty,
|
||||||
ty: receiver_ty,
|
|
||||||
mutbl: Mutability::Not,
|
|
||||||
},
|
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -374,9 +374,9 @@ impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
|
|||||||
fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, &'tcx LayoutError<'tcx>> {
|
fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, &'tcx LayoutError<'tcx>> {
|
||||||
let tcx = layout_cx.tcx;
|
let tcx = layout_cx.tcx;
|
||||||
let mut_raw_ptr =
|
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 =
|
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 {
|
Ok(Self {
|
||||||
unit: layout_cx.layout_of(Ty::new_unit(tcx))?,
|
unit: layout_cx.layout_of(Ty::new_unit(tcx))?,
|
||||||
i8: layout_cx.layout_of(tcx.types.i8)?,
|
i8: layout_cx.layout_of(tcx.types.i8)?,
|
||||||
|
Loading…
Reference in New Issue
Block a user