Skip to content

Commit

Permalink
Auto merge of #75133 - nnethercote:rm-SubstFolder-fields, r=matthewja…
Browse files Browse the repository at this point in the history
…sper

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
  • Loading branch information
bors committed Aug 4, 2020
2 parents 5f6bd6e + eeb4b83 commit d08eb98
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions src/librustc_middle/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
substs: &[GenericArg<'tcx>],
span: Option<Span>,
) -> 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)
}
}
Expand All @@ -441,12 +440,6 @@ struct SubstFolder<'a, 'tcx> {
/// The location for which the substitution is performed, if available.
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
binders_passed: u32,
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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> {
Expand All @@ -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,
);
}
Expand All @@ -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,
);
}
Expand Down

0 comments on commit d08eb98

Please sign in to comment.