From d5d485ef9289589332893f2c0ad96cb366afe9d6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 28 Jun 2020 21:17:27 +0200 Subject: Implement Chalk variable kinds This means we need to keep track of the kinds (general/int/float) of variables in `Canonical`, which requires some more ceremony. (It also exposes some places where we're not really dealing with canonicalization correctly -- another thing to be cleaned up when we switch to using Chalk's types directly.) Should fix the last remaining issue of #2534. --- crates/ra_hir_ty/src/traits.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir_ty/src/traits.rs') diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 6f43c3a22..2a6d7faef 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -1,5 +1,5 @@ //! Trait solving using Chalk. -use std::{panic, sync::Arc}; +use std::sync::Arc; use chalk_ir::cast::Cast; use hir_def::{ @@ -8,7 +8,7 @@ use hir_def::{ use ra_db::{impl_intern_key, salsa, CrateId}; use ra_prof::profile; -use crate::{db::HirDatabase, DebruijnIndex}; +use crate::{db::HirDatabase, DebruijnIndex, Substs}; use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; @@ -190,15 +190,7 @@ fn solution_from_chalk( solution: chalk_solve::Solution, ) -> Solution { let convert_subst = |subst: chalk_ir::Canonical>| { - let value = subst - .value - .iter(&Interner) - .map(|p| match p.ty(&Interner) { - Some(ty) => from_chalk(db, ty.clone()), - None => unimplemented!(), - }) - .collect(); - let result = Canonical { value, num_vars: subst.binders.len(&Interner) }; + let result = from_chalk(db, subst); SolutionVariables(result) }; match solution { @@ -222,7 +214,7 @@ fn solution_from_chalk( } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct SolutionVariables(pub Canonical>); +pub struct SolutionVariables(pub Canonical); #[derive(Clone, Debug, PartialEq, Eq)] /// A (possible) solution for a proposed goal. -- cgit v1.2.3 From 209c492432c15b017f99dba06d5937389c1f9546 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 Jul 2020 15:22:46 +0200 Subject: Upgrade Chalk --- crates/ra_hir_ty/src/traits.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty/src/traits.rs') diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 2a6d7faef..786f758e9 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use chalk_ir::cast::Cast; +use chalk_solve::Solver; use hir_def::{ expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId, }; @@ -32,9 +33,10 @@ struct ChalkContext<'a> { krate: CrateId, } -fn create_chalk_solver() -> chalk_solve::Solver { - let solver_choice = chalk_solve::SolverChoice::recursive(); - solver_choice.into_solver() +fn create_chalk_solver() -> chalk_recursive::RecursiveSolver { + let overflow_depth = 100; + let caching_enabled = true; + chalk_recursive::RecursiveSolver::new(overflow_depth, caching_enabled) } /// A set of clauses that we assume to be true. E.g. if we are inside this function: -- cgit v1.2.3 From 2a4166501d8990d3a489e89af3d92002540c288c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 Jul 2020 16:29:09 +0200 Subject: Remove built-in Unsize impls They exist in Chalk now. --- crates/ra_hir_ty/src/traits.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'crates/ra_hir_ty/src/traits.rs') diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 786f758e9..f7edb4c8b 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -295,13 +295,8 @@ pub enum Impl { /// A normal impl from an impl block. ImplDef(ImplId), /// Closure types implement the Fn traits synthetically. + // FIXME: implement closure support from Chalk, remove this ClosureFnTraitImpl(ClosureFnTraitImplData), - /// [T; n]: Unsize<[T]> - UnsizeArray, - /// T: Unsize where T: Trait - UnsizeToTraitObject(TraitId), - /// dyn Trait: Unsize if Trait: SuperTrait - UnsizeToSuperTraitObject(UnsizeToSuperTraitObjectData), } /// This exists just for Chalk, because our ImplIds are only unique per module. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -- cgit v1.2.3 From a48843a16a2306399f2f6a78c69d9192a6480c88 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 12 Jul 2020 15:26:02 +0200 Subject: Use Chalk closure support --- crates/ra_hir_ty/src/traits.rs | 51 ++---------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) (limited to 'crates/ra_hir_ty/src/traits.rs') diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index f7edb4c8b..3f6d2cf35 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -3,10 +3,8 @@ use std::sync::Arc; use chalk_ir::cast::Cast; use chalk_solve::Solver; -use hir_def::{ - expr::ExprId, lang_item::LangItemTarget, DefWithBodyId, ImplId, TraitId, TypeAliasId, -}; -use ra_db::{impl_intern_key, salsa, CrateId}; +use hir_def::{lang_item::LangItemTarget, TraitId}; +use ra_db::CrateId; use ra_prof::profile; use crate::{db::HirDatabase, DebruijnIndex, Substs}; @@ -16,7 +14,6 @@ use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, use self::chalk::{from_chalk, Interner, ToChalk}; pub(crate) mod chalk; -mod builtin; // This controls the maximum size of types Chalk considers. If we set this too // high, we can run into slow edge cases; if we set it too low, Chalk won't @@ -274,47 +271,3 @@ impl FnTrait { } } } - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct ClosureFnTraitImplData { - def: DefWithBodyId, - expr: ExprId, - fn_trait: FnTrait, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct UnsizeToSuperTraitObjectData { - trait_: TraitId, - super_trait: TraitId, -} - -/// An impl. Usually this comes from an impl block, but some built-in types get -/// synthetic impls. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Impl { - /// A normal impl from an impl block. - ImplDef(ImplId), - /// Closure types implement the Fn traits synthetically. - // FIXME: implement closure support from Chalk, remove this - ClosureFnTraitImpl(ClosureFnTraitImplData), -} -/// This exists just for Chalk, because our ImplIds are only unique per module. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct GlobalImplId(salsa::InternId); -impl_intern_key!(GlobalImplId); - -/// An associated type value. Usually this comes from a `type` declaration -/// inside an impl block, but for built-in impls we have to synthesize it. -/// (We only need this because Chalk wants a unique ID for each of these.) -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum AssocTyValue { - /// A normal assoc type value from an impl block. - TypeAlias(TypeAliasId), - /// The output type of the Fn trait implementation. - ClosureFnTraitImplOutput(ClosureFnTraitImplData), -} -/// This exists just for Chalk, because it needs a unique ID for each associated -/// type value in an impl (even synthetic ones). -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct AssocTyValueId(salsa::InternId); -impl_intern_key!(AssocTyValueId); -- cgit v1.2.3