Move TyCtxt::mk_x
to Ty::new_x
where applicable
This commit is contained in:
parent
5dac6b320b
commit
12138b8e5e
164 changed files with 1386 additions and 1185 deletions
|
@ -155,7 +155,7 @@ fn insert_alignment_check<'tcx>(
|
|||
new_block: BasicBlock,
|
||||
) {
|
||||
// Cast the pointer to a *const ()
|
||||
let const_raw_ptr = tcx.mk_ptr(TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
|
||||
let const_raw_ptr = Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
|
||||
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
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn build_ptr_tys<'tcx>(
|
|||
let substs = tcx.mk_substs(&[pointee.into()]);
|
||||
let unique_ty = tcx.type_of(unique_did).subst(tcx, substs);
|
||||
let nonnull_ty = tcx.type_of(nonnull_did).subst(tcx, substs);
|
||||
let ptr_ty = tcx.mk_imm_ptr(pointee);
|
||||
let ptr_ty = Ty::new_imm_ptr(tcx, pointee);
|
||||
|
||||
(unique_ty, nonnull_ty, ptr_ty)
|
||||
}
|
||||
|
|
|
@ -413,8 +413,11 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
|
|||
fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let gen_ty = body.local_decls.raw[1].ty;
|
||||
|
||||
let ref_gen_ty =
|
||||
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut });
|
||||
let ref_gen_ty = Ty::new_ref(
|
||||
tcx,
|
||||
tcx.lifetimes.re_erased,
|
||||
ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut },
|
||||
);
|
||||
|
||||
// Replace the by value generator argument
|
||||
body.local_decls.raw[1].ty = ref_gen_ty;
|
||||
|
@ -429,7 +432,7 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
|
|||
let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span));
|
||||
let pin_adt_ref = tcx.adt_def(pin_did);
|
||||
let substs = tcx.mk_substs(&[ref_gen_ty.into()]);
|
||||
let pin_ref_gen_ty = tcx.mk_adt(pin_adt_ref, substs);
|
||||
let pin_ref_gen_ty = Ty::new_adt(tcx, pin_adt_ref, substs);
|
||||
|
||||
// Replace the by ref generator argument
|
||||
body.local_decls.raw[1].ty = pin_ref_gen_ty;
|
||||
|
@ -481,7 +484,7 @@ fn replace_local<'tcx>(
|
|||
/// still using the `ResumeTy` indirection for the time being, and that indirection
|
||||
/// is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
|
||||
fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let context_mut_ref = tcx.mk_task_context();
|
||||
let context_mut_ref = Ty::new_task_context(tcx);
|
||||
|
||||
// replace the type of the `resume` argument
|
||||
replace_resume_ty_local(tcx, body, Local::new(2), context_mut_ref);
|
||||
|
@ -1130,13 +1133,13 @@ fn create_generator_drop_shim<'tcx>(
|
|||
}
|
||||
|
||||
// Replace the return variable
|
||||
body.local_decls[RETURN_PLACE] = LocalDecl::with_source_info(tcx.mk_unit(), source_info);
|
||||
body.local_decls[RETURN_PLACE] = LocalDecl::with_source_info(Ty::new_unit(tcx), source_info);
|
||||
|
||||
make_generator_state_argument_indirect(tcx, &mut body);
|
||||
|
||||
// Change the generator argument from &mut to *mut
|
||||
body.local_decls[SELF_ARG] = LocalDecl::with_source_info(
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: gen_ty, mutbl: hir::Mutability::Mut }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: gen_ty, mutbl: hir::Mutability::Mut }),
|
||||
source_info,
|
||||
);
|
||||
|
||||
|
@ -1493,7 +1496,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
|||
let state_substs = tcx.mk_substs(&[yield_ty.into(), body.return_ty().into()]);
|
||||
(state_adt_ref, state_substs)
|
||||
};
|
||||
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
|
||||
let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_substs);
|
||||
|
||||
// We rename RETURN_PLACE which has type mir.return_ty to new_ret_local
|
||||
// RETURN_PLACE then is a fresh unused local with type ret_ty.
|
||||
|
@ -1509,8 +1512,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
|||
// case there is no `Assign` to it that the transform can turn into a store to the generator
|
||||
// state. After the yield the slot in the generator state would then be uninitialized.
|
||||
let resume_local = Local::new(2);
|
||||
let resume_ty =
|
||||
if is_async_kind { tcx.mk_task_context() } else { body.local_decls[resume_local].ty };
|
||||
let resume_ty = if is_async_kind {
|
||||
Ty::new_task_context(tcx)
|
||||
} else {
|
||||
body.local_decls[resume_local].ty
|
||||
};
|
||||
let new_resume_local = replace_local(resume_local, resume_ty, body, tcx);
|
||||
|
||||
// When first entering the generator, move the resume argument into its new local.
|
||||
|
|
|
@ -141,7 +141,7 @@ impl EnumSizeOpt {
|
|||
self.candidate(tcx, param_env, ty, &mut alloc_cache)?;
|
||||
let alloc = tcx.global_alloc(alloc_id).unwrap_memory();
|
||||
|
||||
let tmp_ty = tcx.mk_array(tcx.types.usize, num_variants as u64);
|
||||
let tmp_ty = Ty::new_array(tcx, tcx.types.usize, num_variants as u64);
|
||||
|
||||
let size_array_local = local_decls.push(LocalDecl::new(tmp_ty, span));
|
||||
let store_live = Statement {
|
||||
|
@ -208,8 +208,9 @@ impl EnumSizeOpt {
|
|||
))),
|
||||
};
|
||||
|
||||
let dst =
|
||||
Place::from(local_decls.push(LocalDecl::new(tcx.mk_mut_ptr(ty), span)));
|
||||
let dst = Place::from(
|
||||
local_decls.push(LocalDecl::new(Ty::new_mut_ptr(tcx, ty), span)),
|
||||
);
|
||||
|
||||
let dst_ptr = Statement {
|
||||
source_info,
|
||||
|
@ -219,7 +220,7 @@ impl EnumSizeOpt {
|
|||
))),
|
||||
};
|
||||
|
||||
let dst_cast_ty = tcx.mk_mut_ptr(tcx.types.u8);
|
||||
let dst_cast_ty = Ty::new_mut_ptr(tcx, tcx.types.u8);
|
||||
let dst_cast_place =
|
||||
Place::from(local_decls.push(LocalDecl::new(dst_cast_ty, span)));
|
||||
|
||||
|
@ -231,8 +232,9 @@ impl EnumSizeOpt {
|
|||
))),
|
||||
};
|
||||
|
||||
let src =
|
||||
Place::from(local_decls.push(LocalDecl::new(tcx.mk_imm_ptr(ty), span)));
|
||||
let src = Place::from(
|
||||
local_decls.push(LocalDecl::new(Ty::new_imm_ptr(tcx, ty), span)),
|
||||
);
|
||||
|
||||
let src_ptr = Statement {
|
||||
source_info,
|
||||
|
@ -242,7 +244,7 @@ impl EnumSizeOpt {
|
|||
))),
|
||||
};
|
||||
|
||||
let src_cast_ty = tcx.mk_imm_ptr(tcx.types.u8);
|
||||
let src_cast_ty = Ty::new_imm_ptr(tcx, tcx.types.u8);
|
||||
let src_cast_place =
|
||||
Place::from(local_decls.push(LocalDecl::new(src_cast_ty, span)));
|
||||
|
||||
|
|
|
@ -485,7 +485,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
|||
let tcx = self.tcx;
|
||||
|
||||
// `func == Clone::clone(&ty) -> ty`
|
||||
let func_ty = tcx.mk_fn_def(self.def_id, [ty]);
|
||||
let func_ty = Ty::new_fn_def(tcx, self.def_id, [ty]);
|
||||
let func = Operand::Constant(Box::new(Constant {
|
||||
span: self.span,
|
||||
user_ty: None,
|
||||
|
@ -494,7 +494,11 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
|||
|
||||
let ref_loc = self.make_place(
|
||||
Mutability::Not,
|
||||
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ref(
|
||||
tcx,
|
||||
tcx.lifetimes.re_erased,
|
||||
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
|
||||
),
|
||||
);
|
||||
|
||||
// `let ref_loc: &ty = &src;`
|
||||
|
@ -644,7 +648,7 @@ fn build_call_shim<'tcx>(
|
|||
let untuple_args = sig.inputs();
|
||||
|
||||
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
|
||||
let arg_tup = tcx.mk_tup(untuple_args);
|
||||
let arg_tup = Ty::new_tup(tcx, untuple_args);
|
||||
|
||||
(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
|
||||
} else {
|
||||
|
@ -680,9 +684,9 @@ fn build_call_shim<'tcx>(
|
|||
*self_arg = match rcvr_adjustment.unwrap() {
|
||||
Adjustment::Identity => fnty,
|
||||
Adjustment::Deref { source } => match source {
|
||||
DerefSource::ImmRef => tcx.mk_imm_ref(tcx.lifetimes.re_erased, fnty),
|
||||
DerefSource::MutRef => tcx.mk_mut_ref(tcx.lifetimes.re_erased, fnty),
|
||||
DerefSource::MutPtr => tcx.mk_mut_ptr(fnty),
|
||||
DerefSource::ImmRef => Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, fnty),
|
||||
DerefSource::MutRef => Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, fnty),
|
||||
DerefSource::MutPtr => Ty::new_mut_ptr(tcx, fnty),
|
||||
},
|
||||
Adjustment::RefMut => bug!("`RefMut` is never used with indirect calls: {instance:?}"),
|
||||
};
|
||||
|
@ -696,7 +700,7 @@ fn build_call_shim<'tcx>(
|
|||
let mut inputs_and_output = sig.inputs_and_output.to_vec();
|
||||
let self_arg = &mut inputs_and_output[0];
|
||||
debug_assert!(tcx.generics_of(def_id).has_self && *self_arg == tcx.types.self_param);
|
||||
*self_arg = tcx.mk_mut_ptr(*self_arg);
|
||||
*self_arg = Ty::new_mut_ptr(tcx, *self_arg);
|
||||
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
|
||||
}
|
||||
|
||||
|
@ -720,7 +724,8 @@ fn build_call_shim<'tcx>(
|
|||
// let rcvr = &mut rcvr;
|
||||
let ref_rcvr = local_decls.push(
|
||||
LocalDecl::new(
|
||||
tcx.mk_ref(
|
||||
Ty::new_ref(
|
||||
tcx,
|
||||
tcx.lifetimes.re_erased,
|
||||
ty::TypeAndMut { ty: sig.inputs()[0], mutbl: hir::Mutability::Mut },
|
||||
),
|
||||
|
@ -946,7 +951,7 @@ fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'t
|
|||
let rvalue = Rvalue::Cast(
|
||||
CastKind::FnPtrToPtr,
|
||||
Operand::Move(Place::from(Local::new(1))),
|
||||
tcx.mk_imm_ptr(tcx.types.unit),
|
||||
Ty::new_imm_ptr(tcx, tcx.types.unit),
|
||||
);
|
||||
let stmt = Statement {
|
||||
source_info,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue