@@ -8,6 +8,7 @@ use crate::stack::StackIndex;
8
8
use crate :: strand:: { CanonicalStrand , SelectedSubgoal , Strand } ;
9
9
use crate :: table:: { Answer , AnswerIndex } ;
10
10
use fxhash:: FxHashSet ;
11
+ use std:: marker:: PhantomData ;
11
12
use std:: mem;
12
13
13
14
type RootSearchResult < T > = Result < T , RootSearchFail > ;
@@ -78,7 +79,7 @@ enum EnsureSuccess {
78
79
Coinductive ,
79
80
}
80
81
81
- impl < C : Context > Forest < C > {
82
+ impl < C : Context , CO : ContextOps < C > > Forest < C , CO > {
82
83
/// Ensures that answer with the given index is available from the
83
84
/// given table. This may require activating a strand. Returns
84
85
/// `Ok(())` if the answer is available and otherwise a
@@ -111,11 +112,11 @@ impl<C: Context> Forest<C> {
111
112
) -> bool {
112
113
if let Some ( answer) = self . tables [ table] . answer ( answer) {
113
114
info ! ( "answer cached = {:?}" , answer) ;
114
- return test ( C :: inference_normalized_subst_from_subst ( & answer. subst ) ) ;
115
+ return test ( CO :: inference_normalized_subst_from_subst ( & answer. subst ) ) ;
115
116
}
116
117
117
118
self . tables [ table] . strands_mut ( ) . any ( |strand| {
118
- test ( C :: inference_normalized_subst_from_ex_clause ( & strand. canonical_ex_clause ) )
119
+ test ( CO :: inference_normalized_subst_from_ex_clause ( & strand. canonical_ex_clause ) )
119
120
} )
120
121
}
121
122
@@ -205,7 +206,7 @@ impl<C: Context> Forest<C> {
205
206
loop {
206
207
match self . tables [ table] . pop_next_strand ( ) {
207
208
Some ( canonical_strand) => {
208
- let num_universes = C :: num_universes ( & self . tables [ table] . table_goal ) ;
209
+ let num_universes = CO :: num_universes ( & self . tables [ table] . table_goal ) ;
209
210
let result = Self :: with_instantiated_strand (
210
211
self . context . clone ( ) ,
211
212
num_universes,
@@ -263,10 +264,10 @@ impl<C: Context> Forest<C> {
263
264
}
264
265
265
266
fn with_instantiated_strand < R > (
266
- context : C ,
267
+ context : CO ,
267
268
num_universes : usize ,
268
269
canonical_strand : & CanonicalStrand < C > ,
269
- op : impl WithInstantiatedStrand < C , Output = R > ,
270
+ op : impl WithInstantiatedStrand < C , CO , Output = R > ,
270
271
) -> R {
271
272
let CanonicalStrand {
272
273
canonical_ex_clause,
@@ -278,15 +279,18 @@ impl<C: Context> Forest<C> {
278
279
With {
279
280
op,
280
281
selected_subgoal : selected_subgoal. clone ( ) ,
282
+ ops : PhantomData ,
281
283
} ,
282
284
) ;
283
285
284
- struct With < C : Context , OP : WithInstantiatedStrand < C > > {
286
+ struct With < C : Context , CO : ContextOps < C > , OP : WithInstantiatedStrand < C , CO > > {
285
287
op : OP ,
286
288
selected_subgoal : Option < SelectedSubgoal < C > > ,
289
+ ops : PhantomData < CO > ,
287
290
}
288
291
289
- impl < C : Context , OP : WithInstantiatedStrand < C > > WithInstantiatedExClause < C > for With < C , OP > {
292
+ impl < C : Context , CO : ContextOps < C > , OP : WithInstantiatedStrand < C , CO > >
293
+ WithInstantiatedExClause < C > for With < C , CO , OP > {
290
294
type Output = OP :: Output ;
291
295
292
296
fn with < I : InferenceContext < C > > (
@@ -399,7 +403,7 @@ impl<C: Context> Forest<C> {
399
403
fn delay_strands_after_cycle ( & mut self , table : TableIndex , visited : & mut FxHashSet < TableIndex > ) {
400
404
let mut tables = vec ! [ ] ;
401
405
402
- let num_universes = C :: num_universes ( & self . tables [ table] . table_goal ) ;
406
+ let num_universes = CO :: num_universes ( & self . tables [ table] . table_goal ) ;
403
407
for canonical_strand in self . tables [ table] . strands_mut ( ) {
404
408
// FIXME if CanonicalExClause were not held abstract, we
405
409
// could do this in place like we used to (and
@@ -627,8 +631,8 @@ impl<C: Context> Forest<C> {
627
631
// must be backed by an impl *eventually*).
628
632
let is_trivial_answer = {
629
633
answer. delayed_literals . is_empty ( )
630
- && C :: is_trivial_substitution ( & self . tables [ table] . table_goal , & answer. subst )
631
- && C :: empty_constraints ( & answer. subst )
634
+ && CO :: is_trivial_substitution ( & self . tables [ table] . table_goal , & answer. subst )
635
+ && CO :: empty_constraints ( & answer. subst )
632
636
} ;
633
637
634
638
if self . tables [ table] . push_answer ( answer) {
@@ -726,12 +730,13 @@ impl<C: Context> Forest<C> {
726
730
PushInitialStrandsInstantiated { table, this : self } ,
727
731
) ;
728
732
729
- struct PushInitialStrandsInstantiated < ' a , C : Context + ' a > {
733
+ struct PushInitialStrandsInstantiated < ' a , C : Context + ' a , CO : ContextOps < C > + ' a > {
730
734
table : TableIndex ,
731
- this : & ' a mut Forest < C > ,
735
+ this : & ' a mut Forest < C , CO > ,
732
736
}
733
737
734
- impl < C : Context > WithInstantiatedUCanonicalGoal < C > for PushInitialStrandsInstantiated < ' a , C > {
738
+ impl < C : Context , CO : ContextOps < C > > WithInstantiatedUCanonicalGoal < C >
739
+ for PushInitialStrandsInstantiated < ' a , C , CO > {
735
740
type Output = ( ) ;
736
741
737
742
fn with < I : InferenceContext < C > > (
@@ -1044,10 +1049,10 @@ impl<C: Context> Forest<C> {
1044
1049
) ,
1045
1050
} ;
1046
1051
1047
- let table_goal = & C :: map_goal_from_canonical ( & universe_map,
1048
- & C :: canonical ( & self . tables [ subgoal_table] . table_goal ) ) ;
1052
+ let table_goal = & CO :: map_goal_from_canonical ( & universe_map,
1053
+ & CO :: canonical ( & self . tables [ subgoal_table] . table_goal ) ) ;
1049
1054
let answer_subst =
1050
- & C :: map_subst_from_canonical ( & universe_map, & self . answer ( subgoal_table, answer_index) . subst ) ;
1055
+ & CO :: map_subst_from_canonical ( & universe_map, & self . answer ( subgoal_table, answer_index) . subst ) ;
1051
1056
match infer. apply_answer_subst ( ex_clause, & subgoal, table_goal, answer_subst) {
1052
1057
Ok ( mut ex_clause) => {
1053
1058
// If the answer had delayed literals, we have to
@@ -1301,18 +1306,18 @@ impl<C: Context> Forest<C> {
1301
1306
}
1302
1307
}
1303
1308
1304
- trait WithInstantiatedStrand < C : Context > {
1309
+ trait WithInstantiatedStrand < C : Context , CO : AggregateOps < C > > {
1305
1310
type Output ;
1306
1311
1307
1312
fn with ( self , strand : Strand < ' _ , C , impl InferenceContext < C > > ) -> Self :: Output ;
1308
1313
}
1309
1314
1310
- struct PursueStrand < ' a , C : Context + ' a > {
1311
- forest : & ' a mut Forest < C > ,
1315
+ struct PursueStrand < ' a , C : Context + ' a , CO : ContextOps < C > + ' a > {
1316
+ forest : & ' a mut Forest < C , CO > ,
1312
1317
depth : StackIndex ,
1313
1318
}
1314
1319
1315
- impl < C : Context > WithInstantiatedStrand < C > for PursueStrand < ' a , C > {
1320
+ impl < C : Context , CO : ContextOps < C > > WithInstantiatedStrand < C , CO > for PursueStrand < ' a , C , CO > {
1316
1321
type Output = StrandResult < C , ( ) > ;
1317
1322
1318
1323
fn with ( self , strand : Strand < ' _ , C , impl InferenceContext < C > > ) -> Self :: Output {
@@ -1324,10 +1329,10 @@ struct DelayStrandAfterCycle {
1324
1329
table : TableIndex ,
1325
1330
}
1326
1331
1327
- impl < C : Context > WithInstantiatedStrand < C > for DelayStrandAfterCycle {
1332
+ impl < C : Context , CO : ContextOps < C > > WithInstantiatedStrand < C , CO > for DelayStrandAfterCycle {
1328
1333
type Output = ( CanonicalStrand < C > , TableIndex ) ;
1329
1334
1330
1335
fn with ( self , strand : Strand < ' _ , C , impl InferenceContext < C > > ) -> Self :: Output {
1331
- <Forest < C > >:: delay_strand_after_cycle ( self . table , strand)
1336
+ <Forest < C , CO > >:: delay_strand_after_cycle ( self . table , strand)
1332
1337
}
1333
1338
}
0 commit comments