Skip to content

Commit a4c9420

Browse files
committed
Rename Fold to TypeFoldable
1 parent 280d955 commit a4c9420

31 files changed

+186
-182
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-
- [Fold and the Folder trait](./types/operations/fold.md)
15+
- [TypeFoldable and the Folder 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: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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
44
chalk-ir and make a copy of it, possibly making small substitutions or
55
alterations along the way. Folding also allows copying a term from one
66
interner 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`
1212
to start):
1313

1414
```rust,ignore
1515
let 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

2020
The folder is some instance of the [`Folder`] trait. This trait
2121
defines 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,
3030
replacing 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

3434
The 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.
3838
2. 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`.
4141
3. 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

7171
In 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
7676
type 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

8282
Any 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
8585
as tuples, references, etc.
8686

8787
The `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.
9494
There 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.

book/src/what_is_chalk/crates.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The following crate is an implementation detail, used internally by `chalk-solve
1919

2020
* The `chalk-engine` crate, which defines the actual engine that solves logical predicate. This
2121
engine is quite general and not really specific to Rust.
22-
* The `chalk-derive` crate defines custom derives for the `chalk_ir::fold::Fold` trait and other
22+
* The `chalk-derive` crate defines custom derives for the `chalk_ir::fold::TypeFoldable` trait and other
2323
such things.
2424

2525
## Crates for standalone REPL and testing
@@ -37,11 +37,11 @@ define a kind of "minimal embedding" of chalk.
3737

3838
## The chalk-solve crate
3939

40-
| The `chalk-solve` crate | |
41-
|---|--- |
42-
| Purpose: | to solve a given goal |
43-
| Depends on IR: | chalk-ir and rust-ir |
44-
| Context required: | `RustIrDatabase` |
40+
| The `chalk-solve` crate | |
41+
| ----------------------- | --------------------- |
42+
| Purpose: | to solve a given goal |
43+
| Depends on IR: | chalk-ir and rust-ir |
44+
| Context required: | `RustIrDatabase` |
4545

4646
The `chalk-solve` crate exposes a key type called `Solver`. This is a
4747
solver that, given a goal (expressed in chalk-ir) will solve the goal
@@ -60,11 +60,11 @@ provide needed context for the solver -- notably, the solver can ask:
6060

6161
## The chalk-engine crate
6262

63-
| The `chalk-engine` crate | |
64-
|---|--- |
65-
| Purpose: | define the base solving strategy |
66-
| IR: | none |
67-
| Context required: | `Context` trait |
63+
| The `chalk-engine` crate | |
64+
| ------------------------ | -------------------------------- |
65+
| Purpose: | define the base solving strategy |
66+
| IR: | none |
67+
| Context required: | `Context` trait |
6868

6969
For the purposes of chalk, the `chalk-engine` crate is effectively
7070
encapsulated by `chalk-solve`. It defines the base SLG engine. It is

chalk-derive/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ enum DeriveKind {
120120
decl_derive!([HasInterner, attributes(has_interner)] => derive_has_interner);
121121
decl_derive!([Visit, attributes(has_interner)] => derive_visit);
122122
decl_derive!([SuperVisit, attributes(has_interner)] => derive_super_visit);
123-
decl_derive!([Fold, attributes(has_interner)] => derive_fold);
123+
decl_derive!([TypeFoldable, attributes(has_interner)] => derive_type_foldable);
124124
decl_derive!([Zip, attributes(has_interner)] => derive_zip);
125125

126126
fn derive_has_interner(mut s: synstructure::Structure) -> TokenStream {
@@ -250,11 +250,11 @@ fn derive_zip(mut s: synstructure::Structure) -> TokenStream {
250250
)
251251
}
252252

253-
/// Derives Fold for structs and enums for which one of the following is true:
253+
/// Derives TypeFoldable for structs and enums for which one of the following is true:
254254
/// - It has a `#[has_interner(TheInterner)]` attribute
255255
/// - There is a single parameter `T: HasInterner` (does not have to be named `T`)
256256
/// - There is a single parameter `I: Interner` (does not have to be named `I`)
257-
fn derive_fold(mut s: synstructure::Structure) -> TokenStream {
257+
fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream {
258258
s.underscore_const(true);
259259
s.bind_with(|_| synstructure::BindStyle::Move);
260260

@@ -265,7 +265,7 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream {
265265
vi.construct(|_, index| {
266266
let bind = &bindings[index];
267267
quote! {
268-
::chalk_ir::fold::Fold::fold_with(#bind, folder, outer_binder)?
268+
::chalk_ir::fold::TypeFoldable::fold_with(#bind, folder, outer_binder)?
269269
}
270270
})
271271
});
@@ -277,7 +277,7 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream {
277277
let param = get_generic_param_name(input).unwrap();
278278
s.add_impl_generic(parse_quote! { _U })
279279
.add_where_predicate(
280-
parse_quote! { #param: ::chalk_ir::fold::Fold<#interner, Result = _U> },
280+
parse_quote! { #param: ::chalk_ir::fold::TypeFoldable<#interner, Result = _U> },
281281
)
282282
.add_where_predicate(
283283
parse_quote! { _U: ::chalk_ir::interner::HasInterner<Interner = #interner> },
@@ -289,7 +289,7 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream {
289289

290290
s.add_bounds(synstructure::AddBounds::None);
291291
s.bound_impl(
292-
quote!(::chalk_ir::fold::Fold<#interner>),
292+
quote!(::chalk_ir::fold::TypeFoldable<#interner>),
293293
quote! {
294294
type Result = #result;
295295

chalk-engine/src/lib.rs

Lines changed: 5 additions & 5 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::{Fold, HasInterner, Visit};
59+
use chalk_derive::{HasInterner, TypeFoldable, Visit};
6060
use chalk_ir::interner::Interner;
6161
use chalk_ir::{
6262
AnswerSubst, Canonical, ConstrainedSubst, Constraint, DebruijnIndex, Goal, InEnvironment,
@@ -78,13 +78,13 @@ mod table;
7878
mod tables;
7979

8080
index_struct! {
81-
pub struct TableIndex { // FIXME: pub b/c Fold
81+
pub struct TableIndex { // FIXME: pub b/c TypeFoldable
8282
value: usize,
8383
}
8484
}
8585

8686
/// The paper describes these as `A :- D | G`.
87-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)]
87+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit, 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, Fold, Visit)]
171+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit)]
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, Fold, Visit)]
212+
#[derive(Clone, Debug, TypeFoldable, Visit)]
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: 2 additions & 2 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::{Fold, Folder};
2+
use chalk_ir::fold::{Folder, TypeFoldable};
33
use chalk_ir::interner::Interner;
44
use chalk_ir::*;
55
use chalk_solve::infer::InferenceTable;
@@ -21,7 +21,7 @@ impl<I: Interner> DeepNormalizer<'_, I> {
2121
/// See also `InferenceTable::canonicalize`, which -- during real
2222
/// processing -- is often used to capture the "current state" of
2323
/// variables.
24-
pub fn normalize_deep<T: Fold<I>>(
24+
pub fn normalize_deep<T: TypeFoldable<I>>(
2525
table: &mut InferenceTable<I>,
2626
interner: I,
2727
value: T,

chalk-engine/src/slg/resolvent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::slg::ResolventOps;
33
use crate::{ExClause, Literal, TimeStamp};
44
use chalk_ir::cast::Caster;
55
use chalk_ir::fold::shift::Shift;
6-
use chalk_ir::fold::Fold;
6+
use chalk_ir::fold::TypeFoldable;
77
use chalk_ir::interner::{HasInterner, Interner};
88
use chalk_ir::zip::{Zip, Zipper};
99
use chalk_ir::*;
@@ -708,7 +708,7 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
708708
pending: &Binders<T>,
709709
) -> Fallible<()>
710710
where
711-
T: HasInterner<Interner = I> + Zip<I> + Fold<I, Result = T>,
711+
T: HasInterner<Interner = I> + Zip<I> + TypeFoldable<I, Result = T>,
712712
{
713713
self.outer_binder.shift_in();
714714
Zip::zip_with(

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::{Fold, Folder};
6+
use chalk_ir::fold::{Folder, TypeFoldable};
77
use chalk_ir::interner::Interner;
88
use chalk_ir::{Canonical, DebruijnIndex, UniverseMap};
99

@@ -35,7 +35,7 @@ pub(crate) struct SelectedSubgoal {
3535
pub(crate) universe_map: UniverseMap,
3636
}
3737

38-
impl<I: Interner> Fold<I> for Strand<I> {
38+
impl<I: Interner> TypeFoldable<I> for Strand<I> {
3939
type Result = Strand<I>;
4040
fn fold_with<E>(
4141
self,

chalk-ir/src/fold.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use self::subst::Subst;
1616
/// some term -- that is, some bit of IR, such as a `Goal` -- with
1717
/// certain changes applied. The idea is that it contains methods that
1818
/// let you swap types/lifetimes for new types/lifetimes; meanwhile,
19-
/// each bit of IR implements the `Fold` trait which, given a
19+
/// each bit of IR implements the `TypeFoldable` trait which, given a
2020
/// `Folder`, will reconstruct itself, invoking the folder's methods
2121
/// to transform each of the types/lifetimes embedded within.
2222
///
@@ -49,7 +49,7 @@ pub use self::subst::Subst;
4949
/// that appear in the term being folded (use
5050
/// `DefaultPlaceholderFolder` to ignore/forbid these altogether)
5151
///
52-
/// To **apply** a folder, use the `Fold::fold_with` method, like so
52+
/// To **apply** a folder, use the `TypeFoldable::fold_with` method, like so
5353
///
5454
/// ```rust,ignore
5555
/// let x = x.fold_with(&mut folder, 0);
@@ -310,11 +310,11 @@ pub trait Folder<I: Interner> {
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
312312
/// `T`; well, actually `T::Result`).
313-
pub trait Fold<I: Interner>: Debug {
313+
pub trait TypeFoldable<I: Interner>: Debug {
314314
/// The type of value that will be produced once folding is done.
315315
/// Typically this is `Self`, unless `Self` contains borrowed
316316
/// values, in which case owned values are produced (for example,
317-
/// one can fold over a `&T` value where `T: Fold`, in which case
317+
/// one can fold over a `&T` value where `T: TypeFoldable`, in which case
318318
/// you get back a `T`, not a `&T`).
319319
type Result;
320320

@@ -333,7 +333,7 @@ pub trait Fold<I: Interner>: Debug {
333333
/// For types where "fold" invokes a callback on the `Folder`, the
334334
/// `SuperFold` trait captures the recursive behavior that folds all
335335
/// the contents of the type.
336-
pub trait SuperFold<I: Interner>: Fold<I> {
336+
pub trait SuperFold<I: Interner>: TypeFoldable<I> {
337337
/// Recursively folds the value.
338338
fn super_fold_with<E>(
339339
self,
@@ -345,7 +345,7 @@ pub trait SuperFold<I: Interner>: Fold<I> {
345345
/// "Folding" a type invokes the `fold_ty` method on the folder; this
346346
/// usually (in turn) invokes `super_fold_ty` to fold the individual
347347
/// parts.
348-
impl<I: Interner> Fold<I> for Ty<I> {
348+
impl<I: Interner> TypeFoldable<I> for Ty<I> {
349349
type Result = Ty<I>;
350350

351351
fn fold_with<E>(
@@ -469,7 +469,7 @@ where
469469
/// "Folding" a lifetime invokes the `fold_lifetime` method on the folder; this
470470
/// usually (in turn) invokes `super_fold_lifetime` to fold the individual
471471
/// parts.
472-
impl<I: Interner> Fold<I> for Lifetime<I> {
472+
impl<I: Interner> TypeFoldable<I> for Lifetime<I> {
473473
type Result = Lifetime<I>;
474474

475475
fn fold_with<E>(
@@ -521,7 +521,7 @@ where
521521
/// "Folding" a const invokes the `fold_const` method on the folder; this
522522
/// usually (in turn) invokes `super_fold_const` to fold the individual
523523
/// parts.
524-
impl<I: Interner> Fold<I> for Const<I> {
524+
impl<I: Interner> TypeFoldable<I> for Const<I> {
525525
type Result = Const<I>;
526526

527527
fn fold_with<E>(
@@ -572,7 +572,7 @@ where
572572

573573
/// Folding a goal invokes the `fold_goal` callback (which will, by
574574
/// default, invoke super-fold).
575-
impl<I: Interner> Fold<I> for Goal<I> {
575+
impl<I: Interner> TypeFoldable<I> for Goal<I> {
576576
type Result = Goal<I>;
577577

578578
fn fold_with<E>(
@@ -604,7 +604,7 @@ impl<I: Interner> SuperFold<I> for Goal<I> {
604604
/// Folding a program clause invokes the `fold_program_clause`
605605
/// callback on the folder (which will, by default, invoke the
606606
/// `super_fold_with` method on the program clause).
607-
impl<I: Interner> Fold<I> for ProgramClause<I> {
607+
impl<I: Interner> TypeFoldable<I> for ProgramClause<I> {
608608
type Result = ProgramClause<I>;
609609

610610
fn fold_with<E>(

0 commit comments

Comments
 (0)