mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +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]]
|
||||
name = "chalk-derive"
|
||||
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 = [
|
||||
"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)",
|
||||
|
@ -141,27 +141,27 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "chalk-engine"
|
||||
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 = [
|
||||
"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)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chalk-ir"
|
||||
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 = [
|
||||
"chalk-derive 0.1.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=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
||||
"chalk-macros 0.1.1 (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=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||
"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)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chalk-macros"
|
||||
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 = [
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -169,24 +169,24 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "chalk-rust-ir"
|
||||
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 = [
|
||||
"chalk-derive 0.1.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=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
||||
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
||||
"chalk-macros 0.1.1 (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=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||
"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=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chalk-solve"
|
||||
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 = [
|
||||
"chalk-derive 0.1.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=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
||||
"chalk-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)",
|
||||
"chalk-macros 0.1.1 (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=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=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||
"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=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||
"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)",
|
||||
"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)",
|
||||
|
@ -1004,9 +1004,9 @@ name = "ra_hir_ty"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"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-rust-ir 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=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=af48f302a1f571b3ca418f7c5aa639a144a34f75)",
|
||||
"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)",
|
||||
"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)",
|
||||
|
@ -1775,12 +1775,12 @@ dependencies = [
|
|||
"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 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-engine 0.9.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=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
||||
"checksum chalk-macros 0.1.1 (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=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
|
||||
"checksum chalk-solve 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=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<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=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<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=af48f302a1f571b3ca418f7c5aa639a144a34f75)" = "<none>"
|
||||
"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 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" }
|
||||
test_utils = { path = "../test_utils" }
|
||||
|
||||
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
|
||||
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5" }
|
||||
chalk-ir = { 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 = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
|
||||
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
|
||||
|
||||
lalrpop-intern = "0.15.1"
|
||||
|
||||
|
|
|
@ -50,10 +50,19 @@ impl TraitSolver {
|
|||
Err(_) => ra_db::Canceled::throw(),
|
||||
};
|
||||
|
||||
let fuel = std::cell::Cell::new(CHALK_SOLVER_FUEL);
|
||||
|
||||
let solution = panic::catch_unwind({
|
||||
let solver = panic::AssertUnwindSafe(&mut solver);
|
||||
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 {
|
||||
|
@ -79,6 +88,9 @@ impl TraitSolver {
|
|||
/// high, we can run into slow edge cases; if we set it too low, Chalk won't
|
||||
/// find some solutions.
|
||||
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)]
|
||||
struct ChalkContext<'a, DB> {
|
||||
|
@ -97,7 +109,8 @@ pub(crate) fn trait_solver_query(
|
|||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -232,7 +245,6 @@ fn solution_from_chalk(
|
|||
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| {
|
||||
let value = subst
|
||||
.value
|
||||
.parameters
|
||||
.into_iter()
|
||||
.map(|p| {
|
||||
let ty = match p.ty() {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{fmt, sync::Arc};
|
|||
|
||||
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 ra_db::{
|
||||
|
@ -24,6 +24,8 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
|
|||
type InternedType = Box<chalk_ir::TyData<Self>>;
|
||||
type InternedLifetime = chalk_ir::LifetimeData<Self>;
|
||||
type InternedParameter = chalk_ir::ParameterData<Self>;
|
||||
type InternedGoal = Arc<GoalData<Self>>;
|
||||
type InternedSubstitution = Vec<Parameter<Self>>;
|
||||
type DefId = InternId;
|
||||
|
||||
// FIXME: implement these
|
||||
|
@ -48,8 +50,8 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
|
|||
None
|
||||
}
|
||||
|
||||
fn debug_projection(
|
||||
_projection: &chalk_ir::ProjectionTy<Self>,
|
||||
fn debug_alias(
|
||||
_projection: &chalk_ir::AliasTy<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
|
@ -78,6 +80,24 @@ impl chalk_ir::family::TypeFamily for TypeFamily {
|
|||
fn parameter_data(parameter: &chalk_ir::ParameterData<Self>) -> &chalk_ir::ParameterData<Self> {
|
||||
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 {
|
||||
|
@ -114,13 +134,13 @@ impl ToChalk for Ty {
|
|||
match self {
|
||||
Ty::Apply(apply_ty) => {
|
||||
let name = apply_ty.ctor.to_chalk(db);
|
||||
let parameters = apply_ty.parameters.to_chalk(db);
|
||||
chalk_ir::ApplicationTy { name, parameters }.cast().intern()
|
||||
let substitution = apply_ty.parameters.to_chalk(db);
|
||||
chalk_ir::ApplicationTy { name, substitution }.cast().intern()
|
||||
}
|
||||
Ty::Projection(proj_ty) => {
|
||||
let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
|
||||
let parameters = proj_ty.parameters.to_chalk(db);
|
||||
chalk_ir::ProjectionTy { associated_ty_id, parameters }.cast().intern()
|
||||
let substitution = proj_ty.parameters.to_chalk(db);
|
||||
chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern()
|
||||
}
|
||||
Ty::Param { idx, .. } => {
|
||||
PlaceholderIndex { ui: UniverseIndex::ROOT, idx: idx as usize }
|
||||
|
@ -135,23 +155,13 @@ impl ToChalk for Ty {
|
|||
.cloned()
|
||||
.map(|p| p.to_chalk(db))
|
||||
.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()
|
||||
}
|
||||
Ty::Opaque(predicates) => {
|
||||
let where_clauses = predicates
|
||||
.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();
|
||||
Ty::Opaque(_) | Ty::Unknown => {
|
||||
let substitution = chalk_ir::Substitution::empty();
|
||||
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,
|
||||
_ => {
|
||||
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 })
|
||||
}
|
||||
},
|
||||
|
@ -169,12 +179,12 @@ impl ToChalk for Ty {
|
|||
assert_eq!(idx.ui, UniverseIndex::ROOT);
|
||||
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 parameters = from_chalk(db, proj.parameters);
|
||||
let parameters = from_chalk(db, proj.substitution);
|
||||
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::InferenceVar(_iv) => Ty::Unknown,
|
||||
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();
|
||||
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 {
|
||||
type Chalk = Vec<chalk_ir::Parameter<TypeFamily>>;
|
||||
type Chalk = chalk_ir::Substitution<TypeFamily>;
|
||||
|
||||
fn to_chalk(self, db: &impl HirDatabase) -> Vec<Parameter<TypeFamily>> {
|
||||
self.iter().map(|ty| ty.clone().to_chalk(db).cast()).collect()
|
||||
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Substitution<TypeFamily> {
|
||||
chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db)))
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
db: &impl HirDatabase,
|
||||
parameters: Vec<chalk_ir::Parameter<TypeFamily>>,
|
||||
) -> Substs {
|
||||
fn from_chalk(db: &impl HirDatabase, parameters: chalk_ir::Substitution<TypeFamily>) -> Substs {
|
||||
let tys = parameters
|
||||
.into_iter()
|
||||
.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> {
|
||||
let trait_id = self.trait_.to_chalk(db);
|
||||
let parameters = self.substs.to_chalk(db);
|
||||
chalk_ir::TraitRef { trait_id, parameters }
|
||||
let substitution = self.substs.to_chalk(db);
|
||||
chalk_ir::TraitRef { trait_id, substitution }
|
||||
}
|
||||
|
||||
fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef<TypeFamily>) -> Self {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
@ -317,8 +318,8 @@ impl ToChalk for GenericPredicate {
|
|||
make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0)
|
||||
}
|
||||
GenericPredicate::Projection(projection_pred) => make_binders(
|
||||
chalk_ir::WhereClause::ProjectionEq(chalk_ir::ProjectionEq {
|
||||
projection: projection_pred.projection_ty.to_chalk(db),
|
||||
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
|
||||
alias: projection_pred.projection_ty.to_chalk(db),
|
||||
ty: projection_pred.ty.to_chalk(db),
|
||||
}),
|
||||
0,
|
||||
|
@ -335,8 +336,8 @@ impl ToChalk for GenericPredicate {
|
|||
chalk_ir::WhereClause::Implemented(tr) => {
|
||||
GenericPredicate::Implemented(from_chalk(db, tr))
|
||||
}
|
||||
chalk_ir::WhereClause::ProjectionEq(projection_eq) => {
|
||||
let projection_ty = from_chalk(db, projection_eq.projection);
|
||||
chalk_ir::WhereClause::AliasEq(projection_eq) => {
|
||||
let projection_ty = from_chalk(db, projection_eq.alias);
|
||||
let ty = from_chalk(db, projection_eq.ty);
|
||||
GenericPredicate::Projection(super::ProjectionPredicate { projection_ty, ty })
|
||||
}
|
||||
|
@ -345,22 +346,22 @@ impl ToChalk for GenericPredicate {
|
|||
}
|
||||
|
||||
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> {
|
||||
chalk_ir::ProjectionTy {
|
||||
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::AliasTy<TypeFamily> {
|
||||
chalk_ir::AliasTy {
|
||||
associated_ty_id: self.associated_ty.to_chalk(db),
|
||||
parameters: self.parameters.to_chalk(db),
|
||||
substitution: self.parameters.to_chalk(db),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
db: &impl HirDatabase,
|
||||
projection_ty: chalk_ir::ProjectionTy<TypeFamily>,
|
||||
projection_ty: chalk_ir::AliasTy<TypeFamily>,
|
||||
) -> ProjectionTy {
|
||||
ProjectionTy {
|
||||
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>;
|
||||
|
||||
fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize<TypeFamily> {
|
||||
chalk_ir::Normalize {
|
||||
projection: self.projection_ty.to_chalk(db),
|
||||
ty: self.ty.to_chalk(db),
|
||||
}
|
||||
chalk_ir::Normalize { alias: self.projection_ty.to_chalk(db), ty: self.ty.to_chalk(db) }
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize<TypeFamily>) -> Self {
|
||||
|
|
Loading…
Reference in a new issue