Skip to content

Change Fold and Folder traits to take values #644

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

Closed
wants to merge 2 commits into from

Conversation

lnicola
Copy link
Member

@lnicola lnicola commented Oct 30, 2020

Fixes #642

folder: &mut dyn Folder<'i, I, TI>,
outer_binder: DebruijnIndex,
) -> Fallible<Self::Result>
where
I: 'i,
TI: 'i,
{
(**self).fold_with(folder, outer_binder)
unimplemented!();
Copy link
Member Author

@lnicola lnicola Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: I think this implementation should be removed, but I haven't quite figured how to do that.

Or.. maybe not, since it broke every test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a bit of a weird case, since self.fold_with() would call this impl recursively.
This should be self.clone.fold_with() instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (*self).clone(), but it fails to build because of some missing Clone bounds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   1: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I,TI> for &T>::fold_with
             at ./chalk-ir/src/fold/boring_impls.rs:23:9
   2: <T as chalk_ir::fold::shift::Shift<I>>::shifted_in_from
             at ./chalk-ir/src/fold/shift.rs:32:9
   3: <T as chalk_ir::fold::shift::Shift<I>>::shifted_in
             at ./chalk-ir/src/fold/shift.rs:28:9
   4: chalk_solve::coherence::solve::<impl chalk_solve::coherence::CoherenceSolver<I>>::disjoint::{{closure}}
             at ./chalk-solve/src/coherence/solve.rs:104:26

folder: &mut dyn Folder<'i, I, TI>,
outer_binder: DebruijnIndex,
) -> ::chalk_ir::Fallible<Self::Result>
where
I: 'i,
TI: 'i,
{
let clause = self.data(folder.interner());
let clause = self.data(folder.interner()).clone();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: clone() here from borrowed data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.

@@ -80,7 +81,7 @@ pub trait UniverseMapExt {
fn add(&mut self, universe: UniverseIndex);
fn map_universe_to_canonical(&self, universe: UniverseIndex) -> Option<UniverseIndex>;
fn map_universe_from_canonical(&self, universe: UniverseIndex) -> UniverseIndex;
fn map_from_canonical<T, I>(
fn map_from_canonical<T: Clone, I>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: new Clone bounds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no way around this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we take canonical_value by value...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good poing, updated, but there are still two clone()s needed in merge_answer_into_strand.

@lnicola lnicola force-pushed the fold-self branch 2 times, most recently from c614895 to 88d3e30 Compare October 30, 2020 21:38
@@ -84,7 +84,7 @@ pub(super) trait RecursiveInferenceTable<I: Interner> {
T: Fold<I>,
T::Result: HasInterner<Interner = I>;

fn u_canonicalize<T>(
fn u_canonicalize<T: Clone>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, should we just take value0 by value?

@@ -80,7 +81,7 @@ pub trait UniverseMapExt {
fn add(&mut self, universe: UniverseIndex);
fn map_universe_to_canonical(&self, universe: UniverseIndex) -> Option<UniverseIndex>;
fn map_universe_from_canonical(&self, universe: UniverseIndex) -> UniverseIndex;
fn map_from_canonical<T, I>(
fn map_from_canonical<T: Clone, I>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we take canonical_value by value...

folder: &mut dyn Folder<'i, I, TI>,
outer_binder: DebruijnIndex,
) -> ::chalk_ir::Fallible<Self::Result>
where
I: 'i,
TI: 'i,
{
let clause = self.data(folder.interner());
let clause = self.data(folder.interner()).clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.

@bors
Copy link
Contributor

bors commented Nov 5, 2020

☔ The latest upstream changes (presumably #648) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@lnicola
Copy link
Member Author

lnicola commented Nov 27, 2020

Closing this for now. I'm still not sure how to make it work, and I haven't had much time for it lately 😞.

@lnicola lnicola closed this Nov 27, 2020
@jackh726
Copy link
Member

@lnicola thanks for trying regardless

@lnicola
Copy link
Member Author

lnicola commented Nov 27, 2020

I dropped the changes adding extra Clone bounds and rebased, just in case someone wants to take it from here.

To recap, there's this impl:

impl<'a, T: Fold<I>, I: Interner> Fold<I> for &'a T {
    type Result = T::Result;
    fn fold_with<'i>(
        self,
        _folder: &mut dyn Folder<'i, I>,
        _outer_binder: DebruijnIndex,
    ) -> Fallible<Self::Result>
    where
        I: 'i,
    {
        unreachable!();
        // (*self).fold_with(folder, outer_binder)
    }
}
  • the old code can't work because it's moving out of a reference (self)
  • I tried adding Clone bounds everywhere but it was a mess and I still couldn't make it compile
  • the impl itself is used, but I'm not sure where -- if you comment it out, the compiler will complain about the code derived for Fold, but I don't see any reference used there (EDIT: actually, Shift::shifted_in_from is one place which calls it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Fold to take by value
4 participants