Skip to content

Commit

Permalink
Find program clauses for canonical goals in SLG
Browse files Browse the repository at this point in the history
Instead of instantiating goals first, as is the case currently
  • Loading branch information
nathanwhit authored and jackh726 committed Dec 8, 2020
1 parent 40c4789 commit cc4778e
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions chalk-engine/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::{

use chalk_ir::interner::Interner;
use chalk_ir::{
AnswerSubst, Canonical, CanonicalVarKinds, ConstrainedSubst, FallibleOrFloundered, Floundered,
Goal, GoalData, InEnvironment, NoSolution, Substitution, UCanonical, UniverseMap,
AnswerSubst, Canonical, ConstrainedSubst, FallibleOrFloundered, Floundered, Goal, GoalData,
InEnvironment, NoSolution, Substitution, UCanonical, UniverseMap,
};
use chalk_solve::clauses::program_clauses_for_goal;
use chalk_solve::coinductive_goal::IsCoinductive;
Expand Down Expand Up @@ -253,24 +253,35 @@ impl<I: Interner> Forest<I> {
) -> Table<I> {
let coinductive = goal.is_coinductive(context.program());
let mut table = Table::new(goal.clone(), coinductive);
let (infer, subst, InEnvironment { environment, goal }) =
chalk_solve::infer::InferenceTable::from_canonical(
context.program().interner(),
goal.universes,
goal.canonical,
);
let mut infer = TruncatingInferenceTable::new(context.max_size(), infer);
let goal_data = goal.data(context.program().interner());

let goal_data = goal.canonical.value.goal.data(context.program().interner());
match goal_data {
GoalData::DomainGoal(domain_goal) => {
let program = context.program();

let canon_domain_goal = UCanonical {
canonical: Canonical {
binders: goal.canonical.binders,
value: InEnvironment::new(
&goal.canonical.value.environment,
domain_goal.clone(),
),
},
universes: goal.universes,
};
let clauses = program_clauses_for_goal(
program,
&environment,
&domain_goal,
&CanonicalVarKinds::empty(program.interner()),
&canon_domain_goal.canonical.value.environment,
&canon_domain_goal.canonical.value.goal,
&canon_domain_goal.canonical.binders,
);
let (infer, subst, InEnvironment { environment, goal }) =
chalk_solve::infer::InferenceTable::from_canonical(
context.program().interner(),
canon_domain_goal.universes,
canon_domain_goal.canonical,
);
let infer = TruncatingInferenceTable::new(context.max_size(), infer);

match clauses {
Ok(clauses) => {
Expand All @@ -281,7 +292,7 @@ impl<I: Interner> Forest<I> {
context.unification_database(),
context.program().interner(),
&environment,
&domain_goal,
&goal,
&subst,
&clause,
) {
Expand Down Expand Up @@ -309,6 +320,13 @@ impl<I: Interner> Forest<I> {
}

_ => {
let (infer, subst, InEnvironment { environment, goal }) =
chalk_solve::infer::InferenceTable::from_canonical(
context.program().interner(),
goal.universes,
goal.canonical,
);
let mut infer = TruncatingInferenceTable::new(context.max_size(), infer);
// `canonical_goal` is a goal. We can simplify it
// into a series of *literals*, all of which must be
// true. Thus, in EWFS terms, we are effectively
Expand Down

0 comments on commit cc4778e

Please sign in to comment.