diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 7e76f6cb452..62ec466f486 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -12,7 +12,7 @@ - [Application types](./types/rust_types/application_ty.md) - [Rust lifetimes](./types/rust_lifetimes.md) - [Operations](./types/operations.md) - - [Fold and the Folder trait](./types/operations/fold.md) + - [TypeFoldable and the TypeFolder trait](./types/operations/fold.md) - [Lowering Rust IR to logic](./clauses.md) - [Goals and clauses](./clauses/goals_and_clauses.md) - [Type equality and unification](./clauses/type_equality.md) diff --git a/book/src/types/operations/fold.md b/book/src/types/operations/fold.md index 44d8a77afa9..403e50431e7 100644 --- a/book/src/types/operations/fold.md +++ b/book/src/types/operations/fold.md @@ -1,13 +1,13 @@ -# Fold and the Folder trait +# TypeFoldable and the TypeFolder trait -The [`Fold`] trait permits one to traverse a type or other term in the +The [`TypeFoldable`] trait permits one to traverse a type or other term in the chalk-ir and make a copy of it, possibly making small substitutions or alterations along the way. Folding also allows copying a term from one interner to another. -[`Fold`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Fold.html +[`TypeFoldable`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable.html -To use the [`Fold`] trait, one invokes the [`Fold::fold_with`] method, supplying some +To use the [`TypeFoldable`] trait, one invokes the [`TypeFoldable::fold_with`] method, supplying some "folder" as well as the number of "in scope binders" for that term (typically `0` to start): @@ -15,50 +15,50 @@ to start): let output_ty = input_ty.fold_with(&mut folder, 0); ``` -[`Fold::fold_with`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Fold.html#tymethod.fold_with +[`TypeFoldable::fold_with`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable.html#tymethod.fold_with -The folder is some instance of the [`Folder`] trait. This trait +The folder is some instance of the [`TypeFolder`] trait. This trait defines a few key callbacks that allow you to substitute different values as the fold proceeds. For example, when a type is folded, the folder can substitute a new type in its place. -[`Folder`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Folder.html +[`TypeFolder`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFolder.html ## Uses for folders -A common use for `Fold` is to permit a substitution -- that is, +A common use for `TypeFoldable` is to permit a substitution -- that is, replacing generic type parameters with their values. -## From Fold to Folder to SuperFold and back again +## From TypeFoldable to TypeFolder to TypeSuperFoldable and back again The overall flow of folding is like this. -1. [`Fold::fold_with`] is invoked on the outermost term. It recursively +1. [`TypeFoldable::fold_with`] is invoked on the outermost term. It recursively walks the term. 2. For those sorts of terms (types, lifetimes, goals, program clauses) that have - callbacks in the [`Folder`] trait, invoking [`Fold::fold_with`] will in turn - invoke the corresponding method on the [`Folder`] trait, such as `Folder::fold_ty`. -3. The default implementation of `Folder::fold_ty`, in turn, invokes - `SuperFold::super_fold_with`. This will recursively fold the + callbacks in the [`TypeFolder`] trait, invoking [`TypeFoldable::fold_with`] will in turn + invoke the corresponding method on the [`TypeFolder`] trait, such as `TypeFolder::fold_ty`. +3. The default implementation of `TypeFolder::fold_ty`, in turn, invokes + `TypeSuperFoldable::super_fold_with`. This will recursively fold the contents of the type. In some cases, the `super_fold_with` - implementation invokes more specialized methods on [`Folder`], such - as [`Folder::fold_free_var_ty`], which makes it easier to write + implementation invokes more specialized methods on [`TypeFolder`], such + as [`TypeFolder::fold_free_var_ty`], which makes it easier to write folders that just intercept *certain* types. -[`Folder::fold_free_var_ty`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Folder.html#method.fold_free_var_ty +[`TypeFolder::fold_free_var_ty`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFolder.html#method.fold_free_var_ty Thus, as a user, you can customize folding by: -* Defining your own `Folder` type +* Defining your own `TypeFolder` type * Implementing the appropriate methods to "intercept" types/lifetimes/etc at the right level of detail * In those methods, if you find a case where you would prefer not to - substitute a new value, then invoke `SuperFold::super_fold_with` to + substitute a new value, then invoke `TypeSuperFoldable::super_fold_with` to return to the default behavior. ## The `binders` argument -Each callback in the [`Folder`] trait takes a `binders` argument. This indicates +Each callback in the [`TypeFolder`] trait takes a `binders` argument. This indicates the number of binders that we have traversed during folding, which is relevant for De Bruijn indices. 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. @@ -70,32 +70,32 @@ Foo<'a>: for<'b> Bar<'b> In this case, `Foo<'a>` gets visited with depth 0 and `Bar<'b>` gets visited with depth 1. -## The `Fold::Result` associated type +## The `TypeFoldable::Result` associated type -The `Fold` trait defines a [`Result`] associated type, indicating the +The `TypeFoldable` trait defines a [`Result`] associated type, indicating the type that will result from folding. -[`Result`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.Fold.html#associatedtype.Result +[`Result`]: https://rust-lang.github.io/chalk/chalk_ir/fold/trait.TypeFoldable.html#associatedtype.Result -## When to implement the Fold and SuperFold traits +## When to implement the TypeFoldable and TypeSuperFoldable traits Any piece of IR that represents a kind of "term" (e.g., a type, part -of a type, or a goal, etc) in the logic should implement `Fold`. We -also implement `Fold` for common collection types like `Vec` as well +of a type, or a goal, etc) in the logic should implement `TypeFoldable`. We +also implement `TypeFoldable` for common collection types like `Vec` as well as tuples, references, etc. -The `SuperFold` trait should only be implemented for those types that -have a callback defined on the `Folder` trait (e.g., types and +The `TypeSuperFoldable` trait should only be implemented for those types that +have a callback defined on the `TypeFolder` trait (e.g., types and lifetimes). ## Derives -Using the `chalk-derive` crate, you can auto-derive the `Fold` trait. -There isn't presently a derive for `SuperFold` since it is very rare -to require it. The derive for `Fold` is a bit cludgy and requires: +Using the `chalk-derive` crate, you can auto-derive the `TypeFoldable` trait. +There isn't presently a derive for `TypeSuperFoldable` since it is very rare +to require it. The derive for `TypeFoldable` is a bit cludgy and requires: -* You must import `Fold` into scope. -* The type you are deriving `Fold` on must have either: +* You must import `TypeFoldable` into scope. +* The type you are deriving `TypeFoldable` on must have either: * A type parameter that has a `Interner` bound, like `I: Interner` * A type parameter that has a `HasInterner` bound, like `I: HasInterner` * The `has_interner(XXX)` attribute. diff --git a/book/src/what_is_chalk/crates.md b/book/src/what_is_chalk/crates.md index 2fc09c5555c..feacb411959 100644 --- a/book/src/what_is_chalk/crates.md +++ b/book/src/what_is_chalk/crates.md @@ -19,7 +19,7 @@ The following crate is an implementation detail, used internally by `chalk-solve * The `chalk-engine` crate, which defines the actual engine that solves logical predicate. This engine is quite general and not really specific to Rust. -* The `chalk-derive` crate defines custom derives for the `chalk_ir::fold::Fold` trait and other +* The `chalk-derive` crate defines custom derives for the `chalk_ir::fold::TypeFoldable` trait and other such things. ## Crates for standalone REPL and testing @@ -37,11 +37,11 @@ define a kind of "minimal embedding" of chalk. ## The chalk-solve crate -| The `chalk-solve` crate | | -|---|--- | -| Purpose: | to solve a given goal | -| Depends on IR: | chalk-ir and rust-ir | -| Context required: | `RustIrDatabase` | +| The `chalk-solve` crate | | +| ----------------------- | --------------------- | +| Purpose: | to solve a given goal | +| Depends on IR: | chalk-ir and rust-ir | +| Context required: | `RustIrDatabase` | The `chalk-solve` crate exposes a key type called `Solver`. This is a 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: ## The chalk-engine crate -| The `chalk-engine` crate | | -|---|--- | -| Purpose: | define the base solving strategy | -| IR: | none | -| Context required: | `Context` trait | +| The `chalk-engine` crate | | +| ------------------------ | -------------------------------- | +| Purpose: | define the base solving strategy | +| IR: | none | +| Context required: | `Context` trait | For the purposes of chalk, the `chalk-engine` crate is effectively encapsulated by `chalk-solve`. It defines the base SLG engine. It is diff --git a/chalk-derive/src/lib.rs b/chalk-derive/src/lib.rs index 99e602f2135..522d7831726 100644 --- a/chalk-derive/src/lib.rs +++ b/chalk-derive/src/lib.rs @@ -118,9 +118,9 @@ enum DeriveKind { } decl_derive!([HasInterner, attributes(has_interner)] => derive_has_interner); -decl_derive!([Visit, attributes(has_interner)] => derive_visit); -decl_derive!([SuperVisit, attributes(has_interner)] => derive_super_visit); -decl_derive!([Fold, attributes(has_interner)] => derive_fold); +decl_derive!([TypeVisitable, attributes(has_interner)] => derive_type_visitable); +decl_derive!([TypeSuperVisitable, attributes(has_interner)] => derive_type_super_visitable); +decl_derive!([TypeFoldable, attributes(has_interner)] => derive_type_foldable); decl_derive!([Zip, attributes(has_interner)] => derive_zip); fn derive_has_interner(mut s: synstructure::Structure) -> TokenStream { @@ -136,24 +136,28 @@ fn derive_has_interner(mut s: synstructure::Structure) -> TokenStream { ) } -/// Derives Visit for structs and enums for which one of the following is true: +/// Derives TypeVisitable for structs and enums for which one of the following is true: /// - It has a `#[has_interner(TheInterner)]` attribute /// - There is a single parameter `T: HasInterner` (does not have to be named `T`) /// - There is a single parameter `I: Interner` (does not have to be named `I`) -fn derive_visit(s: synstructure::Structure) -> TokenStream { - derive_any_visit(s, parse_quote! { Visit }, parse_quote! { visit_with }) +fn derive_type_visitable(s: synstructure::Structure) -> TokenStream { + derive_any_type_visitable( + s, + parse_quote! { TypeVisitable }, + parse_quote! { visit_with }, + ) } -/// Same as Visit, but derives SuperVisit instead -fn derive_super_visit(s: synstructure::Structure) -> TokenStream { - derive_any_visit( +/// Same as TypeVisitable, but derives TypeSuperVisitable instead +fn derive_type_super_visitable(s: synstructure::Structure) -> TokenStream { + derive_any_type_visitable( s, - parse_quote! { SuperVisit }, + parse_quote! { TypeSuperVisitable }, parse_quote! { super_visit_with }, ) } -fn derive_any_visit( +fn derive_any_type_visitable( mut s: synstructure::Structure, trait_name: Ident, method_name: Ident, @@ -164,13 +168,13 @@ fn derive_any_visit( let body = s.each(|bi| { quote! { - ::chalk_ir::try_break!(::chalk_ir::visit::Visit::visit_with(#bi, visitor, outer_binder)); + ::chalk_ir::try_break!(::chalk_ir::visit::TypeVisitable::visit_with(#bi, visitor, outer_binder)); } }); if kind == DeriveKind::FromHasInterner { let param = get_generic_param_name(input).unwrap(); - s.add_where_predicate(parse_quote! { #param: ::chalk_ir::visit::Visit<#interner> }); + s.add_where_predicate(parse_quote! { #param: ::chalk_ir::visit::TypeVisitable<#interner> }); } s.add_bounds(synstructure::AddBounds::None); @@ -179,7 +183,7 @@ fn derive_any_visit( quote! { fn #method_name ( &self, - visitor: &mut dyn ::chalk_ir::visit::Visitor < #interner, BreakTy = B >, + visitor: &mut dyn ::chalk_ir::visit::TypeVisitor < #interner, BreakTy = B >, outer_binder: ::chalk_ir::DebruijnIndex, ) -> std::ops::ControlFlow { match *self { @@ -250,11 +254,11 @@ fn derive_zip(mut s: synstructure::Structure) -> TokenStream { ) } -/// Derives Fold for structs and enums for which one of the following is true: +/// Derives TypeFoldable for structs and enums for which one of the following is true: /// - It has a `#[has_interner(TheInterner)]` attribute /// - There is a single parameter `T: HasInterner` (does not have to be named `T`) /// - There is a single parameter `I: Interner` (does not have to be named `I`) -fn derive_fold(mut s: synstructure::Structure) -> TokenStream { +fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream { s.underscore_const(true); s.bind_with(|_| synstructure::BindStyle::Move); @@ -265,7 +269,7 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream { vi.construct(|_, index| { let bind = &bindings[index]; quote! { - ::chalk_ir::fold::Fold::fold_with(#bind, folder, outer_binder)? + ::chalk_ir::fold::TypeFoldable::fold_with(#bind, folder, outer_binder)? } }) }); @@ -277,7 +281,7 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream { let param = get_generic_param_name(input).unwrap(); s.add_impl_generic(parse_quote! { _U }) .add_where_predicate( - parse_quote! { #param: ::chalk_ir::fold::Fold<#interner, Result = _U> }, + parse_quote! { #param: ::chalk_ir::fold::TypeFoldable<#interner, Result = _U> }, ) .add_where_predicate( parse_quote! { _U: ::chalk_ir::interner::HasInterner }, @@ -289,13 +293,13 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream { s.add_bounds(synstructure::AddBounds::None); s.bound_impl( - quote!(::chalk_ir::fold::Fold<#interner>), + quote!(::chalk_ir::fold::TypeFoldable<#interner>), quote! { type Result = #result; fn fold_with( self, - folder: &mut dyn ::chalk_ir::fold::Folder < #interner, Error = E >, + folder: &mut dyn ::chalk_ir::fold::TypeFolder < #interner, Error = E >, outer_binder: ::chalk_ir::DebruijnIndex, ) -> ::std::result::Result { Ok(match self { #body }) diff --git a/chalk-engine/src/lib.rs b/chalk-engine/src/lib.rs index 499b33e4f39..f139f5cc033 100644 --- a/chalk-engine/src/lib.rs +++ b/chalk-engine/src/lib.rs @@ -56,7 +56,7 @@ use std::cmp::min; use std::usize; -use chalk_derive::{Fold, HasInterner, Visit}; +use chalk_derive::{HasInterner, TypeFoldable, TypeVisitable}; use chalk_ir::interner::Interner; use chalk_ir::{ AnswerSubst, Canonical, ConstrainedSubst, Constraint, DebruijnIndex, Goal, InEnvironment, @@ -78,13 +78,13 @@ mod table; mod tables; index_struct! { - pub struct TableIndex { // FIXME: pub b/c Fold + pub struct TableIndex { // FIXME: pub b/c TypeFoldable value: usize, } } /// The paper describes these as `A :- D | G`. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct ExClause { /// The substitution which, applied to the goal of our table, /// would yield A. @@ -168,7 +168,7 @@ impl TimeStamp { /// /// trying to solve `?T: Foo` would immediately require solving `?T: /// Sized`, and hence would flounder. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub struct FlounderedSubgoal { /// Literal that floundered. pub floundered_literal: Literal, @@ -209,7 +209,7 @@ pub struct CompleteAnswer { } /// Either `A` or `~A`, where `A` is a `Env |- Goal`. -#[derive(Clone, Debug, Fold, Visit)] +#[derive(Clone, Debug, TypeFoldable, TypeVisitable)] pub enum Literal { // FIXME: pub b/c fold Positive(InEnvironment>), diff --git a/chalk-engine/src/normalize_deep.rs b/chalk-engine/src/normalize_deep.rs index 0c4a01ccbef..e89a083b714 100644 --- a/chalk-engine/src/normalize_deep.rs +++ b/chalk-engine/src/normalize_deep.rs @@ -1,5 +1,5 @@ use chalk_ir::fold::shift::Shift; -use chalk_ir::fold::{Fold, Folder}; +use chalk_ir::fold::{TypeFoldable, TypeFolder}; use chalk_ir::interner::Interner; use chalk_ir::*; use chalk_solve::infer::InferenceTable; @@ -21,7 +21,7 @@ impl DeepNormalizer<'_, I> { /// See also `InferenceTable::canonicalize`, which -- during real /// processing -- is often used to capture the "current state" of /// variables. - pub fn normalize_deep>( + pub fn normalize_deep>( table: &mut InferenceTable, interner: I, value: T, @@ -35,10 +35,10 @@ impl DeepNormalizer<'_, I> { } } -impl Folder for DeepNormalizer<'_, I> { +impl TypeFolder for DeepNormalizer<'_, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-engine/src/slg/resolvent.rs b/chalk-engine/src/slg/resolvent.rs index c6d0f8d5c6d..2cb7fa5f4b3 100644 --- a/chalk-engine/src/slg/resolvent.rs +++ b/chalk-engine/src/slg/resolvent.rs @@ -3,7 +3,7 @@ use crate::slg::ResolventOps; use crate::{ExClause, Literal, TimeStamp}; use chalk_ir::cast::Caster; use chalk_ir::fold::shift::Shift; -use chalk_ir::fold::Fold; +use chalk_ir::fold::TypeFoldable; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::zip::{Zip, Zipper}; use chalk_ir::*; @@ -708,7 +708,7 @@ impl<'i, I: Interner> Zipper for AnswerSubstitutor<'i, I> { pending: &Binders, ) -> Fallible<()> where - T: HasInterner + Zip + Fold, + T: HasInterner + Zip + TypeFoldable, { self.outer_binder.shift_in(); Zip::zip_with( diff --git a/chalk-engine/src/strand.rs b/chalk-engine/src/strand.rs index 91196ec94c6..5796ee5a7a0 100644 --- a/chalk-engine/src/strand.rs +++ b/chalk-engine/src/strand.rs @@ -3,7 +3,7 @@ use crate::{ExClause, TableIndex, TimeStamp}; use std::fmt::Debug; use chalk_derive::HasInterner; -use chalk_ir::fold::{Fold, Folder}; +use chalk_ir::fold::{TypeFoldable, TypeFolder}; use chalk_ir::interner::Interner; use chalk_ir::{Canonical, DebruijnIndex, UniverseMap}; @@ -35,11 +35,11 @@ pub(crate) struct SelectedSubgoal { pub(crate) universe_map: UniverseMap, } -impl Fold for Strand { +impl TypeFoldable for Strand { type Result = Strand; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { Ok(Strand { diff --git a/chalk-ir/src/fold.rs b/chalk-ir/src/fold.rs index e7db1574459..a49cd14ce62 100644 --- a/chalk-ir/src/fold.rs +++ b/chalk-ir/src/fold.rs @@ -16,8 +16,8 @@ pub use self::subst::Subst; /// some term -- that is, some bit of IR, such as a `Goal` -- with /// certain changes applied. The idea is that it contains methods that /// let you swap types/lifetimes for new types/lifetimes; meanwhile, -/// each bit of IR implements the `Fold` trait which, given a -/// `Folder`, will reconstruct itself, invoking the folder's methods +/// each bit of IR implements the `TypeFoldable` trait which, given a +/// `TypeFolder`, will reconstruct itself, invoking the folder's methods /// to transform each of the types/lifetimes embedded within. /// /// # Usage patterns @@ -29,14 +29,14 @@ pub use self::subst::Subst; /// more often, just free existential variables) that appear within /// the term. /// -/// For this reason, the `Folder` trait extends two other traits that +/// For this reason, the `TypeFolder` trait extends two other traits that /// contain methods that are invoked when just those particular /// /// In particular, folders can intercept references to free variables /// (either existentially or universally quantified) and replace them /// with other types/lifetimes as appropriate. /// -/// To create a folder `F`, one never implements `Folder` directly, but instead +/// To create a folder `F`, one never implements `TypeFolder` directly, but instead /// implements one of each of these three sub-traits: /// /// - `FreeVarFolder` -- folds `BoundVar` instances that appear free @@ -49,24 +49,24 @@ pub use self::subst::Subst; /// that appear in the term being folded (use /// `DefaultPlaceholderFolder` to ignore/forbid these altogether) /// -/// To **apply** a folder, use the `Fold::fold_with` method, like so +/// To **apply** a folder, use the `TypeFoldable::fold_with` method, like so /// /// ```rust,ignore /// let x = x.fold_with(&mut folder, 0); /// ``` -pub trait Folder { +pub trait TypeFolder { /// The type this folder returns when folding fails. This is /// commonly [`NoSolution`]. type Error; /// Creates a `dyn` value from this folder. Unfortunately, this - /// must be added manually to each impl of Folder; it permits the - /// default implements below to create a `&mut dyn Folder` from + /// must be added manually to each impl of TypeFolder; it permits the + /// default implements below to create a `&mut dyn TypeFolder` from /// `Self` without knowing what `Self` is (by invoking this - /// method). Effectively, this limits impls of `Folder` to types + /// method). Effectively, this limits impls of `TypeFolder` to types /// for which we are able to create a dyn value (i.e., not `[T]` /// types). - fn as_dyn(&mut self) -> &mut dyn Folder; + fn as_dyn(&mut self) -> &mut dyn TypeFolder; /// Top-level callback: invoked for each `Ty` that is /// encountered when folding. By default, invokes @@ -305,16 +305,16 @@ pub trait Folder { fn interner(&self) -> I; } -/// Applies the given `Folder` to a value, producing a folded result +/// Applies the given `TypeFolder` to a value, producing a folded result /// of type `Self::Result`. The result type is typically the same as /// the source type, but in some cases we convert from borrowed /// to owned as well (e.g., the folder for `&T` will fold to a fresh /// `T`; well, actually `T::Result`). -pub trait Fold: Debug { +pub trait TypeFoldable: Debug { /// The type of value that will be produced once folding is done. /// Typically this is `Self`, unless `Self` contains borrowed /// values, in which case owned values are produced (for example, - /// one can fold over a `&T` value where `T: Fold`, in which case + /// one can fold over a `&T` value where `T: TypeFoldable`, in which case /// you get back a `T`, not a `&T`). type Result; @@ -325,19 +325,19 @@ pub trait Fold: Debug { /// constructs. fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result; } -/// For types where "fold" invokes a callback on the `Folder`, the -/// `SuperFold` trait captures the recursive behavior that folds all +/// For types where "fold" invokes a callback on the `TypeFolder`, the +/// `TypeSuperFoldable` trait captures the recursive behavior that folds all /// the contents of the type. -pub trait SuperFold: Fold { +pub trait TypeSuperFoldable: TypeFoldable { /// Recursively folds the value. fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result; } @@ -345,12 +345,12 @@ pub trait SuperFold: Fold { /// "Folding" a type invokes the `fold_ty` method on the folder; this /// usually (in turn) invokes `super_fold_ty` to fold the individual /// parts. -impl Fold for Ty { +impl TypeFoldable for Ty { type Result = Ty; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { folder.fold_ty(self, outer_binder) @@ -358,13 +358,13 @@ impl Fold for Ty { } /// "Super fold" for a type invokes te more detailed callbacks on the type -impl SuperFold for Ty +impl TypeSuperFoldable for Ty where I: Interner, { fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result, E> { let interner = folder.interner(); @@ -469,25 +469,25 @@ where /// "Folding" a lifetime invokes the `fold_lifetime` method on the folder; this /// usually (in turn) invokes `super_fold_lifetime` to fold the individual /// parts. -impl Fold for Lifetime { +impl TypeFoldable for Lifetime { type Result = Lifetime; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { folder.fold_lifetime(self, outer_binder) } } -impl SuperFold for Lifetime +impl TypeSuperFoldable for Lifetime where I: Interner, { fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result, E> { let interner = folder.interner(); @@ -521,25 +521,25 @@ where /// "Folding" a const invokes the `fold_const` method on the folder; this /// usually (in turn) invokes `super_fold_const` to fold the individual /// parts. -impl Fold for Const { +impl TypeFoldable for Const { type Result = Const; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { folder.fold_const(self, outer_binder) } } -impl SuperFold for Const +impl TypeSuperFoldable for Const where I: Interner, { fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result, E> { let interner = folder.interner(); @@ -572,12 +572,12 @@ where /// Folding a goal invokes the `fold_goal` callback (which will, by /// default, invoke super-fold). -impl Fold for Goal { +impl TypeFoldable for Goal { type Result = Goal; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { folder.fold_goal(self, outer_binder) @@ -585,10 +585,10 @@ impl Fold for Goal { } /// Superfold folds recursively. -impl SuperFold for Goal { +impl TypeSuperFoldable for Goal { fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -604,12 +604,12 @@ impl SuperFold for Goal { /// Folding a program clause invokes the `fold_program_clause` /// callback on the folder (which will, by default, invoke the /// `super_fold_with` method on the program clause). -impl Fold for ProgramClause { +impl TypeFoldable for ProgramClause { type Result = ProgramClause; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { folder.fold_program_clause(self, outer_binder) diff --git a/chalk-ir/src/fold/binder_impls.rs b/chalk-ir/src/fold/binder_impls.rs index baa91249974..22801b47b9d 100644 --- a/chalk-ir/src/fold/binder_impls.rs +++ b/chalk-ir/src/fold/binder_impls.rs @@ -1,15 +1,15 @@ -//! This module contains impls of `Fold` for those types that +//! This module contains impls of `TypeFoldable` for those types that //! introduce binders. //! -//! The more interesting impls of `Fold` remain in the `fold` module. +//! The more interesting impls of `TypeFoldable` remain in the `fold` module. use crate::*; -impl Fold for FnPointer { +impl TypeFoldable for FnPointer { type Result = FnPointer; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let FnPointer { @@ -29,16 +29,16 @@ impl Fold for FnPointer { } } -impl Fold for Binders +impl TypeFoldable for Binders where - T: HasInterner + Fold, - >::Result: HasInterner, + T: HasInterner + TypeFoldable, + >::Result: HasInterner, I: Interner, { type Result = Binders; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let Binders { @@ -53,16 +53,16 @@ where } } -impl Fold for Canonical +impl TypeFoldable for Canonical where I: Interner, - T: HasInterner + Fold, - >::Result: HasInterner, + T: HasInterner + TypeFoldable, + >::Result: HasInterner, { type Result = Canonical; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let Canonical { diff --git a/chalk-ir/src/fold/boring_impls.rs b/chalk-ir/src/fold/boring_impls.rs index 9210ecac8c9..d8366e7a28a 100644 --- a/chalk-ir/src/fold/boring_impls.rs +++ b/chalk-ir/src/fold/boring_impls.rs @@ -1,29 +1,29 @@ -//! This module contains "rote and uninteresting" impls of `Fold` for -//! various types. In general, we prefer to derive `Fold`, but +//! This module contains "rote and uninteresting" impls of `TypeFoldable` for +//! various types. In general, we prefer to derive `TypeFoldable`, but //! sometimes that doesn't work for whatever reason. //! -//! The more interesting impls of `Fold` remain in the `fold` module. +//! The more interesting impls of `TypeFoldable` remain in the `fold` module. use super::in_place; use crate::*; use std::marker::PhantomData; -impl, I: Interner> Fold for Vec { +impl, I: Interner> TypeFoldable for Vec { type Result = Vec; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { in_place::fallible_map_vec(self, |e| e.fold_with(folder, outer_binder)) } } -impl, I: Interner> Fold for Box { +impl, I: Interner> TypeFoldable for Box { type Result = Box; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { in_place::fallible_map_box(self, |e| e.fold_with(folder, outer_binder)) @@ -32,9 +32,9 @@ impl, I: Interner> Fold for Box { macro_rules! tuple_fold { ($($n:ident),*) => { - impl<$($n: Fold,)* I: Interner> Fold for ($($n,)*) { + impl<$($n: TypeFoldable,)* I: Interner> TypeFoldable for ($($n,)*) { type Result = ($($n::Result,)*); - fn fold_with(self, folder: &mut dyn Folder, outer_binder: DebruijnIndex) -> Result + fn fold_with(self, folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex) -> Result { #[allow(non_snake_case)] let ($($n),*) = self; @@ -49,11 +49,11 @@ tuple_fold!(A, B, C); tuple_fold!(A, B, C, D); tuple_fold!(A, B, C, D, E); -impl, I: Interner> Fold for Option { +impl, I: Interner> TypeFoldable for Option { type Result = Option; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { match self { @@ -63,11 +63,11 @@ impl, I: Interner> Fold for Option { } } -impl Fold for GenericArg { +impl TypeFoldable for GenericArg { type Result = GenericArg; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -80,11 +80,11 @@ impl Fold for GenericArg { } } -impl Fold for Substitution { +impl TypeFoldable for Substitution { type Result = Substitution; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -97,11 +97,11 @@ impl Fold for Substitution { } } -impl Fold for Goals { +impl TypeFoldable for Goals { type Result = Goals; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -113,11 +113,11 @@ impl Fold for Goals { } } -impl Fold for ProgramClauses { +impl TypeFoldable for ProgramClauses { type Result = ProgramClauses; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -129,11 +129,11 @@ impl Fold for ProgramClauses { } } -impl Fold for QuantifiedWhereClauses { +impl TypeFoldable for QuantifiedWhereClauses { type Result = QuantifiedWhereClauses; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -145,11 +145,11 @@ impl Fold for QuantifiedWhereClauses { } } -impl Fold for Constraints { +impl TypeFoldable for Constraints { type Result = Constraints; fn fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> Result { let interner = folder.interner(); @@ -165,11 +165,11 @@ impl Fold for Constraints { #[macro_export] macro_rules! copy_fold { ($t:ty) => { - impl $crate::fold::Fold for $t { + impl $crate::fold::TypeFoldable for $t { type Result = Self; fn fold_with( self, - _folder: &mut dyn ($crate::fold::Folder), + _folder: &mut dyn ($crate::fold::TypeFolder), _outer_binder: DebruijnIndex, ) -> ::std::result::Result { Ok(self) @@ -197,11 +197,11 @@ copy_fold!(Safety); #[macro_export] macro_rules! id_fold { ($t:ident) => { - impl $crate::fold::Fold for $t { + impl $crate::fold::TypeFoldable for $t { type Result = $t; fn fold_with( self, - _folder: &mut dyn ($crate::fold::Folder), + _folder: &mut dyn ($crate::fold::TypeFolder), _outer_binder: DebruijnIndex, ) -> ::std::result::Result { Ok(self) @@ -220,20 +220,20 @@ id_fold!(ClosureId); id_fold!(GeneratorId); id_fold!(ForeignDefId); -impl SuperFold for ProgramClauseData { +impl TypeSuperFoldable for ProgramClauseData { fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> ::std::result::Result { Ok(ProgramClauseData(self.0.fold_with(folder, outer_binder)?)) } } -impl SuperFold for ProgramClause { +impl TypeSuperFoldable for ProgramClause { fn super_fold_with( self, - folder: &mut dyn Folder, + folder: &mut dyn TypeFolder, outer_binder: DebruijnIndex, ) -> ::std::result::Result { let clause = self.data(folder.interner()).clone(); @@ -243,12 +243,12 @@ impl SuperFold for ProgramClause { } } -impl Fold for PhantomData { +impl TypeFoldable for PhantomData { type Result = PhantomData; fn fold_with( self, - _folder: &mut dyn Folder, + _folder: &mut dyn TypeFolder, _outer_binder: DebruijnIndex, ) -> ::std::result::Result { Ok(PhantomData) diff --git a/chalk-ir/src/fold/in_place.rs b/chalk-ir/src/fold/in_place.rs index c81d9113af1..263da617d97 100644 --- a/chalk-ir/src/fold/in_place.rs +++ b/chalk-ir/src/fold/in_place.rs @@ -1,4 +1,4 @@ -//! Subroutines to help implementers of `Fold` avoid unnecessary heap allocations. +//! Subroutines to help implementers of `TypeFoldable` avoid unnecessary heap allocations. use std::marker::PhantomData; use std::{mem, ptr}; diff --git a/chalk-ir/src/fold/shift.rs b/chalk-ir/src/fold/shift.rs index 2ea957b289a..a56218fd0e3 100644 --- a/chalk-ir/src/fold/shift.rs +++ b/chalk-ir/src/fold/shift.rs @@ -1,11 +1,11 @@ //! Shifting of debruijn indices -use super::Fold; +use super::TypeFoldable; use crate::*; /// Methods for converting debruijn indices to move values into or out /// of binders. -pub trait Shift: Fold { +pub trait Shift: TypeFoldable { /// Shifts this term in one level of binders. fn shifted_in(self, interner: I) -> Self::Result; @@ -23,7 +23,7 @@ pub trait Shift: Fold { fn shifted_out_to(self, interner: I, target_binder: DebruijnIndex) -> Fallible; } -impl, I: Interner> Shift for T { +impl, I: Interner> Shift for T { fn shifted_in(self, interner: I) -> Self::Result { self.shifted_in_from(interner, DebruijnIndex::ONE) } @@ -71,10 +71,10 @@ impl Shifter { } } -impl Folder for Shifter { +impl TypeFolder for Shifter { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } @@ -141,10 +141,10 @@ impl DownShifter { } } -impl Folder for DownShifter { +impl TypeFolder for DownShifter { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-ir/src/fold/subst.rs b/chalk-ir/src/fold/subst.rs index f7a0b2d69bb..534f83213ea 100644 --- a/chalk-ir/src/fold/subst.rs +++ b/chalk-ir/src/fold/subst.rs @@ -12,7 +12,11 @@ pub struct Subst<'s, I: Interner> { impl Subst<'_, I> { /// Applies the substitution by folding - pub fn apply>(interner: I, parameters: &[GenericArg], value: T) -> T::Result { + pub fn apply>( + interner: I, + parameters: &[GenericArg], + value: T, + ) -> T::Result { value .fold_with( &mut Subst { @@ -25,10 +29,10 @@ impl Subst<'_, I> { } } -impl Folder for Subst<'_, I> { +impl TypeFolder for Subst<'_, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-ir/src/interner.rs b/chalk-ir/src/interner.rs index 8a3f88cc4af..4959e4b7452 100644 --- a/chalk-ir/src/interner.rs +++ b/chalk-ir/src/interner.rs @@ -647,7 +647,7 @@ pub trait Interner: Debug + Copy + Eq + Hash + Sized { /// are virtually all of the types in chalk-ir, for example). /// This lets us map from a type like `Ty` to the parameter `I`. /// -/// It's particularly useful for writing `Fold` impls for generic types like +/// It's particularly useful for writing `TypeFoldable` impls for generic types like /// `Binder`, since it allows us to figure out the interner of `T`. pub trait HasInterner { /// The interner associated with the type. diff --git a/chalk-ir/src/lib.rs b/chalk-ir/src/lib.rs index 9376a6563b0..d8ffe4b78c8 100644 --- a/chalk-ir/src/lib.rs +++ b/chalk-ir/src/lib.rs @@ -8,9 +8,9 @@ extern crate self as chalk_ir; use crate::cast::{Cast, CastTo, Caster}; use crate::fold::shift::Shift; -use crate::fold::{Fold, Folder, Subst, SuperFold}; -use crate::visit::{SuperVisit, Visit, VisitExt, Visitor}; -use chalk_derive::{Fold, HasInterner, SuperVisit, Visit, Zip}; +use crate::fold::{Subst, TypeFoldable, TypeFolder, TypeSuperFoldable}; +use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor, VisitExt}; +use chalk_derive::{HasInterner, TypeFoldable, TypeSuperVisitable, TypeVisitable, Zip}; use std::marker::PhantomData; use std::ops::ControlFlow; @@ -147,7 +147,7 @@ impl Variance { } } -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] /// The set of assumptions we've made so far, and the current number of /// universal (forall) quantifiers we're within. pub struct Environment { @@ -197,7 +197,7 @@ impl Environment { } /// A goal with an environment to solve it in. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] #[allow(missing_docs)] pub struct InEnvironment { pub environment: Environment, @@ -1021,7 +1021,7 @@ impl DebruijnIndex { /// known. It is referenced within the type using `^1.0`, indicating /// a bound type with debruijn index 1 (i.e., skipping through one /// level of binder). -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct DynTy { /// The unknown self type. pub bounds: Binders>, @@ -1084,7 +1084,7 @@ pub struct FnSig { pub variadic: bool, } /// A wrapper for the substs on a Fn. -#[derive(Clone, PartialEq, Eq, Hash, HasInterner, Fold, Visit)] +#[derive(Clone, PartialEq, Eq, Hash, HasInterner, TypeFoldable, TypeVisitable)] pub struct FnSubst(pub Substitution); impl Copy for FnSubst where I::InternedSubstitution: Copy {} @@ -1516,7 +1516,7 @@ impl GenericArg { } /// Generic arguments data. -#[derive(Clone, PartialEq, Eq, Hash, Visit, Fold, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeVisitable, TypeFoldable, Zip)] pub enum GenericArgData { /// Type argument Ty(Ty), @@ -1601,7 +1601,7 @@ impl WithKind { pub type CanonicalVarKind = WithKind; /// An alias, which is a trait indirection such as a projection or opaque type. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] pub enum AliasTy { /// An associated type projection. Projection(ProjectionTy), @@ -1631,7 +1631,7 @@ impl AliasTy { } /// A projection `>::AssocItem`. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct ProjectionTy { /// The id for the associated type member. pub associated_ty_id: AssocTypeId, @@ -1653,7 +1653,7 @@ impl ProjectionTy { } /// An opaque type `opaque type T<..>: Trait = HiddenTy`. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct OpaqueTy { /// The id for the opaque type. pub opaque_ty_id: OpaqueTyId, @@ -1669,7 +1669,7 @@ impl Copy for OpaqueTy where I::InternedSubstitution: Copy {} /// implements the trait. /// - `>` (e.g. `i32 as Copy`), which casts the type to /// that specific trait. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct TraitRef { /// The trait id. pub trait_id: TraitId, @@ -1706,7 +1706,7 @@ impl TraitRef { /// Lifetime outlives, which for `'a: 'b`` checks that the lifetime `'a` /// is a superset of the value of `'b`. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] #[allow(missing_docs)] pub struct LifetimeOutlives { pub a: Lifetime, @@ -1717,7 +1717,7 @@ impl Copy for LifetimeOutlives where I::InternedLifetime: Copy { /// Type outlives, which for `T: 'a` checks that the type `T` /// lives at least as long as the lifetime `'a` -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] pub struct TypeOutlives { /// The type which must outlive the given lifetime. pub ty: Ty, @@ -1733,7 +1733,7 @@ where } /// Where clauses that can be written by a Rust programmer. -#[derive(Clone, PartialEq, Eq, Hash, Fold, SuperVisit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeSuperVisitable, HasInterner, Zip)] pub enum WhereClause { /// Type implements a trait. Implemented(TraitRef), @@ -1754,7 +1754,7 @@ where } /// Checks whether a type or trait ref is well-formed. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] pub enum WellFormed { /// A predicate which is true when some trait ref is well-formed. /// For example, given the following trait definitions: @@ -1792,7 +1792,7 @@ where } /// Checks whether a type or trait ref can be derived from the contents of the environment. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] pub enum FromEnv { /// A predicate which enables deriving everything which should be true if we *know* that /// some trait ref is well-formed. For example given the above trait definitions, we can use @@ -1831,7 +1831,7 @@ where /// A "domain goal" is a goal that is directly about Rust, rather than a pure /// logical statement. As much as possible, the Chalk solver should avoid /// decomposing this enum, and instead treat its values opaquely. -#[derive(Clone, PartialEq, Eq, Hash, Fold, SuperVisit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeSuperVisitable, HasInterner, Zip)] pub enum DomainGoal { /// Simple goal that is true if the where clause is true. Holds(WhereClause), @@ -1990,7 +1990,7 @@ impl DomainGoal { } /// Equality goal: tries to prove that two values are equal. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)] #[allow(missing_docs)] pub struct EqGoal { pub a: GenericArg, @@ -2000,7 +2000,7 @@ pub struct EqGoal { impl Copy for EqGoal where I::InternedGenericArg: Copy {} /// Subtype goal: tries to prove that `a` is a subtype of `b` -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)] #[allow(missing_docs)] pub struct SubtypeGoal { pub a: Ty, @@ -2013,7 +2013,7 @@ impl Copy for SubtypeGoal where I::InternedType: Copy {} /// type. A projection `T::Foo` normalizes to the type `U` if we can /// **match it to an impl** and that impl has a `type Foo = V` where /// `U = V`. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)] #[allow(missing_docs)] pub struct Normalize { pub alias: AliasTy, @@ -2028,7 +2028,7 @@ where } /// Proves **equality** between an alias and a type. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)] #[allow(missing_docs)] pub struct AliasEq { pub alias: AliasTy, @@ -2197,7 +2197,7 @@ impl Binders { impl Binders> where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, T::Result: HasInterner, I: Interner, { @@ -2233,7 +2233,7 @@ impl From> for (VariableKinds, T) { impl Binders where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, I: Interner, { /// Substitute `parameters` for the variables introduced by these @@ -2291,7 +2291,7 @@ where /// Represents one clause of the form `consequence :- conditions` where /// `conditions = cond_1 && cond_2 && ...` is the conjunction of the individual /// conditions. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] pub struct ProgramClauseImplication { /// The consequence of the clause, which holds if the conditions holds. pub consequence: DomainGoal, @@ -2327,7 +2327,7 @@ impl std::ops::BitAnd for ClausePriority { } /// Contains the data for a program clause. -#[derive(Clone, PartialEq, Eq, Hash, Fold, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, HasInterner, Zip)] pub struct ProgramClauseData(pub Binders>); impl ProgramClauseImplication { @@ -2571,7 +2571,7 @@ where } } -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] /// A general goal; this is the full range of questions you can pose to Chalk. pub enum GoalData { /// Introduces a binding at depth 0, shifting other bindings up @@ -2654,7 +2654,7 @@ pub enum QuantifierKind { /// lifetime constraints, instead gathering them up to return with our solution /// for later checking. This allows for decoupling between type and region /// checking in the compiler. -#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)] +#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)] pub enum Constraint { /// Outlives constraint `'a: 'b`, indicating that the value of `'a` must be /// a superset of the value of `'b`. @@ -2708,7 +2708,7 @@ impl Substitution { /// Apply the substitution to a value. pub fn apply(&self, value: T, interner: I) -> T::Result where - T: Fold, + T: TypeFoldable, { Substitute::apply(self, value, interner) } @@ -2787,13 +2787,13 @@ where /// that it can applied as a substituion to a value pub trait Substitute: AsParameters { /// Apply the substitution to a value. - fn apply>(&self, value: T, interner: I) -> T::Result; + fn apply>(&self, value: T, interner: I) -> T::Result; } impl> Substitute for A { fn apply(&self, value: T, interner: I) -> T::Result where - T: Fold, + T: TypeFoldable, { value .fold_with( @@ -2830,10 +2830,10 @@ impl<'a, I: Interner> ToGenericArg for (usize, &'a VariableKind) { } } -impl<'i, I: Interner, A: AsParameters> Folder for &SubstFolder<'i, I, A> { +impl<'i, I: Interner, A: AsParameters> TypeFolder for &SubstFolder<'i, I, A> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } @@ -3037,7 +3037,7 @@ impl Variances { /// substitution stores the values for the query's unknown variables, /// and the constraints represents any region constraints that must /// additionally be solved. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct ConstrainedSubst { /// The substitution that is being constrained. /// @@ -3049,7 +3049,7 @@ pub struct ConstrainedSubst { } /// The resulting substitution after solving a goal. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct AnswerSubst { /// The substitution result. /// diff --git a/chalk-ir/src/visit.rs b/chalk-ir/src/visit.rs index ace1fd5cfa0..7e2a17debc2 100644 --- a/chalk-ir/src/visit.rs +++ b/chalk-ir/src/visit.rs @@ -30,24 +30,24 @@ macro_rules! try_break { /// such as a `Goal`, and computes a value as a result. /// /// -/// To **apply** a visitor, use the `Visit::visit_with` method, like so +/// To **apply** a visitor, use the `TypeVisitable::visit_with` method, like so /// /// ```rust,ignore /// let result = x.visit_with(&mut visitor, 0); /// ``` -pub trait Visitor { +pub trait TypeVisitor { /// The "break type" of the visitor, often `()`. It represents the result /// the visitor yields when it stops visiting. type BreakTy; /// Creates a `dyn` value from this visitor. Unfortunately, this /// must be added manually to each impl of visitor; it permits the - /// default implements below to create a `&mut dyn Visitor` from + /// default implements below to create a `&mut dyn TypeVisitor` from /// `Self` without knowing what `Self` is (by invoking this /// method). Effectively, this limits impls of `visitor` to types /// for which we are able to create a dyn value (i.e., not `[T]` /// types). - fn as_dyn(&mut self) -> &mut dyn Visitor; + fn as_dyn(&mut self) -> &mut dyn TypeVisitor; /// Top-level callback: invoked for each `Ty` that is /// encountered when visiting. By default, invokes @@ -187,8 +187,8 @@ pub trait Visitor { } /// Applies the given `visitor` to a value, producing a visited result -/// of type `Visitor::Result`. -pub trait Visit: Debug { +/// of type `TypeVisitor::Result`. +pub trait TypeVisitable: Debug { /// Apply the given visitor `visitor` to `self`; `binders` is the /// number of binders that are in scope when beginning the /// visitor. Typically `binders` starts as 0, but is adjusted when @@ -196,19 +196,19 @@ pub trait Visit: Debug { /// constructs. fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow; } /// For types where "visit" invokes a callback on the `visitor`, the -/// `SuperVisit` trait captures the recursive behavior that visits all +/// `TypeSuperVisitable` trait captures the recursive behavior that visits all /// the contents of the type. -pub trait SuperVisit: Visit { +pub trait TypeSuperVisitable: TypeVisitable { /// Recursively visits the type contents. fn super_visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow; } @@ -216,10 +216,10 @@ pub trait SuperVisit: Visit { /// "visiting" a type invokes the `visit_ty` method on the visitor; this /// usually (in turn) invokes `super_visit_ty` to visit the individual /// parts. -impl Visit for Ty { +impl TypeVisitable for Ty { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_ty(self, outer_binder) @@ -227,13 +227,13 @@ impl Visit for Ty { } /// "Super visit" for a type invokes the more detailed callbacks on the type -impl SuperVisit for Ty +impl TypeSuperVisitable for Ty where I: Interner, { fn super_visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -301,20 +301,20 @@ where } } -impl Visit for Lifetime { +impl TypeVisitable for Lifetime { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_lifetime(self, outer_binder) } } -impl SuperVisit for Lifetime { +impl TypeSuperVisitable for Lifetime { fn super_visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -338,20 +338,20 @@ impl SuperVisit for Lifetime { } } -impl Visit for Const { +impl TypeVisitable for Const { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_const(self, outer_binder) } } -impl SuperVisit for Const { +impl TypeSuperVisitable for Const { fn super_visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -372,20 +372,20 @@ impl SuperVisit for Const { } } -impl Visit for Goal { +impl TypeVisitable for Goal { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_goal(self, outer_binder) } } -impl SuperVisit for Goal { +impl TypeSuperVisitable for Goal { fn super_visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -393,30 +393,30 @@ impl SuperVisit for Goal { } } -impl Visit for ProgramClause { +impl TypeVisitable for ProgramClause { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_program_clause(self, outer_binder) } } -impl Visit for WhereClause { +impl TypeVisitable for WhereClause { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_where_clause(self, outer_binder) } } -impl Visit for DomainGoal { +impl TypeVisitable for DomainGoal { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visitor.visit_domain_goal(self, outer_binder) diff --git a/chalk-ir/src/visit/binder_impls.rs b/chalk-ir/src/visit/binder_impls.rs index 074450a53a0..709f9904425 100644 --- a/chalk-ir/src/visit/binder_impls.rs +++ b/chalk-ir/src/visit/binder_impls.rs @@ -1,15 +1,17 @@ -//! This module contains impls of `Visit` for those types that +//! This module contains impls of `TypeVisitable` for those types that //! introduce binders. //! -//! The more interesting impls of `Visit` remain in the `visit` module. +//! The more interesting impls of `TypeVisitable` remain in the `visit` module. use crate::interner::HasInterner; -use crate::{Binders, Canonical, ControlFlow, DebruijnIndex, FnPointer, Interner, Visit, Visitor}; +use crate::{ + Binders, Canonical, ControlFlow, DebruijnIndex, FnPointer, Interner, TypeVisitable, TypeVisitor, +}; -impl Visit for FnPointer { +impl TypeVisitable for FnPointer { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { self.substitution @@ -17,27 +19,27 @@ impl Visit for FnPointer { } } -impl Visit for Binders +impl TypeVisitable for Binders where - T: HasInterner + Visit, + T: HasInterner + TypeVisitable, { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { self.value.visit_with(visitor, outer_binder.shifted_in()) } } -impl Visit for Canonical +impl TypeVisitable for Canonical where I: Interner, - T: HasInterner + Visit, + T: HasInterner + TypeVisitable, { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { self.value.visit_with(visitor, outer_binder.shifted_in()) diff --git a/chalk-ir/src/visit/boring_impls.rs b/chalk-ir/src/visit/boring_impls.rs index d4e52d15b35..512d9ecd800 100644 --- a/chalk-ir/src/visit/boring_impls.rs +++ b/chalk-ir/src/visit/boring_impls.rs @@ -1,26 +1,26 @@ -//! This module contains "rote and uninteresting" impls of `Visit` for -//! various types. In general, we prefer to derive `Visit`, but +//! This module contains "rote and uninteresting" impls of `TypeVisitable` for +//! various types. In general, we prefer to derive `TypeVisitable`, but //! sometimes that doesn't work for whatever reason. //! -//! The more interesting impls of `Visit` remain in the `visit` module. +//! The more interesting impls of `TypeVisitable` remain in the `visit` module. use crate::{ try_break, AdtId, AssocTypeId, ClausePriority, ClosureId, Constraints, ControlFlow, DebruijnIndex, FloatTy, FnDefId, ForeignDefId, GeneratorId, GenericArg, Goals, ImplId, IntTy, Interner, Mutability, OpaqueTyId, PlaceholderIndex, ProgramClause, ProgramClauses, - QuantifiedWhereClauses, QuantifierKind, Safety, Scalar, Substitution, SuperVisit, TraitId, - UintTy, UniverseIndex, Visit, Visitor, + QuantifiedWhereClauses, QuantifierKind, Safety, Scalar, Substitution, TraitId, + TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, UniverseIndex, }; use std::{marker::PhantomData, sync::Arc}; /// Convenience function to visit all the items in the iterator it. pub fn visit_iter<'i, T, I, B>( it: impl Iterator, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow where - T: Visit, + T: TypeVisitable, I: 'i + Interner, { for e in it { @@ -29,50 +29,50 @@ where ControlFlow::Continue(()) } -impl, I: Interner> Visit for &T { +impl, I: Interner> TypeVisitable for &T { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { T::visit_with(self, visitor, outer_binder) } } -impl, I: Interner> Visit for Vec { +impl, I: Interner> TypeVisitable for Vec { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visit_iter(self.iter(), visitor, outer_binder) } } -impl, I: Interner> Visit for &[T] { +impl, I: Interner> TypeVisitable for &[T] { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { visit_iter(self.iter(), visitor, outer_binder) } } -impl, I: Interner> Visit for Box { +impl, I: Interner> TypeVisitable for Box { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { T::visit_with(self, visitor, outer_binder) } } -impl, I: Interner> Visit for Arc { +impl, I: Interner> TypeVisitable for Arc { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { T::visit_with(self, visitor, outer_binder) @@ -81,8 +81,8 @@ impl, I: Interner> Visit for Arc { macro_rules! tuple_visit { ($($n:ident),*) => { - impl<$($n: Visit,)* I: Interner> Visit for ($($n,)*) { - fn visit_with(&self, visitor: &mut dyn Visitor, outer_binder: DebruijnIndex) -> ControlFlow { + impl<$($n: TypeVisitable,)* I: Interner> TypeVisitable for ($($n,)*) { + fn visit_with(&self, visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex) -> ControlFlow { #[allow(non_snake_case)] let &($(ref $n),*) = self; $( @@ -99,10 +99,10 @@ tuple_visit!(A, B, C); tuple_visit!(A, B, C, D); tuple_visit!(A, B, C, D, E); -impl, I: Interner> Visit for Option { +impl, I: Interner> TypeVisitable for Option { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { match self { @@ -112,10 +112,10 @@ impl, I: Interner> Visit for Option { } } -impl Visit for GenericArg { +impl TypeVisitable for GenericArg { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -123,10 +123,10 @@ impl Visit for GenericArg { } } -impl Visit for Substitution { +impl TypeVisitable for Substitution { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -134,10 +134,10 @@ impl Visit for Substitution { } } -impl Visit for Goals { +impl TypeVisitable for Goals { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -149,10 +149,10 @@ impl Visit for Goals { #[macro_export] macro_rules! const_visit { ($t:ty) => { - impl $crate::visit::Visit for $t { + impl $crate::visit::TypeVisitable for $t { fn visit_with( &self, - _visitor: &mut dyn ($crate::visit::Visitor), + _visitor: &mut dyn ($crate::visit::TypeVisitor), _outer_binder: DebruijnIndex, ) -> ControlFlow { ControlFlow::Continue(()) @@ -180,10 +180,10 @@ const_visit!(Safety); #[macro_export] macro_rules! id_visit { ($t:ident) => { - impl $crate::visit::Visit for $t { + impl $crate::visit::TypeVisitable for $t { fn visit_with( &self, - _visitor: &mut dyn ($crate::visit::Visitor), + _visitor: &mut dyn ($crate::visit::TypeVisitor), _outer_binder: DebruijnIndex, ) -> ControlFlow { ControlFlow::Continue(()) @@ -202,10 +202,10 @@ id_visit!(ClosureId); id_visit!(GeneratorId); id_visit!(ForeignDefId); -impl SuperVisit for ProgramClause { +impl TypeSuperVisitable for ProgramClause { fn super_visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -214,10 +214,10 @@ impl SuperVisit for ProgramClause { } } -impl Visit for ProgramClauses { +impl TypeVisitable for ProgramClauses { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -226,10 +226,10 @@ impl Visit for ProgramClauses { } } -impl Visit for Constraints { +impl TypeVisitable for Constraints { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -238,10 +238,10 @@ impl Visit for Constraints { } } -impl Visit for QuantifiedWhereClauses { +impl TypeVisitable for QuantifiedWhereClauses { fn visit_with( &self, - visitor: &mut dyn Visitor, + visitor: &mut dyn TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { let interner = visitor.interner(); @@ -250,10 +250,10 @@ impl Visit for QuantifiedWhereClauses { } } -impl Visit for PhantomData { +impl TypeVisitable for PhantomData { fn visit_with( &self, - _visitor: &mut dyn Visitor, + _visitor: &mut dyn TypeVisitor, _outer_binder: DebruijnIndex, ) -> ControlFlow { ControlFlow::Continue(()) diff --git a/chalk-ir/src/visit/visitors.rs b/chalk-ir/src/visit/visitors.rs index 486b51d8675..51c08784041 100644 --- a/chalk-ir/src/visit/visitors.rs +++ b/chalk-ir/src/visit/visitors.rs @@ -1,9 +1,9 @@ -//! Visitor helpers +//! TypeVisitor helpers -use crate::{BoundVar, ControlFlow, DebruijnIndex, Interner, Visit, Visitor}; +use crate::{BoundVar, ControlFlow, DebruijnIndex, Interner, TypeVisitable, TypeVisitor}; -/// Visitor extensions. -pub trait VisitExt: Visit { +/// TypeVisitor extensions. +pub trait VisitExt: TypeVisitable { /// Check whether there are free (non-bound) variables. fn has_free_vars(&self, interner: I) -> bool { let flow = self.visit_with( @@ -14,16 +14,16 @@ pub trait VisitExt: Visit { } } -impl VisitExt for T where T: Visit {} +impl VisitExt for T where T: TypeVisitable {} struct FindFreeVarsVisitor { interner: I, } -impl Visitor for FindFreeVarsVisitor { +impl TypeVisitor for FindFreeVarsVisitor { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } diff --git a/chalk-ir/src/zip.rs b/chalk-ir/src/zip.rs index f17a5f84bf2..53686c63ed3 100644 --- a/chalk-ir/src/zip.rs +++ b/chalk-ir/src/zip.rs @@ -1,6 +1,6 @@ //! Traits for "zipping" types, walking through two structures and checking that they match. -use crate::fold::Fold; +use crate::fold::TypeFoldable; use crate::*; use std::fmt::Debug; use std::sync::Arc; @@ -44,7 +44,7 @@ pub trait Zipper { b: &Binders, ) -> Fallible<()> where - T: Clone + HasInterner + Zip + Fold; + T: Clone + HasInterner + Zip + TypeFoldable; /// Zips two substs fn zip_substs( @@ -98,7 +98,7 @@ where fn zip_binders(&mut self, variance: Variance, a: &Binders, b: &Binders) -> Fallible<()> where - T: Clone + HasInterner + Zip + Fold, + T: Clone + HasInterner + Zip + TypeFoldable, { (**self).zip_binders(variance, a, b) } @@ -248,7 +248,7 @@ impl Zip for Const { } impl Zip for Binders where - T: Clone + HasInterner + Zip + Fold, + T: Clone + HasInterner + Zip + TypeFoldable, { fn zip_with>( zipper: &mut Z, diff --git a/chalk-recursive/src/fulfill.rs b/chalk-recursive/src/fulfill.rs index d854dcc701c..fec068dfd91 100644 --- a/chalk-recursive/src/fulfill.rs +++ b/chalk-recursive/src/fulfill.rs @@ -1,9 +1,9 @@ use crate::fixed_point::Minimums; use crate::solve::SolveDatabase; use chalk_ir::cast::Cast; -use chalk_ir::fold::Fold; +use chalk_ir::fold::TypeFoldable; use chalk_ir::interner::{HasInterner, Interner}; -use chalk_ir::visit::Visit; +use chalk_ir::visit::TypeVisitable; use chalk_ir::zip::Zip; use chalk_ir::{ Binders, BoundVar, Canonical, ConstrainedSubst, Constraint, Constraints, DomainGoal, @@ -65,7 +65,7 @@ fn canonicalize( value: T, ) -> (Canonical, Vec>) where - T: Fold, + T: TypeFoldable, T::Result: HasInterner, { let res = infer.canonicalize(interner, value); @@ -83,7 +83,7 @@ fn u_canonicalize( value0: &Canonical, ) -> (UCanonical, UniverseMap) where - T: Clone + HasInterner + Fold + Visit, + T: Clone + HasInterner + TypeFoldable + TypeVisitable, T::Result: HasInterner, { let res = InferenceTable::u_canonicalize(interner, value0); diff --git a/chalk-recursive/src/solve.rs b/chalk-recursive/src/solve.rs index 47db7080ab3..aa033589cc1 100644 --- a/chalk-recursive/src/solve.rs +++ b/chalk-recursive/src/solve.rs @@ -3,7 +3,7 @@ use super::fulfill::Fulfill; use crate::fixed_point::Minimums; use crate::UCanonicalGoal; use chalk_ir::could_match::CouldMatch; -use chalk_ir::fold::Fold; +use chalk_ir::fold::TypeFoldable; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::{ Canonical, ClausePriority, DomainGoal, Fallible, Floundered, Goal, GoalData, InEnvironment, @@ -196,7 +196,7 @@ trait SolveIterationHelpers: SolveDatabase { } } - fn new_inference_table + HasInterner + Clone>( + fn new_inference_table + HasInterner + Clone>( &self, ucanonical_goal: &UCanonical>, ) -> (InferenceTable, Substitution, InEnvironment) { diff --git a/chalk-solve/src/clauses/builder.rs b/chalk-solve/src/clauses/builder.rs index de63f33dabc..9d0383a3465 100644 --- a/chalk-solve/src/clauses/builder.rs +++ b/chalk-solve/src/clauses/builder.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::cast::{Cast, CastTo}; use crate::RustIrDatabase; -use chalk_ir::fold::{Fold, Shift}; +use chalk_ir::fold::{Shift, TypeFoldable}; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::*; use tracing::{debug, instrument}; @@ -135,7 +135,7 @@ impl<'me, I: Interner> ClauseBuilder<'me, I> { op: impl FnOnce(&mut Self, V::Result) -> R, ) -> R where - V: Fold + HasInterner, + V: TypeFoldable + HasInterner, V::Result: std::fmt::Debug, { let old_len = self.binders.len(); diff --git a/chalk-solve/src/clauses/builtin_traits/unsize.rs b/chalk-solve/src/clauses/builtin_traits/unsize.rs index ad4240a8ad9..6682735b692 100644 --- a/chalk-solve/src/clauses/builtin_traits/unsize.rs +++ b/chalk-solve/src/clauses/builtin_traits/unsize.rs @@ -8,7 +8,7 @@ use crate::{Interner, RustIrDatabase, TraitRef, WellKnownTrait}; use chalk_ir::{ cast::Cast, interner::HasInterner, - visit::{SuperVisit, Visit, Visitor}, + visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, Binders, Const, ConstValue, DebruijnIndex, DomainGoal, DynTy, EqGoal, Goal, LifetimeOutlives, QuantifiedWhereClauses, Substitution, TraitId, Ty, TyKind, TypeOutlives, WhereClause, }; @@ -19,10 +19,10 @@ struct UnsizeParameterCollector { parameters: HashSet, } -impl Visitor for UnsizeParameterCollector { +impl TypeVisitor for UnsizeParameterCollector { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } @@ -60,7 +60,7 @@ impl Visitor for UnsizeParameterCollector { fn outer_binder_parameters_used( interner: I, - v: &Binders + HasInterner>, + v: &Binders + HasInterner>, ) -> HashSet { let mut visitor = UnsizeParameterCollector { interner, @@ -76,10 +76,10 @@ struct ParameterOccurenceCheck<'p, I: Interner> { parameters: &'p HashSet, } -impl<'p, I: Interner> Visitor for ParameterOccurenceCheck<'p, I> { +impl<'p, I: Interner> TypeVisitor for ParameterOccurenceCheck<'p, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } @@ -124,7 +124,7 @@ impl<'p, I: Interner> Visitor for ParameterOccurenceCheck<'p, I> { fn uses_outer_binder_params( interner: I, - v: &Binders + HasInterner>, + v: &Binders + HasInterner>, parameters: &HashSet, ) -> bool { let mut visitor = ParameterOccurenceCheck { diff --git a/chalk-solve/src/clauses/env_elaborator.rs b/chalk-solve/src/clauses/env_elaborator.rs index 3c490258029..29032a7ad2f 100644 --- a/chalk-solve/src/clauses/env_elaborator.rs +++ b/chalk-solve/src/clauses/env_elaborator.rs @@ -8,7 +8,7 @@ use crate::RustIrDatabase; use crate::Ty; use crate::{debug_span, TyKind}; use chalk_ir::interner::Interner; -use chalk_ir::visit::{Visit, Visitor}; +use chalk_ir::visit::{TypeVisitable, TypeVisitor}; use chalk_ir::{DebruijnIndex, Environment}; use rustc_hash::FxHashSet; use std::ops::ControlFlow; @@ -43,10 +43,10 @@ struct EnvElaborator<'me, 'builder, I: Interner> { environment: &'me Environment, } -impl<'me, 'builder, I: Interner> Visitor for EnvElaborator<'me, 'builder, I> { +impl<'me, 'builder, I: Interner> TypeVisitor for EnvElaborator<'me, 'builder, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } diff --git a/chalk-solve/src/clauses/generalize.rs b/chalk-solve/src/clauses/generalize.rs index 91391ae4ca1..f2438946e2b 100644 --- a/chalk-solve/src/clauses/generalize.rs +++ b/chalk-solve/src/clauses/generalize.rs @@ -7,7 +7,7 @@ //! types passed to `program_clauses` in the clauses we generate. use chalk_ir::{ - fold::{Fold, Folder}, + fold::{TypeFoldable, TypeFolder}, interner::{HasInterner, Interner}, Binders, BoundVar, Const, ConstData, ConstValue, DebruijnIndex, Fallible, Lifetime, LifetimeData, NoSolution, Ty, TyKind, TyVariableKind, VariableKind, VariableKinds, @@ -23,7 +23,7 @@ pub struct Generalize { impl Generalize { pub fn apply(interner: I, value: T) -> Binders where - T: HasInterner + Fold, + T: HasInterner + TypeFoldable, T::Result: HasInterner, { let mut generalize = Generalize { @@ -41,10 +41,10 @@ impl Generalize { } } -impl Folder for Generalize { +impl TypeFolder for Generalize { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-solve/src/coherence.rs b/chalk-solve/src/coherence.rs index 20759dacea6..5528b9a21fd 100644 --- a/chalk-solve/src/coherence.rs +++ b/chalk-solve/src/coherence.rs @@ -96,7 +96,7 @@ where let forest = self.build_specialization_forest()?; - // Visit every root in the forest & set specialization + // TypeVisitable every root in the forest & set specialization // priority for the tree that is the root of. for root_idx in forest.externals(Direction::Incoming) { self.set_priorities(root_idx, &forest, 0, &mut result); @@ -141,7 +141,7 @@ where map.insert(*impl_id, SpecializationPriority(p)); } - // Visit all children of this node, setting their priority to this + 1 + // TypeVisitable all children of this node, setting their priority to this + 1 for child_idx in forest.neighbors(idx) { self.set_priorities(child_idx, forest, p + 1, map); } diff --git a/chalk-solve/src/ext.rs b/chalk-solve/src/ext.rs index 4941dd9d326..1b83a628f30 100644 --- a/chalk-solve/src/ext.rs +++ b/chalk-solve/src/ext.rs @@ -1,5 +1,5 @@ use crate::infer::InferenceTable; -use chalk_ir::fold::Fold; +use chalk_ir::fold::TypeFoldable; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::*; @@ -7,8 +7,8 @@ pub trait CanonicalExt { fn map(self, interner: I, op: OP) -> Canonical where OP: FnOnce(T::Result) -> U, - T: Fold, - U: Fold, + T: TypeFoldable, + U: TypeFoldable, U::Result: HasInterner; } @@ -27,8 +27,8 @@ where fn map(self, interner: I, op: OP) -> Canonical where OP: FnOnce(T::Result) -> U, - T: Fold, - U: Fold, + T: TypeFoldable, + U: TypeFoldable, U::Result: HasInterner, { // Subtle: It is only quite rarely correct to apply `op` and diff --git a/chalk-solve/src/goal_builder.rs b/chalk-solve/src/goal_builder.rs index 1ac558b486b..c7b0bbaec58 100644 --- a/chalk-solve/src/goal_builder.rs +++ b/chalk-solve/src/goal_builder.rs @@ -4,7 +4,7 @@ use chalk_ir::cast::Cast; use chalk_ir::cast::Caster; use chalk_ir::*; use fold::shift::Shift; -use fold::Fold; +use fold::TypeFoldable; use interner::{HasInterner, Interner}; pub struct GoalBuilder<'i, I: Interner> { @@ -80,7 +80,7 @@ impl<'i, I: Interner> GoalBuilder<'i, I> { ) -> Goal where B: HasInterner, - P: Fold, + P: TypeFoldable, G: CastTo>, { self.quantified(QuantifierKind::ForAll, binders, passthru, body) @@ -95,7 +95,7 @@ impl<'i, I: Interner> GoalBuilder<'i, I> { ) -> Goal where B: HasInterner, - P: Fold, + P: TypeFoldable, G: CastTo>, { self.quantified(QuantifierKind::Exists, binders, passthru, body) @@ -117,7 +117,7 @@ impl<'i, I: Interner> GoalBuilder<'i, I> { ) -> Goal where B: HasInterner, - P: Fold, + P: TypeFoldable, G: CastTo>, { let interner = self.interner(); diff --git a/chalk-solve/src/infer.rs b/chalk-solve/src/infer.rs index ffe5e6ab445..82ceec9b503 100644 --- a/chalk-solve/src/infer.rs +++ b/chalk-solve/src/infer.rs @@ -1,6 +1,6 @@ use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::*; -use chalk_ir::{cast::Cast, fold::Fold}; +use chalk_ir::{cast::Cast, fold::TypeFoldable}; use tracing::debug; mod canonicalize; @@ -52,7 +52,7 @@ impl InferenceTable { canonical: Canonical, ) -> (Self, Substitution, T) where - T: HasInterner + Fold + Clone, + T: HasInterner + TypeFoldable + Clone, { let mut table = InferenceTable::new(); diff --git a/chalk-solve/src/infer/canonicalize.rs b/chalk-solve/src/infer/canonicalize.rs index a9f968f5c65..3ea05251d0d 100644 --- a/chalk-solve/src/infer/canonicalize.rs +++ b/chalk-solve/src/infer/canonicalize.rs @@ -1,6 +1,6 @@ use crate::debug_span; use chalk_ir::fold::shift::Shift; -use chalk_ir::fold::{Fold, Folder, SuperFold}; +use chalk_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::*; use std::cmp::max; @@ -29,7 +29,7 @@ impl InferenceTable { /// also returned. pub fn canonicalize(&mut self, interner: I, value: T) -> Canonicalized where - T: Fold, + T: TypeFoldable, T::Result: HasInterner, { debug_span!("canonicalize", "{:#?}", value); @@ -101,10 +101,10 @@ impl<'q, I: Interner> Canonicalizer<'q, I> { } } -impl<'i, I: Interner> Folder for Canonicalizer<'i, I> { +impl<'i, I: Interner> TypeFolder for Canonicalizer<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-solve/src/infer/instantiate.rs b/chalk-solve/src/infer/instantiate.rs index 91a048a80f3..6ec82904787 100644 --- a/chalk-solve/src/infer/instantiate.rs +++ b/chalk-solve/src/infer/instantiate.rs @@ -28,7 +28,7 @@ impl InferenceTable { /// Variant on `instantiate` that takes a `Canonical`. pub fn instantiate_canonical(&mut self, interner: I, bound: Canonical) -> T::Result where - T: HasInterner + Fold + Debug, + T: HasInterner + TypeFoldable + Debug, { let subst = self.fresh_subst(interner, bound.binders.as_slice(interner)); subst.apply(bound.value, interner) @@ -47,7 +47,7 @@ impl InferenceTable { arg: T, ) -> T::Result where - T: Fold, + T: TypeFoldable, { let binders: Vec<_> = binders .map(|pk| CanonicalVarKind::new(pk, universe)) @@ -64,7 +64,7 @@ impl InferenceTable { arg: Binders, ) -> T::Result where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, { let (value, binders) = arg.into_value_and_skipped_binders(); @@ -80,7 +80,7 @@ impl InferenceTable { #[instrument(level = "debug", skip(self, interner))] pub fn instantiate_binders_universally(&mut self, interner: I, arg: Binders) -> T::Result where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, { let (value, binders) = arg.into_value_and_skipped_binders(); diff --git a/chalk-solve/src/infer/invert.rs b/chalk-solve/src/infer/invert.rs index 0f088543a8e..4c53410ad41 100644 --- a/chalk-solve/src/infer/invert.rs +++ b/chalk-solve/src/infer/invert.rs @@ -1,5 +1,5 @@ use chalk_ir::fold::shift::Shift; -use chalk_ir::fold::{Fold, Folder}; +use chalk_ir::fold::{TypeFoldable, TypeFolder}; use chalk_ir::interner::HasInterner; use chalk_ir::interner::Interner; use chalk_ir::*; @@ -73,7 +73,7 @@ impl InferenceTable { /// `None`) until the second unification has occurred.) pub fn invert(&mut self, interner: I, value: T) -> Option where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, { let Canonicalized { free_vars, @@ -103,7 +103,7 @@ impl InferenceTable { value: T, ) -> Option> where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, { let snapshot = self.snapshot(); let result = self.invert(interner, value); @@ -131,10 +131,10 @@ impl<'q, I: Interner> Inverter<'q, I> { } } -impl<'i, I: Interner> Folder for Inverter<'i, I> { +impl<'i, I: Interner> TypeFolder for Inverter<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-solve/src/infer/ucanonicalize.rs b/chalk-solve/src/infer/ucanonicalize.rs index f6c81f86d73..a0bed3b0e84 100644 --- a/chalk-solve/src/infer/ucanonicalize.rs +++ b/chalk-solve/src/infer/ucanonicalize.rs @@ -1,7 +1,7 @@ use crate::debug_span; -use chalk_ir::fold::{Fold, Folder}; +use chalk_ir::fold::{TypeFoldable, TypeFolder}; use chalk_ir::interner::{HasInterner, Interner}; -use chalk_ir::visit::{Visit, Visitor}; +use chalk_ir::visit::{TypeVisitable, TypeVisitor}; use chalk_ir::*; use std::ops::ControlFlow; @@ -10,7 +10,7 @@ use super::InferenceTable; impl InferenceTable { pub fn u_canonicalize(interner: I, value0: &Canonical) -> UCanonicalized where - T: Clone + HasInterner + Fold + Visit, + T: Clone + HasInterner + TypeFoldable + TypeVisitable, T::Result: HasInterner, { debug_span!("u_canonicalize", "{:#?}", value0); @@ -84,7 +84,7 @@ pub trait UniverseMapExt { canonical_value: &Canonical, ) -> Canonical where - T: Clone + Fold + HasInterner, + T: Clone + TypeFoldable + HasInterner, T::Result: HasInterner, I: Interner; } @@ -163,7 +163,7 @@ impl UniverseMapExt for UniverseMap { canonical_value: &Canonical, ) -> Canonical where - T: Clone + Fold + HasInterner, + T: Clone + TypeFoldable + HasInterner, T::Result: HasInterner, I: Interner, { @@ -200,10 +200,10 @@ struct UCollector<'q, I> { interner: I, } -impl Visitor for UCollector<'_, I> { +impl TypeVisitor for UCollector<'_, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } @@ -230,10 +230,10 @@ struct UMapToCanonical<'q, I> { universes: &'q UniverseMap, } -impl<'i, I: Interner> Folder for UMapToCanonical<'i, I> { +impl<'i, I: Interner> TypeFolder for UMapToCanonical<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } @@ -302,10 +302,10 @@ struct UMapFromCanonical<'q, I> { universes: &'q UniverseMap, } -impl<'i, I: Interner> Folder for UMapFromCanonical<'i, I> { +impl<'i, I: Interner> TypeFolder for UMapFromCanonical<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-solve/src/infer/unify.rs b/chalk-solve/src/infer/unify.rs index e5e169fdc75..e1c057ee85c 100644 --- a/chalk-solve/src/infer/unify.rs +++ b/chalk-solve/src/infer/unify.rs @@ -2,7 +2,7 @@ use super::var::*; use super::*; use crate::debug_span; use chalk_ir::cast::Cast; -use chalk_ir::fold::{Fold, Folder}; +use chalk_ir::fold::{TypeFoldable, TypeFolder}; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::zip::{Zip, Zipper}; use chalk_ir::UnificationDatabase; @@ -397,8 +397,8 @@ impl<'t, I: Interner> Unifier<'t, I> { b: &Binders, ) -> Fallible<()> where - T: Clone + Fold + HasInterner, - R: Zip + Fold, + T: Clone + TypeFoldable + HasInterner, + R: Zip + TypeFoldable, 't: 'a, { // for<'a...> T == for<'b...> U @@ -1202,7 +1202,7 @@ impl<'i, I: Interner> Zipper for Unifier<'i, I> { fn zip_binders(&mut self, variance: Variance, a: &Binders, b: &Binders) -> Fallible<()> where - T: Clone + HasInterner + Zip + Fold, + T: Clone + HasInterner + Zip + TypeFoldable, { // The binders that appear in types (apart from quantified types, which are // handled in `unify_ty`) appear as part of `dyn Trait` and `impl Trait` types. @@ -1247,10 +1247,10 @@ impl<'u, 't, I: Interner> OccursCheck<'u, 't, I> { } } -impl<'i, I: Interner> Folder for OccursCheck<'_, 'i, I> { +impl<'i, I: Interner> TypeFolder for OccursCheck<'_, 'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/chalk-solve/src/logging_db/id_collector.rs b/chalk-solve/src/logging_db/id_collector.rs index 893652b70c4..41aa38166fd 100644 --- a/chalk-solve/src/logging_db/id_collector.rs +++ b/chalk-solve/src/logging_db/id_collector.rs @@ -2,8 +2,8 @@ use super::RecordedItemId; use crate::RustIrDatabase; use chalk_ir::{ interner::Interner, - visit::Visitor, - visit::{SuperVisit, Visit}, + visit::TypeVisitor, + visit::{TypeSuperVisitable, TypeVisitable}, AliasTy, DebruijnIndex, TyKind, WhereClause, }; use std::ops::ControlFlow; @@ -116,10 +116,10 @@ impl<'i, I: Interner, DB: RustIrDatabase> IdCollector<'i, I, DB> { } } -impl<'i, I: Interner, DB: RustIrDatabase> Visitor for IdCollector<'i, I, DB> { +impl<'i, I: Interner, DB: RustIrDatabase> TypeVisitor for IdCollector<'i, I, DB> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } fn interner(&self) -> I { diff --git a/chalk-solve/src/rust_ir.rs b/chalk-solve/src/rust_ir.rs index 7983b75f2e4..aa9f06ece8e 100644 --- a/chalk-solve/src/rust_ir.rs +++ b/chalk-solve/src/rust_ir.rs @@ -2,13 +2,13 @@ //! version of the AST, roughly corresponding to [the HIR] in the Rust //! compiler. -use chalk_derive::{Fold, HasInterner, Visit}; +use chalk_derive::{HasInterner, TypeFoldable, TypeVisitable}; use chalk_ir::cast::Cast; use chalk_ir::fold::shift::Shift; use chalk_ir::interner::Interner; use chalk_ir::{ - try_break, visit::Visit, AdtId, AliasEq, AliasTy, AssocTypeId, Binders, DebruijnIndex, FnDefId, - GenericArg, ImplId, OpaqueTyId, ProjectionTy, QuantifiedWhereClause, Substitution, + try_break, visit::TypeVisitable, AdtId, AliasEq, AliasTy, AssocTypeId, Binders, DebruijnIndex, + FnDefId, GenericArg, ImplId, OpaqueTyId, ProjectionTy, QuantifiedWhereClause, Substitution, ToGenericArg, TraitId, TraitRef, Ty, TyKind, VariableKind, WhereClause, WithKind, }; use std::iter; @@ -21,7 +21,7 @@ pub struct AssociatedTyValueId(pub I::DefId); chalk_ir::id_visit!(AssociatedTyValueId); chalk_ir::id_fold!(AssociatedTyValueId); -#[derive(Clone, Debug, PartialEq, Eq, Hash, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeVisitable)] pub struct ImplDatum { pub polarity: Polarity, pub binders: Binders>, @@ -52,7 +52,7 @@ impl ImplDatum { } } -#[derive(Clone, Debug, PartialEq, Eq, Hash, HasInterner, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, HasInterner, TypeFoldable, TypeVisitable)] pub struct ImplDatumBound { pub trait_ref: TraitRef, pub where_clauses: Vec>, @@ -77,7 +77,7 @@ pub struct DefaultImplDatumBound { pub accessible_tys: Vec>, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeVisitable)] pub struct AdtDatum { pub binders: Binders>, pub id: AdtId, @@ -94,13 +94,13 @@ pub enum AdtKind { chalk_ir::const_visit!(AdtKind); -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner, TypeVisitable)] pub struct AdtDatumBound { pub variants: Vec>, pub where_clauses: Vec>, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner, TypeVisitable)] pub struct AdtVariantDatum { pub fields: Vec>, } @@ -157,10 +157,10 @@ pub struct FnDefDatum { } /// Avoids visiting `I::FnAbi` -impl Visit for FnDefDatum { +impl TypeVisitable for FnDefDatum { fn visit_with( &self, - visitor: &mut dyn chalk_ir::visit::Visitor, + visitor: &mut dyn chalk_ir::visit::TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { try_break!(self.id.visit_with(visitor, outer_binder)); @@ -170,7 +170,7 @@ impl Visit for FnDefDatum { /// Represents the inputs and outputs on a `FnDefDatum`. This is split /// from the where clauses, since these can contain bound lifetimes. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner, TypeVisitable)] pub struct FnDefInputsAndOutputDatum { /// Types of the function's arguments /// ```ignore @@ -187,7 +187,7 @@ pub struct FnDefInputsAndOutputDatum { pub return_type: Ty, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner, TypeVisitable)] /// Represents the bounds on a `FnDefDatum`, including /// the function definition's type signature and where clauses. pub struct FnDefDatumBound { @@ -238,7 +238,7 @@ pub struct FnDefDatumBound { /// /// [`ImplDatum`]: struct.ImplDatum.html /// [`AssociatedTyDatum`]: struct.AssociatedTyDatum.html -#[derive(Visit)] +#[derive(TypeVisitable)] pub struct TraitDatum { pub id: TraitId, @@ -304,7 +304,7 @@ impl TraitDatum { } } -#[derive(Clone, Debug, PartialEq, Eq, Hash, HasInterner, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, HasInterner, TypeVisitable)] pub struct TraitDatumBound { /// Where clauses defined on the trait: /// @@ -351,7 +351,7 @@ pub struct TraitFlags { chalk_ir::const_visit!(TraitFlags); /// An inline bound, e.g. `: Foo` in `impl> SomeType`. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub enum InlineBound { TraitBound(TraitBound), AliasEqBound(AliasEqBound), @@ -395,7 +395,7 @@ impl IntoWhereClauses for QuantifiedInlineBound { /// Represents a trait bound on e.g. a type or type parameter. /// Does not know anything about what it's binding. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub struct TraitBound { pub trait_id: TraitId, pub args_no_self: Vec>, @@ -420,7 +420,7 @@ impl TraitBound { /// Represents an alias equality bound on e.g. a type or type parameter. /// Does not know anything about what it's binding. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub struct AliasEqBound { pub trait_bound: TraitBound, pub associated_ty_id: AssocTypeId, @@ -504,10 +504,10 @@ pub struct AssociatedTyDatum { } // Manual implementation to avoid I::Identifier type. -impl Visit for AssociatedTyDatum { +impl TypeVisitable for AssociatedTyDatum { fn visit_with( &self, - visitor: &mut dyn chalk_ir::visit::Visitor, + visitor: &mut dyn chalk_ir::visit::TypeVisitor, outer_binder: DebruijnIndex, ) -> ControlFlow { try_break!(self.trait_id.visit_with(visitor, outer_binder)); @@ -518,7 +518,7 @@ impl Visit for AssociatedTyDatum { /// Encodes the parts of `AssociatedTyDatum` where the parameters /// `P0..Pm` are in scope (`bounds` and `where_clauses`). -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct AssociatedTyDatumBound { /// Bounds on the associated type itself. /// @@ -580,7 +580,7 @@ impl AssociatedTyDatum { /// type Item = XXX; // <-- represents this line! /// } /// ``` -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub struct AssociatedTyValue { /// Impl in which this associated type value is found. You might /// need to look at this to find the generic parameters defined on @@ -619,7 +619,7 @@ pub struct AssociatedTyValue { pub value: Binders>, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)] pub struct AssociatedTyValueBound { /// Type that we normalize to. The X in `type Foo<'a> = X`. pub ty: Ty, @@ -630,7 +630,7 @@ pub struct AssociatedTyValueBound { /// ```ignore /// opaque type T: A + B = HiddenTy; /// ``` -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub struct OpaqueTyDatum { /// The placeholder `!T` that corresponds to the opaque type `T`. pub opaque_ty_id: OpaqueTyId, @@ -639,7 +639,7 @@ pub struct OpaqueTyDatum { pub bound: Binders>, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner, Visit)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner, TypeVisitable)] pub struct OpaqueTyDatumBound { /// Trait bounds for the opaque type. These are bounds that the hidden type must meet. pub bounds: Binders>>, @@ -659,7 +659,7 @@ pub enum Movability { chalk_ir::copy_fold!(Movability); /// Represents a generator type. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner)] pub struct GeneratorDatum { // Can the generator be moved (is Unpin or not) pub movability: Movability, @@ -670,7 +670,7 @@ pub struct GeneratorDatum { } /// The nested types for a generator. This always appears inside a `GeneratorDatum` -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner)] pub struct GeneratorInputOutputDatum { /// The generator resume type - a value of this type /// is supplied by the caller when resuming the generator. @@ -698,7 +698,7 @@ pub struct GeneratorInputOutputDatum { /// `GeneratorWitnessDatum` is logically 'inside' a generator - this only /// matters when we treat the witness type as a 'constituent type for the /// purposes of determining auto trait implementations. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner)] pub struct GeneratorWitnessDatum { /// This binder is identical to the `input_output` binder in `GeneratorWitness` - /// it binds the types and lifetimes that the generator is generic over. @@ -717,7 +717,7 @@ pub struct GeneratorWitnessDatum { /// Unlike the binder in `GeneratorWitnessDatum`, this `Binder` never gets substituted /// via an `Ty`. Instead, we handle this `Binders` specially when determining /// auto trait impls. See `push_auto_trait_impls_generator_witness` for more details. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, HasInterner)] pub struct GeneratorWitnessExistential { pub types: Binders>>, } diff --git a/chalk-solve/src/solve/truncate.rs b/chalk-solve/src/solve/truncate.rs index b48a0324c69..1ed47b94fd0 100644 --- a/chalk-solve/src/solve/truncate.rs +++ b/chalk-solve/src/solve/truncate.rs @@ -2,7 +2,7 @@ use crate::infer::InferenceTable; use chalk_ir::interner::Interner; -use chalk_ir::visit::{SuperVisit, Visit, Visitor}; +use chalk_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}; use chalk_ir::*; use std::cmp::max; use std::ops::ControlFlow; @@ -23,7 +23,7 @@ pub fn needs_truncation( interner: I, infer: &mut InferenceTable, max_size: usize, - value: impl Visit, + value: impl TypeVisitable, ) -> bool { let mut visitor = TySizeVisitor::new(interner, infer); value.visit_with(&mut visitor, DebruijnIndex::INNERMOST); @@ -51,10 +51,10 @@ impl<'infer, I: Interner> TySizeVisitor<'infer, I> { } } -impl<'infer, I: Interner> Visitor for TySizeVisitor<'infer, I> { +impl<'infer, I: Interner> TypeVisitor for TySizeVisitor<'infer, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } diff --git a/chalk-solve/src/wf.rs b/chalk-solve/src/wf.rs index 60d92860faa..84d9724171d 100644 --- a/chalk-solve/src/wf.rs +++ b/chalk-solve/src/wf.rs @@ -8,7 +8,7 @@ use chalk_ir::{ cast::*, fold::shift::Shift, interner::Interner, - visit::{Visit, Visitor}, + visit::{TypeVisitable, TypeVisitor}, *, }; use tracing::debug; @@ -62,16 +62,16 @@ impl InputTypeCollector { } } - fn types_in(interner: I, value: impl Visit) -> Vec> { + fn types_in(interner: I, value: impl TypeVisitable) -> Vec> { let mut collector = Self::new(interner); value.visit_with(&mut collector, DebruijnIndex::INNERMOST); collector.types } } -impl Visitor for InputTypeCollector { +impl TypeVisitor for InputTypeCollector { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor { + fn as_dyn(&mut self) -> &mut dyn TypeVisitor { self } @@ -571,9 +571,9 @@ fn compute_assoc_ty_goal( let interner = gb.interner(); let db = gb.db(); - // Hmm, because `Arc` does not implement `Fold`, we can't pass this value through, + // Hmm, because `Arc` does not implement `TypeFoldable`, we can't pass this value through, // just the id, so we have to fetch `assoc_ty` from the database again. - // Implementing `Fold` for `AssociatedTyValue` doesn't *quite* seem right though, as that + // Implementing `TypeFoldable` for `AssociatedTyValue` doesn't *quite* seem right though, as that // would result in a deep clone, and the value is inert. We could do some more refatoring // (move the `Arc` behind a newtype, for example) to fix this, but for now doesn't // seem worth it.