diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_hir_ty/src/traits.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_hir_ty/src/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 80 |
1 files changed, 11 insertions, 69 deletions
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 6f43c3a22..3f6d2cf35 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -1,21 +1,19 @@ | |||
1 | //! Trait solving using Chalk. | 1 | //! Trait solving using Chalk. |
2 | use std::{panic, sync::Arc}; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use chalk_ir::cast::Cast; | 4 | use chalk_ir::cast::Cast; |
5 | use hir_def::{ | 5 | use chalk_solve::Solver; |
6 | expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId, | 6 | use hir_def::{lang_item::LangItemTarget, TraitId}; |
7 | }; | 7 | use ra_db::CrateId; |
8 | use ra_db::{impl_intern_key, salsa, CrateId}; | ||
9 | use ra_prof::profile; | 8 | use ra_prof::profile; |
10 | 9 | ||
11 | use crate::{db::HirDatabase, DebruijnIndex}; | 10 | use crate::{db::HirDatabase, DebruijnIndex, Substs}; |
12 | 11 | ||
13 | use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; | 12 | use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; |
14 | 13 | ||
15 | use self::chalk::{from_chalk, Interner, ToChalk}; | 14 | use self::chalk::{from_chalk, Interner, ToChalk}; |
16 | 15 | ||
17 | pub(crate) mod chalk; | 16 | pub(crate) mod chalk; |
18 | mod builtin; | ||
19 | 17 | ||
20 | // This controls the maximum size of types Chalk considers. If we set this too | 18 | // This controls the maximum size of types Chalk considers. If we set this too |
21 | // high, we can run into slow edge cases; if we set it too low, Chalk won't | 19 | // high, we can run into slow edge cases; if we set it too low, Chalk won't |
@@ -32,9 +30,10 @@ struct ChalkContext<'a> { | |||
32 | krate: CrateId, | 30 | krate: CrateId, |
33 | } | 31 | } |
34 | 32 | ||
35 | fn create_chalk_solver() -> chalk_solve::Solver<Interner> { | 33 | fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> { |
36 | let solver_choice = chalk_solve::SolverChoice::recursive(); | 34 | let overflow_depth = 100; |
37 | solver_choice.into_solver() | 35 | let caching_enabled = true; |
36 | chalk_recursive::RecursiveSolver::new(overflow_depth, caching_enabled) | ||
38 | } | 37 | } |
39 | 38 | ||
40 | /// A set of clauses that we assume to be true. E.g. if we are inside this function: | 39 | /// A set of clauses that we assume to be true. E.g. if we are inside this function: |
@@ -190,15 +189,7 @@ fn solution_from_chalk( | |||
190 | solution: chalk_solve::Solution<Interner>, | 189 | solution: chalk_solve::Solution<Interner>, |
191 | ) -> Solution { | 190 | ) -> Solution { |
192 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| { | 191 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| { |
193 | let value = subst | 192 | let result = from_chalk(db, subst); |
194 | .value | ||
195 | .iter(&Interner) | ||
196 | .map(|p| match p.ty(&Interner) { | ||
197 | Some(ty) => from_chalk(db, ty.clone()), | ||
198 | None => unimplemented!(), | ||
199 | }) | ||
200 | .collect(); | ||
201 | let result = Canonical { value, num_vars: subst.binders.len(&Interner) }; | ||
202 | SolutionVariables(result) | 193 | SolutionVariables(result) |
203 | }; | 194 | }; |
204 | match solution { | 195 | match solution { |
@@ -222,7 +213,7 @@ fn solution_from_chalk( | |||
222 | } | 213 | } |
223 | 214 | ||
224 | #[derive(Clone, Debug, PartialEq, Eq)] | 215 | #[derive(Clone, Debug, PartialEq, Eq)] |
225 | pub struct SolutionVariables(pub Canonical<Vec<Ty>>); | 216 | pub struct SolutionVariables(pub Canonical<Substs>); |
226 | 217 | ||
227 | #[derive(Clone, Debug, PartialEq, Eq)] | 218 | #[derive(Clone, Debug, PartialEq, Eq)] |
228 | /// A (possible) solution for a proposed goal. | 219 | /// A (possible) solution for a proposed goal. |
@@ -280,52 +271,3 @@ impl FnTrait { | |||
280 | } | 271 | } |
281 | } | 272 | } |
282 | } | 273 | } |
283 | |||
284 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
285 | pub struct ClosureFnTraitImplData { | ||
286 | def: DefWithBodyId, | ||
287 | expr: ExprId, | ||
288 | fn_trait: FnTrait, | ||
289 | } | ||
290 | |||
291 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
292 | pub struct UnsizeToSuperTraitObjectData { | ||
293 | trait_: TraitId, | ||
294 | super_trait: TraitId, | ||
295 | } | ||
296 | |||
297 | /// An impl. Usually this comes from an impl block, but some built-in types get | ||
298 | /// synthetic impls. | ||
299 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
300 | pub enum Impl { | ||
301 | /// A normal impl from an impl block. | ||
302 | ImplDef(ImplId), | ||
303 | /// Closure types implement the Fn traits synthetically. | ||
304 | ClosureFnTraitImpl(ClosureFnTraitImplData), | ||
305 | /// [T; n]: Unsize<[T]> | ||
306 | UnsizeArray, | ||
307 | /// T: Unsize<dyn Trait> where T: Trait | ||
308 | UnsizeToTraitObject(TraitId), | ||
309 | /// dyn Trait: Unsize<dyn SuperTrait> if Trait: SuperTrait | ||
310 | UnsizeToSuperTraitObject(UnsizeToSuperTraitObjectData), | ||
311 | } | ||
312 | /// This exists just for Chalk, because our ImplIds are only unique per module. | ||
313 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
314 | pub struct GlobalImplId(salsa::InternId); | ||
315 | impl_intern_key!(GlobalImplId); | ||
316 | |||
317 | /// An associated type value. Usually this comes from a `type` declaration | ||
318 | /// inside an impl block, but for built-in impls we have to synthesize it. | ||
319 | /// (We only need this because Chalk wants a unique ID for each of these.) | ||
320 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
321 | pub enum AssocTyValue { | ||
322 | /// A normal assoc type value from an impl block. | ||
323 | TypeAlias(TypeAliasId), | ||
324 | /// The output type of the Fn trait implementation. | ||
325 | ClosureFnTraitImplOutput(ClosureFnTraitImplData), | ||
326 | } | ||
327 | /// This exists just for Chalk, because it needs a unique ID for each associated | ||
328 | /// type value in an impl (even synthetic ones). | ||
329 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
330 | pub struct AssocTyValueId(salsa::InternId); | ||
331 | impl_intern_key!(AssocTyValueId); | ||