1- # TypeFoldable and the Folder trait
1+ # TypeFoldable and the TypeFolder trait
22
33The [ ` TypeFoldable ` ] trait permits one to traverse a type or other term in the
44chalk-ir and make a copy of it, possibly making small substitutions or
@@ -17,48 +17,48 @@ 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
2121defines a few key callbacks that allow you to substitute different
2222values as the fold proceeds. For example, when a type is folded, the
2323folder 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
2929A common use for ` TypeFoldable ` is to permit a substitution -- that is,
3030replacing generic type parameters with their values.
3131
32- ## From TypeFoldable to Folder to SuperFold and back again
32+ ## From TypeFoldable to TypeFolder to TypeSuperFoldable and back again
3333
3434The overall flow of folding is like this.
3535
36361 . [ ` TypeFoldable::fold_with ` ] is invoked on the outermost term. It recursively
3737 walks the term.
38382 . 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
42- ` SuperFold ::super_fold_with` . This will recursively fold the
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
42+ ` 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
5050Thus, 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
56- substitute a new value, then invoke ` SuperFold ::super_fold_with` to
56+ substitute a new value, then invoke ` TypeSuperFoldable ::super_fold_with` to
5757 return to the default behavior.
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
6262the number of binders that we have traversed during folding, which is relevant for De Bruijn indices.
6363So 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
@@ -77,21 +77,21 @@ type that will result from folding.
7777
7878[ `Result` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable.html#associatedtype.Result
7979
80- ## When to implement the TypeFoldable and SuperFold traits
80+ ## When to implement the TypeFoldable and TypeSuperFoldable traits
8181
8282Any piece of IR that represents a kind of "term" (e.g., a type, part
8383of a type, or a goal, etc) in the logic should implement ` TypeFoldable ` . We
8484also implement ` TypeFoldable ` for common collection types like ` Vec ` as well
8585as tuples, references, etc.
8686
87- The ` SuperFold ` trait should only be implemented for those types that
88- have a callback defined on the ` Folder ` trait (e.g., types and
87+ The ` TypeSuperFoldable ` trait should only be implemented for those types that
88+ have a callback defined on the ` TypeFolder ` trait (e.g., types and
8989lifetimes).
9090
9191## Derives
9292
9393Using the ` chalk-derive ` crate, you can auto-derive the ` TypeFoldable ` trait.
94- There isn't presently a derive for ` SuperFold ` since it is very rare
94+ There isn't presently a derive for ` TypeSuperFoldable ` since it is very rare
9595to require it. The derive for ` TypeFoldable ` is a bit cludgy and requires:
9696
9797* You must import ` TypeFoldable ` into scope.
0 commit comments