1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
use crate::fallible::Fallible;
use crate::{ExClause, SimplifiedAnswer};
use crate::hh::HhGoal;
use std::fmt::Debug;
use std::hash::Hash;
crate mod prelude;
pub trait Context
: Sized + Clone + Debug + ContextOps<Self> + Aggregate<Self>
{
type Environment: Environment<Self>;
type Goal: Goal<Self>;
type DomainGoal: DomainGoal<Self>;
type UniverseMap: UniverseMap<Self>;
type GoalInEnvironment: GoalInEnvironment<Self>;
type CanonicalExClause: Debug + Clone;
type CanonicalGoalInEnvironment: Debug + Clone;
type UCanonicalGoalInEnvironment: UCanonicalGoalInEnvironment<Self>;
type RegionConstraint: ConstraintInEnvironment<Self>;
type Substitution: Substitution<Self>;
type CanonicalConstrainedSubst: CanonicalConstrainedSubst<Self>;
type BindersGoal: BindersGoal<Self>;
type Parameter: Parameter<Self>;
type ProgramClause: ProgramClause<Self>;
type UnificationResult: UnificationResult<Self>;
type Solution;
}
pub trait TruncateOps<C: Context> {
fn truncate_goal(
&mut self,
subgoal: &C::GoalInEnvironment,
) -> Option<C::GoalInEnvironment>;
fn truncate_answer(
&mut self,
subst: &C::Substitution,
) -> Option<C::Substitution>;
}
pub trait ContextOps<C: Context> {
fn is_coinductive(&self, goal: &C::UCanonicalGoalInEnvironment) -> bool;
fn program_clauses(
&self,
environment: &C::Environment,
goal: &C::DomainGoal,
) -> Vec<C::ProgramClause>;
fn goal_in_environment(environment: &C::Environment, goal: C::Goal) -> C::GoalInEnvironment;
fn instantiate_ucanonical_goal<R>(
&self,
arg: &C::UCanonicalGoalInEnvironment,
op: impl FnOnce(&mut dyn InferenceTable<C>, C::Substitution, C::Environment, C::Goal) -> R,
) -> R;
fn instantiate_ex_clause<R>(
&self,
num_universes: usize,
canonical_ex_clause: &C::CanonicalExClause,
op: impl FnOnce(&mut dyn InferenceTable<C>, ExClause<C>) -> R
) -> R;
}
pub trait ResolventOps<C: Context> {
fn resolvent_clause(
&mut self,
environment: &C::Environment,
goal: &C::DomainGoal,
subst: &C::Substitution,
clause: &C::ProgramClause,
) -> Fallible<C::CanonicalExClause>;
fn apply_answer_subst(
&mut self,
ex_clause: ExClause<C>,
selected_goal: &C::GoalInEnvironment,
answer_table_goal: &C::CanonicalGoalInEnvironment,
canonical_answer_subst: &C::CanonicalConstrainedSubst,
) -> Fallible<ExClause<C>>;
}
pub trait Aggregate<C: Context> {
fn make_solution(
&self,
root_goal: &C::CanonicalGoalInEnvironment,
simplified_answers: impl IntoIterator<Item = SimplifiedAnswer<C>>,
) -> Option<C::Solution>;
}
pub trait UCanonicalGoalInEnvironment<C: Context>: Debug + Clone + Eq + Hash {
fn canonical(&self) -> &C::CanonicalGoalInEnvironment;
fn is_trivial_substitution(&self, canonical_subst: &C::CanonicalConstrainedSubst) -> bool;
fn num_universes(&self) -> usize;
}
pub trait GoalInEnvironment<C: Context>: Debug + Clone + Eq + Ord + Hash {
fn environment(&self) -> &C::Environment;
}
pub trait Environment<C: Context>: Debug + Clone + Eq + Ord + Hash {
fn add_clauses(&self, clauses: impl IntoIterator<Item = C::DomainGoal>) -> Self;
}
pub trait InferenceTable<C: Context>: ResolventOps<C> + TruncateOps<C> {
fn instantiate_binders_universally(&mut self, arg: &C::BindersGoal) -> C::Goal;
fn instantiate_binders_existentially(&mut self, arg: &C::BindersGoal) -> C::Goal;
fn debug_ex_clause(&mut self, value: &'v ExClause<C>) -> Box<dyn Debug + 'v>;
fn canonicalize_goal(&mut self, value: &C::GoalInEnvironment) -> C::CanonicalGoalInEnvironment;
fn canonicalize_ex_clause(&mut self, value: &ExClause<C>) -> C::CanonicalExClause;
fn canonicalize_constrained_subst(
&mut self,
subst: C::Substitution,
constraints: Vec<C::RegionConstraint>,
) -> C::CanonicalConstrainedSubst;
fn u_canonicalize_goal(
&mut self,
value: &C::CanonicalGoalInEnvironment,
) -> (C::UCanonicalGoalInEnvironment, C::UniverseMap);
fn invert_goal(&mut self, value: &C::GoalInEnvironment) -> Option<C::GoalInEnvironment>;
fn unify_parameters(
&mut self,
environment: &C::Environment,
a: &C::Parameter,
b: &C::Parameter,
) -> Fallible<C::UnificationResult>;
}
pub trait Substitution<C: Context>: Clone + Debug {}
pub trait CanonicalConstrainedSubst<C: Context>: Clone + Debug + Eq + Hash + Ord {
fn empty_constraints(&self) -> bool;
}
pub trait ConstraintInEnvironment<C: Context>: Clone + Debug + Eq + Hash + Ord {}
pub trait DomainGoal<C: Context>: Clone + Debug + Eq + Hash + Ord {
fn into_goal(self) -> C::Goal;
}
pub trait Goal<C: Context>: Clone + Debug + Eq + Hash + Ord {
fn cannot_prove() -> Self;
fn into_hh_goal(self) -> HhGoal<C>;
}
pub trait Parameter<C: Context>: Clone + Debug + Eq + Hash + Ord {}
pub trait ProgramClause<C: Context>: Debug {}
pub trait BindersGoal<C: Context>: Clone + Debug + Eq + Hash + Ord {}
pub trait UniverseMap<C: Context>: Clone + Debug {
fn map_goal_from_canonical(
&self,
value: &C::CanonicalGoalInEnvironment,
) -> C::CanonicalGoalInEnvironment;
fn map_subst_from_canonical(
&self,
value: &C::CanonicalConstrainedSubst,
) -> C::CanonicalConstrainedSubst;
}
pub trait UnificationResult<C: Context> {
fn into_ex_clause(self, ex_clause: &mut ExClause<C>);
}