@@ -6,7 +6,7 @@ use crate::forest::Forest;
66use crate :: hh:: HhGoal ;
77use crate :: stack:: { Stack , StackIndex } ;
88use crate :: strand:: { CanonicalStrand , SelectedSubgoal , Strand } ;
9- use crate :: table:: AnswerIndex ;
9+ use crate :: table:: { AnswerIndex , Table } ;
1010use crate :: {
1111 Answer , CompleteAnswer , ExClause , FlounderedSubgoal , Literal , Minimums , TableIndex , TimeStamp ,
1212} ;
@@ -221,10 +221,8 @@ impl<C: Context> Forest<C> {
221221 self . tables. next_index( ) ,
222222 goal
223223 ) ;
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)
228226 }
229227
230228 /// When a table is first created, this function is invoked to
@@ -238,23 +236,13 @@ impl<C: Context> Forest<C> {
238236 /// In terms of the NFTD paper, this corresponds to the *Program
239237 /// Clause Resolution* step being applied eagerly, as many times
240238 /// 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 (
250240 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) ;
258246 match context. into_hh_goal ( goal) {
259247 HhGoal :: DomainGoal ( domain_goal) => {
260248 match context. program_clauses ( & environment, & domain_goal, & mut infer) {
@@ -277,13 +265,13 @@ impl<C: Context> Forest<C> {
277265 last_pursued_time : TimeStamp :: default ( ) ,
278266 } ;
279267 let canonical_strand = Self :: canonicalize_strand ( context, strand) ;
280- table_ref . enqueue_strand ( canonical_strand) ;
268+ table . enqueue_strand ( canonical_strand) ;
281269 }
282270 }
283271 }
284272 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 ( ) ;
287275 }
288276 }
289277 }
@@ -311,10 +299,12 @@ impl<C: Context> Forest<C> {
311299 last_pursued_time : TimeStamp :: default ( ) ,
312300 } ;
313301 let canonical_strand = Self :: canonicalize_strand ( context, strand) ;
314- table_ref . enqueue_strand ( canonical_strand) ;
302+ table . enqueue_strand ( canonical_strand) ;
315303 }
316304 }
317305 }
306+
307+ table
318308 }
319309
320310 /// Given a selected positive subgoal, applies the subgoal
0 commit comments