Skip to content

Commit 7912627

Browse files
committed
Rename TypeFolder to FallibleTypeFolder
1 parent 4991b7d commit 7912627

File tree

14 files changed

+77
-76
lines changed

14 files changed

+77
-76
lines changed

chalk-derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream {
287287
quote! {
288288
fn fold_with<E>(
289289
self,
290-
folder: &mut dyn ::chalk_ir::fold::TypeFolder < #interner, Error = E >,
290+
folder: &mut dyn ::chalk_ir::fold::FallibleTypeFolder < #interner, Error = E >,
291291
outer_binder: ::chalk_ir::DebruijnIndex,
292292
) -> ::std::result::Result<Self, E> {
293293
Ok(match self { #body })

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::{TypeFoldable, TypeFolder};
2+
use chalk_ir::fold::{FallibleTypeFolder, TypeFoldable};
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> TypeFolder<I> for DeepNormalizer<'_, I> {
38+
impl<I: Interner> FallibleTypeFolder<I> for DeepNormalizer<'_, I> {
3939
type Error = NoSolution;
4040

41-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<I, Error = Self::Error> {
41+
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<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::{TypeFoldable, TypeFolder};
6+
use chalk_ir::fold::{FallibleTypeFolder, TypeFoldable};
77
use chalk_ir::interner::Interner;
88
use chalk_ir::{Canonical, DebruijnIndex, UniverseMap};
99

@@ -38,7 +38,7 @@ pub(crate) struct SelectedSubgoal {
3838
impl<I: Interner> TypeFoldable<I> for Strand<I> {
3939
fn fold_with<E>(
4040
self,
41-
folder: &mut dyn TypeFolder<I, Error = E>,
41+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
4242
outer_binder: DebruijnIndex,
4343
) -> Result<Self, E> {
4444
Ok(Strand {

chalk-ir/src/fold.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ 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-
/// `TypeFolder`, will reconstruct itself, invoking the folder's methods
21-
/// to transform each of the types/lifetimes embedded within.
20+
/// `FallibleTypeFolder`, will reconstruct itself, invoking the folder's
21+
/// methods to transform each of the types/lifetimes embedded within.
2222
///
2323
/// # Usage patterns
2424
///
@@ -29,15 +29,15 @@ pub use self::subst::Subst;
2929
/// more often, just free existential variables) that appear within
3030
/// the term.
3131
///
32-
/// For this reason, the `TypeFolder` trait extends two other traits that
33-
/// contain methods that are invoked when just those particular
32+
/// For this reason, the `FallibleTypeFolder` trait extends two other
33+
/// traits that 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 `TypeFolder` directly, but instead
40-
/// implements one of each of these three sub-traits:
39+
/// To create a folder `F`, one never implements `FallibleTypeFolder`
40+
/// directly, but instead implements one of each of these three sub-traits:
4141
///
4242
/// - `FreeVarFolder` -- folds `BoundVar` instances that appear free
4343
/// in the term being folded (use `DefaultFreeVarFolder` to
@@ -49,24 +49,25 @@ 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 `TypeFoldable::fold_with` method, like so
52+
/// To **apply** a folder, use the `TypeFoldable::fold_with` method,
53+
/// like so
5354
///
5455
/// ```rust,ignore
5556
/// let x = x.fold_with(&mut folder, 0);
5657
/// ```
57-
pub trait TypeFolder<I: Interner> {
58+
pub trait FallibleTypeFolder<I: Interner> {
5859
/// The type this folder returns when folding fails. This is
5960
/// commonly [`NoSolution`].
6061
type Error;
6162

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

7172
/// Top-level callback: invoked for each `Ty<I>` that is
7273
/// encountered when folding. By default, invokes
@@ -318,7 +319,7 @@ pub trait TypeFoldable<I: Interner>: Debug + Sized {
318319
/// constructs.
319320
fn fold_with<E>(
320321
self,
321-
folder: &mut dyn TypeFolder<I, Error = E>,
322+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
322323
outer_binder: DebruijnIndex,
323324
) -> Result<Self, E>;
324325
}
@@ -330,7 +331,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
330331
/// Recursively folds the value.
331332
fn super_fold_with<E>(
332333
self,
333-
folder: &mut dyn TypeFolder<I, Error = E>,
334+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
334335
outer_binder: DebruijnIndex,
335336
) -> Result<Self, E>;
336337
}
@@ -341,7 +342,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
341342
impl<I: Interner> TypeFoldable<I> for Ty<I> {
342343
fn fold_with<E>(
343344
self,
344-
folder: &mut dyn TypeFolder<I, Error = E>,
345+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
345346
outer_binder: DebruijnIndex,
346347
) -> Result<Self, E> {
347348
folder.fold_ty(self, outer_binder)
@@ -355,7 +356,7 @@ where
355356
{
356357
fn super_fold_with<E>(
357358
self,
358-
folder: &mut dyn TypeFolder<I, Error = E>,
359+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
359360
outer_binder: DebruijnIndex,
360361
) -> Result<Ty<I>, E> {
361362
let interner = folder.interner();
@@ -463,7 +464,7 @@ where
463464
impl<I: Interner> TypeFoldable<I> for Lifetime<I> {
464465
fn fold_with<E>(
465466
self,
466-
folder: &mut dyn TypeFolder<I, Error = E>,
467+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
467468
outer_binder: DebruijnIndex,
468469
) -> Result<Self, E> {
469470
folder.fold_lifetime(self, outer_binder)
@@ -476,7 +477,7 @@ where
476477
{
477478
fn super_fold_with<E>(
478479
self,
479-
folder: &mut dyn TypeFolder<I, Error = E>,
480+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
480481
outer_binder: DebruijnIndex,
481482
) -> Result<Lifetime<I>, E> {
482483
let interner = folder.interner();
@@ -513,7 +514,7 @@ where
513514
impl<I: Interner> TypeFoldable<I> for Const<I> {
514515
fn fold_with<E>(
515516
self,
516-
folder: &mut dyn TypeFolder<I, Error = E>,
517+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
517518
outer_binder: DebruijnIndex,
518519
) -> Result<Self, E> {
519520
folder.fold_const(self, outer_binder)
@@ -526,7 +527,7 @@ where
526527
{
527528
fn super_fold_with<E>(
528529
self,
529-
folder: &mut dyn TypeFolder<I, Error = E>,
530+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
530531
outer_binder: DebruijnIndex,
531532
) -> Result<Const<I>, E> {
532533
let interner = folder.interner();
@@ -562,7 +563,7 @@ where
562563
impl<I: Interner> TypeFoldable<I> for Goal<I> {
563564
fn fold_with<E>(
564565
self,
565-
folder: &mut dyn TypeFolder<I, Error = E>,
566+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
566567
outer_binder: DebruijnIndex,
567568
) -> Result<Self, E> {
568569
folder.fold_goal(self, outer_binder)
@@ -573,7 +574,7 @@ impl<I: Interner> TypeFoldable<I> for Goal<I> {
573574
impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
574575
fn super_fold_with<E>(
575576
self,
576-
folder: &mut dyn TypeFolder<I, Error = E>,
577+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
577578
outer_binder: DebruijnIndex,
578579
) -> Result<Self, E> {
579580
let interner = folder.interner();
@@ -592,7 +593,7 @@ impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
592593
impl<I: Interner> TypeFoldable<I> for ProgramClause<I> {
593594
fn fold_with<E>(
594595
self,
595-
folder: &mut dyn TypeFolder<I, Error = E>,
596+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
596597
outer_binder: DebruijnIndex,
597598
) -> Result<Self, E> {
598599
folder.fold_program_clause(self, outer_binder)

chalk-ir/src/fold/binder_impls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::*;
88
impl<I: Interner> TypeFoldable<I> for FnPointer<I> {
99
fn fold_with<E>(
1010
self,
11-
folder: &mut dyn TypeFolder<I, Error = E>,
11+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
1212
outer_binder: DebruijnIndex,
1313
) -> Result<Self, E> {
1414
let FnPointer {
@@ -35,7 +35,7 @@ where
3535
{
3636
fn fold_with<E>(
3737
self,
38-
folder: &mut dyn TypeFolder<I, Error = E>,
38+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
3939
outer_binder: DebruijnIndex,
4040
) -> Result<Self, E> {
4141
let Binders {
@@ -57,7 +57,7 @@ where
5757
{
5858
fn fold_with<E>(
5959
self,
60-
folder: &mut dyn TypeFolder<I, Error = E>,
60+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
6161
outer_binder: DebruijnIndex,
6262
) -> Result<Self, E> {
6363
let Canonical {

chalk-ir/src/fold/boring_impls.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::marker::PhantomData;
1111
impl<T: TypeFoldable<I>, I: Interner> TypeFoldable<I> for Vec<T> {
1212
fn fold_with<E>(
1313
self,
14-
folder: &mut dyn TypeFolder<I, Error = E>,
14+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
1515
outer_binder: DebruijnIndex,
1616
) -> Result<Self, E> {
1717
in_place::fallible_map_vec(self, |e| e.fold_with(folder, outer_binder))
@@ -21,7 +21,7 @@ impl<T: TypeFoldable<I>, I: Interner> TypeFoldable<I> for Vec<T> {
2121
impl<T: TypeFoldable<I>, I: Interner> TypeFoldable<I> for Box<T> {
2222
fn fold_with<E>(
2323
self,
24-
folder: &mut dyn TypeFolder<I, Error = E>,
24+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
2525
outer_binder: DebruijnIndex,
2626
) -> Result<Self, E> {
2727
in_place::fallible_map_box(self, |e| e.fold_with(folder, outer_binder))
@@ -31,7 +31,7 @@ impl<T: TypeFoldable<I>, I: Interner> TypeFoldable<I> for Box<T> {
3131
macro_rules! tuple_fold {
3232
($($n:ident),*) => {
3333
impl<$($n: TypeFoldable<I>,)* I: Interner> TypeFoldable<I> for ($($n,)*) {
34-
fn fold_with<Error>(self, folder: &mut dyn TypeFolder<I, Error = Error>, outer_binder: DebruijnIndex) -> Result<Self, Error>
34+
fn fold_with<Error>(self, folder: &mut dyn FallibleTypeFolder<I, Error = Error>, outer_binder: DebruijnIndex) -> Result<Self, Error>
3535
{
3636
#[allow(non_snake_case)]
3737
let ($($n),*) = self;
@@ -49,7 +49,7 @@ tuple_fold!(A, B, C, D, E);
4949
impl<T: TypeFoldable<I>, I: Interner> TypeFoldable<I> for Option<T> {
5050
fn fold_with<E>(
5151
self,
52-
folder: &mut dyn TypeFolder<I, Error = E>,
52+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
5353
outer_binder: DebruijnIndex,
5454
) -> Result<Self, E> {
5555
match self {
@@ -62,7 +62,7 @@ impl<T: TypeFoldable<I>, I: Interner> TypeFoldable<I> for Option<T> {
6262
impl<I: Interner> TypeFoldable<I> for GenericArg<I> {
6363
fn fold_with<E>(
6464
self,
65-
folder: &mut dyn TypeFolder<I, Error = E>,
65+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
6666
outer_binder: DebruijnIndex,
6767
) -> Result<Self, E> {
6868
let interner = folder.interner();
@@ -78,7 +78,7 @@ impl<I: Interner> TypeFoldable<I> for GenericArg<I> {
7878
impl<I: Interner> TypeFoldable<I> for Substitution<I> {
7979
fn fold_with<E>(
8080
self,
81-
folder: &mut dyn TypeFolder<I, Error = E>,
81+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
8282
outer_binder: DebruijnIndex,
8383
) -> Result<Self, E> {
8484
let interner = folder.interner();
@@ -94,7 +94,7 @@ impl<I: Interner> TypeFoldable<I> for Substitution<I> {
9494
impl<I: Interner> TypeFoldable<I> for Goals<I> {
9595
fn fold_with<E>(
9696
self,
97-
folder: &mut dyn TypeFolder<I, Error = E>,
97+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
9898
outer_binder: DebruijnIndex,
9999
) -> Result<Self, E> {
100100
let interner = folder.interner();
@@ -109,7 +109,7 @@ impl<I: Interner> TypeFoldable<I> for Goals<I> {
109109
impl<I: Interner> TypeFoldable<I> for ProgramClauses<I> {
110110
fn fold_with<E>(
111111
self,
112-
folder: &mut dyn TypeFolder<I, Error = E>,
112+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
113113
outer_binder: DebruijnIndex,
114114
) -> Result<Self, E> {
115115
let interner = folder.interner();
@@ -124,7 +124,7 @@ impl<I: Interner> TypeFoldable<I> for ProgramClauses<I> {
124124
impl<I: Interner> TypeFoldable<I> for QuantifiedWhereClauses<I> {
125125
fn fold_with<E>(
126126
self,
127-
folder: &mut dyn TypeFolder<I, Error = E>,
127+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
128128
outer_binder: DebruijnIndex,
129129
) -> Result<Self, E> {
130130
let interner = folder.interner();
@@ -139,7 +139,7 @@ impl<I: Interner> TypeFoldable<I> for QuantifiedWhereClauses<I> {
139139
impl<I: Interner> TypeFoldable<I> for Constraints<I> {
140140
fn fold_with<E>(
141141
self,
142-
folder: &mut dyn TypeFolder<I, Error = E>,
142+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
143143
outer_binder: DebruijnIndex,
144144
) -> Result<Self, E> {
145145
let interner = folder.interner();
@@ -158,7 +158,7 @@ macro_rules! copy_fold {
158158
impl<I: Interner> $crate::fold::TypeFoldable<I> for $t {
159159
fn fold_with<E>(
160160
self,
161-
_folder: &mut dyn ($crate::fold::TypeFolder<I, Error = E>),
161+
_folder: &mut dyn ($crate::fold::FallibleTypeFolder<I, Error = E>),
162162
_outer_binder: DebruijnIndex,
163163
) -> ::std::result::Result<Self, E> {
164164
Ok(self)
@@ -189,7 +189,7 @@ macro_rules! id_fold {
189189
impl<I: Interner> $crate::fold::TypeFoldable<I> for $t<I> {
190190
fn fold_with<E>(
191191
self,
192-
_folder: &mut dyn ($crate::fold::TypeFolder<I, Error = E>),
192+
_folder: &mut dyn ($crate::fold::FallibleTypeFolder<I, Error = E>),
193193
_outer_binder: DebruijnIndex,
194194
) -> ::std::result::Result<Self, E> {
195195
Ok(self)
@@ -211,7 +211,7 @@ id_fold!(ForeignDefId);
211211
impl<I: Interner> TypeSuperFoldable<I> for ProgramClauseData<I> {
212212
fn super_fold_with<E>(
213213
self,
214-
folder: &mut dyn TypeFolder<I, Error = E>,
214+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
215215
outer_binder: DebruijnIndex,
216216
) -> ::std::result::Result<Self, E> {
217217
Ok(ProgramClauseData(self.0.fold_with(folder, outer_binder)?))
@@ -221,7 +221,7 @@ impl<I: Interner> TypeSuperFoldable<I> for ProgramClauseData<I> {
221221
impl<I: Interner> TypeSuperFoldable<I> for ProgramClause<I> {
222222
fn super_fold_with<E>(
223223
self,
224-
folder: &mut dyn TypeFolder<I, Error = E>,
224+
folder: &mut dyn FallibleTypeFolder<I, Error = E>,
225225
outer_binder: DebruijnIndex,
226226
) -> ::std::result::Result<Self, E> {
227227
let clause = self.data(folder.interner()).clone();
@@ -234,7 +234,7 @@ impl<I: Interner> TypeSuperFoldable<I> for ProgramClause<I> {
234234
impl<I: Interner> TypeFoldable<I> for PhantomData<I> {
235235
fn fold_with<E>(
236236
self,
237-
_folder: &mut dyn TypeFolder<I, Error = E>,
237+
_folder: &mut dyn FallibleTypeFolder<I, Error = E>,
238238
_outer_binder: DebruijnIndex,
239239
) -> ::std::result::Result<Self, E> {
240240
Ok(PhantomData)

chalk-ir/src/fold/shift.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ impl<I> Shifter<I> {
7171
}
7272
}
7373

74-
impl<I: Interner> TypeFolder<I> for Shifter<I> {
74+
impl<I: Interner> FallibleTypeFolder<I> for Shifter<I> {
7575
type Error = NoSolution;
7676

77-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<I, Error = Self::Error> {
77+
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<I, Error = Self::Error> {
7878
self
7979
}
8080

@@ -141,10 +141,10 @@ impl<I> DownShifter<I> {
141141
}
142142
}
143143

144-
impl<I: Interner> TypeFolder<I> for DownShifter<I> {
144+
impl<I: Interner> FallibleTypeFolder<I> for DownShifter<I> {
145145
type Error = NoSolution;
146146

147-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<I, Error = Self::Error> {
147+
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<I, Error = Self::Error> {
148148
self
149149
}
150150

0 commit comments

Comments
 (0)