Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
partially revertish `lazily "compute" anon const default substs` reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted why revert: <https://github.com/rust-lang/rust/pull/92805#issuecomment-1010736049> r? `@lcnr`
This commit is contained in:
commit
7be8693984
123 changed files with 405 additions and 886 deletions
|
@ -573,7 +573,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
|
|||
let type_length = instance
|
||||
.substs
|
||||
.iter()
|
||||
.flat_map(|arg| arg.walk(tcx))
|
||||
.flat_map(|arg| arg.walk())
|
||||
.filter(|arg| match arg.unpack() {
|
||||
GenericArgKind::Type(_) | GenericArgKind::Const(_) => true,
|
||||
GenericArgKind::Lifetime(_) => false,
|
||||
|
|
|
@ -303,9 +303,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
|
|||
|
||||
// When polymorphization is enabled, methods which do not depend on their generic
|
||||
// parameters, but the self-type of their impl block do will fail to normalize.
|
||||
if !tcx.sess.opts.debugging_opts.polymorphize
|
||||
|| !instance.definitely_needs_subst(tcx)
|
||||
{
|
||||
if !tcx.sess.opts.debugging_opts.polymorphize || !instance.needs_subst() {
|
||||
// This is a method within an impl, find out what the self-type is:
|
||||
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
|
|
|
@ -277,12 +277,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
Some(self.tcx)
|
||||
}
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
if !c.potentially_has_param_types_or_consts() {
|
||||
if !c.has_param_types_or_consts() {
|
||||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -292,7 +289,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
self.unused_parameters.clear(param.index);
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted: Some(p)})
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted: Some(p)})
|
||||
// Avoid considering `T` unused when constants are of the form:
|
||||
// `<Self as Foo<T>>::foo::promoted[p]`
|
||||
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self =>
|
||||
|
@ -306,7 +303,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
ty::ConstKind::Unevaluated(uv)
|
||||
if matches!(self.tcx.def_kind(uv.def.did), DefKind::AnonConst | DefKind::InlineConst) =>
|
||||
{
|
||||
self.visit_child_body(uv.def.did, uv.substs(self.tcx));
|
||||
self.visit_child_body(uv.def.did, uv.substs);
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
_ => c.super_visit_with(self),
|
||||
|
@ -315,7 +312,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
if !ty.potentially_has_param_types_or_consts() {
|
||||
if !ty.has_param_types_or_consts() {
|
||||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -343,21 +340,16 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Visitor used to check if a generic parameter is used.
|
||||
struct HasUsedGenericParams<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
struct HasUsedGenericParams<'a> {
|
||||
unused_parameters: &'a FiniteBitSet<u32>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> {
|
||||
impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
|
||||
type BreakTy = ();
|
||||
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
Some(self.tcx)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
if !c.potentially_has_param_types_or_consts() {
|
||||
if !c.has_param_types_or_consts() {
|
||||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -375,7 +367,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> {
|
|||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
if !ty.potentially_has_param_types_or_consts() {
|
||||
if !ty.has_param_types_or_consts() {
|
||||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue