From cf6366babafb3b08c3944ee0a25e398af2657ed5 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 16 Sep 2022 11:02:11 +0000 Subject: [PATCH] Revert TypeVisitor changes --- compiler/rustc_middle/src/infer/canonical.rs | 15 ++++++-------- .../rustc_middle/src/mir/type_visitable.rs | 6 ++++++ .../rustc_middle/src/ty/structural_impls.rs | 20 +++++++++++++++++++ compiler/rustc_middle/src/ty/subst.rs | 8 +++++++- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index d3cf519b633..4bad0950451 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -44,15 +44,6 @@ pub struct Canonical<'tcx, V> { pub type CanonicalVarInfos<'tcx> = &'tcx List>; -impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> { - fn try_fold_with>( - self, - folder: &mut F, - ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_canonical_var_infos(v)) - } -} - /// A set of values corresponding to the canonical variables from some /// `Canonical`. You can give these values to /// `canonical_value.substitute` to substitute them into the canonical @@ -314,6 +305,12 @@ pub fn unchecked_map(self, map_op: impl FnOnce(V) -> W) -> Canonical<'tcx, W> } } +TrivialTypeTraversalImpls! { + for <'tcx> { + crate::infer::canonical::CanonicalVarInfos<'tcx>, + } +} + impl<'tcx> CanonicalVarValues<'tcx> { #[inline] pub fn len(&self) -> usize { diff --git a/compiler/rustc_middle/src/mir/type_visitable.rs b/compiler/rustc_middle/src/mir/type_visitable.rs index 27a251f2f56..56fa7f1ede3 100644 --- a/compiler/rustc_middle/src/mir/type_visitable.rs +++ b/compiler/rustc_middle/src/mir/type_visitable.rs @@ -8,6 +8,12 @@ fn visit_with>(&self, _: &mut V) -> ControlFlow } } +impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List> { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + impl<'tcx> TypeVisitable<'tcx> for ConstantKind<'tcx> { fn visit_with>(&self, visitor: &mut V) -> ControlFlow { visitor.visit_mir_const(*self) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index f5fd1f6ffaf..ecbb2a16b69 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -602,12 +602,26 @@ fn try_fold_with>(self, folder: &mut F) -> Result TypeVisitable<'tcx> + for &'tcx ty::List>> +{ + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|p| p.visit_with(visitor)) + } +} + impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List { fn try_fold_with>(self, folder: &mut F) -> Result { ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v)) } } +impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { fn try_fold_with>(self, folder: &mut F) -> Result { folder.try_fold_ty(self) @@ -783,6 +797,12 @@ fn try_fold_with>(self, folder: &mut F) -> Result TypeVisitable<'tcx> for &'tcx ty::List> { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|p| p.visit_with(visitor)) + } +} + impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec { fn try_fold_with>(self, folder: &mut F) -> Result { self.try_map_id(|x| x.try_fold_with(folder)) diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 8e69bf067d0..6262aa18075 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -459,6 +459,12 @@ fn try_fold_with>(self, folder: &mut F) -> Result TypeVisitable<'tcx> for SubstsRef<'tcx> { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.iter().try_for_each(|t| t.visit_with(visitor)) + } +} + impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn try_fold_with>(self, folder: &mut F) -> Result { // This code is fairly hot, though not as hot as `SubstsRef`. @@ -491,7 +497,7 @@ fn try_fold_with>(self, folder: &mut F) -> Result> TypeVisitable<'tcx> for &'tcx ty::List { +impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List> { fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) }