@@ -6,7 +6,7 @@ use crate::forest::Forest;
6
6
use crate :: hh:: HhGoal ;
7
7
use crate :: stack:: { Stack , StackIndex } ;
8
8
use crate :: strand:: { CanonicalStrand , SelectedSubgoal , Strand } ;
9
- use crate :: table:: AnswerIndex ;
9
+ use crate :: table:: { AnswerIndex , Table } ;
10
10
use crate :: {
11
11
Answer , CompleteAnswer , ExClause , FlounderedSubgoal , Literal , Minimums , TableIndex , TimeStamp ,
12
12
} ;
@@ -221,10 +221,8 @@ impl<C: Context> Forest<C> {
221
221
self . tables. next_index( ) ,
222
222
goal
223
223
) ;
224
- let coinductive_goal = context. is_coinductive ( & goal) ;
225
- let table = self . tables . insert ( goal, coinductive_goal) ;
226
- self . push_initial_strands ( context, table) ;
227
- table
224
+ let table = Self :: build_table ( context, self . tables . next_index ( ) , goal) ;
225
+ self . tables . insert ( table)
228
226
}
229
227
230
228
/// When a table is first created, this function is invoked to
@@ -238,23 +236,13 @@ impl<C: Context> Forest<C> {
238
236
/// In terms of the NFTD paper, this corresponds to the *Program
239
237
/// Clause Resolution* step being applied eagerly, as many times
240
238
/// as possible.
241
- fn push_initial_strands ( & mut self , context : & impl ContextOps < C > , table : TableIndex ) {
242
- // Instantiate the table goal with fresh inference variables.
243
- let table_goal = self . tables [ table] . table_goal . clone ( ) ;
244
- let ( infer, subst, environment, goal) = context. instantiate_ucanonical_goal ( & table_goal) ;
245
- self . push_initial_strands_instantiated ( context, table, infer, subst, environment, goal) ;
246
- }
247
-
248
- fn push_initial_strands_instantiated (
249
- & mut self ,
239
+ fn build_table (
250
240
context : & impl ContextOps < C > ,
251
- table : TableIndex ,
252
- mut infer : C :: InferenceTable ,
253
- subst : C :: Substitution ,
254
- environment : C :: Environment ,
255
- goal : C :: Goal ,
256
- ) {
257
- let table_ref = & mut self . tables [ table] ;
241
+ table_idx : TableIndex ,
242
+ goal : C :: UCanonicalGoalInEnvironment ,
243
+ ) -> Table < C > {
244
+ let mut table = Table :: new ( goal. clone ( ) , context. is_coinductive ( & goal) ) ;
245
+ let ( mut infer, subst, environment, goal) = context. instantiate_ucanonical_goal ( & goal) ;
258
246
match context. into_hh_goal ( goal) {
259
247
HhGoal :: DomainGoal ( domain_goal) => {
260
248
match context. program_clauses ( & environment, & domain_goal, & mut infer) {
@@ -277,13 +265,13 @@ impl<C: Context> Forest<C> {
277
265
last_pursued_time : TimeStamp :: default ( ) ,
278
266
} ;
279
267
let canonical_strand = Self :: canonicalize_strand ( context, strand) ;
280
- table_ref . enqueue_strand ( canonical_strand) ;
268
+ table . enqueue_strand ( canonical_strand) ;
281
269
}
282
270
}
283
271
}
284
272
Err ( Floundered ) => {
285
- debug ! ( "Marking table {:?} as floundered!" , table ) ;
286
- table_ref . mark_floundered ( ) ;
273
+ debug ! ( "Marking table {:?} as floundered!" , table_idx ) ;
274
+ table . mark_floundered ( ) ;
287
275
}
288
276
}
289
277
}
@@ -311,10 +299,12 @@ impl<C: Context> Forest<C> {
311
299
last_pursued_time : TimeStamp :: default ( ) ,
312
300
} ;
313
301
let canonical_strand = Self :: canonicalize_strand ( context, strand) ;
314
- table_ref . enqueue_strand ( canonical_strand) ;
302
+ table . enqueue_strand ( canonical_strand) ;
315
303
}
316
304
}
317
305
}
306
+
307
+ table
318
308
}
319
309
320
310
/// Given a selected positive subgoal, applies the subgoal
0 commit comments