|
1 | 1 | use cast::Cast;
|
2 | 2 | use chalk_parse::ast;
|
3 |
| -use fold::Subst; |
4 | 3 | use lalrpop_intern::InternedString;
|
5 | 4 | use solve::infer::{TyInferenceVariable, LifetimeInferenceVariable};
|
6 |
| -use std::collections::{HashSet, HashMap, BTreeMap}; |
| 5 | +use std::collections::{HashMap, BTreeMap}; |
7 | 6 | use std::sync::Arc;
|
8 | 7 |
|
9 | 8 | pub type Identifier = InternedString;
|
@@ -95,58 +94,6 @@ impl Environment {
|
95 | 94 | env.universe = UniverseIndex { counter: self.universe.counter + 1 };
|
96 | 95 | Arc::new(env)
|
97 | 96 | }
|
98 |
| - |
99 |
| - /// Generate the full set of clauses that are "syntactically implied" by the |
100 |
| - /// clauses in this environment. Currently this consists of two kinds of expansions: |
101 |
| - /// |
102 |
| - /// - Supertraits are added, so `T: Ord` would expand to `T: Ord, T: PartialOrd` |
103 |
| - /// - Projections imply that a trait is implemented, to `T: Iterator<Item=Foo>` expands to |
104 |
| - /// `T: Iterator, T: Iterator<Item=Foo>` |
105 |
| - pub fn elaborated_clauses(&self, program: &ProgramEnvironment) -> impl Iterator<Item = DomainGoal> { |
106 |
| - let mut set = HashSet::new(); |
107 |
| - set.extend(self.clauses.iter().cloned()); |
108 |
| - |
109 |
| - let mut stack: Vec<_> = set.iter().cloned().collect(); |
110 |
| - |
111 |
| - while let Some(clause) = stack.pop() { |
112 |
| - let mut push_clause = |clause: DomainGoal| { |
113 |
| - if !set.contains(&clause) { |
114 |
| - set.insert(clause.clone()); |
115 |
| - stack.push(clause); |
116 |
| - } |
117 |
| - }; |
118 |
| - |
119 |
| - match clause { |
120 |
| - DomainGoal::Implemented(ref trait_ref) => { |
121 |
| - // trait Foo<A> where Self: Bar<A> { } |
122 |
| - // T: Foo<U> |
123 |
| - // ---------------------------------------------------------- |
124 |
| - // T: Bar<U> |
125 |
| - |
126 |
| - let trait_datum = &program.trait_data[&trait_ref.trait_id]; |
127 |
| - for where_clause in &trait_datum.binders.value.where_clauses { |
128 |
| - let where_clause = Subst::apply(&trait_ref.parameters, where_clause); |
129 |
| - push_clause(where_clause); |
130 |
| - } |
131 |
| - } |
132 |
| - DomainGoal::Normalize(Normalize { ref projection, ty: _ }) => { |
133 |
| - // <T as Trait<U>>::Foo ===> V |
134 |
| - // ---------------------------------------------------------- |
135 |
| - // T: Trait<U> |
136 |
| - |
137 |
| - let (associated_ty_data, trait_params, _) = program.split_projection(projection); |
138 |
| - let trait_ref = TraitRef { |
139 |
| - trait_id: associated_ty_data.trait_id, |
140 |
| - parameters: trait_params.to_owned() |
141 |
| - }; |
142 |
| - push_clause(trait_ref.cast()); |
143 |
| - } |
144 |
| - _ => {} |
145 |
| - } |
146 |
| - } |
147 |
| - |
148 |
| - set.into_iter() |
149 |
| - } |
150 | 97 | }
|
151 | 98 |
|
152 | 99 | #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
@@ -249,6 +196,7 @@ pub struct StructDatum {
|
249 | 196 | #[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
250 | 197 | pub struct StructDatumBound {
|
251 | 198 | pub self_ty: ApplicationTy,
|
| 199 | + pub fields: Vec<Ty>, |
252 | 200 | pub where_clauses: Vec<DomainGoal>,
|
253 | 201 | }
|
254 | 202 |
|
@@ -420,6 +368,28 @@ impl DomainGoal {
|
420 | 368 | fallback_clause: false,
|
421 | 369 | }
|
422 | 370 | }
|
| 371 | + |
| 372 | + /// A clause of the form (T: Foo) expands to (T: Foo), WF(T: Foo). |
| 373 | + /// A clause of the form (T: Foo<Item = U>) expands to (T: Foo<Item = U>), WF(T: Foo). |
| 374 | + pub fn expanded(self, program: &Program) -> impl Iterator<Item = DomainGoal> { |
| 375 | + let mut expanded = vec![]; |
| 376 | + match self { |
| 377 | + DomainGoal::Implemented(ref trait_ref) => { |
| 378 | + expanded.push(WellFormed::TraitRef(trait_ref.clone()).cast()); |
| 379 | + } |
| 380 | + DomainGoal::Normalize(Normalize { ref projection, .. }) => { |
| 381 | + let (associated_ty_data, trait_params, _) = program.split_projection(&projection); |
| 382 | + let trait_ref = TraitRef { |
| 383 | + trait_id: associated_ty_data.trait_id, |
| 384 | + parameters: trait_params.to_owned() |
| 385 | + }; |
| 386 | + expanded.push(WellFormed::TraitRef(trait_ref).cast()); |
| 387 | + } |
| 388 | + _ => () |
| 389 | + }; |
| 390 | + expanded.push(self.cast()); |
| 391 | + expanded.into_iter() |
| 392 | + } |
423 | 393 | }
|
424 | 394 |
|
425 | 395 | #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
0 commit comments