Skip to content

Commit 9374586

Browse files
committed
Make program_clauses_for_env add the actual env clauses as well
The `program_clauses_for_env` function only added elaborated clauses, not the actual clauses from the environment. Instead, both solvers added the clauses afterwards. It seems easier to just add the direct clauses as well.
1 parent 62b0da6 commit 9374586

File tree

4 files changed

+5
-63
lines changed

4 files changed

+5
-63
lines changed

chalk-solve/src/clauses.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ fn program_clauses_for_env<'db, I: Interner>(
415415
environment: &Environment<I>,
416416
clauses: &mut Vec<ProgramClause<I>>,
417417
) {
418+
clauses.extend(environment.clauses.iter().cloned());
419+
418420
let mut last_round = FxHashSet::default();
419421
elaborate_env_clauses(
420422
db,

chalk-solve/src/recursive/mod.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use chalk_engine::{
1111
context::Floundered,
1212
fallible::{Fallible, NoSolution},
1313
};
14-
use chalk_ir::could_match::CouldMatch;
1514
use clauses::program_clauses_for_goal;
1615
use rustc_hash::FxHashMap;
1716

@@ -253,19 +252,6 @@ impl<'me, I: Interner> Solver<'me, I> {
253252
// clauses. We try each approach in turn:
254253

255254
let InEnvironment { environment, goal } = &canonical_goal.canonical.value;
256-
let (env_solution, env_prio) = {
257-
debug_heading!("env_clauses");
258-
259-
// TODO use code from clauses module
260-
let env_clauses: Vec<_> = environment
261-
.clauses
262-
.iter()
263-
.filter(|&clause| clause.could_match(self.program.interner(), goal))
264-
.cloned()
265-
.collect();
266-
self.solve_from_clauses(&canonical_goal, env_clauses, minimums)
267-
};
268-
debug!("env_solution={:?}", env_solution);
269255

270256
let (prog_solution, prog_prio) = {
271257
debug_heading!("prog_clauses");
@@ -282,18 +268,7 @@ impl<'me, I: Interner> Solver<'me, I> {
282268
};
283269
debug!("prog_solution={:?}", prog_solution);
284270

285-
// Now that we have all the outcomes, we attempt to combine
286-
// them. Here, we apply a heuristic (also found in rustc): if we
287-
// have possible solutions via both the environment *and* the
288-
// program, we favor the environment; this only impacts type
289-
// inference. The idea is that the assumptions you've explicitly
290-
// made in a given context are more likely to be relevant than
291-
// general `impl`s.
292-
// TODO can we combine this logic with the priorization logic?
293-
(
294-
env_solution.merge_with(prog_solution, |env, prog| env.favor_over(prog)),
295-
prog_prio & env_prio, // FIXME
296-
)
271+
(prog_solution, prog_prio)
297272
}
298273

299274
_ => {

chalk-solve/src/solve.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,6 @@ impl<I: Interner> Solution<I> {
9292
Solution::Ambig(guidance)
9393
}
9494

95-
/// There are multiple candidate solutions, which may or may not agree on
96-
/// the values for existential variables; attempt to combine them, while
97-
/// favoring `self` for the purposes of giving suggestions to type
98-
/// inference. This is used in particular to favor the `where` clause
99-
/// environment over `impl`s in guiding inference in ambiguous situations.
100-
///
101-
/// It should always be the case that `x.favor_over(y)` is at least as
102-
/// informative as `x.combine(y)`, in terms of guidance to type inference.
103-
pub(crate) fn favor_over(self, other: Solution<I>) -> Solution<I> {
104-
use self::Guidance::*;
105-
106-
if self == other {
107-
return self;
108-
}
109-
110-
debug!("favor_over {} with {}", self, other);
111-
112-
// Otherwise, always downgrade to Ambig:
113-
114-
let guidance = match (self.into_guidance(), other.into_guidance()) {
115-
(Definite(subst), _) | (Suggested(subst), _) => Suggested(subst),
116-
_ => Unknown,
117-
};
118-
Solution::Ambig(guidance)
119-
}
120-
12195
/// View this solution purely in terms of type inference guidance
12296
pub(crate) fn into_guidance(self) -> Guidance<I> {
12397
match self {

chalk-solve/src/solve/slg.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use chalk_engine::{CompleteAnswer, ExClause, Literal};
1515
use chalk_ir::cast::Cast;
1616
use chalk_ir::cast::Caster;
1717
use chalk_ir::could_match::CouldMatch;
18-
use chalk_ir::interner::Interner;
18+
use chalk_ir::interner::{HasInterner, Interner};
1919
use chalk_ir::*;
2020

2121
use std::fmt::Debug;
@@ -177,18 +177,9 @@ impl<'me, I: Interner> context::ContextOps<SlgContext<I>> for SlgContextOps<'me,
177177
goal: &DomainGoal<I>,
178178
_infer: &mut TruncatingInferenceTable<I>,
179179
) -> Result<Vec<ProgramClause<I>>, Floundered> {
180-
let interner = self.program.interner();
181-
let mut clauses: Vec<_> =
180+
let clauses: Vec<_> =
182181
program_clauses_for_goal(self.program, environment, goal).ok_or(Floundered)?;
183182

184-
clauses.extend(
185-
environment
186-
.clauses
187-
.iter(interner)
188-
.filter(|&env_clause| env_clause.could_match(interner, goal))
189-
.cloned(),
190-
);
191-
192183
Ok(clauses)
193184
}
194185

0 commit comments

Comments
 (0)