mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Upgrade Chalk
This commit is contained in:
parent
1916a78c6a
commit
96ddf2962c
4 changed files with 99 additions and 89 deletions
56
Cargo.lock
generated
56
Cargo.lock
generated
|
@ -131,7 +131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-derive"
|
name = "chalk-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
|
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -141,27 +141,27 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-engine"
|
name = "chalk-engine"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
|
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-ir"
|
name = "chalk-ir"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
|
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-macros"
|
name = "chalk-macros"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
|
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
@ -169,24 +169,24 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-rust-ir"
|
name = "chalk-rust-ir"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
|
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chalk-solve"
|
name = "chalk-solve"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5#ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5"
|
source = "git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75#af48f302a1f571b3ca418f7c5aa639a144a34f75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1004,9 +1004,9 @@ name = "ra_hir_ty"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
"chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||||
"ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"insta 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"insta 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1775,12 +1775,12 @@ dependencies = [
|
||||||
"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202"
|
"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202"
|
||||||
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
|
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
|
||||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||||
"checksum chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
"checksum chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||||
"checksum chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
"checksum chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||||
"checksum chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
"checksum chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||||
"checksum chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
"checksum chalk-macros 0.1.1 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||||
"checksum chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
"checksum chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||||
"checksum chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
"checksum chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||||
"checksum clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e"
|
"checksum clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e"
|
||||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||||
"checksum console 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "45e0f3986890b3acbc782009e2629dfe2baa430ac091519ce3be26164a2ae6c0"
|
"checksum console 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "45e0f3986890b3acbc782009e2629dfe2baa430ac091519ce3be26164a2ae6c0"
|
||||||
|
|
|
@ -21,9 +21,9 @@ ra_prof = { path = "../ra_prof" }
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
|
||||||
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
|
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
|
||||||
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
|
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
|
||||||
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
|
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
|
||||||
|
|
||||||
lalrpop-intern = "0.15.1"
|
lalrpop-intern = "0.15.1"
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,19 @@ impl TraitSolver {
|
||||||
Err(_) => ra_db::Canceled::throw(),
|
Err(_) => ra_db::Canceled::throw(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let fuel = std::cell::Cell::new(CHALK_SOLVER_FUEL);
|
||||||
|
|
||||||
let solution = panic::catch_unwind({
|
let solution = panic::catch_unwind({
|
||||||
let solver = panic::AssertUnwindSafe(&mut solver);
|
let solver = panic::AssertUnwindSafe(&mut solver);
|
||||||
let context = panic::AssertUnwindSafe(&context);
|
let context = panic::AssertUnwindSafe(&context);
|
||||||
move || solver.0.solve(context.0, goal)
|
move || {
|
||||||
|
solver.0.solve_limited(context.0, goal, || {
|
||||||
|
context.0.db.check_canceled();
|
||||||
|
let remaining = fuel.get();
|
||||||
|
fuel.set(remaining - 1);
|
||||||
|
remaining > 0
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let solution = match solution {
|
let solution = match solution {
|
||||||
|
@ -79,6 +88,9 @@ impl TraitSolver {
|
||||||
/// high, we can run into slow edge cases; if we set it too low, Chalk won't
|
/// high, we can run into slow edge cases; if we set it too low, Chalk won't
|
||||||
/// find some solutions.
|
/// find some solutions.
|
||||||
const CHALK_SOLVER_MAX_SIZE: usize = 4;
|
const CHALK_SOLVER_MAX_SIZE: usize = 4;
|
||||||
|
/// This controls how much 'time' we give the Chalk solver before giving up.
|
||||||
|
const CHALK_SOLVER_FUEL: i32 = 100;
|
||||||
|
// TODO: tune both these values
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
struct ChalkContext<'a, DB> {
|
struct ChalkContext<'a, DB> {
|
||||||
|
@ -97,7 +109,8 @@ pub(crate) fn trait_solver_query(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> {
|
fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> {
|
||||||
let solver_choice = chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE };
|
let solver_choice =
|
||||||
|
chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE, expected_answers: None };
|
||||||
solver_choice.into_solver()
|
solver_choice.into_solver()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +245,6 @@ fn solution_from_chalk(
|
||||||
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| {
|
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| {
|
||||||
let value = subst
|
let value = subst
|
||||||
.value
|
.value
|
||||||
.parameters
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
let ty = match p.ty() {
|
let ty = match p.ty() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{fmt, sync::Arc};
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use chalk_ir::{cast::Cast, Parameter, PlaceholderIndex, TypeName, UniverseIndex};
|
use chalk_ir::{cast::Cast, GoalData, Parameter, PlaceholderIndex, TypeName, UniverseIndex};
|
||||||
|
|
||||||
use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId};
|
use hir_def::{AssocContainerId, AssocItemId, GenericDefId, HasModule, Lookup, TypeAliasId};
|
||||||
use ra_db::{
|
use ra_db::{
|
||||||
|
@ -24,6 +24,8 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
|
||||||
type InternedType = Box<chalk_ir::TyData<Self>>;
|
type InternedType = Box<chalk_ir::TyData<Self>>;
|
||||||
type InternedLifetime = chalk_ir::LifetimeData<Self>;
|
type InternedLifetime = chalk_ir::LifetimeData<Self>;
|
||||||
type InternedParameter = chalk_ir::ParameterData<Self>;
|
type InternedParameter = chalk_ir::ParameterData<Self>;
|
||||||
|
type InternedGoal = Arc<GoalData<Self>>;
|
||||||
|
type InternedSubstitution = Vec<Parameter<Self>>;
|
||||||
type DefId = InternId;
|
type DefId = InternId;
|
||||||
|
|
||||||
// FIXME: implement these
|
// FIXME: implement these
|
||||||
|
@ -48,8 +50,8 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_projection(
|
fn debug_alias(
|
||||||
_projection: &chalk_ir::ProjectionTy<Self>,
|
_projection: &chalk_ir::AliasTy<Self>,
|
||||||
_fmt: &mut fmt::Formatter<'_>,
|
_fmt: &mut fmt::Formatter<'_>,
|
||||||
) -> Option<fmt::Result> {
|
) -> Option<fmt::Result> {
|
||||||
None
|
None
|
||||||
|
@ -78,6 +80,24 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
|
||||||
fn parameter_data(parameter: &chalk_ir::ParameterData<Self>) -> &chalk_ir::ParameterData<Self> {
|
fn parameter_data(parameter: &chalk_ir::ParameterData<Self>) -> &chalk_ir::ParameterData<Self> {
|
||||||
parameter
|
parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn intern_goal(goal: GoalData<Self>) -> Arc<GoalData<Self>> {
|
||||||
|
Arc::new(goal)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn goal_data(goal: &Arc<GoalData<Self>>) -> &GoalData<Self> {
|
||||||
|
goal
|
||||||
|
}
|
||||||
|
|
||||||
|
fn intern_substitution<E>(
|
||||||
|
data: impl IntoIterator<Item = Result<Parameter<Self>, E>>,
|
||||||
|
) -> Result<Vec<Parameter<Self>>, E> {
|
||||||
|
data.into_iter().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn substitution_data(substitution: &Vec<Parameter<Self>>) -> &[Parameter<Self>] {
|
||||||
|
substitution
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl chalk_ir::family::HasTypeFamily for TypeFamily {
|
impl chalk_ir::family::HasTypeFamily for TypeFamily {
|
||||||
|
@ -114,13 +134,13 @@ impl ToChalk for Ty {
|
||||||
match self {
|
match self {
|
||||||
Ty::Apply(apply_ty) => {
|
Ty::Apply(apply_ty) => {
|
||||||
let name = apply_ty.ctor.to_chalk(db);
|
let name = apply_ty.ctor.to_chalk(db);
|
||||||
let parameters = apply_ty.parameters.to_chalk(db);
|
let substitution = apply_ty.parameters.to_chalk(db);
|
||||||
chalk_ir::ApplicationTy { name, parameters }.cast().intern()
|
chalk_ir::ApplicationTy { name, substitution }.cast().intern()
|
||||||
}
|
}
|
||||||
Ty::Projection(proj_ty) => {
|
Ty::Projection(proj_ty) => {
|
||||||
let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
|
let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
|
||||||
let parameters = proj_ty.parameters.to_chalk(db);
|
let substitution = proj_ty.parameters.to_chalk(db);
|
||||||
chalk_ir::ProjectionTy { associated_ty_id, parameters }.cast().intern()
|
chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern()
|
||||||
}
|
}
|
||||||
Ty::Param { idx, .. } => {
|
Ty::Param { idx, .. } => {
|
||||||
PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }
|
PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }
|
||||||
|
@ -135,23 +155,13 @@ impl ToChalk for Ty {
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|p| p.to_chalk(db))
|
.map(|p| p.to_chalk(db))
|
||||||
.collect();
|
.collect();
|
||||||
let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
|
let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) };
|
||||||
chalk_ir::TyData::Dyn(bounded_ty).intern()
|
chalk_ir::TyData::Dyn(bounded_ty).intern()
|
||||||
}
|
}
|
||||||
Ty::Opaque(predicates) => {
|
Ty::Opaque(_) | Ty::Unknown => {
|
||||||
let where_clauses = predicates
|
let substitution = chalk_ir::Substitution::empty();
|
||||||
.iter()
|
|
||||||
.filter(|p| !p.is_error())
|
|
||||||
.cloned()
|
|
||||||
.map(|p| p.to_chalk(db))
|
|
||||||
.collect();
|
|
||||||
let bounded_ty = chalk_ir::BoundedTy { bounds: make_binders(where_clauses, 1) };
|
|
||||||
chalk_ir::TyData::Opaque(bounded_ty).intern()
|
|
||||||
}
|
|
||||||
Ty::Unknown => {
|
|
||||||
let parameters = Vec::new();
|
|
||||||
let name = TypeName::Error;
|
let name = TypeName::Error;
|
||||||
chalk_ir::ApplicationTy { name, parameters }.cast().intern()
|
chalk_ir::ApplicationTy { name, substitution }.cast().intern()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +171,7 @@ impl ToChalk for Ty {
|
||||||
TypeName::Error => Ty::Unknown,
|
TypeName::Error => Ty::Unknown,
|
||||||
_ => {
|
_ => {
|
||||||
let ctor = from_chalk(db, apply_ty.name);
|
let ctor = from_chalk(db, apply_ty.name);
|
||||||
let parameters = from_chalk(db, apply_ty.parameters);
|
let parameters = from_chalk(db, apply_ty.substitution);
|
||||||
Ty::Apply(ApplicationTy { ctor, parameters })
|
Ty::Apply(ApplicationTy { ctor, parameters })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -169,12 +179,12 @@ impl ToChalk for Ty {
|
||||||
assert_eq!(idx.ui, UniverseIndex::ROOT);
|
assert_eq!(idx.ui, UniverseIndex::ROOT);
|
||||||
Ty::Param { idx: idx.idx as u32, name: crate::Name::missing() }
|
Ty::Param { idx: idx.idx as u32, name: crate::Name::missing() }
|
||||||
}
|
}
|
||||||
chalk_ir::TyData::Projection(proj) => {
|
chalk_ir::TyData::Alias(proj) => {
|
||||||
let associated_ty = from_chalk(db, proj.associated_ty_id);
|
let associated_ty = from_chalk(db, proj.associated_ty_id);
|
||||||
let parameters = from_chalk(db, proj.parameters);
|
let parameters = from_chalk(db, proj.substitution);
|
||||||
Ty::Projection(ProjectionTy { associated_ty, parameters })
|
Ty::Projection(ProjectionTy { associated_ty, parameters })
|
||||||
}
|
}
|
||||||
chalk_ir::TyData::ForAll(_) => unimplemented!(),
|
chalk_ir::TyData::Function(_) => unimplemented!(),
|
||||||
chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32),
|
chalk_ir::TyData::BoundVar(idx) => Ty::Bound(idx as u32),
|
||||||
chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown,
|
chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown,
|
||||||
chalk_ir::TyData::Dyn(where_clauses) => {
|
chalk_ir::TyData::Dyn(where_clauses) => {
|
||||||
|
@ -183,27 +193,18 @@ impl ToChalk for Ty {
|
||||||
where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect();
|
where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect();
|
||||||
Ty::Dyn(predicates)
|
Ty::Dyn(predicates)
|
||||||
}
|
}
|
||||||
chalk_ir::TyData::Opaque(where_clauses) => {
|
|
||||||
assert_eq!(where_clauses.bounds.binders.len(), 1);
|
|
||||||
let predicates =
|
|
||||||
where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect();
|
|
||||||
Ty::Opaque(predicates)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToChalk for Substs {
|
impl ToChalk for Substs {
|
||||||
type Chalk = Vec<chalk_ir::Parameter<TypeFamily>>;
|
type Chalk = chalk_ir::Substitution<TypeFamily>;
|
||||||
|
|
||||||
fn to_chalk(self, db: &impl HirDatabase) -> Vec<Parameter<TypeFamily>> {
|
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Substitution<TypeFamily> {
|
||||||
self.iter().map(|ty| ty.clone().to_chalk(db).cast()).collect()
|
chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_chalk(
|
fn from_chalk(db: &impl HirDatabase, parameters: chalk_ir::Substitution<TypeFamily>) -> Substs {
|
||||||
db: &impl HirDatabase,
|
|
||||||
parameters: Vec<chalk_ir::Parameter<TypeFamily>>,
|
|
||||||
) -> Substs {
|
|
||||||
let tys = parameters
|
let tys = parameters
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| match p.ty() {
|
.map(|p| match p.ty() {
|
||||||
|
@ -220,13 +221,13 @@ impl ToChalk for TraitRef {
|
||||||
|
|
||||||
fn to_chalk(self: TraitRef, db: &impl HirDatabase) -> chalk_ir::TraitRef<TypeFamily> {
|
fn to_chalk(self: TraitRef, db: &impl HirDatabase) -> chalk_ir::TraitRef<TypeFamily> {
|
||||||
let trait_id = self.trait_.to_chalk(db);
|
let trait_id = self.trait_.to_chalk(db);
|
||||||
let parameters = self.substs.to_chalk(db);
|
let substitution = self.substs.to_chalk(db);
|
||||||
chalk_ir::TraitRef { trait_id, parameters }
|
chalk_ir::TraitRef { trait_id, substitution }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef<TypeFamily>) -> Self {
|
fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef<TypeFamily>) -> Self {
|
||||||
let trait_ = from_chalk(db, trait_ref.trait_id);
|
let trait_ = from_chalk(db, trait_ref.trait_id);
|
||||||
let substs = from_chalk(db, trait_ref.parameters);
|
let substs = from_chalk(db, trait_ref.substitution);
|
||||||
TraitRef { trait_, substs }
|
TraitRef { trait_, substs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,8 +318,8 @@ impl ToChalk for GenericPredicate {
|
||||||
make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0)
|
make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0)
|
||||||
}
|
}
|
||||||
GenericPredicate::Projection(projection_pred) => make_binders(
|
GenericPredicate::Projection(projection_pred) => make_binders(
|
||||||
chalk_ir::WhereClause::ProjectionEq(chalk_ir::ProjectionEq {
|
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
|
||||||
projection: projection_pred.projection_ty.to_chalk(db),
|
alias: projection_pred.projection_ty.to_chalk(db),
|
||||||
ty: projection_pred.ty.to_chalk(db),
|
ty: projection_pred.ty.to_chalk(db),
|
||||||
}),
|
}),
|
||||||
0,
|
0,
|
||||||
|
@ -335,8 +336,8 @@ impl ToChalk for GenericPredicate {
|
||||||
chalk_ir::WhereClause::Implemented(tr) => {
|
chalk_ir::WhereClause::Implemented(tr) => {
|
||||||
GenericPredicate::Implemented(from_chalk(db, tr))
|
GenericPredicate::Implemented(from_chalk(db, tr))
|
||||||
}
|
}
|
||||||
chalk_ir::WhereClause::ProjectionEq(projection_eq) => {
|
chalk_ir::WhereClause::AliasEq(projection_eq) => {
|
||||||
let projection_ty = from_chalk(db, projection_eq.projection);
|
let projection_ty = from_chalk(db, projection_eq.alias);
|
||||||
let ty = from_chalk(db, projection_eq.ty);
|
let ty = from_chalk(db, projection_eq.ty);
|
||||||
GenericPredicate::Projection(super::ProjectionPredicate { projection_ty, ty })
|
GenericPredicate::Projection(super::ProjectionPredicate { projection_ty, ty })
|
||||||
}
|
}
|
||||||
|
@ -345,22 +346,22 @@ impl ToChalk for GenericPredicate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToChalk for ProjectionTy {
|
impl ToChalk for ProjectionTy {
|
||||||
type Chalk = chalk_ir::ProjectionTy<TypeFamily>;
|
type Chalk = chalk_ir::AliasTy<TypeFamily>;
|
||||||
|
|
||||||
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::ProjectionTy<TypeFamily> {
|
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::AliasTy<TypeFamily> {
|
||||||
chalk_ir::ProjectionTy {
|
chalk_ir::AliasTy {
|
||||||
associated_ty_id: self.associated_ty.to_chalk(db),
|
associated_ty_id: self.associated_ty.to_chalk(db),
|
||||||
parameters: self.parameters.to_chalk(db),
|
substitution: self.parameters.to_chalk(db),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_chalk(
|
fn from_chalk(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
projection_ty: chalk_ir::ProjectionTy<TypeFamily>,
|
projection_ty: chalk_ir::AliasTy<TypeFamily>,
|
||||||
) -> ProjectionTy {
|
) -> ProjectionTy {
|
||||||
ProjectionTy {
|
ProjectionTy {
|
||||||
associated_ty: from_chalk(db, projection_ty.associated_ty_id),
|
associated_ty: from_chalk(db, projection_ty.associated_ty_id),
|
||||||
parameters: from_chalk(db, projection_ty.parameters),
|
parameters: from_chalk(db, projection_ty.substitution),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,10 +370,7 @@ impl ToChalk for super::ProjectionPredicate {
|
||||||
type Chalk = chalk_ir::Normalize<TypeFamily>;
|
type Chalk = chalk_ir::Normalize<TypeFamily>;
|
||||||
|
|
||||||
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize<TypeFamily> {
|
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize<TypeFamily> {
|
||||||
chalk_ir::Normalize {
|
chalk_ir::Normalize { alias: self.projection_ty.to_chalk(db), ty: self.ty.to_chalk(db) }
|
||||||
projection: self.projection_ty.to_chalk(db),
|
|
||||||
ty: self.ty.to_chalk(db),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize<TypeFamily>) -> Self {
|
fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize<TypeFamily>) -> Self {
|
||||||
|
|
Loading…
Reference in a new issue