Skip to content

Remove unused Result assoc type from Fold trait #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions chalk-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -275,33 +275,21 @@ fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream {
});

let input = s.ast();
let type_name = &input.ident;

let result = if kind == DeriveKind::FromHasInterner {
if kind == DeriveKind::FromHasInterner {
let param = get_generic_param_name(input).unwrap();
s.add_impl_generic(parse_quote! { _U })
.add_where_predicate(
parse_quote! { #param: ::chalk_ir::fold::TypeFoldable<#interner, Result = _U> },
)
.add_where_predicate(
parse_quote! { _U: ::chalk_ir::interner::HasInterner<Interner = #interner> },
);
quote! { #type_name <_U> }
} else {
quote! { #type_name < #interner > }
s.add_where_predicate(parse_quote! { #param: ::chalk_ir::fold::TypeFoldable<#interner> });
};

s.add_bounds(synstructure::AddBounds::None);
s.bound_impl(
quote!(::chalk_ir::fold::TypeFoldable<#interner>),
quote! {
type Result = #result;

fn fold_with<E>(
self,
folder: &mut dyn ::chalk_ir::fold::TypeFolder < #interner, Error = E >,
outer_binder: ::chalk_ir::DebruijnIndex,
) -> ::std::result::Result<Self::Result, E> {
) -> ::std::result::Result<Self, E> {
Ok(match self { #body })
}
},
2 changes: 1 addition & 1 deletion chalk-engine/src/normalize_deep.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ impl<I: Interner> DeepNormalizer<'_, I> {
table: &mut InferenceTable<I>,
interner: I,
value: T,
) -> T::Result {
) -> T {
value
.fold_with(
&mut DeepNormalizer { interner, table },
2 changes: 1 addition & 1 deletion chalk-engine/src/slg/resolvent.rs
Original file line number Diff line number Diff line change
@@ -708,7 +708,7 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
pending: &Binders<T>,
) -> Fallible<()>
where
T: HasInterner<Interner = I> + Zip<I> + TypeFoldable<I, Result = T>,
T: HasInterner<Interner = I> + Zip<I> + TypeFoldable<I>,
{
self.outer_binder.shift_in();
Zip::zip_with(
3 changes: 1 addition & 2 deletions chalk-engine/src/strand.rs
Original file line number Diff line number Diff line change
@@ -36,12 +36,11 @@ pub(crate) struct SelectedSubgoal {
}

impl<I: Interner> TypeFoldable<I> for Strand<I> {
type Result = Strand<I>;
fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
Ok(Strand {
ex_clause: self.ex_clause.fold_with(folder, outer_binder)?,
last_pursued_time: self.last_pursued_time,
35 changes: 9 additions & 26 deletions chalk-ir/src/fold.rs
Original file line number Diff line number Diff line change
@@ -310,14 +310,7 @@ pub trait TypeFolder<I: Interner> {
/// 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 TypeFoldable<I: Interner>: 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: TypeFoldable`, in which case
/// you get back a `T`, not a `&T`).
type Result;

pub trait TypeFoldable<I: Interner>: Debug + Sized {
/// Apply the given folder `folder` to `self`; `binders` is the
/// number of binders that are in scope when beginning the
/// folder. Typically `binders` starts as 0, but is adjusted when
@@ -327,7 +320,7 @@ pub trait TypeFoldable<I: Interner>: Debug {
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E>;
) -> Result<Self, E>;
}

/// For types where "fold" invokes a callback on the `TypeFolder`, the
@@ -339,20 +332,18 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E>;
) -> Result<Self, E>;
}

/// "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<I: Interner> TypeFoldable<I> for Ty<I> {
type Result = Ty<I>;

fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
folder.fold_ty(self, outer_binder)
}
}
@@ -470,13 +461,11 @@ where
/// usually (in turn) invokes `super_fold_lifetime` to fold the individual
/// parts.
impl<I: Interner> TypeFoldable<I> for Lifetime<I> {
type Result = Lifetime<I>;

fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
folder.fold_lifetime(self, outer_binder)
}
}
@@ -522,13 +511,11 @@ where
/// usually (in turn) invokes `super_fold_const` to fold the individual
/// parts.
impl<I: Interner> TypeFoldable<I> for Const<I> {
type Result = Const<I>;

fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
folder.fold_const(self, outer_binder)
}
}
@@ -573,13 +560,11 @@ where
/// Folding a goal invokes the `fold_goal` callback (which will, by
/// default, invoke super-fold).
impl<I: Interner> TypeFoldable<I> for Goal<I> {
type Result = Goal<I>;

fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
folder.fold_goal(self, outer_binder)
}
}
@@ -590,7 +575,7 @@ impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
let interner = folder.interner();
Ok(Goal::new(
interner,
@@ -605,13 +590,11 @@ impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
/// callback on the folder (which will, by default, invoke the
/// `super_fold_with` method on the program clause).
impl<I: Interner> TypeFoldable<I> for ProgramClause<I> {
type Result = ProgramClause<I>;

fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
folder.fold_program_clause(self, outer_binder)
}
}
11 changes: 3 additions & 8 deletions chalk-ir/src/fold/binder_impls.rs
Original file line number Diff line number Diff line change
@@ -6,12 +6,11 @@
use crate::*;

impl<I: Interner> TypeFoldable<I> for FnPointer<I> {
type Result = FnPointer<I>;
fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
let FnPointer {
num_binders,
substitution,
@@ -32,15 +31,13 @@ impl<I: Interner> TypeFoldable<I> for FnPointer<I> {
impl<T, I: Interner> TypeFoldable<I> for Binders<T>
where
T: HasInterner<Interner = I> + TypeFoldable<I>,
<T as TypeFoldable<I>>::Result: HasInterner<Interner = I>,
I: Interner,
{
type Result = Binders<T::Result>;
fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
let Binders {
binders: self_binders,
value: self_value,
@@ -57,14 +54,12 @@ impl<I, T> TypeFoldable<I> for Canonical<T>
where
I: Interner,
T: HasInterner<Interner = I> + TypeFoldable<I>,
<T as TypeFoldable<I>>::Result: HasInterner<Interner = I>,
{
type Result = Canonical<T::Result>;
fn fold_with<E>(
self,
folder: &mut dyn TypeFolder<I, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E> {
) -> Result<Self, E> {
let Canonical {
binders: self_binders,
value: self_value,
Loading