Skip to content

Commit da0d8e7

Browse files
authored
Merge pull request #462 from hashedone/issue260
Issue260
2 parents 1927311 + 2c232fc commit da0d8e7

File tree

5 files changed

+363
-31
lines changed

5 files changed

+363
-31
lines changed

chalk-engine/src/logic.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::forest::Forest;
66
use crate::hh::HhGoal;
77
use crate::stack::{Stack, StackIndex};
88
use crate::strand::{CanonicalStrand, SelectedSubgoal, Strand};
9-
use crate::table::AnswerIndex;
9+
use crate::table::{AnswerIndex, Table};
1010
use 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

chalk-engine/src/tables.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ impl<C: Context> Tables<C> {
2929
}
3030
}
3131

32-
pub(super) fn insert(
33-
&mut self,
34-
goal: C::UCanonicalGoalInEnvironment,
35-
coinductive_goal: bool,
36-
) -> TableIndex {
32+
pub(super) fn insert(&mut self, table: Table<C>) -> TableIndex {
33+
let goal = table.table_goal.clone();
3734
let index = self.next_index();
38-
self.tables.push(Table::new(goal.clone(), coinductive_goal));
35+
self.tables.push(table);
3936
self.table_indices.insert(goal, index);
4037
index
4138
}

tests/integration/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod panic;

0 commit comments

Comments
 (0)