Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for trivial cycles in persue_answer #469

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions chalk-engine/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,14 +909,9 @@ impl<'forest, C: Context + 'forest, CO: ContextOps<C> + 'forest> SolveState<'for
// we might have to build on it (see the
// Delayed Trivial Self Cycle, Variant 3
// example).
let (_, _, _, table_goal) = self
.context
.instantiate_ucanonical_goal(&self.forest.tables[table].table_goal);

let answer = self.forest.answer(table, answer_index);
if let Some(strand) =
self.create_refinement_strand(table, answer, table_goal)
{
if let Some(strand) = self.create_refinement_strand(table, answer) {
self.forest.tables[table].enqueue_strand(strand);
}

Expand Down Expand Up @@ -964,7 +959,6 @@ impl<'forest, C: Context + 'forest, CO: ContextOps<C> + 'forest> SolveState<'for
&self,
table: TableIndex,
answer: &Answer<C>,
table_goal: C::Goal,
) -> Option<CanonicalStrand<C>> {
// If there are no delayed subgoals, then there is no need for
// a refinement strand.
Expand All @@ -977,16 +971,8 @@ impl<'forest, C: Context + 'forest, CO: ContextOps<C> + 'forest> SolveState<'for
.context
.instantiate_answer_subst(num_universes, &answer.subst);

// FIXME: it would be nice if these delayed subgoals didn't get added to the answer
// at all. However, we can't compare the delayed subgoals with the table goal until
// we call `canonicalize_answer_subst` in `pursue_answer`. However, at this point,
// it's a bit late since `pursue_answer` doesn't know about the table goal. This could
// be refactored a bit.
let filtered_delayed_subgoals = delayed_subgoals
let delayed_subgoals = delayed_subgoals
.into_iter()
.filter(|delayed_subgoal| {
*C::goal_from_goal_in_environment(delayed_subgoal) != table_goal
})
.map(Literal::Positive)
.collect();

Expand All @@ -996,7 +982,7 @@ impl<'forest, C: Context + 'forest, CO: ContextOps<C> + 'forest> SolveState<'for
subst,
ambiguous: answer.ambiguous,
constraints,
subgoals: filtered_delayed_subgoals,
subgoals: delayed_subgoals,
delayed_subgoals: Vec::new(),
answer_time: TimeStamp::default(),
floundered_subgoals: Vec::new(),
Expand Down Expand Up @@ -1328,11 +1314,23 @@ impl<'forest, C: Context + 'forest, CO: ContextOps<C> + 'forest> SolveState<'for
return None;
}

let table = self.stack.top().table;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already in scope at the beginning of the function.

let table_goal = &self.forest.tables[table].table_goal;

let filtered_delayed_subgoals = delayed_subgoals
.into_iter()
.filter(|delayed_subgoal| {
let (canonicalized, _) =
infer.fully_canonicalize_goal(self.context.interner(), delayed_subgoal);
jackh726 marked this conversation as resolved.
Show resolved Hide resolved
*table_goal != canonicalized
})
.collect();

let subst = infer.canonicalize_answer_subst(
self.context.interner(),
subst,
constraints,
delayed_subgoals,
filtered_delayed_subgoals,
);
debug!("answer: table={:?}, subst={:?}", table, subst);

Expand Down
19 changes: 3 additions & 16 deletions chalk-solve/src/solve/slg/resolvent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ impl<I: Interner> context::ResolventOps<SlgContext<I>> for TruncatingInferenceTa
.infer
.instantiate_canonical(interner, &canonical_answer_subst);

let table_goal = self
.infer
.instantiate_canonical(interner, &answer_table_goal);

AnswerSubstitutor::substitute(
interner,
&mut self.infer,
Expand All @@ -250,18 +246,9 @@ impl<I: Interner> context::ResolventOps<SlgContext<I>> for TruncatingInferenceTa
selected_goal,
)?;
ex_clause.constraints.extend(answer_constraints);

for delayed_subgoal in delayed_subgoals {
// FIXME: is this always valid or would we ever run
// into an issue with normalization? (Would this even
// be a "trivial self-cycle"?)
// Only add the delayed_subgoals to the ex-clause if
// it isn't a trivial self-cycle
if delayed_subgoal.goal != table_goal.goal {
ex_clause.delayed_subgoals.push(delayed_subgoal);
}
}

// at that point we should only have goals that stemmed
// from non trivial self cycles
ex_clause.delayed_subgoals.extend(delayed_subgoals);
Ok(())
}
}
Expand Down