Skip to content

Commit ed52d0c

Browse files
committed
Auto merge of #151039 - nnethercote:inline-super-fold-visit, r=<try>
Inline super visit/fold methods.
2 parents 2f1bd3f + 805b068 commit ed52d0c

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
371371
}
372372

373373
impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
374+
#[inline]
374375
fn try_super_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
375376
self,
376377
folder: &mut F,
@@ -419,6 +420,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
419420
Ok(if *self.kind() == kind { self } else { folder.cx().mk_ty_from_kind(kind) })
420421
}
421422

423+
#[inline]
422424
fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
423425
let kind = match *self.kind() {
424426
ty::RawPtr(ty, mutbl) => ty::RawPtr(ty.fold_with(folder), mutbl),
@@ -460,6 +462,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
460462
}
461463

462464
impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
465+
#[inline]
463466
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
464467
match self.kind() {
465468
ty::RawPtr(ty, _mutbl) => ty.visit_with(visitor),
@@ -582,6 +585,7 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Clause<'tcx> {
582585
}
583586

584587
impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
588+
#[inline]
585589
fn try_super_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
586590
self,
587591
folder: &mut F,
@@ -596,6 +600,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
596600
Ok(folder.cx().reuse_or_mk_predicate(self, new))
597601
}
598602

603+
#[inline]
599604
fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
600605
// See comment in `Predicate::try_super_fold_with`.
601606
let new = self.kind().fold_with(folder);
@@ -604,6 +609,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
604609
}
605610

606611
impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
612+
#[inline]
607613
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
608614
// See comment in `Predicate::try_super_fold_with`.
609615
self.kind().visit_with(visitor)
@@ -617,19 +623,22 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Clauses<'tcx> {
617623
}
618624

619625
impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Clauses<'tcx> {
626+
#[inline]
620627
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
621628
self.as_slice().visit_with(visitor)
622629
}
623630
}
624631

625632
impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Clauses<'tcx> {
633+
#[inline]
626634
fn try_super_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
627635
self,
628636
folder: &mut F,
629637
) -> Result<Self, F::Error> {
630638
ty::util::try_fold_list(self, folder, |tcx, v| tcx.mk_clauses(v))
631639
}
632640

641+
#[inline]
633642
fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
634643
ty::util::fold_list(self, folder, |tcx, v| tcx.mk_clauses(v))
635644
}
@@ -655,6 +664,7 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
655664
}
656665

657666
impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
667+
#[inline]
658668
fn try_super_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
659669
self,
660670
folder: &mut F,
@@ -673,6 +683,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
673683
if kind != self.kind() { Ok(folder.cx().mk_ct_from_kind(kind)) } else { Ok(self) }
674684
}
675685

686+
#[inline]
676687
fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
677688
let kind = match self.kind() {
678689
ConstKind::Unevaluated(uv) => ConstKind::Unevaluated(uv.fold_with(folder)),
@@ -690,6 +701,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
690701
}
691702

692703
impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
704+
#[inline]
693705
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
694706
match self.kind() {
695707
ConstKind::Unevaluated(uv) => uv.visit_with(visitor),

compiler/rustc_type_ir/src/binder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,22 @@ impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
133133
}
134134

135135
impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
136+
#[inline]
136137
fn try_super_fold_with<F: FallibleTypeFolder<I>>(
137138
self,
138139
folder: &mut F,
139140
) -> Result<Self, F::Error> {
140141
self.try_map_bound(|t| t.try_fold_with(folder))
141142
}
142143

144+
#[inline]
143145
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self {
144146
self.map_bound(|t| t.fold_with(folder))
145147
}
146148
}
147149

148150
impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
151+
#[inline]
149152
fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
150153
self.as_ref().skip_binder().visit_with(visitor)
151154
}

compiler/rustc_type_ir/src/fold.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
111111
) -> Result<Self, F::Error>;
112112

113113
/// A convenient alternative to `try_super_fold_with` for use with
114-
/// infallible folders. Do not override this method, to ensure coherence
115-
/// with `try_super_fold_with`.
114+
/// infallible folders.
116115
fn super_fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self;
117116
}
118117

@@ -121,10 +120,6 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
121120
/// default that does an "identity" fold. Implementations of these methods
122121
/// often fall back to a `super_fold_with` method if the primary argument
123122
/// doesn't satisfy a particular condition.
124-
///
125-
/// A blanket implementation of [`FallibleTypeFolder`] will defer to
126-
/// the infallible methods of this trait to ensure that the two APIs
127-
/// are coherent.
128123
pub trait TypeFolder<I: Interner>: Sized {
129124
fn cx(&self) -> I;
130125

@@ -161,10 +156,6 @@ pub trait TypeFolder<I: Interner>: Sized {
161156
/// This trait is implemented for every folding traversal. There is a fold
162157
/// method defined for every type of interest. Each such method has a default
163158
/// that does an "identity" fold.
164-
///
165-
/// A blanket implementation of this trait (that defers to the relevant
166-
/// method of [`TypeFolder`]) is provided for all infallible folders in
167-
/// order to ensure the two APIs are coherent.
168159
pub trait FallibleTypeFolder<I: Interner>: Sized {
169160
type Error;
170161

0 commit comments

Comments
 (0)