1
Fork 0

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

@ -36,10 +36,10 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b
ty::Tuple(tys) => {
depth == 0 || tys.iter().any(|ty| may_contain_reference(ty, depth - 1, tcx))
}
ty::Adt(adt, subst) => {
ty::Adt(adt, args) => {
depth == 0
|| adt.variants().iter().any(|v| {
v.fields.iter().any(|f| may_contain_reference(f.ty(tcx, subst), depth - 1, tcx))
v.fields.iter().any(|f| may_contain_reference(f.ty(tcx, args), depth - 1, tcx))
})
}
// Conservative fallback

View file

@ -205,8 +205,8 @@ pub fn deduced_param_attrs<'tcx>(
|(arg_index, local_decl)| DeducedParamAttrs {
read_only: !deduce_read_only.mutable_args.contains(arg_index)
// We must normalize here to reveal opaques and normalize
// their substs, otherwise we'll see exponential blow-up in
// compile times: #113372
// their generic parameters, otherwise we'll see exponential
// blow-up in compile times: #113372
&& tcx
.normalize_erasing_regions(param_env, local_decl.ty)
.is_freeze(tcx, param_env),

View file

@ -63,7 +63,7 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
/// Emits a lint for function reference arguments bound by `fmt::Pointer` in calls to the
/// function defined by `def_id` with the substitutions `args_ref`.
/// function defined by `def_id` with the generic parameters `args_ref`.
fn check_bound_args(
&self,
def_id: DefId,
@ -83,11 +83,11 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
for inner_ty in arg_def.walk().filter_map(|arg| arg.as_type()) {
// If the inner type matches the type bound by `Pointer`
if inner_ty == bound_ty {
// Do a substitution using the parameters from the callsite
let subst_ty =
// Do an instantiation using the parameters from the callsite
let instantiated_ty =
EarlyBinder::bind(inner_ty).instantiate(self.tcx, args_ref);
if let Some((fn_id, fn_args)) =
FunctionItemRefChecker::is_fn_ref(subst_ty)
FunctionItemRefChecker::is_fn_ref(instantiated_ty)
{
let mut span = self.nth_arg_span(args, arg_num);
if span.from_expansion() {

View file

@ -853,10 +853,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
fn simplify_discriminant(&mut self, place: VnIndex) -> Option<VnIndex> {
if let Value::Aggregate(enum_ty, variant, _) = *self.get(place)
&& let AggregateTy::Def(enum_did, enum_substs) = enum_ty
&& let AggregateTy::Def(enum_did, enum_args) = enum_ty
&& let DefKind::Enum = self.tcx.def_kind(enum_did)
{
let enum_ty = self.tcx.type_of(enum_did).instantiate(self.tcx, enum_substs);
let enum_ty = self.tcx.type_of(enum_did).instantiate(self.tcx, enum_args);
let discr = self.ecx.discriminant_for_variant(enum_ty, variant).ok()?;
return Some(self.insert_scalar(discr.to_scalar(), discr.layout.ty));
}
@ -899,13 +899,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
assert!(!fields.is_empty());
(AggregateTy::Tuple, FIRST_VARIANT)
}
AggregateKind::Closure(did, substs)
| AggregateKind::CoroutineClosure(did, substs)
| AggregateKind::Coroutine(did, substs) => {
(AggregateTy::Def(did, substs), FIRST_VARIANT)
}
AggregateKind::Adt(did, variant_index, substs, _, None) => {
(AggregateTy::Def(did, substs), variant_index)
AggregateKind::Closure(did, args)
| AggregateKind::CoroutineClosure(did, args)
| AggregateKind::Coroutine(did, args) => (AggregateTy::Def(did, args), FIRST_VARIANT),
AggregateKind::Adt(did, variant_index, args, _, None) => {
(AggregateTy::Def(did, args), variant_index)
}
// Do not track unions.
AggregateKind::Adt(_, _, _, _, Some(_)) => return None,

View file

@ -80,7 +80,7 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
}
// These have no own callable MIR.
InstanceDef::Intrinsic(_) | InstanceDef::Virtual(..) => continue,
// These have MIR and if that MIR is inlined, substituted and then inlining is run
// These have MIR and if that MIR is inlined, instantiated and then inlining is run
// again, a function item can end up getting inlined. Thus we'll be able to cause
// a cycle that way
InstanceDef::VTableShim(_)
@ -95,7 +95,7 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
// This shim does not call any other functions, thus there can be no recursion.
InstanceDef::FnPtrAddrShim(..) => continue,
InstanceDef::DropGlue(..) => {
// FIXME: A not fully substituted drop shim can cause ICEs if one attempts to
// FIXME: A not fully instantiated drop shim can cause ICEs if one attempts to
// have its MIR built. Likely oli-obk just screwed up the `ParamEnv`s, so this
// needs some more analysis.
if callee.has_param() {

View file

@ -211,7 +211,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
// Only bother looking more if it's easy to know what we're calling
let Some((fn_def_id, fn_args)) = func.const_fn_def() else { return };
// Clone needs one subst, so we can cheaply rule out other stuff
// Clone needs one arg, so we can cheaply rule out other stuff
if fn_args.len() != 1 {
return;
}

View file

@ -436,7 +436,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
//
// We manually filter the predicates, skipping anything that's not
// "global". We are in a potentially generic context
// (e.g. we are evaluating a function without substituting generic
// (e.g. we are evaluating a function without instantiating generic
// parameters, so this filtering serves two purposes:
//
// 1. We skip evaluating any predicates that we would
@ -576,10 +576,10 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&inline::Inline,
// Code from other crates may have storage markers, so this needs to happen after inlining.
&remove_storage_markers::RemoveStorageMarkers,
// Inlining and substitution may introduce ZST and useless drops.
// Inlining and instantiation may introduce ZST and useless drops.
&remove_zsts::RemoveZsts,
&remove_unneeded_drops::RemoveUnneededDrops,
// Type substitution may create uninhabited enums.
// Type instantiation may create uninhabited enums.
&uninhabited_enum_branching::UninhabitedEnumBranching,
&unreachable_prop::UnreachablePropagation,
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
@ -673,7 +673,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
}
/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for
/// constant evaluation once all substitutions become known.
/// constant evaluation once all generic parameters become known.
fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_>> {
if tcx.is_constructor(def.to_def_id()) {
return tcx.arena.alloc(IndexVec::new());

View file

@ -44,7 +44,7 @@ use crate::ssa::{SsaLocals, StorageLiveLocals};
///
/// # Liveness
///
/// When performing a substitution, we must take care not to introduce uses of dangling locals.
/// When performing an instantiation, we must take care not to introduce uses of dangling locals.
/// To ensure this, we walk the body with the `MaybeStorageDead` dataflow analysis:
/// - if we want to replace `*x` by reborrow `*y` and `y` may be dead, we allow replacement and
/// mark storage statements on `y` for removal;
@ -55,7 +55,7 @@ use crate::ssa::{SsaLocals, StorageLiveLocals};
///
/// For `&mut` borrows, we also need to preserve the uniqueness property:
/// we must avoid creating a state where we interleave uses of `*_1` and `_2`.
/// To do it, we only perform full substitution of mutable borrows:
/// To do it, we only perform full instantiation of mutable borrows:
/// we replace either all or none of the occurrences of `*_1`.
///
/// Some care has to be taken when `_1` is copied in other locals.
@ -63,10 +63,10 @@ use crate::ssa::{SsaLocals, StorageLiveLocals};
/// _3 = *_1;
/// _4 = _1
/// _5 = *_4
/// In such cases, fully substituting `_1` means fully substituting all of the copies.
/// In such cases, fully instantiating `_1` means fully instantiating all of the copies.
///
/// For immutable borrows, we do not need to preserve such uniqueness property,
/// so we perform all the possible substitutions without removing the `_1 = &_2` statement.
/// so we perform all the possible instantiations without removing the `_1 = &_2` statement.
pub struct ReferencePropagation;
impl<'tcx> MirPass<'tcx> for ReferencePropagation {

View file

@ -477,7 +477,7 @@ struct CloneShimBuilder<'tcx> {
impl<'tcx> CloneShimBuilder<'tcx> {
fn new(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Self {
// we must subst the self_ty because it's
// we must instantiate 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).instantiate(tcx, &[self_ty.into()]);
@ -716,8 +716,8 @@ fn build_call_shim<'tcx>(
call_kind: CallKind<'tcx>,
) -> Body<'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`).
// to instantiate into the signature of the shim. It is not necessary for users of this
// MIR body to perform further instantiations (see `InstanceDef::has_polymorphic_mir_body`).
let (sig_args, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance {
let sig = tcx.instantiate_bound_regions_with_erased(ty.fn_sig(tcx));

View file

@ -170,7 +170,7 @@ impl SsaLocals {
/// _c => _a
/// _d => _a // transitively through _c
///
/// Exception: we do not see through the return place, as it cannot be substituted.
/// Exception: we do not see through the return place, as it cannot be instantiated.
pub fn copy_classes(&self) -> &IndexSlice<Local, Local> {
&self.copy_classes
}