aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-27 19:12:09 +0000
committerAleksey Kladov <[email protected]>2019-11-27 19:12:09 +0000
commit8d3469682681d5b206d5ae31fc63fb97d9cedb3a (patch)
treee575e72ac9a441b5f9d6112087dab201e9a506ac /crates/ra_hir_ty/src/infer
parent27b362b05910c81fd5b28f6cd5d2c075311032f9 (diff)
Memoize impl resolutions
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r--crates/ra_hir_ty/src/infer/coerce.rs22
-rw-r--r--crates/ra_hir_ty/src/infer/path.rs10
2 files changed, 10 insertions, 22 deletions
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs
index d66a21932..719a0f395 100644
--- a/crates/ra_hir_ty/src/infer/coerce.rs
+++ b/crates/ra_hir_ty/src/infer/coerce.rs
@@ -4,16 +4,11 @@
4//! 4//!
5//! See: https://doc.rust-lang.org/nomicon/coercions.html 5//! See: https://doc.rust-lang.org/nomicon/coercions.html
6 6
7use hir_def::{ 7use hir_def::{lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AdtId};
8 lang_item::LangItemTarget,
9 resolver::{HasResolver, Resolver},
10 type_ref::Mutability,
11 AdtId,
12};
13use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
14use test_utils::tested_by; 9use test_utils::tested_by;
15 10
16use crate::{autoderef, db::HirDatabase, Substs, TraitRef, Ty, TypeCtor, TypeWalk}; 11use crate::{autoderef, db::HirDatabase, ImplTy, Substs, Ty, TypeCtor, TypeWalk};
17 12
18use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; 13use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue};
19 14
@@ -59,17 +54,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
59 impls 54 impls
60 .iter() 55 .iter()
61 .filter_map(|&impl_id| { 56 .filter_map(|&impl_id| {
62 let impl_data = db.impl_data(impl_id); 57 let trait_ref = match db.impl_ty(impl_id) {
63 let resolver = impl_id.resolver(db); 58 ImplTy::TraitRef(it) => it,
64 let target_ty = Ty::from_hir(db, &resolver, &impl_data.target_type); 59 ImplTy::Inherent(_) => return None,
60 };
65 61
66 // `CoerseUnsized` has one generic parameter for the target type. 62 // `CoerseUnsized` has one generic parameter for the target type.
67 let trait_ref = TraitRef::from_hir(
68 db,
69 &resolver,
70 impl_data.target_trait.as_ref()?,
71 Some(target_ty),
72 )?;
73 let cur_from_ty = trait_ref.substs.0.get(0)?; 63 let cur_from_ty = trait_ref.substs.0.get(0)?;
74 let cur_to_ty = trait_ref.substs.0.get(1)?; 64 let cur_to_ty = trait_ref.substs.0.get(1)?;
75 65
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs
index e6676e1aa..14be66836 100644
--- a/crates/ra_hir_ty/src/infer/path.rs
+++ b/crates/ra_hir_ty/src/infer/path.rs
@@ -2,7 +2,7 @@
2 2
3use hir_def::{ 3use hir_def::{
4 path::{Path, PathKind, PathSegment}, 4 path::{Path, PathKind, PathSegment},
5 resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs}, 5 resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs},
6 AssocItemId, ContainerId, Lookup, 6 AssocItemId, ContainerId, Lookup,
7}; 7};
8use hir_expand::name::Name; 8use hir_expand::name::Name;
@@ -244,17 +244,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
244 ContainerId::ImplId(it) => it, 244 ContainerId::ImplId(it) => it,
245 _ => return None, 245 _ => return None,
246 }; 246 };
247 let resolver = impl_id.resolver(self.db); 247 let self_ty = self.db.impl_ty(impl_id).self_type().clone();
248 let impl_data = self.db.impl_data(impl_id); 248 let self_ty_substs = self_ty.substs()?;
249 let impl_block = Ty::from_hir(self.db, &resolver, &impl_data.target_type);
250 let impl_block_substs = impl_block.substs()?;
251 let actual_substs = actual_def_ty.substs()?; 249 let actual_substs = actual_def_ty.substs()?;
252 250
253 let mut new_substs = vec![Ty::Unknown; gen.count_parent_params()]; 251 let mut new_substs = vec![Ty::Unknown; gen.count_parent_params()];
254 252
255 // The following code *link up* the function actual parma type 253 // The following code *link up* the function actual parma type
256 // and impl_block type param index 254 // and impl_block type param index
257 impl_block_substs.iter().zip(actual_substs.iter()).for_each(|(param, pty)| { 255 self_ty_substs.iter().zip(actual_substs.iter()).for_each(|(param, pty)| {
258 if let Ty::Param { idx, .. } = param { 256 if let Ty::Param { idx, .. } = param {
259 if let Some(s) = new_substs.get_mut(*idx as usize) { 257 if let Some(s) = new_substs.get_mut(*idx as usize) {
260 *s = pty.clone(); 258 *s = pty.clone();