Skip to content

Commit dcc1036

Browse files
committed
Rename Folder to TypeFolder
1 parent ae33a00 commit dcc1036

File tree

16 files changed

+85
-85
lines changed

16 files changed

+85
-85
lines changed

book/src/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- [Application types](./types/rust_types/application_ty.md)
1313
- [Rust lifetimes](./types/rust_lifetimes.md)
1414
- [Operations](./types/operations.md)
15-
- [TypeFoldable and the Folder trait](./types/operations/fold.md)
15+
- [TypeFoldable and the TypeFolder trait](./types/operations/fold.md)
1616
- [Lowering Rust IR to logic](./clauses.md)
1717
- [Goals and clauses](./clauses/goals_and_clauses.md)
1818
- [Type equality and unification](./clauses/type_equality.md)

book/src/types/operations/fold.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# TypeFoldable and the Folder trait
1+
# TypeFoldable and the TypeFolder trait
22

33
The [`TypeFoldable`] trait permits one to traverse a type or other term in the
44
chalk-ir and make a copy of it, possibly making small substitutions or
@@ -17,39 +17,39 @@ let output_ty = input_ty.fold_with(&mut folder, 0);
1717

1818
[`TypeFoldable::fold_with`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable.html#tymethod.fold_with
1919

20-
The folder is some instance of the [`Folder`] trait. This trait
20+
The folder is some instance of the [`TypeFolder`] trait. This trait
2121
defines a few key callbacks that allow you to substitute different
2222
values as the fold proceeds. For example, when a type is folded, the
2323
folder can substitute a new type in its place.
2424

25-
[`Folder`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Folder.html
25+
[`TypeFolder`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFolder.html
2626

2727
## Uses for folders
2828

2929
A common use for `TypeFoldable` is to permit a substitution -- that is,
3030
replacing generic type parameters with their values.
3131

32-
## From TypeFoldable to Folder to TypeSuperFoldable and back again
32+
## From TypeFoldable to TypeFolder to TypeSuperFoldable and back again
3333

3434
The overall flow of folding is like this.
3535

3636
1. [`TypeFoldable::fold_with`] is invoked on the outermost term. It recursively
3737
walks the term.
3838
2. For those sorts of terms (types, lifetimes, goals, program clauses) that have
39-
callbacks in the [`Folder`] trait, invoking [`TypeFoldable::fold_with`] will in turn
40-
invoke the corresponding method on the [`Folder`] trait, such as `Folder::fold_ty`.
41-
3. The default implementation of `Folder::fold_ty`, in turn, invokes
39+
callbacks in the [`TypeFolder`] trait, invoking [`TypeFoldable::fold_with`] will in turn
40+
invoke the corresponding method on the [`TypeFolder`] trait, such as `TypeFolder::fold_ty`.
41+
3. The default implementation of `TypeFolder::fold_ty`, in turn, invokes
4242
`TypeSuperFoldable::super_fold_with`. This will recursively fold the
4343
contents of the type. In some cases, the `super_fold_with`
44-
implementation invokes more specialized methods on [`Folder`], such
45-
as [`Folder::fold_free_var_ty`], which makes it easier to write
44+
implementation invokes more specialized methods on [`TypeFolder`], such
45+
as [`TypeFolder::fold_free_var_ty`], which makes it easier to write
4646
folders that just intercept *certain* types.
4747

48-
[`Folder::fold_free_var_ty`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Folder.html#method.fold_free_var_ty
48+
[`TypeFolder::fold_free_var_ty`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFolder.html#method.fold_free_var_ty
4949

5050
Thus, as a user, you can customize folding by:
5151

52-
* Defining your own `Folder` type
52+
* Defining your own `TypeFolder` type
5353
* Implementing the appropriate methods to "intercept" types/lifetimes/etc at the right level of
5454
detail
5555
* In those methods, if you find a case where you would prefer not to
@@ -58,7 +58,7 @@ Thus, as a user, you can customize folding by:
5858

5959
## The `binders` argument
6060

61-
Each callback in the [`Folder`] trait takes a `binders` argument. This indicates
61+
Each callback in the [`TypeFolder`] trait takes a `binders` argument. This indicates
6262
the number of binders that we have traversed during folding, which is relevant for De Bruijn indices.
6363
So e.g. a bound variable with depth 1, if invoked with a `binders` value of 1, indicates something that was bound to something external to the fold.
6464

@@ -85,7 +85,7 @@ also implement `TypeFoldable` for common collection types like `Vec` as well
8585
as tuples, references, etc.
8686

8787
The `TypeSuperFoldable` trait should only be implemented for those types that
88-
have a callback defined on the `Folder` trait (e.g., types and
88+
have a callback defined on the `TypeFolder` trait (e.g., types and
8989
lifetimes).
9090

9191
## Derives

chalk-derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream {
299299

300300
fn fold_with<E>(
301301
self,
302-
folder: &mut dyn ::chalk_ir::fold::Folder < #interner, Error = E >,
302+
folder: &mut dyn ::chalk_ir::fold::TypeFolder < #interner, Error = E >,
303303
outer_binder: ::chalk_ir::DebruijnIndex,
304304
) -> ::std::result::Result<Self::Result, E> {
305305
Ok(match self { #body })

chalk-engine/src/normalize_deep.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chalk_ir::fold::shift::Shift;
2-
use chalk_ir::fold::{Folder, TypeFoldable};
2+
use chalk_ir::fold::{TypeFoldable, TypeFolder};
33
use chalk_ir::interner::Interner;
44
use chalk_ir::*;
55
use chalk_solve::infer::InferenceTable;
@@ -35,10 +35,10 @@ impl<I: Interner> DeepNormalizer<'_, I> {
3535
}
3636
}
3737

38-
impl<I: Interner> Folder<I> for DeepNormalizer<'_, I> {
38+
impl<I: Interner> TypeFolder<I> for DeepNormalizer<'_, I> {
3939
type Error = NoSolution;
4040

41-
fn as_dyn(&mut self) -> &mut dyn Folder<I, Error = Self::Error> {
41+
fn as_dyn(&mut self) -> &mut dyn TypeFolder<I, Error = Self::Error> {
4242
self
4343
}
4444

chalk-engine/src/strand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{ExClause, TableIndex, TimeStamp};
33
use std::fmt::Debug;
44

55
use chalk_derive::HasInterner;
6-
use chalk_ir::fold::{Folder, TypeFoldable};
6+
use chalk_ir::fold::{TypeFoldable, TypeFolder};
77
use chalk_ir::interner::Interner;
88
use chalk_ir::{Canonical, DebruijnIndex, UniverseMap};
99

@@ -39,7 +39,7 @@ impl<I: Interner> TypeFoldable<I> for Strand<I> {
3939
type Result = Strand<I>;
4040
fn fold_with<E>(
4141
self,
42-
folder: &mut dyn Folder<I, Error = E>,
42+
folder: &mut dyn TypeFolder<I, Error = E>,
4343
outer_binder: DebruijnIndex,
4444
) -> Result<Self::Result, E> {
4545
Ok(Strand {

chalk-ir/src/fold.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::subst::Subst;
1717
/// certain changes applied. The idea is that it contains methods that
1818
/// let you swap types/lifetimes for new types/lifetimes; meanwhile,
1919
/// each bit of IR implements the `TypeFoldable` trait which, given a
20-
/// `Folder`, will reconstruct itself, invoking the folder's methods
20+
/// `TypeFolder`, will reconstruct itself, invoking the folder's methods
2121
/// to transform each of the types/lifetimes embedded within.
2222
///
2323
/// # Usage patterns
@@ -29,14 +29,14 @@ pub use self::subst::Subst;
2929
/// more often, just free existential variables) that appear within
3030
/// the term.
3131
///
32-
/// For this reason, the `Folder` trait extends two other traits that
32+
/// For this reason, the `TypeFolder` trait extends two other traits that
3333
/// contain methods that are invoked when just those particular
3434
///
3535
/// In particular, folders can intercept references to free variables
3636
/// (either existentially or universally quantified) and replace them
3737
/// with other types/lifetimes as appropriate.
3838
///
39-
/// To create a folder `F`, one never implements `Folder` directly, but instead
39+
/// To create a folder `F`, one never implements `TypeFolder` directly, but instead
4040
/// implements one of each of these three sub-traits:
4141
///
4242
/// - `FreeVarFolder` -- folds `BoundVar` instances that appear free
@@ -54,19 +54,19 @@ pub use self::subst::Subst;
5454
/// ```rust,ignore
5555
/// let x = x.fold_with(&mut folder, 0);
5656
/// ```
57-
pub trait Folder<I: Interner> {
57+
pub trait TypeFolder<I: Interner> {
5858
/// The type this folder returns when folding fails. This is
5959
/// commonly [`NoSolution`].
6060
type Error;
6161

6262
/// Creates a `dyn` value from this folder. Unfortunately, this
63-
/// must be added manually to each impl of Folder; it permits the
64-
/// default implements below to create a `&mut dyn Folder` from
63+
/// must be added manually to each impl of TypeFolder; it permits the
64+
/// default implements below to create a `&mut dyn TypeFolder` from
6565
/// `Self` without knowing what `Self` is (by invoking this
66-
/// method). Effectively, this limits impls of `Folder` to types
66+
/// method). Effectively, this limits impls of `TypeFolder` to types
6767
/// for which we are able to create a dyn value (i.e., not `[T]`
6868
/// types).
69-
fn as_dyn(&mut self) -> &mut dyn Folder<I, Error = Self::Error>;
69+
fn as_dyn(&mut self) -> &mut dyn TypeFolder<I, Error = Self::Error>;
7070

7171
/// Top-level callback: invoked for each `Ty<I>` that is
7272
/// encountered when folding. By default, invokes
@@ -305,7 +305,7 @@ pub trait Folder<I: Interner> {
305305
fn interner(&self) -> I;
306306
}
307307

308-
/// Applies the given `Folder` to a value, producing a folded result
308+
/// Applies the given `TypeFolder` to a value, producing a folded result
309309
/// of type `Self::Result`. The result type is typically the same as
310310
/// the source type, but in some cases we convert from borrowed
311311
/// to owned as well (e.g., the folder for `&T` will fold to a fresh
@@ -325,19 +325,19 @@ pub trait TypeFoldable<I: Interner>: Debug {
325325
/// constructs.
326326
fn fold_with<E>(
327327
self,
328-
folder: &mut dyn Folder<I, Error = E>,
328+
folder: &mut dyn TypeFolder<I, Error = E>,
329329
outer_binder: DebruijnIndex,
330330
) -> Result<Self::Result, E>;
331331
}
332332

333-
/// For types where "fold" invokes a callback on the `Folder`, the
333+
/// For types where "fold" invokes a callback on the `TypeFolder`, the
334334
/// `TypeSuperFoldable` trait captures the recursive behavior that folds all
335335
/// the contents of the type.
336336
pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
337337
/// Recursively folds the value.
338338
fn super_fold_with<E>(
339339
self,
340-
folder: &mut dyn Folder<I, Error = E>,
340+
folder: &mut dyn TypeFolder<I, Error = E>,
341341
outer_binder: DebruijnIndex,
342342
) -> Result<Self::Result, E>;
343343
}
@@ -350,7 +350,7 @@ impl<I: Interner> TypeFoldable<I> for Ty<I> {
350350

351351
fn fold_with<E>(
352352
self,
353-
folder: &mut dyn Folder<I, Error = E>,
353+
folder: &mut dyn TypeFolder<I, Error = E>,
354354
outer_binder: DebruijnIndex,
355355
) -> Result<Self::Result, E> {
356356
folder.fold_ty(self, outer_binder)
@@ -364,7 +364,7 @@ where
364364
{
365365
fn super_fold_with<E>(
366366
self,
367-
folder: &mut dyn Folder<I, Error = E>,
367+
folder: &mut dyn TypeFolder<I, Error = E>,
368368
outer_binder: DebruijnIndex,
369369
) -> Result<Ty<I>, E> {
370370
let interner = folder.interner();
@@ -474,7 +474,7 @@ impl<I: Interner> TypeFoldable<I> for Lifetime<I> {
474474

475475
fn fold_with<E>(
476476
self,
477-
folder: &mut dyn Folder<I, Error = E>,
477+
folder: &mut dyn TypeFolder<I, Error = E>,
478478
outer_binder: DebruijnIndex,
479479
) -> Result<Self::Result, E> {
480480
folder.fold_lifetime(self, outer_binder)
@@ -487,7 +487,7 @@ where
487487
{
488488
fn super_fold_with<E>(
489489
self,
490-
folder: &mut dyn Folder<I, Error = E>,
490+
folder: &mut dyn TypeFolder<I, Error = E>,
491491
outer_binder: DebruijnIndex,
492492
) -> Result<Lifetime<I>, E> {
493493
let interner = folder.interner();
@@ -526,7 +526,7 @@ impl<I: Interner> TypeFoldable<I> for Const<I> {
526526

527527
fn fold_with<E>(
528528
self,
529-
folder: &mut dyn Folder<I, Error = E>,
529+
folder: &mut dyn TypeFolder<I, Error = E>,
530530
outer_binder: DebruijnIndex,
531531
) -> Result<Self::Result, E> {
532532
folder.fold_const(self, outer_binder)
@@ -539,7 +539,7 @@ where
539539
{
540540
fn super_fold_with<E>(
541541
self,
542-
folder: &mut dyn Folder<I, Error = E>,
542+
folder: &mut dyn TypeFolder<I, Error = E>,
543543
outer_binder: DebruijnIndex,
544544
) -> Result<Const<I>, E> {
545545
let interner = folder.interner();
@@ -577,7 +577,7 @@ impl<I: Interner> TypeFoldable<I> for Goal<I> {
577577

578578
fn fold_with<E>(
579579
self,
580-
folder: &mut dyn Folder<I, Error = E>,
580+
folder: &mut dyn TypeFolder<I, Error = E>,
581581
outer_binder: DebruijnIndex,
582582
) -> Result<Self::Result, E> {
583583
folder.fold_goal(self, outer_binder)
@@ -588,7 +588,7 @@ impl<I: Interner> TypeFoldable<I> for Goal<I> {
588588
impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
589589
fn super_fold_with<E>(
590590
self,
591-
folder: &mut dyn Folder<I, Error = E>,
591+
folder: &mut dyn TypeFolder<I, Error = E>,
592592
outer_binder: DebruijnIndex,
593593
) -> Result<Self::Result, E> {
594594
let interner = folder.interner();
@@ -609,7 +609,7 @@ impl<I: Interner> TypeFoldable<I> for ProgramClause<I> {
609609

610610
fn fold_with<E>(
611611
self,
612-
folder: &mut dyn Folder<I, Error = E>,
612+
folder: &mut dyn TypeFolder<I, Error = E>,
613613
outer_binder: DebruijnIndex,
614614
) -> Result<Self::Result, E> {
615615
folder.fold_program_clause(self, outer_binder)

chalk-ir/src/fold/binder_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl<I: Interner> TypeFoldable<I> for FnPointer<I> {
99
type Result = FnPointer<I>;
1010
fn fold_with<E>(
1111
self,
12-
folder: &mut dyn Folder<I, Error = E>,
12+
folder: &mut dyn TypeFolder<I, Error = E>,
1313
outer_binder: DebruijnIndex,
1414
) -> Result<Self::Result, E> {
1515
let FnPointer {
@@ -38,7 +38,7 @@ where
3838
type Result = Binders<T::Result>;
3939
fn fold_with<E>(
4040
self,
41-
folder: &mut dyn Folder<I, Error = E>,
41+
folder: &mut dyn TypeFolder<I, Error = E>,
4242
outer_binder: DebruijnIndex,
4343
) -> Result<Self::Result, E> {
4444
let Binders {
@@ -62,7 +62,7 @@ where
6262
type Result = Canonical<T::Result>;
6363
fn fold_with<E>(
6464
self,
65-
folder: &mut dyn Folder<I, Error = E>,
65+
folder: &mut dyn TypeFolder<I, Error = E>,
6666
outer_binder: DebruijnIndex,
6767
) -> Result<Self::Result, E> {
6868
let Canonical {

0 commit comments

Comments
 (0)