Skip to content
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

Opaque type issue #700

Open
cynecx opened this issue Apr 12, 2021 · 1 comment
Open

Opaque type issue #700

cynecx opened this issue Apr 12, 2021 · 1 comment
Labels
C-chalk-solve Issues related to the chalk-solve crate

Comments

@cynecx
Copy link

cynecx commented Apr 12, 2021

This chalk test fails:

#[test]
fn warp() {
    test! {
        program {
            struct Product<H, T>
            where
              T: HList
            {}

            trait HList {
              type Tuple: Tuple<HList=Self>;
            }

            trait Tuple {
              type HList: HList<Tuple=Self>;
            }

            trait Combine<T>
            where
              T: HList
            {
              type Output: HList;
            }

            impl<T> Combine<T> for ()
            where
                T: HList
            {
                type Output = T;
            }

            impl<H, T, U> Combine<U> for Product<H, T>
            where
                T: HList,
                T: Combine<U>,
                U: HList,
                Product<H, <T as Combine<U>>::Output>: HList,
            {
                type Output = Product<H, <T as Combine<U>>::Output>;
            }

            impl HList for () {
                type Tuple = ();
            }

            impl Tuple for () {
                type HList = ();
            }

            impl<T16> HList for Product<T16, ()> {
                type Tuple = (T16,);
            }
            impl<T16> Tuple for (T16,) {
                type HList = Product<T16, ()>;
            }

            trait FilterBase {
              type Extract: Tuple;
            }

            trait Filter
            where Self: FilterBase {
            }

            impl<T> Filter for T
            where T: FilterBase {}

            trait Mumbo {
              type Extract;
            }

            impl<T, U> Mumbo for (T, U)
            where
              T: Filter,
              U: Filter,
              <<T as FilterBase>::Extract as Tuple>::HList: Combine<<<U as FilterBase>::Extract as Tuple>::HList>
            {
              type Extract = <<<<T as FilterBase>::Extract as Tuple>::HList as Combine<<<U as FilterBase>::Extract as Tuple>::HList>>::Output as HList>::Tuple;
            }

            struct Exact<T> {}
            impl<T> FilterBase for Exact<T> {
              type Extract = ();
            }

            struct Param {}
            impl FilterBase for Param {
              type Extract = (usize,);
            }

            opaque type AnonParam: FilterBase<Extract = (usize,)> = Param;
        }

        goal {
            (Exact<usize>, Param): Mumbo
        } yields {
            "Unique; substitution [], lifetime constraints []"
        }

        goal {
            (Exact<usize>, AnonParam): Mumbo
        } yields {
            "Unique; substitution [], lifetime constraints []"
        }
    }
}

The second goal should succeed, however it fails with "No possible solution".

Ref: rust-lang/rust-analyzer#4774

@detrumi detrumi self-assigned this Apr 12, 2021
@jackh726 jackh726 added the C-chalk-solve Issues related to the chalk-solve crate label Feb 22, 2022
@shamatar
Copy link
Contributor

I've tried to solve it. One aspect that I've found that for any tuple facts about it's members were missing, like the fact of aliasing AnonParam and Param. Unfortunately it was not enough to guide the solver. I think the problem is in trying to prove for<type, type> Implemented(<<Exact<Uint(Usize)> as FilterBase>::Extract as Tuple>::HList: Combine<<<^0.0 as FilterBase>::Extract as Tuple>::HList>) :- Implemented(^0.1: Combine<<<^0.0 as FilterBase>::Extract as Tuple>::HList>), AliasEq(<<Exact<Uint(Usize)> as FilterBase>::Extract as Tuple>::HList = ^0.1) roughly reading that for some ^0.1 that is ^0.0...HList for some ^0.0 such ^0.1 is itself a HList for Exact<Uint(Usize)>. Logically we should normalize <Exact<Uint(Usize)> as FilterBase>::Extract as Tuple>::HList immediately and check for all available implementations for concrete substitution of ^0.1. But solver goes some other way for<type, type> AliasEq(<<Exact<Uint(Usize)> as FilterBase>::Extract as Tuple>::HList = ^0.0) :- AliasEq(<^0.1 as Tuple>::HList = ^0.0), AliasEq(<Exact<Uint(Usize)> as FilterBase>::Extract = ^0.1) that makes more substitutions and while it's formally correct it's kind of road to nowhere.

May be someone can provide extra guideness

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-chalk-solve Issues related to the chalk-solve crate
Projects
None yet
Development

No branches or pull requests

4 participants