Skip to content

Commit 82657b9

Browse files
committed
Clone should_continue closure to avoid rustc/LLVM bug #95734
1 parent 8da2e1d commit 82657b9

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

chalk-engine/src/slg/aggregate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub trait AggregateOps<I: Interner> {
1717
&self,
1818
root_goal: &UCanonical<InEnvironment<Goal<I>>>,
1919
answers: impl context::AnswerStream<I>,
20-
should_continue: impl std::ops::Fn() -> bool,
20+
should_continue: impl std::ops::Fn() -> bool + Clone,
2121
) -> Option<Solution<I>>;
2222
}
2323

@@ -28,7 +28,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
2828
&self,
2929
root_goal: &UCanonical<InEnvironment<Goal<I>>>,
3030
mut answers: impl context::AnswerStream<I>,
31-
should_continue: impl std::ops::Fn() -> bool,
31+
should_continue: impl std::ops::Fn() -> bool + Clone,
3232
) -> Option<Solution<I>> {
3333
let interner = self.program.interner();
3434
let CompleteAnswer { subst, ambiguous } = match answers.next_answer(&should_continue) {

chalk-recursive/src/fixed_point.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
context: &mut RecursiveContext<K, V>,
4444
goal: &K,
4545
minimums: &mut Minimums,
46-
should_continue: impl std::ops::Fn() -> bool,
46+
should_continue: impl std::ops::Fn() -> bool + Clone,
4747
) -> V;
4848
fn reached_fixed_point(self, old_value: &V, new_value: &V) -> bool;
4949
fn error_value(self) -> V;
@@ -105,7 +105,7 @@ where
105105
&mut self,
106106
canonical_goal: &K,
107107
solver_stuff: impl SolverStuff<K, V>,
108-
should_continue: impl std::ops::Fn() -> bool,
108+
should_continue: impl std::ops::Fn() -> bool + Clone,
109109
) -> V {
110110
debug!("solve_root_goal(canonical_goal={:?})", canonical_goal);
111111
assert!(self.stack.is_empty());
@@ -122,7 +122,7 @@ where
122122
goal: &K,
123123
minimums: &mut Minimums,
124124
solver_stuff: impl SolverStuff<K, V>,
125-
should_continue: impl std::ops::Fn() -> bool,
125+
should_continue: impl std::ops::Fn() -> bool + Clone,
126126
) -> V {
127127
// First check the cache.
128128
if let Some(cache) = &self.cache {
@@ -201,7 +201,7 @@ where
201201
depth: StackDepth,
202202
dfn: DepthFirstNumber,
203203
solver_stuff: impl SolverStuff<K, V>,
204-
should_continue: impl std::ops::Fn() -> bool,
204+
should_continue: impl std::ops::Fn() -> bool + Clone,
205205
) -> Minimums {
206206
// We start with `answer = None` and try to solve the goal. At the end of the iteration,
207207
// `answer` will be updated with the result of the solving process. If we detect a cycle
@@ -214,8 +214,12 @@ where
214214
// so this function will eventually be constant and the loop terminates.
215215
loop {
216216
let minimums = &mut Minimums::new();
217-
let current_answer =
218-
solver_stuff.solve_iteration(self, canonical_goal, minimums, &should_continue);
217+
let current_answer = solver_stuff.solve_iteration(
218+
self,
219+
canonical_goal,
220+
minimums,
221+
should_continue.clone(),
222+
);
219223

220224
debug!(
221225
"solve_new_subgoal: loop iteration result = {:?} with minimums {:?}",

chalk-recursive/src/fulfill.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
347347
&mut self,
348348
wc: InEnvironment<Goal<I>>,
349349
minimums: &mut Minimums,
350-
should_continue: impl std::ops::Fn() -> bool,
350+
should_continue: impl std::ops::Fn() -> bool + Clone,
351351
) -> Fallible<PositiveSolution<I>> {
352352
let interner = self.solver.interner();
353353
let (quantified, free_vars) = canonicalize(&mut self.infer, interner, wc);
@@ -365,7 +365,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
365365
fn refute(
366366
&mut self,
367367
goal: InEnvironment<Goal<I>>,
368-
should_continue: impl std::ops::Fn() -> bool,
368+
should_continue: impl std::ops::Fn() -> bool + Clone,
369369
) -> Fallible<NegativeSolution> {
370370
let canonicalized = match self
371371
.infer
@@ -444,7 +444,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
444444
fn fulfill(
445445
&mut self,
446446
minimums: &mut Minimums,
447-
should_continue: impl std::ops::Fn() -> bool,
447+
should_continue: impl std::ops::Fn() -> bool + Clone,
448448
) -> Fallible<Outcome> {
449449
debug_span!("fulfill", obligations=?self.obligations);
450450

@@ -474,7 +474,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
474474
free_vars,
475475
universes,
476476
solution,
477-
} = self.prove(wc.clone(), minimums, &should_continue)?;
477+
} = self.prove(wc.clone(), minimums, should_continue.clone())?;
478478

479479
if let Some(constrained_subst) = solution.definite_subst(self.interner()) {
480480
// If the substitution is trivial, we won't actually make any progress by applying it!
@@ -498,7 +498,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
498498
solution.is_ambig()
499499
}
500500
Obligation::Refute(goal) => {
501-
let answer = self.refute(goal.clone(), &should_continue)?;
501+
let answer = self.refute(goal.clone(), should_continue.clone())?;
502502
answer == NegativeSolution::Ambiguous
503503
}
504504
};
@@ -531,9 +531,9 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
531531
pub(super) fn solve(
532532
mut self,
533533
minimums: &mut Minimums,
534-
should_continue: impl std::ops::Fn() -> bool,
534+
should_continue: impl std::ops::Fn() -> bool + Clone,
535535
) -> Fallible<Solution<I>> {
536-
let outcome = match self.fulfill(minimums, &should_continue) {
536+
let outcome = match self.fulfill(minimums, should_continue.clone()) {
537537
Ok(o) => o,
538538
Err(e) => return Err(e),
539539
};
@@ -585,7 +585,7 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>> Fulfill<'s, I, Solver> {
585585
free_vars,
586586
universes,
587587
solution,
588-
} = self.prove(goal, minimums, &should_continue).unwrap();
588+
} = self.prove(goal, minimums, should_continue.clone()).unwrap();
589589
if let Some(constrained_subst) =
590590
solution.constrained_subst(self.solver.interner())
591591
{

chalk-recursive/src/recursive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<I: Interner> SolverStuff<UCanonicalGoal<I>, Fallible<Solution<I>>> for &dyn
7676
context: &mut RecursiveContext<UCanonicalGoal<I>, Fallible<Solution<I>>>,
7777
goal: &UCanonicalGoal<I>,
7878
minimums: &mut Minimums,
79-
should_continue: impl std::ops::Fn() -> bool,
79+
should_continue: impl std::ops::Fn() -> bool + Clone,
8080
) -> Fallible<Solution<I>> {
8181
Solver::new(context, self).solve_iteration(goal, minimums, should_continue)
8282
}
@@ -109,7 +109,7 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
109109
&mut self,
110110
goal: UCanonicalGoal<I>,
111111
minimums: &mut Minimums,
112-
should_continue: impl std::ops::Fn() -> bool,
112+
should_continue: impl std::ops::Fn() -> bool + Clone,
113113
) -> Fallible<Solution<I>> {
114114
self.context
115115
.solve_goal(&goal, minimums, self.program, should_continue)

chalk-recursive/src/solve.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) trait SolveDatabase<I: Interner>: Sized {
2020
&mut self,
2121
goal: UCanonical<InEnvironment<Goal<I>>>,
2222
minimums: &mut Minimums,
23-
should_continue: impl std::ops::Fn() -> bool,
23+
should_continue: impl std::ops::Fn() -> bool + Clone,
2424
) -> Fallible<Solution<I>>;
2525

2626
fn max_size(&self) -> usize;
@@ -41,7 +41,7 @@ pub(super) trait SolveIteration<I: Interner>: SolveDatabase<I> {
4141
&mut self,
4242
canonical_goal: &UCanonicalGoal<I>,
4343
minimums: &mut Minimums,
44-
should_continue: impl std::ops::Fn() -> bool,
44+
should_continue: impl std::ops::Fn() -> bool + Clone,
4545
) -> Fallible<Solution<I>> {
4646
let UCanonical {
4747
universes,
@@ -110,7 +110,7 @@ trait SolveIterationHelpers<I: Interner>: SolveDatabase<I> {
110110
&mut self,
111111
canonical_goal: &UCanonicalGoal<I>,
112112
minimums: &mut Minimums,
113-
should_continue: impl std::ops::Fn() -> bool,
113+
should_continue: impl std::ops::Fn() -> bool + Clone,
114114
) -> Fallible<Solution<I>> {
115115
let (infer, subst, goal) = self.new_inference_table(canonical_goal);
116116
match Fulfill::new_with_simplification(self, infer, subst, goal) {
@@ -126,7 +126,7 @@ trait SolveIterationHelpers<I: Interner>: SolveDatabase<I> {
126126
&mut self,
127127
canonical_goal: &UCanonical<InEnvironment<DomainGoal<I>>>,
128128
minimums: &mut Minimums,
129-
should_continue: impl std::ops::Fn() -> bool,
129+
should_continue: impl std::ops::Fn() -> bool + Clone,
130130
) -> Fallible<Solution<I>> {
131131
let mut clauses = vec![];
132132

@@ -164,7 +164,7 @@ trait SolveIterationHelpers<I: Interner>: SolveDatabase<I> {
164164
let goal = goal.clone();
165165
let res = match Fulfill::new_with_clause(self, infer, subst, goal, implication) {
166166
Ok(fulfill) => (
167-
fulfill.solve(minimums, &should_continue),
167+
fulfill.solve(minimums, should_continue.clone()),
168168
implication.skip_binders().priority,
169169
),
170170
Err(e) => (Err(e), ClausePriority::High),

0 commit comments

Comments
 (0)