@@ -9,9 +9,8 @@ use crate::hh::HhGoal;
9
9
use crate :: { CompleteAnswer , ExClause } ;
10
10
use chalk_base:: results:: { Fallible , Floundered } ;
11
11
use chalk_ir:: interner:: Interner ;
12
- use chalk_ir:: { Canonical , ConstrainedSubst , Constraint , DomainGoal , Environment , GenericArg , Goal , InEnvironment , Substitution , UCanonical } ;
12
+ use chalk_ir:: { AnswerSubst , Binders , Canonical , ConstrainedSubst , Constraint , DomainGoal , Environment , GenericArg , Goal , InEnvironment , ProgramClause , ProgramClauses , Substitution , UCanonical , UniverseMap } ;
13
13
use std:: fmt:: Debug ;
14
- use std:: hash:: Hash ;
15
14
16
15
/// The "context" in which the SLG solver operates. It defines all the
17
16
/// types that the SLG solver may need to refer to, as well as a few
@@ -33,57 +32,19 @@ use std::hash::Hash;
33
32
/// FIXME: Clone and Debug bounds are just for easy derive, they are
34
33
/// not actually necessary. But dang are they convenient.
35
34
pub trait Context < I : Interner > : Clone + Debug {
36
- /// A map between universes. These are produced when
37
- /// u-canonicalizing something; they map canonical results back to
38
- /// the universes from the original.
39
- type UniverseMap : Clone + Debug ;
40
-
41
- /// Extracted from a canonicalized substitution or canonicalized ex clause, this is the type of
42
- /// substitution that is fully normalized with respect to inference variables.
43
- type InferenceNormalizedSubst : Debug ;
44
-
45
- /// A u-canonicalized `GoalInEnvironment` -- this is one where the
46
- /// free universes are renumbered to consecutive integers starting
47
- /// from U1 (but preserving their relative order).
48
- type UCanonicalGoalInEnvironment : Debug + Clone + Eq + Hash ;
49
-
50
35
/// A final solution that is passed back to the user. This is
51
36
/// completely opaque to the SLG solver; it is produced by
52
37
/// `make_solution`.
53
38
type Solution ;
54
39
55
- /// Part of an answer: the canonical version of a substitution,
56
- /// region constraints, and delayed literals.
57
- type CanonicalAnswerSubst : Clone + Debug + Eq + Hash ;
58
-
59
40
/// Represents an inference table.
60
41
type InferenceTable : InferenceTable < I , Self > + Clone ;
61
42
62
- /// A "higher-order" goal, quantified over some types and/or
63
- /// lifetimes. When you have a quantification, like `forall<T> { G
64
- /// }` or `exists<T> { G }`, this represents the `<T> { G }` part.
65
- ///
66
- /// (In Lambda Prolog, this would be a "lambda predicate", like `T
67
- /// \ Goal`).
68
- type BindersGoal : Debug ;
69
-
70
- /// A rule like `DomainGoal :- Goal`.
71
- ///
72
- /// `resolvent_clause` combines a program-clause and a concrete
73
- /// goal we are trying to solve to produce an ex-clause.
74
- type ProgramClause : Debug ;
75
-
76
- /// A vector of program clauses.
77
- type ProgramClauses : Debug ;
78
-
79
43
/// How to relate two kinds when unifying: for example in rustc, we
80
44
/// may want to unify parameters either for the sub-typing relation or for
81
45
/// the equality relation.
82
46
type Variance ;
83
47
84
- /// The type used to store concrete representations of "core types" from chalk-ir.
85
- type Interner ;
86
-
87
48
/// Given an environment and a goal, glue them together to create
88
49
/// a `GoalInEnvironment`.
89
50
fn goal_in_environment (
@@ -94,24 +55,24 @@ pub trait Context<I: Interner>: Clone + Debug {
94
55
/// Extracts the inner normalized substitution from a canonical ex-clause.
95
56
fn inference_normalized_subst_from_ex_clause (
96
57
canon_ex_clause : & Canonical < ExClause < I > > ,
97
- ) -> & Self :: InferenceNormalizedSubst ;
58
+ ) -> & Substitution < I > ;
98
59
99
60
/// Extracts the inner normalized substitution from a canonical constraint subst.
100
61
fn inference_normalized_subst_from_subst (
101
- canon_ex_clause : & Self :: CanonicalAnswerSubst ,
102
- ) -> & Self :: InferenceNormalizedSubst ;
62
+ canon_ex_clause : & Canonical < AnswerSubst < I > > ,
63
+ ) -> & Substitution < I > ;
103
64
104
65
/// True if this solution has no region constraints.
105
- fn empty_constraints ( ccs : & Self :: CanonicalAnswerSubst ) -> bool ;
66
+ fn empty_constraints ( ccs : & Canonical < AnswerSubst < I > > ) -> bool ;
106
67
107
68
fn canonical ( u_canon : & UCanonical < InEnvironment < Goal < I > > > ) -> & Canonical < InEnvironment < Goal < I > > > ;
108
69
109
- fn has_delayed_subgoals ( canonical_subst : & Self :: CanonicalAnswerSubst ) -> bool ;
70
+ fn has_delayed_subgoals ( canonical_subst : & Canonical < AnswerSubst < I > > ) -> bool ;
110
71
111
72
fn num_universes ( _: & UCanonical < InEnvironment < Goal < I > > > ) -> usize ;
112
73
113
74
fn canonical_constrained_subst_from_canonical_constrained_answer (
114
- canonical_subst : & Self :: CanonicalAnswerSubst ,
75
+ canonical_subst : & Canonical < AnswerSubst < I > > ,
115
76
) -> Canonical < ConstrainedSubst < I > > ;
116
77
117
78
fn goal_from_goal_in_environment ( goal : & InEnvironment < Goal < I > > ) -> & Goal < I > ;
@@ -137,10 +98,10 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
137
98
environment : & Environment < I > ,
138
99
goal : & DomainGoal < I > ,
139
100
infer : & mut C :: InferenceTable ,
140
- ) -> Result < Vec < C :: ProgramClause > , Floundered > ;
101
+ ) -> Result < Vec < ProgramClause < I > > , Floundered > ;
141
102
142
103
// Used by: simplify
143
- fn add_clauses ( & self , env : & Environment < I > , clauses : C :: ProgramClauses ) -> Environment < I > ;
104
+ fn add_clauses ( & self , env : & Environment < I > , clauses : ProgramClauses < I > ) -> Environment < I > ;
144
105
145
106
/// Create an inference table for processing a new goal and instantiate that goal
146
107
/// in that context, returning "all the pieces".
@@ -169,7 +130,7 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
169
130
fn instantiate_answer_subst (
170
131
& self ,
171
132
num_universes : usize ,
172
- answer : & C :: CanonicalAnswerSubst ,
133
+ answer : & Canonical < AnswerSubst < I > > ,
173
134
) -> (
174
135
C :: InferenceTable ,
175
136
Substitution < I > ,
@@ -194,7 +155,7 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
194
155
/// but for the universes of universally quantified names.
195
156
fn map_goal_from_canonical (
196
157
& self ,
197
- _: & C :: UniverseMap ,
158
+ _: & UniverseMap ,
198
159
value : & Canonical < InEnvironment < Goal < I > > > ,
199
160
) -> Canonical < InEnvironment < Goal < I > > > ;
200
161
@@ -204,19 +165,19 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
204
165
/// names.
205
166
fn map_subst_from_canonical (
206
167
& self ,
207
- _: & C :: UniverseMap ,
208
- value : & C :: CanonicalAnswerSubst ,
209
- ) -> C :: CanonicalAnswerSubst ;
168
+ _: & UniverseMap ,
169
+ value : & Canonical < AnswerSubst < I > > ,
170
+ ) -> Canonical < AnswerSubst < I > > ;
210
171
211
- fn interner ( & self ) -> & C :: Interner ;
172
+ fn interner ( & self ) -> & I ;
212
173
213
174
/// Upcast this domain goal into a more general goal.
214
175
fn into_goal ( & self , domain_goal : DomainGoal < I > ) -> Goal < I > ;
215
176
216
177
fn is_trivial_substitution (
217
178
& self ,
218
179
u_canon : & UCanonical < InEnvironment < Goal < I > > > ,
219
- canonical_subst : & C :: CanonicalAnswerSubst ,
180
+ canonical_subst : & Canonical < AnswerSubst < I > > ,
220
181
) -> bool ;
221
182
222
183
/// Convert the context's goal type into the `HhGoal` type that
@@ -249,59 +210,59 @@ pub trait UnificationOps<I: Interner, C: Context<I>> {
249
210
// Used by: simplify
250
211
fn instantiate_binders_universally (
251
212
& mut self ,
252
- interner : & C :: Interner ,
253
- arg : & C :: BindersGoal ,
213
+ interner : & I ,
214
+ arg : & Binders < Goal < I > > ,
254
215
) -> Goal < I > ;
255
216
256
217
// Used by: simplify
257
218
fn instantiate_binders_existentially (
258
219
& mut self ,
259
- interner : & C :: Interner ,
260
- arg : & C :: BindersGoal ,
220
+ interner : & I ,
221
+ arg : & Binders < Goal < I > > ,
261
222
) -> Goal < I > ;
262
223
263
224
// Used by: logic (but for debugging only)
264
225
fn debug_ex_clause < ' v > (
265
226
& mut self ,
266
- interner : & C :: Interner ,
227
+ interner : & I ,
267
228
value : & ' v ExClause < I > ,
268
229
) -> Box < dyn Debug + ' v > ;
269
230
270
231
// Used by: logic
271
232
fn fully_canonicalize_goal (
272
233
& mut self ,
273
- interner : & C :: Interner ,
234
+ interner : & I ,
274
235
value : & InEnvironment < Goal < I > > ,
275
- ) -> ( UCanonical < InEnvironment < Goal < I > > > , C :: UniverseMap ) ;
236
+ ) -> ( UCanonical < InEnvironment < Goal < I > > > , UniverseMap ) ;
276
237
277
238
// Used by: logic
278
239
fn canonicalize_ex_clause (
279
240
& mut self ,
280
- interner : & C :: Interner ,
241
+ interner : & I ,
281
242
value : & ExClause < I > ,
282
243
) -> Canonical < ExClause < I > > ;
283
244
284
245
// Used by: logic
285
246
fn canonicalize_constrained_subst (
286
247
& mut self ,
287
- interner : & C :: Interner ,
248
+ interner : & I ,
288
249
subst : Substitution < I > ,
289
250
constraints : Vec < InEnvironment < Constraint < I > > > ,
290
251
) -> Canonical < ConstrainedSubst < I > > ;
291
252
292
253
// Used by: logic
293
254
fn canonicalize_answer_subst (
294
255
& mut self ,
295
- interner : & C :: Interner ,
256
+ interner : & I ,
296
257
subst : Substitution < I > ,
297
258
constraints : Vec < InEnvironment < Constraint < I > > > ,
298
259
delayed_subgoals : Vec < InEnvironment < Goal < I > > > ,
299
- ) -> C :: CanonicalAnswerSubst ;
260
+ ) -> Canonical < AnswerSubst < I > > ;
300
261
301
262
// Used by: logic
302
263
fn invert_goal (
303
264
& mut self ,
304
- interner : & C :: Interner ,
265
+ interner : & I ,
305
266
value : & InEnvironment < Goal < I > > ,
306
267
) -> Option < InEnvironment < Goal < I > > > ;
307
268
@@ -313,7 +274,7 @@ pub trait UnificationOps<I: Interner, C: Context<I>> {
313
274
// Used by: simplify
314
275
fn unify_generic_args_into_ex_clause (
315
276
& mut self ,
316
- interner : & C :: Interner ,
277
+ interner : & I ,
317
278
environment : & Environment < I > ,
318
279
variance : C :: Variance ,
319
280
a : & GenericArg < I > ,
@@ -338,12 +299,12 @@ pub trait TruncateOps<I: Interner, C: Context<I>> {
338
299
/// Check if `subgoal` is too large
339
300
fn goal_needs_truncation (
340
301
& mut self ,
341
- interner : & C :: Interner ,
302
+ interner : & I ,
342
303
subgoal : & InEnvironment < Goal < I > > ,
343
304
) -> bool ;
344
305
345
306
/// Check if `subst` is too large
346
- fn answer_needs_truncation ( & mut self , interner : & C :: Interner , subst : & Substitution < I > ) -> bool ;
307
+ fn answer_needs_truncation ( & mut self , interner : & I , subst : & Substitution < I > ) -> bool ;
347
308
}
348
309
349
310
pub trait ResolventOps < I : Interner , C : Context < I > > {
@@ -354,20 +315,20 @@ pub trait ResolventOps<I: Interner, C: Context<I>> {
354
315
/// The bindings in `infer` are unaffected by this operation.
355
316
fn resolvent_clause (
356
317
& mut self ,
357
- interner : & C :: Interner ,
318
+ interner : & I ,
358
319
environment : & Environment < I > ,
359
320
goal : & DomainGoal < I > ,
360
321
subst : & Substitution < I > ,
361
- clause : & C :: ProgramClause ,
322
+ clause : & ProgramClause < I > ,
362
323
) -> Fallible < ExClause < I > > ;
363
324
364
325
fn apply_answer_subst (
365
326
& mut self ,
366
- interner : & C :: Interner ,
327
+ interner : & I ,
367
328
ex_clause : & mut ExClause < I > ,
368
329
selected_goal : & InEnvironment < Goal < I > > ,
369
330
answer_table_goal : & Canonical < InEnvironment < Goal < I > > > ,
370
- canonical_answer_subst : & C :: CanonicalAnswerSubst ,
331
+ canonical_answer_subst : & Canonical < AnswerSubst < I > > ,
371
332
) -> Fallible < ( ) > ;
372
333
}
373
334
@@ -438,5 +399,5 @@ pub trait AnswerStream<I: Interner, C: Context<I>> {
438
399
439
400
/// Invokes `test` with each possible future answer, returning true immediately
440
401
/// if we find any answer for which `test` returns true.
441
- fn any_future_answer ( & self , test : impl Fn ( & C :: InferenceNormalizedSubst ) -> bool ) -> bool ;
402
+ fn any_future_answer ( & self , test : impl Fn ( & Substitution < I > ) -> bool ) -> bool ;
442
403
}
0 commit comments