Skip to content

Commit 3238c6d

Browse files
authored
Merge pull request #193 from KiChjang/smarter-goal-selection
Implement goal prioritization in logic
2 parents 6fd1808 + a859d09 commit 3238c6d

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

chalk-engine/src/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ pub trait InferenceTable<C: Context, I: Context>:
262262

263263
/// Create a "cannot prove" goal (see `HhGoal::CannotProve`).
264264
fn cannot_prove(&self) -> I::Goal;
265+
266+
/// Selects the next appropriate subgoal index for evaluation.
267+
/// Used by: logic
268+
fn next_subgoal_index(&mut self, ex_clause: &ExClause<I>) -> usize;
265269
}
266270

267271
/// Methods for unifying and manipulating terms and binders.

chalk-engine/src/logic.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,7 @@ impl<C: Context> Forest<C> {
497497
return self.pursue_answer(depth, strand);
498498
}
499499

500-
// For now, we always pick the last subgoal in the
501-
// list.
502-
//
503-
// FIXME(rust-lang/chalk#80) -- we should be more
504-
// selective. For example, we don't want to pick a
505-
// negative literal that will flounder, and we don't want
506-
// to pick things like `?T: Sized` if we can help it.
507-
let subgoal_index = strand.ex_clause.subgoals.len() - 1;
500+
let subgoal_index = strand.infer.next_subgoal_index(&strand.ex_clause);
508501

509502
// Get or create table for this subgoal.
510503
match self.get_or_create_table_for_subgoal(

chalk-solve/src/solve/slg.rs

+12
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ impl<'me> context::InferenceTable<SlgContext, SlgContext> for TruncatingInferenc
210210
fn cannot_prove(&self) -> Goal {
211211
Goal::CannotProve(())
212212
}
213+
214+
// Used by: logic
215+
fn next_subgoal_index(&mut self, ex_clause: &ExClause<SlgContext>) -> usize {
216+
// For now, we always pick the last subgoal in the
217+
// list.
218+
//
219+
// FIXME(rust-lang-nursery/chalk#80) -- we should be more
220+
// selective. For example, we don't want to pick a
221+
// negative literal that will flounder, and we don't want
222+
// to pick things like `?T: Sized` if we can help it.
223+
ex_clause.subgoals.len() - 1
224+
}
213225
}
214226

215227
impl<'me> context::UnificationOps<SlgContext, SlgContext> for TruncatingInferenceTable<'me> {

0 commit comments

Comments
 (0)