Dejargnonize subst

This commit is contained in:
Shoyu Vanilla 2024-02-12 15:39:32 +09:00
parent 084ce5bdb5
commit 3856df059e
128 changed files with 574 additions and 541 deletions

View file

@ -50,7 +50,7 @@ fn fn_sig_for_fn_abi<'tcx>(
// `tests/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
// track of a polymorphization `ParamEnv` to allow normalizing later.
//
// We normalize the `fn_sig` again after substituting at a later point.
// We normalize the `fn_sig` again after instantiating at a later point.
let mut sig = match *ty.kind() {
ty::FnDef(def_id, args) => tcx
.fn_sig(def_id)
@ -163,7 +163,7 @@ fn fn_sig_for_fn_abi<'tcx>(
// a separate def-id for these bodies.
if let InstanceDef::CoroutineKindShim { target_kind, .. } = instance.def {
// Grab the parent coroutine-closure. It has the same args for the purposes
// of substitution, so this will be okay to do.
// of instantiation, so this will be okay to do.
let ty::CoroutineClosure(_, coroutine_closure_args) = *tcx
.instantiate_and_normalize_erasing_regions(
args,

View file

@ -741,7 +741,7 @@ fn coroutine_layout<'tcx>(
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
use SavedLocalEligibility::*;
let tcx = cx.tcx;
let subst_field = |ty: Ty<'tcx>| EarlyBinder::bind(ty).instantiate(tcx, args);
let instantiate_field = |ty: Ty<'tcx>| EarlyBinder::bind(ty).instantiate(tcx, args);
let Some(info) = tcx.coroutine_layout(def_id) else {
return Err(error(cx, LayoutError::Unknown(ty)));
@ -763,7 +763,7 @@ fn coroutine_layout<'tcx>(
let tag_layout = cx.tcx.mk_layout(LayoutS::scalar(cx, tag));
let promoted_layouts = ineligible_locals.iter().map(|local| {
let field_ty = subst_field(info.field_tys[local].ty);
let field_ty = instantiate_field(info.field_tys[local].ty);
let uninit_ty = Ty::new_maybe_uninit(tcx, field_ty);
Ok(cx.spanned_layout_of(uninit_ty, info.field_tys[local].source_info.span)?.layout)
});
@ -838,7 +838,7 @@ fn coroutine_layout<'tcx>(
Ineligible(_) => false,
})
.map(|local| {
let field_ty = subst_field(info.field_tys[*local].ty);
let field_ty = instantiate_field(info.field_tys[*local].ty);
Ty::new_maybe_uninit(tcx, field_ty)
});

View file

@ -264,9 +264,9 @@ fn drop_tys_helper<'tcx>(
) -> NeedsDropResult<Vec<Ty<'tcx>>> {
iter.into_iter().try_fold(Vec::new(), |mut vec, subty| {
match subty.kind() {
ty::Adt(adt_id, subst) => {
ty::Adt(adt_id, args) => {
for subty in tcx.adt_drop_tys(adt_id.did())? {
vec.push(EarlyBinder::bind(subty).instantiate(tcx, subst));
vec.push(EarlyBinder::bind(subty).instantiate(tcx, args));
}
}
_ => vec.push(subty),
@ -300,7 +300,10 @@ fn drop_tys_helper<'tcx>(
} else {
let field_tys = adt_def.all_fields().map(|field| {
let r = tcx.type_of(field.did).instantiate(tcx, args);
debug!("drop_tys_helper: Subst into {:?} with {:?} getting {:?}", field, args, r);
debug!(
"drop_tys_helper: Instantiate into {:?} with {:?} getting {:?}",
field, args, r
);
r
});
if only_significant {
@ -363,7 +366,7 @@ fn adt_drop_tys<'tcx>(
.map(|components| tcx.mk_type_list(&components))
}
// If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed
// a `tcx.make_ty(def, identity_args)` and as such it is legal to substitute the generic parameters
// a `tcx.make_ty(def, identity_args)` and as such it is legal to instantiate the generic parameters
// of the ADT into the outputted `ty`s.
fn adt_significant_drop_tys(
tcx: TyCtxt<'_>,

View file

@ -155,7 +155,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
// Collect opaque types nested within the associated type bounds of this opaque type.
// We use identity args here, because we already know that the opaque type uses
// only generic parameters, and thus substituting would not give us more information.
// only generic parameters, and thus instantiating would not give us more information.
for (pred, span) in self
.tcx
.explicit_item_bounds(alias_ty.def_id)
@ -211,7 +211,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
// in the same impl block.
if let Some(parent_trait_ref) = self.parent_trait_ref() {
// If the trait ref of the associated item and the impl differs,
// then we can't use the impl's identity substitutions below, so
// then we can't use the impl's identity args below, so
// just skip.
if alias_ty.trait_ref(self.tcx) == parent_trait_ref {
let parent = self.parent().expect("we should have a parent here");
@ -258,11 +258,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
for field in variant.fields.iter() {
// Don't use the `ty::Adt` args, we either
// * found the opaque in the args
// * will find the opaque in the unsubstituted fields
// The only other situation that can occur is that after substituting,
// * will find the opaque in the uninstantiated fields
// The only other situation that can occur is that after instantiating,
// some projection resolves to an opaque that we would have otherwise
// not found. While we could substitute and walk those, that would mean we
// would have to walk all substitutions of an Adt, which can quickly
// not found. While we could instantiate and walk those, that would mean we
// would have to walk all generic parameters of an Adt, which can quickly
// degenerate into looking at an exponential number of types.
let ty = self.tcx.type_of(field.did).instantiate_identity();
self.visit_spanned(self.tcx.def_span(field.did), ty);
@ -306,7 +306,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInAssocTypeCollector<'tcx> {
.parent_trait_ref()
.expect("impl trait in assoc type collector used on non-assoc item");
// If the trait ref of the associated item and the impl differs,
// then we can't use the impl's identity substitutions below, so
// then we can't use the impl's identity args below, so
// just skip.
if alias_ty.trait_ref(self.0.tcx) == parent_trait_ref {
let parent = self.0.parent().expect("we should have a parent here");

View file

@ -73,8 +73,8 @@ fn representability_adt_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Representab
// At this point, we know that the item of the ADT type is representable;
// but the type parameters may cause a cycle with an upstream type
let params_in_repr = tcx.params_in_repr(adt.did());
for (i, subst) in args.iter().enumerate() {
if let ty::GenericArgKind::Type(ty) = subst.unpack() {
for (i, arg) in args.iter().enumerate() {
if let ty::GenericArgKind::Type(ty) = arg.unpack() {
if params_in_repr.contains(i as u32) {
rtry!(representability_ty(tcx, ty));
}
@ -103,8 +103,8 @@ fn params_in_repr_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, params_in_repr: &mut
match *ty.kind() {
ty::Adt(adt, args) => {
let inner_params_in_repr = tcx.params_in_repr(adt.did());
for (i, subst) in args.iter().enumerate() {
if let ty::GenericArgKind::Type(ty) = subst.unpack() {
for (i, arg) in args.iter().enumerate() {
if let ty::GenericArgKind::Type(ty) = arg.unpack() {
if inner_params_in_repr.contains(i as u32) {
params_in_repr_ty(tcx, ty, params_in_repr);
}