summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_mir_transform/src/shim.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_mir_transform/src/shim.rs')
-rw-r--r--compiler/rustc_mir_transform/src/shim.rs65
1 files changed, 36 insertions, 29 deletions
diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs
index b176db3c9..223dc59c6 100644
--- a/compiler/rustc_mir_transform/src/shim.rs
+++ b/compiler/rustc_mir_transform/src/shim.rs
@@ -3,8 +3,8 @@ use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_middle::mir::*;
use rustc_middle::query::Providers;
-use rustc_middle::ty::InternalSubsts;
-use rustc_middle::ty::{self, EarlyBinder, GeneratorSubsts, Ty, TyCtxt};
+use rustc_middle::ty::GenericArgs;
+use rustc_middle::ty::{self, EarlyBinder, GeneratorArgs, Ty, TyCtxt};
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use rustc_index::{Idx, IndexVec};
@@ -69,10 +69,19 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
ty::InstanceDef::DropGlue(def_id, ty) => {
// FIXME(#91576): Drop shims for generators aren't subject to the MIR passes at the end
// of this function. Is this intentional?
- if let Some(ty::Generator(gen_def_id, substs, _)) = ty.map(Ty::kind) {
+ if let Some(ty::Generator(gen_def_id, args, _)) = ty.map(Ty::kind) {
let body = tcx.optimized_mir(*gen_def_id).generator_drop().unwrap();
- let body = EarlyBinder::bind(body.clone()).subst(tcx, substs);
+ let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args);
debug!("make_shim({:?}) = {:?}", instance, body);
+
+ // Run empty passes to mark phase change and perform validation.
+ pm::run_passes(
+ tcx,
+ &mut body,
+ &[],
+ Some(MirPhase::Runtime(RuntimePhase::Optimized)),
+ );
+
return body;
}
@@ -160,12 +169,12 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
assert!(!matches!(ty, Some(ty) if ty.is_generator()));
- let substs = if let Some(ty) = ty {
- tcx.mk_substs(&[ty.into()])
+ let args = if let Some(ty) = ty {
+ tcx.mk_args(&[ty.into()])
} else {
- InternalSubsts::identity_for_item(tcx, def_id)
+ GenericArgs::identity_for_item(tcx, def_id)
};
- let sig = tcx.fn_sig(def_id).subst(tcx, substs);
+ let sig = tcx.fn_sig(def_id).instantiate(tcx, args);
let sig = tcx.erase_late_bound_regions(sig);
let span = tcx.def_span(def_id);
@@ -377,12 +386,10 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
match self_ty.kind() {
_ if is_copy => builder.copy_shim(),
- ty::Closure(_, substs) => {
- builder.tuple_like_shim(dest, src, substs.as_closure().upvar_tys())
- }
+ ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
- ty::Generator(gen_def_id, substs, hir::Movability::Movable) => {
- builder.generator_shim(dest, src, *gen_def_id, substs.as_generator())
+ ty::Generator(gen_def_id, args, hir::Movability::Movable) => {
+ builder.generator_shim(dest, src, *gen_def_id, args.as_generator())
}
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),
};
@@ -404,7 +411,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
// we must subst the self_ty because it's
// otherwise going to be TySelf and we can't index
// or access fields of a Place of type TySelf.
- let sig = tcx.fn_sig(def_id).subst(tcx, &[self_ty.into()]);
+ let sig = tcx.fn_sig(def_id).instantiate(tcx, &[self_ty.into()]);
let sig = tcx.erase_late_bound_regions(sig);
let span = tcx.def_span(def_id);
@@ -587,17 +594,17 @@ impl<'tcx> CloneShimBuilder<'tcx> {
dest: Place<'tcx>,
src: Place<'tcx>,
gen_def_id: DefId,
- substs: GeneratorSubsts<'tcx>,
+ args: GeneratorArgs<'tcx>,
) {
self.block(vec![], TerminatorKind::Goto { target: self.block_index_offset(3) }, false);
let unwind = self.block(vec![], TerminatorKind::Resume, true);
// This will get overwritten with a switch once we know the target blocks
let switch = self.block(vec![], TerminatorKind::Unreachable, false);
- let unwind = self.clone_fields(dest, src, switch, unwind, substs.upvar_tys());
+ let unwind = self.clone_fields(dest, src, switch, unwind, args.upvar_tys());
let target = self.block(vec![], TerminatorKind::Return, false);
let unreachable = self.block(vec![], TerminatorKind::Unreachable, false);
- let mut cases = Vec::with_capacity(substs.state_tys(gen_def_id, self.tcx).count());
- for (index, state_tys) in substs.state_tys(gen_def_id, self.tcx).enumerate() {
+ let mut cases = Vec::with_capacity(args.state_tys(gen_def_id, self.tcx).count());
+ for (index, state_tys) in args.state_tys(gen_def_id, self.tcx).enumerate() {
let variant_index = VariantIdx::new(index);
let dest = self.tcx.mk_place_downcast_unnamed(dest, variant_index);
let src = self.tcx.mk_place_downcast_unnamed(src, variant_index);
@@ -613,7 +620,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
cases.push((index as u128, start_block));
let _final_cleanup_block = self.clone_fields(dest, src, target, unwind, state_tys);
}
- let discr_ty = substs.discr_ty(self.tcx);
+ let discr_ty = args.discr_ty(self.tcx);
let temp = self.make_place(Mutability::Mut, discr_ty);
let rvalue = Rvalue::Discriminant(src);
let statement = self.make_statement(StatementKind::Assign(Box::new((temp, rvalue))));
@@ -642,7 +649,7 @@ fn build_call_shim<'tcx>(
// `FnPtrShim` contains the fn pointer type that a call shim is being built for - this is used
// to substitute into the signature of the shim. It is not necessary for users of this
// MIR body to perform further substitutions (see `InstanceDef::has_polymorphic_mir_body`).
- let (sig_substs, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance {
+ let (sig_args, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance {
let sig = tcx.erase_late_bound_regions(ty.fn_sig(tcx));
let untuple_args = sig.inputs();
@@ -659,11 +666,11 @@ fn build_call_shim<'tcx>(
let sig = tcx.fn_sig(def_id);
let sig = sig.map_bound(|sig| tcx.erase_late_bound_regions(sig));
- assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
- let mut sig = if let Some(sig_substs) = sig_substs {
- sig.subst(tcx, &sig_substs)
+ assert_eq!(sig_args.is_some(), !instance.has_polymorphic_mir_body());
+ let mut sig = if let Some(sig_args) = sig_args {
+ sig.instantiate(tcx, &sig_args)
} else {
- sig.subst_identity()
+ sig.instantiate_identity()
};
if let CallKind::Indirect(fnty) = call_kind {
@@ -751,7 +758,7 @@ fn build_call_shim<'tcx>(
// `FnDef` call with optional receiver.
CallKind::Direct(def_id) => {
- let ty = tcx.type_of(def_id).subst_identity();
+ let ty = tcx.type_of(def_id).instantiate_identity();
(
Operand::Constant(Box::new(Constant {
span,
@@ -868,12 +875,12 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
// Normalize the sig.
let sig = tcx
.fn_sig(ctor_id)
- .subst_identity()
+ .instantiate_identity()
.no_bound_vars()
.expect("LBR in ADT constructor signature");
let sig = tcx.normalize_erasing_regions(param_env, sig);
- let ty::Adt(adt_def, substs) = sig.output().kind() else {
+ let ty::Adt(adt_def, args) = sig.output().kind() else {
bug!("unexpected type for ADT ctor {:?}", sig.output());
};
@@ -896,7 +903,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
// return;
debug!("build_ctor: variant_index={:?}", variant_index);
- let kind = AggregateKind::Adt(adt_def.did(), variant_index, substs, None, None);
+ let kind = AggregateKind::Adt(adt_def.did(), variant_index, args, None, None);
let variant = adt_def.variant(variant_index);
let statement = Statement {
kind: StatementKind::Assign(Box::new((
@@ -941,7 +948,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Body<'tcx> {
assert!(matches!(self_ty.kind(), ty::FnPtr(..)), "expected fn ptr, found {self_ty}");
let span = tcx.def_span(def_id);
- let Some(sig) = tcx.fn_sig(def_id).subst(tcx, &[self_ty.into()]).no_bound_vars() else {
+ let Some(sig) = tcx.fn_sig(def_id).instantiate(tcx, &[self_ty.into()]).no_bound_vars() else {
span_bug!(span, "FnPtr::addr with bound vars for `{self_ty}`");
};
let locals = local_decls_for_sig(&sig, span);