Skip to content

Commit 61c418a

Browse files
committed
Move subst into Fulfill
1 parent f53558e commit 61c418a

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

chalk-solve/src/recursive.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ impl<'me, I: Interner> Solver<'me, I> {
351351
minimums: &mut Minimums,
352352
) -> (Fallible<Solution<I>>, ClausePriority) {
353353
debug_heading!("solve_via_simplification({:?})", canonical_goal);
354-
let (fulfill, subst) = match Fulfill::new_with_simplification(self, canonical_goal) {
354+
let fulfill = match Fulfill::new_with_simplification(self, canonical_goal) {
355355
Ok(r) => r,
356356
Err(e) => return (Err(e), ClausePriority::High),
357357
};
358-
(fulfill.solve(subst, minimums), ClausePriority::High)
358+
(fulfill.solve(minimums), ClausePriority::High)
359359
}
360360

361361
/// See whether we can solve a goal by implication on any of the given
@@ -426,15 +426,12 @@ impl<'me, I: Interner> Solver<'me, I> {
426426
canonical_goal,
427427
clause
428428
);
429-
let (fulfill, subst) = match Fulfill::new_with_clause(self, canonical_goal, clause) {
429+
let fulfill = match Fulfill::new_with_clause(self, canonical_goal, clause) {
430430
Ok(r) => r,
431431
Err(e) => return (Err(e), ClausePriority::High),
432432
};
433433

434-
(
435-
fulfill.solve(subst, minimums),
436-
clause.skip_binders().priority,
437-
)
434+
(fulfill.solve(minimums), clause.skip_binders().priority)
438435
}
439436

440437
fn program_clauses_for_goal(

chalk-solve/src/recursive/fulfill.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ enum NegativeSolution {
7272
/// goals, and transport what was learned back to the outer context.
7373
pub(crate) struct Fulfill<'s, 'db, I: Interner> {
7474
solver: &'s mut Solver<'db, I>,
75+
subst: Substitution<I>,
7576
infer: InferenceTable<I>,
7677

7778
/// The remaining goals to prove or refute
@@ -91,7 +92,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
9192
fn new<T: Fold<I, I, Result = T> + HasInterner<Interner = I> + Clone>(
9293
solver: &'s mut Solver<'db, I>,
9394
ucanonical_goal: &UCanonical<InEnvironment<T>>,
94-
) -> (Self, Substitution<I>, InEnvironment<T::Result>) {
95+
) -> (Self, InEnvironment<T::Result>) {
9596
let (infer, subst, canonical_goal) = InferenceTable::from_canonical(
9697
solver.program.interner(),
9798
ucanonical_goal.universes,
@@ -100,20 +101,21 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
100101
let fulfill = Fulfill {
101102
solver,
102103
infer,
104+
subst,
103105
obligations: vec![],
104106
constraints: FxHashSet::default(),
105107
cannot_prove: false,
106108
};
107109

108-
(fulfill, subst, canonical_goal)
110+
(fulfill, canonical_goal)
109111
}
110112

111113
pub(crate) fn new_with_clause(
112114
solver: &'s mut Solver<'db, I>,
113115
ucanonical_goal: &UCanonical<InEnvironment<DomainGoal<I>>>,
114116
clause: &Binders<ProgramClauseImplication<I>>,
115-
) -> Fallible<(Self, Substitution<I>)> {
116-
let (mut fulfill, subst, canonical_goal) = Fulfill::new(solver, ucanonical_goal);
117+
) -> Fallible<Self> {
118+
let (mut fulfill, canonical_goal) = Fulfill::new(solver, ucanonical_goal);
117119

118120
let ProgramClauseImplication {
119121
consequence,
@@ -123,7 +125,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
123125
.infer
124126
.instantiate_binders_existentially(fulfill.solver.program.interner(), clause);
125127

126-
debug!("the subst is {:?}", subst);
128+
debug!("the subst is {:?}", fulfill.subst);
127129

128130
if let Err(e) = fulfill.unify(
129131
&canonical_goal.environment,
@@ -140,21 +142,21 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
140142
}
141143
}
142144

143-
Ok((fulfill, subst))
145+
Ok(fulfill)
144146
}
145147

146148
pub(crate) fn new_with_simplification(
147149
solver: &'s mut Solver<'db, I>,
148150
ucanonical_goal: &UCanonical<InEnvironment<Goal<I>>>,
149-
) -> Fallible<(Self, Substitution<I>)> {
150-
let (mut fulfill, subst, canonical_goal) = Fulfill::new(solver, ucanonical_goal);
151+
) -> Fallible<Self> {
152+
let (mut fulfill, canonical_goal) = Fulfill::new(solver, ucanonical_goal);
151153

152154
if let Err(e) = fulfill.push_goal(&canonical_goal.environment, canonical_goal.goal.clone())
153155
{
154156
return Err(e);
155157
}
156158

157-
Ok((fulfill, subst))
159+
Ok(fulfill)
158160
}
159161

160162
fn push_obligation(&mut self, obligation: Obligation<I>) {
@@ -438,11 +440,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
438440
/// Try to fulfill all pending obligations and build the resulting
439441
/// solution. The returned solution will transform `subst` substitution with
440442
/// the outcome of type inference by updating the replacements it provides.
441-
pub(super) fn solve(
442-
mut self,
443-
subst: Substitution<I>,
444-
minimums: &mut Minimums,
445-
) -> Fallible<Solution<I>> {
443+
pub(super) fn solve(mut self, minimums: &mut Minimums) -> Fallible<Solution<I>> {
446444
let outcome = match self.fulfill(minimums) {
447445
Ok(o) => o,
448446
Err(e) => return Err(e),
@@ -459,7 +457,10 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
459457
let constraints = self.constraints.into_iter().collect();
460458
let constrained = self.infer.canonicalize(
461459
self.solver.program.interner(),
462-
&ConstrainedSubst { subst, constraints },
460+
&ConstrainedSubst {
461+
subst: self.subst,
462+
constraints,
463+
},
463464
);
464465
return Ok(Solution::Unique(constrained.quantified));
465466
}
@@ -470,7 +471,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
470471
// inference as an ambiguous solution.
471472

472473
let interner = self.solver.program.interner();
473-
let canonical_subst = self.infer.canonicalize(interner, &subst);
474+
let canonical_subst = self.infer.canonicalize(interner, &self.subst);
474475

475476
if canonical_subst.quantified.value.is_identity_subst(interner) {
476477
// In this case, we didn't learn *anything* definitively. So now, we

0 commit comments

Comments
 (0)