1 // revisions: rfail1 rfail2
3 // error-pattern: not implemented
6 type InternedVariableKinds;
9 trait RustIrDatabase<I: Interner> {
10 fn associated_ty_data(&self) -> AssociatedTyDatum<I>;
11 fn impl_datum(&self) -> ImplDatum<I>;
14 trait Fold<I: Interner> {
17 impl<T, I: Interner> Fold<I> for Binders<T>
19 T: HasInterner<Interner = I> + Fold<I>,
20 <T as Fold<I>>::Result: HasInterner<Interner = I>,
23 type Result = Binders<T::Result>;
25 impl<I: Interner> Fold<I> for WhereClause<I> {
26 type Result = Binders<WhereClause<I>>;
30 type Interner: Interner;
32 impl<T: HasInterner> HasInterner for Vec<T> {
33 type Interner = T::Interner;
35 impl<T: HasInterner + ?Sized> HasInterner for &T {
36 type Interner = T::Interner;
39 pub struct VariableKind<I: Interner> {
40 _marker: std::marker::PhantomData<I>,
43 struct VariableKinds<I: Interner> {
44 _interned: I::InternedVariableKinds,
47 struct WhereClause<I: Interner> {
48 _marker: std::marker::PhantomData<I>,
50 impl<I: Interner> HasInterner for WhereClause<I> {
55 _marker: std::marker::PhantomData<T>,
57 impl<T: HasInterner> HasInterner for Binders<T> {
58 type Interner = T::Interner;
61 fn cloned(self) -> Binders<T> {
65 impl<T: HasInterner> Binders<T> {
66 fn map_ref<'a, U, OP>(&'a self, _op: OP) -> Binders<U>
68 OP: FnOnce(&'a T) -> U,
69 U: HasInterner<Interner = T::Interner>,
74 impl<T, I: Interner> Binders<T>
76 T: Fold<I> + HasInterner<Interner = I>,
79 fn substitute(self) -> T::Result {
83 impl<V, U> IntoIterator for Binders<V>
85 V: HasInterner + IntoIterator<Item = U>,
86 U: HasInterner<Interner = V::Interner>,
88 type Item = Binders<U>;
89 type IntoIter = BindersIntoIterator<V>;
90 fn into_iter(self) -> Self::IntoIter {
94 struct BindersIntoIterator<V: HasInterner> {
95 _binders: VariableKinds<V::Interner>,
97 impl<V> Iterator for BindersIntoIterator<V>
99 V: HasInterner + IntoIterator,
100 <V as IntoIterator>::Item: HasInterner<Interner = V::Interner>,
102 type Item = Binders<<V as IntoIterator>::Item>;
103 fn next(&mut self) -> Option<Self::Item> {
108 struct ImplDatum<I: Interner> {
109 binders: Binders<ImplDatumBound<I>>,
111 struct ImplDatumBound<I: Interner> {
112 where_clauses: Vec<Binders<WhereClause<I>>>,
114 impl<I: Interner> HasInterner for ImplDatumBound<I> {
118 struct AssociatedTyDatum<I: Interner> {
119 binders: Binders<AssociatedTyDatumBound<I>>,
122 struct AssociatedTyDatumBound<I: Interner> {
123 where_clauses: Vec<Binders<WhereClause<I>>>,
125 impl<I: Interner> HasInterner for AssociatedTyDatumBound<I> {
129 struct ClauseBuilder<'me, I: Interner> {
130 db: &'me dyn RustIrDatabase<I>,
132 impl<'me, I: Interner> ClauseBuilder<'me, I> {
136 fn push_clause(&mut self, _conditions: impl Iterator<Item = Binders<Binders<WhereClause<I>>>>) {
141 pub(crate) struct Forest<I: Interner> {
142 _marker: std::marker::PhantomData<I>,
145 impl<I: Interner> Forest<I> {
146 fn iter_answers<'f>(&'f self) {
147 let builder = &mut ClauseBuilder::<I>::new();
148 let impl_datum = builder.db.impl_datum();
149 let impl_where_clauses = impl_datum
151 .map_ref(|b| &b.where_clauses)
153 .map(|wc| wc.cloned().substitute());
154 let associated_ty = builder.db.associated_ty_data();
155 let assoc_ty_where_clauses = associated_ty
157 .map_ref(|b| &b.where_clauses)
159 .map(|wc| wc.cloned().substitute());
160 builder.push_clause(impl_where_clauses.chain(assoc_ty_where_clauses));
164 pub struct SLGSolver {
165 pub(crate) forest: Forest<ChalkIr>,
171 fn solve_multiple(&self) {
172 let _answers = self.forest.iter_answers();
177 impl Interner for ChalkIr {
178 type InternedVariableKinds = Vec<VariableKind<ChalkIr>>;
182 let solver = SLGSolver::new();
183 solver.solve_multiple();