Skip to content

Commit 18964c9

Browse files
committed
construct initial solution outside of search graph
1 parent fbc4bba commit 18964c9

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

chalk-recursive/src/recursive.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::search_graph::SearchGraph;
44
use crate::solve::{SolveDatabase, SolveIteration};
55
use crate::stack::{Stack, StackDepth};
66
use crate::{Minimums, UCanonicalGoal};
7-
use chalk_ir::Fallible;
87
use chalk_ir::{interner::Interner, NoSolution};
98
use chalk_ir::{Canonical, ConstrainedSubst, Goal, InEnvironment, UCanonical};
9+
use chalk_ir::{Constraints, Fallible};
1010
use chalk_solve::{coinductive_goal::IsCoinductive, RustIrDatabase, Solution};
1111
use std::fmt;
1212
use tracing::debug;
@@ -234,12 +234,21 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
234234
// The initial result for this table depends on whether the goal is coinductive.
235235
let coinductive_goal = goal.is_coinductive(self.program);
236236
let depth = self.context.stack.push(coinductive_goal);
237-
let dfn = self.context.search_graph.insert(
238-
&goal,
239-
depth,
240-
coinductive_goal,
241-
self.program.interner(),
242-
);
237+
let initial_solution = if coinductive_goal {
238+
Ok(Solution::Unique(Canonical {
239+
value: ConstrainedSubst {
240+
subst: goal.trivial_substitution(self.interner()),
241+
constraints: Constraints::empty(self.interner()),
242+
},
243+
binders: goal.canonical.binders.clone(),
244+
}))
245+
} else {
246+
Err(NoSolution)
247+
};
248+
let dfn =
249+
self.context
250+
.search_graph
251+
.insert(&goal, depth, coinductive_goal, initial_solution);
243252
let subgoal_minimums = self.solve_new_subgoal(goal, depth, dfn);
244253
self.context.search_graph[dfn].links = subgoal_minimums;
245254
self.context.search_graph[dfn].stack_depth = None;

chalk-recursive/src/search_graph.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,11 @@ impl<I: Interner> SearchGraph<I> {
6666
goal: &UCanonicalGoal<I>,
6767
stack_depth: StackDepth,
6868
coinductive: bool,
69-
interner: &I,
69+
solution: Fallible<Solution<I>>,
7070
) -> DepthFirstNumber {
7171
let dfn = DepthFirstNumber {
7272
index: self.nodes.len(),
7373
};
74-
let solution = if coinductive {
75-
Ok(Solution::Unique(Canonical {
76-
value: ConstrainedSubst {
77-
subst: goal.trivial_substitution(interner),
78-
constraints: Constraints::empty(interner),
79-
},
80-
binders: goal.canonical.binders.clone(),
81-
}))
82-
} else {
83-
Err(NoSolution)
84-
};
8574
let node = Node {
8675
goal: goal.clone(),
8776
solution,

0 commit comments

Comments
 (0)