Skip to content

Commit 0abdef9

Browse files
committed
Don't inherit clause priority in implications
So if we had some implication A => B, if the solution for A had low priority, we also made B low priority. After some testing, I don't think this is right.
1 parent f6c1623 commit 0abdef9

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

chalk-solve/src/recursive/fulfill.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ pub(crate) struct Fulfill<'s, 'db, I: Interner> {
7575
/// The remaining goals to prove or refute
7676
obligations: Vec<Obligation<I>>,
7777

78-
priority: ClausePriority,
79-
8078
/// Lifetime constraints that must be fulfilled for a solution to be fully
8179
/// validated.
8280
constraints: HashSet<InEnvironment<Constraint<I>>>,
@@ -91,7 +89,6 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
9189
pub(crate) fn new<T: Fold<I, I, Result = T> + HasInterner<Interner = I> + Clone>(
9290
solver: &'s mut Solver<'db, I>,
9391
ucanonical_goal: &UCanonical<InEnvironment<T>>,
94-
priority: ClausePriority,
9592
) -> (Self, Substitution<I>, InEnvironment<T::Result>) {
9693
let (infer, subst, canonical_goal) = InferenceTable::from_canonical(
9794
solver.program.interner(),
@@ -102,7 +99,6 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
10299
solver,
103100
infer,
104101
obligations: vec![],
105-
priority,
106102
constraints: HashSet::new(),
107103
cannot_prove: false,
108104
};
@@ -225,8 +221,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
225221
quantified,
226222
universes,
227223
} = self.infer.u_canonicalize(interner, &quantified);
228-
let (result, new_priority) = self.solver.solve_goal(quantified, minimums);
229-
self.priority = self.priority & new_priority;
224+
let result = self.solver.solve_goal(quantified, minimums);
230225
Ok(PositiveSolution {
231226
free_vars,
232227
universes,
@@ -255,7 +250,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
255250
.infer
256251
.u_canonicalize(self.solver.program.interner(), &canonicalized);
257252
let mut minimums = Minimums::new(); // FIXME -- minimums here seems wrong
258-
if let (Ok(solution), _priority) = self.solver.solve_goal(quantified, &mut minimums) {
253+
if let Ok(solution) = self.solver.solve_goal(quantified, &mut minimums) {
259254
if solution.is_unique() {
260255
Err(NoSolution)
261256
} else {
@@ -384,14 +379,14 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
384379
mut self,
385380
subst: Substitution<I>,
386381
minimums: &mut Minimums,
387-
) -> (Fallible<Solution<I>>, ClausePriority) {
382+
) -> Fallible<Solution<I>> {
388383
let outcome = match self.fulfill(minimums) {
389384
Ok(o) => o,
390-
Err(e) => return (Err(e), self.priority),
385+
Err(e) => return Err(e),
391386
};
392387

393388
if self.cannot_prove {
394-
return (Ok(Solution::Ambig(Guidance::Unknown)), self.priority);
389+
return Ok(Solution::Ambig(Guidance::Unknown));
395390
}
396391

397392
if outcome.is_complete() {
@@ -403,7 +398,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
403398
self.solver.program.interner(),
404399
&ConstrainedSubst { subst, constraints },
405400
);
406-
return (Ok(Solution::Unique(constrained.quantified)), self.priority);
401+
return Ok(Solution::Unique(constrained.quantified));
407402
}
408403

409404
// Otherwise, we have (positive or negative) obligations remaining, but
@@ -433,15 +428,12 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
433428
let subst = self
434429
.infer
435430
.canonicalize(self.solver.program.interner(), &subst);
436-
return (
437-
Ok(Solution::Ambig(Guidance::Suggested(subst.quantified))),
438-
self.priority,
439-
);
431+
return Ok(Solution::Ambig(Guidance::Suggested(subst.quantified)));
440432
}
441433
}
442434
}
443435

444-
(Ok(Solution::Ambig(Guidance::Unknown)), self.priority)
436+
Ok(Solution::Ambig(Guidance::Unknown))
445437
} else {
446438
// While we failed to prove the goal, we still learned that
447439
// something had to hold. Here's an example where this happens:
@@ -466,10 +458,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
466458
let subst = self
467459
.infer
468460
.canonicalize(self.solver.program.interner(), &subst);
469-
(
470-
Ok(Solution::Ambig(Guidance::Definite(subst.quantified))),
471-
self.priority,
472-
)
461+
Ok(Solution::Ambig(Guidance::Definite(subst.quantified)))
473462
}
474463
}
475464

chalk-solve/src/recursive/mod.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'me, I: Interner> Solver<'me, I> {
105105
debug!("solve_root_goal(canonical_goal={:?})", canonical_goal);
106106
assert!(self.context.stack.is_empty());
107107
let minimums = &mut Minimums::new();
108-
self.solve_goal(canonical_goal.clone(), minimums).0
108+
self.solve_goal(canonical_goal.clone(), minimums)
109109
}
110110

111111
/// Attempt to solve a goal that has been fully broken down into leaf form
@@ -115,13 +115,13 @@ impl<'me, I: Interner> Solver<'me, I> {
115115
&mut self,
116116
goal: UCanonicalGoal<I>,
117117
minimums: &mut Minimums,
118-
) -> (Fallible<Solution<I>>, ClausePriority) {
118+
) -> Fallible<Solution<I>> {
119119
info_heading!("solve_goal({:?})", goal);
120120

121121
// First check the cache.
122122
if let Some(value) = self.context.cache.get(&goal) {
123123
debug!("solve_reduced_goal: cache hit, value={:?}", value);
124-
return (value.clone(), ClausePriority::High);
124+
return value.clone();
125125
}
126126

127127
// Next, check if the goal is in the search tree already.
@@ -139,13 +139,10 @@ impl<'me, I: Interner> Solver<'me, I> {
139139
constraints: vec![],
140140
};
141141
debug!("applying coinductive semantics");
142-
return (
143-
Ok(Solution::Unique(Canonical {
144-
value,
145-
binders: goal.canonical.binders,
146-
})),
147-
ClausePriority::High,
148-
);
142+
return Ok(Solution::Unique(Canonical {
143+
value,
144+
binders: goal.canonical.binders,
145+
}));
149146
}
150147

151148
self.context.stack[depth].flag_cycle();
@@ -160,7 +157,7 @@ impl<'me, I: Interner> Solver<'me, I> {
160157
"solve_goal: cycle detected, previous solution {:?} with prio {:?}",
161158
previous_solution, previous_solution_priority
162159
);
163-
(previous_solution, previous_solution_priority)
160+
previous_solution
164161
} else {
165162
// Otherwise, push the goal onto the stack and create a table.
166163
// The initial result for this table is error.
@@ -195,7 +192,7 @@ impl<'me, I: Interner> Solver<'me, I> {
195192
}
196193

197194
info!("solve_goal: solution = {:?} prio {:?}", result, priority);
198-
(result, priority)
195+
result
199196
}
200197
}
201198

@@ -345,11 +342,11 @@ impl<'me, I: Interner> Solver<'me, I> {
345342
minimums: &mut Minimums,
346343
) -> (Fallible<Solution<I>>, ClausePriority) {
347344
debug_heading!("solve_via_simplification({:?})", canonical_goal);
348-
let (mut fulfill, subst, goal) = Fulfill::new(self, canonical_goal, ClausePriority::High);
345+
let (mut fulfill, subst, goal) = Fulfill::new(self, canonical_goal);
349346
if let Err(e) = fulfill.push_goal(&goal.environment, goal.goal) {
350347
return (Err(e), ClausePriority::High);
351348
}
352-
fulfill.solve(subst, minimums)
349+
(fulfill.solve(subst, minimums), ClausePriority::High)
353350
}
354351

355352
/// See whether we can solve a goal by implication on any of the given
@@ -434,7 +431,7 @@ impl<'me, I: Interner> Solver<'me, I> {
434431
clause
435432
);
436433
let interner = self.program.interner();
437-
let (mut fulfill, subst, goal) = Fulfill::new(self, canonical_goal, clause.value.priority);
434+
let (mut fulfill, subst, goal) = Fulfill::new(self, canonical_goal);
438435
let ProgramClauseImplication {
439436
consequence,
440437
conditions,
@@ -455,7 +452,7 @@ impl<'me, I: Interner> Solver<'me, I> {
455452
}
456453

457454
// and then try to solve
458-
fulfill.solve(subst, minimums)
455+
(fulfill.solve(subst, minimums), clause.value.priority)
459456
}
460457

461458
fn program_clauses_for_goal(

0 commit comments

Comments
 (0)