@@ -8,7 +8,7 @@ crate mod prelude;
8
8
9
9
/// The "context" in which the SLG solver operates.
10
10
pub trait Context : Sized + Clone + Debug + ContextOps < Self > + AggregateOps < Self > {
11
- type CanonicalExClause : CanonicalExClause < Self > ;
11
+ type CanonicalExClause : Debug ;
12
12
13
13
/// A map between universes. These are produced when
14
14
/// u-canonicalizing something; they map canonical results back to
@@ -41,33 +41,39 @@ pub trait Context: Sized + Clone + Debug + ContextOps<Self> + AggregateOps<Self>
41
41
/// completely opaque to the SLG solver; it is produced by
42
42
/// `make_solution`.
43
43
type Solution ;
44
+
45
+ /// Extracts the inner normalized substitution.
46
+ fn inference_normalized_subst ( canon_ex_clause : & Self :: CanonicalExClause )
47
+ -> & Self :: InferenceNormalizedSubst ;
48
+ }
49
+
50
+ pub trait ExClauseContext < C : Context > : Sized + Debug {
51
+ /// Represents a substitution from the "canonical variables" found
52
+ /// in a canonical goal to specific values.
53
+ type Substitution : Debug ;
54
+
55
+ /// Represents a region constraint that will be propagated back
56
+ /// (but not verified).
57
+ type RegionConstraint : Debug ;
58
+
59
+ /// Represents a goal along with an environment.
60
+ type GoalInEnvironment : Debug + Clone + Eq + Hash ;
44
61
}
45
62
46
63
/// The set of types belonging to an "inference context"; in rustc,
47
64
/// these types are tied to the lifetime of the arena within which an
48
65
/// inference context operates.
49
- pub trait InferenceContext < C : Context > : Sized + Debug {
66
+ pub trait InferenceContext < C : Context > : ExClauseContext < C > {
50
67
/// Represents a set of hypotheses that are assumed to be true.
51
- type Environment : Environment < C , Self > ;
68
+ type Environment : Debug + Clone ;
52
69
53
70
/// Goals correspond to things we can prove.
54
- type Goal : Goal < C , Self > ;
71
+ type Goal : Clone + Debug + Eq ;
55
72
56
73
/// A goal that can be targeted by a program clause. The SLG
57
74
/// solver treats these opaquely; in contrast, it understands
58
75
/// "meta" goals like `G1 && G2` and so forth natively.
59
- type DomainGoal : DomainGoal < C , Self > ;
60
-
61
- /// Represents a goal along with an environment.
62
- type GoalInEnvironment : GoalInEnvironment < C , Self > ;
63
-
64
- /// Represents a region constraint that will be propagated back
65
- /// (but not verified).
66
- type RegionConstraint : Debug ;
67
-
68
- /// Represents a substitution from the "canonical variables" found
69
- /// in a canonical goal to specific values.
70
- type Substitution : Debug ;
76
+ type DomainGoal : Debug ;
71
77
72
78
/// A "higher-order" goal, quantified over some types and/or
73
79
/// lifetimes. When you have a quantification, like `forall<T> { G
@@ -89,7 +95,34 @@ pub trait InferenceContext<C: Context>: Sized + Debug {
89
95
90
96
/// The successful result from unification: contains new subgoals
91
97
/// and things that can be attached to an ex-clause.
92
- type UnificationResult : UnificationResult < C , Self > ;
98
+ type UnificationResult ;
99
+
100
+ fn goal_in_environment ( environment : & Self :: Environment , goal : Self :: Goal ) -> Self :: GoalInEnvironment ;
101
+
102
+ /// Upcast this domain goal into a more general goal.
103
+ fn into_goal ( domain_goal : Self :: DomainGoal ) -> Self :: Goal ;
104
+
105
+ /// Create a "cannot prove" goal (see `HhGoal::CannotProve`).
106
+ fn cannot_prove ( ) -> Self :: Goal ;
107
+
108
+ /// Convert the context's goal type into the `HhGoal` type that
109
+ /// the SLG solver understands. The expectation is that the
110
+ /// context's goal type has the same set of variants, but with
111
+ /// different names and a different setup. If you inspect
112
+ /// `HhGoal`, you will see that this is a "shallow" or "lazy"
113
+ /// conversion -- that is, we convert the outermost goal into an
114
+ /// `HhGoal`, but the goals contained within are left as context
115
+ /// goals.
116
+ fn into_hh_goal ( goal : Self :: Goal ) -> HhGoal < C , Self > ;
117
+
118
+ /// Add the residual subgoals as new subgoals of the ex-clause.
119
+ /// Also add region constraints.
120
+ fn into_ex_clause ( result : Self :: UnificationResult , ex_clause : & mut ExClause < C , Self > ) ;
121
+
122
+ // Used by: simplify
123
+ fn add_clauses ( env : & Self :: Environment ,
124
+ clauses : impl IntoIterator < Item = Self :: ProgramClause > )
125
+ -> Self :: Environment ;
93
126
}
94
127
95
128
pub trait ContextOps < C : Context > {
@@ -273,27 +306,6 @@ pub trait ResolventOps<C: Context, I: InferenceContext<C>> {
273
306
) -> Fallible < ExClause < C , I > > ;
274
307
}
275
308
276
- pub trait GoalInEnvironment < C : Context , I : InferenceContext < C > > :
277
- Debug + Clone + Eq + Ord + Hash
278
- {
279
- fn new (
280
- environment : & I :: Environment ,
281
- goal : I :: Goal ,
282
- ) -> Self ;
283
-
284
- fn environment ( & self ) -> & I :: Environment ;
285
- }
286
-
287
- pub trait Environment < C : Context , I : InferenceContext < C > > : Debug + Clone {
288
- // Used by: simplify
289
- fn add_clauses ( & self , clauses : impl IntoIterator < Item = I :: ProgramClause > ) -> Self ;
290
- }
291
-
292
- pub trait CanonicalExClause < C : Context > : Debug {
293
- /// Extracts the inner normalized substitution.
294
- fn inference_normalized_subst ( & self ) -> & C :: InferenceNormalizedSubst ;
295
- }
296
-
297
309
pub trait CanonicalConstrainedSubst < C : Context > : Clone + Debug + Eq + Hash + Ord {
298
310
/// True if this solution has no region constraints.
299
311
fn empty_constraints ( & self ) -> bool ;
@@ -302,26 +314,6 @@ pub trait CanonicalConstrainedSubst<C: Context>: Clone + Debug + Eq + Hash + Ord
302
314
fn inference_normalized_subst ( & self ) -> & C :: InferenceNormalizedSubst ;
303
315
}
304
316
305
- pub trait DomainGoal < C : Context , I : InferenceContext < C > > : Debug {
306
- /// Upcast this domain goal into a more general goal.
307
- fn into_goal ( self ) -> I :: Goal ;
308
- }
309
-
310
- pub trait Goal < C : Context , I : InferenceContext < C > > : Clone + Debug + Eq {
311
- /// Create a "cannot prove" goal (see `HhGoal::CannotProve`).
312
- fn cannot_prove ( ) -> Self ;
313
-
314
- /// Convert the context's goal type into the `HhGoal` type that
315
- /// the SLG solver understands. The expectation is that the
316
- /// context's goal type has the same set of variants, but with
317
- /// different names and a different setup. If you inspect
318
- /// `HhGoal`, you will see that this is a "shallow" or "lazy"
319
- /// conversion -- that is, we convert the outermost goal into an
320
- /// `HhGoal`, but the goals contained within are left as context
321
- /// goals.
322
- fn into_hh_goal ( self ) -> HhGoal < C , I > ;
323
- }
324
-
325
317
pub trait UniverseMap < C : Context > : Clone + Debug {
326
318
/// Convert a goal G *from* the canonical universes *into* our
327
319
/// local universes. This will yield a goal G' that is the same
@@ -341,23 +333,12 @@ pub trait UniverseMap<C: Context>: Clone + Debug {
341
333
) -> C :: CanonicalConstrainedSubst ;
342
334
}
343
335
344
- /// Embodies the result of a unification operation: we presume that
345
- /// unification may produce new residual subgoals, which must be
346
- /// further proven, as well as region constraints.
347
- pub trait UnificationResult < C : Context , I : InferenceContext < C > > {
348
- /// Add the residual subgoals as new subgoals of the ex-clause.
349
- /// Also add region constraints.
350
- fn into_ex_clause ( self , ex_clause : & mut ExClause < C , I > ) ;
351
- }
352
-
353
336
pub trait AnswerStream < C : Context > {
354
337
fn peek_answer ( & mut self ) -> Option < SimplifiedAnswer < C > > ;
355
338
fn next_answer ( & mut self ) -> Option < SimplifiedAnswer < C > > ;
356
339
357
340
/// Invokes `test` with each possible future answer, returning true immediately
358
341
/// if we find any answer for which `test` returns true.
359
- fn any_future_answer (
360
- & mut self ,
361
- test : impl FnMut ( & C :: InferenceNormalizedSubst ) -> bool ,
362
- ) -> bool ;
342
+ fn any_future_answer ( & mut self , test : impl FnMut ( & C :: InferenceNormalizedSubst ) -> bool )
343
+ -> bool ;
363
344
}
0 commit comments