Auto merge of #75133 - nnethercote:rm-SubstFolder-fields, r=matthewjasper

Remove two fields from `SubstFolder`.

They're only used in error messages printed if there's an internal
compiler error, and the cost of maintaining them is high enough to show
up in profiles.

r? @matthewjasper
This commit is contained in:
bors 2020-08-04 17:07:40 +00:00
commit d08eb98698
1 changed files with 6 additions and 31 deletions

View File

@ -425,8 +425,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
substs: &[GenericArg<'tcx>], substs: &[GenericArg<'tcx>],
span: Option<Span>, span: Option<Span>,
) -> T { ) -> T {
let mut folder = let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
SubstFolder { tcx, substs, span, root_ty: None, ty_stack_depth: 0, binders_passed: 0 };
(*self).fold_with(&mut folder) (*self).fold_with(&mut folder)
} }
} }
@ -441,12 +440,6 @@ struct SubstFolder<'a, 'tcx> {
/// The location for which the substitution is performed, if available. /// The location for which the substitution is performed, if available.
span: Option<Span>, span: Option<Span>,
/// The root type that is being substituted, if available.
root_ty: Option<Ty<'tcx>>,
/// Depth of type stack
ty_stack_depth: usize,
/// Number of region binders we have passed through while doing the substitution /// Number of region binders we have passed through while doing the substitution
binders_passed: u32, binders_passed: u32,
} }
@ -478,9 +471,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
let span = self.span.unwrap_or(DUMMY_SP); let span = self.span.unwrap_or(DUMMY_SP);
let msg = format!( let msg = format!(
"Region parameter out of range \ "Region parameter out of range \
when substituting in region {} (root type={:?}) \ when substituting in region {} (index={})",
(index={})", data.name, data.index
data.name, self.root_ty, data.index
); );
span_bug!(span, "{}", msg); span_bug!(span, "{}", msg);
} }
@ -495,25 +487,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
return t; return t;
} }
// track the root type we were asked to substitute match t.kind {
let depth = self.ty_stack_depth;
if depth == 0 {
self.root_ty = Some(t);
}
self.ty_stack_depth += 1;
let t1 = match t.kind {
ty::Param(p) => self.ty_for_param(p, t), ty::Param(p) => self.ty_for_param(p, t),
_ => t.super_fold_with(self), _ => t.super_fold_with(self),
};
assert_eq!(depth + 1, self.ty_stack_depth);
self.ty_stack_depth -= 1;
if depth == 0 {
self.root_ty = None;
} }
t1
} }
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> { fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
@ -540,12 +517,11 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
span_bug!( span_bug!(
span, span,
"expected type for `{:?}` ({:?}/{}) but found {:?} \ "expected type for `{:?}` ({:?}/{}) but found {:?} \
when substituting (root type={:?}) substs={:?}", when substituting, substs={:?}",
p, p,
source_ty, source_ty,
p.index, p.index,
kind, kind,
self.root_ty,
self.substs, self.substs,
); );
} }
@ -554,11 +530,10 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
span_bug!( span_bug!(
span, span,
"type parameter `{:?}` ({:?}/{}) out of range \ "type parameter `{:?}` ({:?}/{}) out of range \
when substituting (root type={:?}) substs={:?}", when substituting, substs={:?}",
p, p,
source_ty, source_ty,
p.index, p.index,
self.root_ty,
self.substs, self.substs,
); );
} }