diff options
author | Aleksey Kladov <[email protected]> | 2019-11-27 19:12:09 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-27 19:12:09 +0000 |
commit | 8d3469682681d5b206d5ae31fc63fb97d9cedb3a (patch) | |
tree | e575e72ac9a441b5f9d6112087dab201e9a506ac /crates/ra_hir_ty/src/traits | |
parent | 27b362b05910c81fd5b28f6cd5d2c075311032f9 (diff) |
Memoize impl resolutions
Diffstat (limited to 'crates/ra_hir_ty/src/traits')
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 810e8c21a..35de37e6b 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -11,8 +11,8 @@ use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum | |||
11 | use ra_db::CrateId; | 11 | use ra_db::CrateId; |
12 | 12 | ||
13 | use hir_def::{ | 13 | use hir_def::{ |
14 | expr::Expr, lang_item::LangItemTarget, resolver::HasResolver, AssocItemId, AstItemDef, | 14 | expr::Expr, lang_item::LangItemTarget, AssocItemId, AstItemDef, ContainerId, GenericDefId, |
15 | ContainerId, GenericDefId, ImplId, Lookup, TraitId, TypeAliasId, | 15 | ImplId, Lookup, TraitId, TypeAliasId, |
16 | }; | 16 | }; |
17 | use hir_expand::name; | 17 | use hir_expand::name; |
18 | 18 | ||
@@ -20,9 +20,8 @@ use ra_db::salsa::{InternId, InternKey}; | |||
20 | 20 | ||
21 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; | 21 | use super::{AssocTyValue, Canonical, ChalkContext, Impl, Obligation}; |
22 | use crate::{ | 22 | use crate::{ |
23 | db::HirDatabase, | 23 | db::HirDatabase, display::HirDisplay, ApplicationTy, GenericPredicate, ImplTy, ProjectionTy, |
24 | display::HirDisplay, | 24 | Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
25 | {ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, | ||
26 | }; | 25 | }; |
27 | 26 | ||
28 | /// This represents a trait whose name we could not resolve. | 27 | /// This represents a trait whose name we could not resolve. |
@@ -631,13 +630,11 @@ fn impl_block_datum( | |||
631 | chalk_id: chalk_ir::ImplId, | 630 | chalk_id: chalk_ir::ImplId, |
632 | impl_id: ImplId, | 631 | impl_id: ImplId, |
633 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { | 632 | ) -> Option<Arc<ImplDatum<ChalkIr>>> { |
633 | let trait_ref = match db.impl_ty(impl_id) { | ||
634 | ImplTy::TraitRef(it) => it, | ||
635 | ImplTy::Inherent(_) => return None, | ||
636 | }; | ||
634 | let impl_data = db.impl_data(impl_id); | 637 | let impl_data = db.impl_data(impl_id); |
635 | let resolver = impl_id.resolver(db); | ||
636 | let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); | ||
637 | |||
638 | // `CoerseUnsized` has one generic parameter for the target type. | ||
639 | let trait_ref = | ||
640 | TraitRef::from_hir(db, &resolver, impl_data.target_trait.as_ref()?, Some(target_ty))?; | ||
641 | 638 | ||
642 | let generic_params = db.generic_params(impl_id.into()); | 639 | let generic_params = db.generic_params(impl_id.into()); |
643 | let bound_vars = Substs::bound_vars(&generic_params); | 640 | let bound_vars = Substs::bound_vars(&generic_params); |
@@ -790,17 +787,14 @@ fn type_alias_associated_ty_value( | |||
790 | _ => panic!("assoc ty value should be in impl"), | 787 | _ => panic!("assoc ty value should be in impl"), |
791 | }; | 788 | }; |
792 | 789 | ||
793 | let impl_data = db.impl_data(impl_id); | 790 | let trait_ref = match db.impl_ty(impl_id) { |
794 | let resolver = impl_id.resolver(db); | 791 | ImplTy::TraitRef(it) => it, |
795 | let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); | 792 | // we don't return any assoc ty values if the impl'd trait can't be resolved |
796 | let target_trait = impl_data | 793 | ImplTy::Inherent(_) => panic!("assoc ty value should not exist"), |
797 | .target_trait | 794 | }; |
798 | .as_ref() | ||
799 | .and_then(|trait_ref| TraitRef::from_hir(db, &resolver, &trait_ref, Some(target_ty))) | ||
800 | .expect("assoc ty value should not exist"); // we don't return any assoc ty values if the impl'd trait can't be resolved | ||
801 | 795 | ||
802 | let assoc_ty = db | 796 | let assoc_ty = db |
803 | .trait_data(target_trait.trait_) | 797 | .trait_data(trait_ref.trait_) |
804 | .associated_type_by_name(&type_alias_data.name) | 798 | .associated_type_by_name(&type_alias_data.name) |
805 | .expect("assoc ty value should not exist"); // validated when building the impl data as well | 799 | .expect("assoc ty value should not exist"); // validated when building the impl data as well |
806 | let generic_params = db.generic_params(impl_id.into()); | 800 | let generic_params = db.generic_params(impl_id.into()); |