From eeb4b83289e09956e0dda174047729ca87c709fe Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 4 Aug 2020 14:23:56 +1000 Subject: [PATCH] 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. --- src/librustc_middle/ty/subst.rs | 37 ++++++--------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/librustc_middle/ty/subst.rs b/src/librustc_middle/ty/subst.rs index e9fd67a748c85..866b529f35ec3 100644 --- a/src/librustc_middle/ty/subst.rs +++ b/src/librustc_middle/ty/subst.rs @@ -425,8 +425,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T { substs: &[GenericArg<'tcx>], span: Option, ) -> T { - let mut folder = - SubstFolder { tcx, substs, span, root_ty: None, ty_stack_depth: 0, binders_passed: 0 }; + let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 }; (*self).fold_with(&mut folder) } } @@ -441,12 +440,6 @@ struct SubstFolder<'a, 'tcx> { /// The location for which the substitution is performed, if available. span: Option, - /// The root type that is being substituted, if available. - root_ty: Option>, - - /// Depth of type stack - ty_stack_depth: usize, - /// Number of region binders we have passed through while doing the substitution 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 msg = format!( "Region parameter out of range \ - when substituting in region {} (root type={:?}) \ - (index={})", - data.name, self.root_ty, data.index + when substituting in region {} (index={})", + data.name, data.index ); span_bug!(span, "{}", msg); } @@ -495,25 +487,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { return t; } - // track the root type we were asked to substitute - let depth = self.ty_stack_depth; - if depth == 0 { - self.root_ty = Some(t); - } - self.ty_stack_depth += 1; - - let t1 = match t.kind { + match t.kind { ty::Param(p) => self.ty_for_param(p, t), _ => 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> { @@ -540,12 +517,11 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { span_bug!( span, "expected type for `{:?}` ({:?}/{}) but found {:?} \ - when substituting (root type={:?}) substs={:?}", + when substituting, substs={:?}", p, source_ty, p.index, kind, - self.root_ty, self.substs, ); } @@ -554,11 +530,10 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { span_bug!( span, "type parameter `{:?}` ({:?}/{}) out of range \ - when substituting (root type={:?}) substs={:?}", + when substituting, substs={:?}", p, source_ty, p.index, - self.root_ty, self.substs, ); }