Skip to content

Commit 96ddf29

Browse files
committed
Upgrade Chalk
1 parent 1916a78 commit 96ddf29

File tree

4 files changed

+99
-89
lines changed

4 files changed

+99
-89
lines changed

Cargo.lock

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_hir_ty/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ ra_prof = { path = "../ra_prof" }
2121
ra_syntax = { path = "../ra_syntax" }
2222
test_utils = { path = "../test_utils" }
2323

24-
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
25-
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
26-
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
24+
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
25+
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
26+
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
2727

2828
lalrpop-intern = "0.15.1"
2929

crates/ra_hir_ty/src/traits.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ impl TraitSolver {
5050
Err(_) => ra_db::Canceled::throw(),
5151
};
5252

53+
let fuel = std::cell::Cell::new(CHALK_SOLVER_FUEL);
54+
5355
let solution = panic::catch_unwind({
5456
let solver = panic::AssertUnwindSafe(&mut solver);
5557
let context = panic::AssertUnwindSafe(&context);
56-
move || solver.0.solve(context.0, goal)
58+
move || {
59+
solver.0.solve_limited(context.0, goal, || {
60+
context.0.db.check_canceled();
61+
let remaining = fuel.get();
62+
fuel.set(remaining - 1);
63+
remaining > 0
64+
})
65+
}
5766
});
5867

5968
let solution = match solution {
@@ -79,6 +88,9 @@ impl TraitSolver {
7988
/// high, we can run into slow edge cases; if we set it too low, Chalk won't
8089
/// find some solutions.
8190
const CHALK_SOLVER_MAX_SIZE: usize = 4;
91+
/// This controls how much 'time' we give the Chalk solver before giving up.
92+
const CHALK_SOLVER_FUEL: i32 = 100;
93+
// TODO: tune both these values
8294

8395
#[derive(Debug, Copy, Clone)]
8496
struct ChalkContext<'a, DB> {
@@ -97,7 +109,8 @@ pub(crate) fn trait_solver_query(
97109
}
98110

99111
fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> {
100-
let solver_choice = chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE };
112+
let solver_choice =
113+
chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE, expected_answers: None };
101114
solver_choice.into_solver()
102115
}
103116

@@ -232,7 +245,6 @@ fn solution_from_chalk(
232245
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| {
233246
let value = subst
234247
.value
235-
.parameters
236248
.into_iter()
237249
.map(|p| {
238250
let ty = match p.ty() {

0 commit comments

Comments
 (0)