Skip to content

Commit 869fa24

Browse files
committed
Rename SuperFold to TypeSuperFoldable
1 parent a4c9420 commit 869fa24

File tree

29 files changed

+232
-226
lines changed

29 files changed

+232
-226
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 18 additions & 18 deletions
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,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
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 SuperFold 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
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

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
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
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

@@ -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

8282
Any piece of IR that represents a kind of "term" (e.g., a type, part
8383
of a type, or a goal, etc) in the logic should implement `TypeFoldable`. We
8484
also implement `TypeFoldable` for common collection types like `Vec` as well
8585
as 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
8989
lifetimes).
9090

9191
## Derives
9292

9393
Using 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
9595
to require it. The derive for `TypeFoldable` is a bit cludgy and requires:
9696

9797
* You must import `TypeFoldable` into scope.

chalk-derive/src/lib.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ enum DeriveKind {
118118
}
119119

120120
decl_derive!([HasInterner, attributes(has_interner)] => derive_has_interner);
121-
decl_derive!([Visit, attributes(has_interner)] => derive_visit);
122-
decl_derive!([SuperVisit, attributes(has_interner)] => derive_super_visit);
121+
decl_derive!([TypeVisitable, attributes(has_interner)] => derive_type_visitable);
122+
decl_derive!([TypeSuperVisitable, attributes(has_interner)] => derive_type_super_visitable);
123123
decl_derive!([TypeFoldable, attributes(has_interner)] => derive_type_foldable);
124124
decl_derive!([Zip, attributes(has_interner)] => derive_zip);
125125

@@ -136,24 +136,28 @@ fn derive_has_interner(mut s: synstructure::Structure) -> TokenStream {
136136
)
137137
}
138138

139-
/// Derives Visit for structs and enums for which one of the following is true:
139+
/// Derives TypeVisitable for structs and enums for which one of the following is true:
140140
/// - It has a `#[has_interner(TheInterner)]` attribute
141141
/// - There is a single parameter `T: HasInterner` (does not have to be named `T`)
142142
/// - There is a single parameter `I: Interner` (does not have to be named `I`)
143-
fn derive_visit(s: synstructure::Structure) -> TokenStream {
144-
derive_any_visit(s, parse_quote! { Visit }, parse_quote! { visit_with })
143+
fn derive_type_visitable(s: synstructure::Structure) -> TokenStream {
144+
derive_any_type_visitable(
145+
s,
146+
parse_quote! { TypeVisitable },
147+
parse_quote! { visit_with },
148+
)
145149
}
146150

147-
/// Same as Visit, but derives SuperVisit instead
148-
fn derive_super_visit(s: synstructure::Structure) -> TokenStream {
149-
derive_any_visit(
151+
/// Same as TypeVisitable, but derives TypeSuperVisitable instead
152+
fn derive_type_super_visitable(s: synstructure::Structure) -> TokenStream {
153+
derive_any_type_visitable(
150154
s,
151-
parse_quote! { SuperVisit },
155+
parse_quote! { TypeSuperVisitable },
152156
parse_quote! { super_visit_with },
153157
)
154158
}
155159

156-
fn derive_any_visit(
160+
fn derive_any_type_visitable(
157161
mut s: synstructure::Structure,
158162
trait_name: Ident,
159163
method_name: Ident,
@@ -164,13 +168,13 @@ fn derive_any_visit(
164168

165169
let body = s.each(|bi| {
166170
quote! {
167-
::chalk_ir::try_break!(::chalk_ir::visit::Visit::visit_with(#bi, visitor, outer_binder));
171+
::chalk_ir::try_break!(::chalk_ir::visit::TypeVisitable::visit_with(#bi, visitor, outer_binder));
168172
}
169173
});
170174

171175
if kind == DeriveKind::FromHasInterner {
172176
let param = get_generic_param_name(input).unwrap();
173-
s.add_where_predicate(parse_quote! { #param: ::chalk_ir::visit::Visit<#interner> });
177+
s.add_where_predicate(parse_quote! { #param: ::chalk_ir::visit::TypeVisitable<#interner> });
174178
}
175179

176180
s.add_bounds(synstructure::AddBounds::None);
@@ -295,7 +299,7 @@ fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream {
295299

296300
fn fold_with<E>(
297301
self,
298-
folder: &mut dyn ::chalk_ir::fold::Folder < #interner, Error = E >,
302+
folder: &mut dyn ::chalk_ir::fold::TypeFolder < #interner, Error = E >,
299303
outer_binder: ::chalk_ir::DebruijnIndex,
300304
) -> ::std::result::Result<Self::Result, E> {
301305
Ok(match self { #body })

chalk-engine/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
use std::cmp::min;
5757
use std::usize;
5858

59-
use chalk_derive::{HasInterner, TypeFoldable, Visit};
59+
use chalk_derive::{HasInterner, TypeFoldable, TypeVisitable};
6060
use chalk_ir::interner::Interner;
6161
use chalk_ir::{
6262
AnswerSubst, Canonical, ConstrainedSubst, Constraint, DebruijnIndex, Goal, InEnvironment,
@@ -84,7 +84,7 @@ index_struct! {
8484
}
8585

8686
/// The paper describes these as `A :- D | G`.
87-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
87+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
8888
pub struct ExClause<I: Interner> {
8989
/// The substitution which, applied to the goal of our table,
9090
/// would yield A.
@@ -168,7 +168,7 @@ impl TimeStamp {
168168
///
169169
/// trying to solve `?T: Foo` would immediately require solving `?T:
170170
/// Sized`, and hence would flounder.
171-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit)]
171+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
172172
pub struct FlounderedSubgoal<I: Interner> {
173173
/// Literal that floundered.
174174
pub floundered_literal: Literal<I>,
@@ -209,7 +209,7 @@ pub struct CompleteAnswer<I: Interner> {
209209
}
210210

211211
/// Either `A` or `~A`, where `A` is a `Env |- Goal`.
212-
#[derive(Clone, Debug, TypeFoldable, Visit)]
212+
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
213213
pub enum Literal<I: Interner> {
214214
// FIXME: pub b/c fold
215215
Positive(InEnvironment<Goal<I>>),

chalk-engine/src/normalize_deep.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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 {

0 commit comments

Comments
 (0)