1- # Fold and the Folder trait
1+ # TypeFoldable and the Folder trait
22
3- The [ ` Fold ` ] trait permits one to traverse a type or other term in the
3+ The [ ` 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
55alterations along the way. Folding also allows copying a term from one
66interner to another.
77
8- [ `Fold ` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Fold .html
8+ [ `TypeFoldable ` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable .html
99
10- To use the [ ` Fold ` ] trait, one invokes the [ ` Fold ::fold_with` ] method, supplying some
10+ To use the [ ` TypeFoldable ` ] trait, one invokes the [ ` TypeFoldable ::fold_with` ] method, supplying some
1111"folder" as well as the number of "in scope binders" for that term (typically ` 0 `
1212to start):
1313
1414``` rust,ignore
1515let output_ty = input_ty.fold_with(&mut folder, 0);
1616```
1717
18- [ `Fold ::fold_with` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Fold .html#tymethod.fold_with
18+ [ `TypeFoldable ::fold_with` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable .html#tymethod.fold_with
1919
2020The folder is some instance of the [ ` Folder ` ] trait. This trait
2121defines a few key callbacks that allow you to substitute different
@@ -26,17 +26,17 @@ folder can substitute a new type in its place.
2626
2727## Uses for folders
2828
29- A common use for ` Fold ` is to permit a substitution -- that is,
29+ A common use for ` TypeFoldable ` is to permit a substitution -- that is,
3030replacing generic type parameters with their values.
3131
32- ## From Fold to Folder to SuperFold and back again
32+ ## From TypeFoldable to Folder to SuperFold and back again
3333
3434The overall flow of folding is like this.
3535
36- 1 . [ ` Fold ::fold_with` ] is invoked on the outermost term. It recursively
36+ 1 . [ ` 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 [ ` Fold ::fold_with` ] will in turn
39+ callbacks in the [ ` Folder ` ] trait, invoking [ ` TypeFoldable ::fold_with` ] will in turn
4040 invoke the corresponding method on the [ ` Folder ` ] trait, such as ` Folder::fold_ty ` .
41413 . The default implementation of ` Folder::fold_ty ` , in turn, invokes
4242 ` SuperFold::super_fold_with ` . This will recursively fold the
@@ -70,18 +70,18 @@ Foo<'a>: for<'b> Bar<'b>
7070
7171In this case, ` Foo<'a> ` gets visited with depth 0 and ` Bar<'b> ` gets visited with depth 1.
7272
73- ## The ` Fold ::Result` associated type
73+ ## The ` TypeFoldable ::Result` associated type
7474
75- The ` Fold ` trait defines a [ ` Result ` ] associated type, indicating the
75+ The ` TypeFoldable ` trait defines a [ ` Result ` ] associated type, indicating the
7676type that will result from folding.
7777
78- [ `Result` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Fold .html#associatedtype.Result
78+ [ `Result` ] : https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable .html#associatedtype.Result
7979
80- ## When to implement the Fold and SuperFold traits
80+ ## When to implement the TypeFoldable and SuperFold traits
8181
8282Any piece of IR that represents a kind of "term" (e.g., a type, part
83- of a type, or a goal, etc) in the logic should implement ` Fold ` . We
84- also implement ` Fold ` for common collection types like ` Vec ` as well
83+ of a type, or a goal, etc) in the logic should implement ` TypeFoldable ` . We
84+ also implement ` TypeFoldable ` for common collection types like ` Vec ` as well
8585as tuples, references, etc.
8686
8787The ` SuperFold ` trait should only be implemented for those types that
@@ -90,12 +90,12 @@ lifetimes).
9090
9191## Derives
9292
93- Using the ` chalk-derive ` crate, you can auto-derive the ` Fold ` trait.
93+ Using the ` chalk-derive ` crate, you can auto-derive the ` TypeFoldable ` trait.
9494There isn't presently a derive for ` SuperFold ` since it is very rare
95- to require it. The derive for ` Fold ` is a bit cludgy and requires:
95+ to require it. The derive for ` TypeFoldable ` is a bit cludgy and requires:
9696
97- * You must import ` Fold ` into scope.
98- * The type you are deriving ` Fold ` on must have either:
97+ * You must import ` TypeFoldable ` into scope.
98+ * The type you are deriving ` TypeFoldable ` on must have either:
9999 * A type parameter that has a ` Interner ` bound, like ` I: Interner `
100100 * A type parameter that has a ` HasInterner ` bound, like ` I: HasInterner `
101101 * The ` has_interner(XXX) ` attribute.
0 commit comments