aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs10
-rw-r--r--crates/ra_hir/src/db.rs17
-rw-r--r--crates/ra_hir/src/source_binder.rs6
-rw-r--r--crates/ra_hir/src/ty/infer.rs27
4 files changed, 27 insertions, 33 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 6d71bde92..0e987240a 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -618,7 +618,7 @@ impl Function {
618 } 618 }
619 619
620 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { 620 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
621 db.infer(self.into()) 621 db.infer(self.id.into())
622 } 622 }
623 623
624 /// The containing impl block, if this is a method. 624 /// The containing impl block, if this is a method.
@@ -672,7 +672,7 @@ impl Const {
672 } 672 }
673 673
674 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { 674 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
675 db.infer(self.into()) 675 db.infer(self.id.into())
676 } 676 }
677 677
678 /// The containing impl block, if this is a type alias. 678 /// The containing impl block, if this is a type alias.
@@ -715,7 +715,7 @@ impl Static {
715 } 715 }
716 716
717 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { 717 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
718 db.infer(self.into()) 718 db.infer(self.id.into())
719 } 719 }
720} 720}
721 721
@@ -908,9 +908,9 @@ impl Local {
908 } 908 }
909 909
910 pub fn ty(self, db: &impl HirDatabase) -> Type { 910 pub fn ty(self, db: &impl HirDatabase) -> Type {
911 let infer = db.infer(self.parent);
912 let ty = infer[self.pat_id].clone();
913 let def = DefWithBodyId::from(self.parent); 911 let def = DefWithBodyId::from(self.parent);
912 let infer = db.infer(def);
913 let ty = infer[self.pat_id].clone();
914 let resolver = def.resolver(db); 914 let resolver = def.resolver(db);
915 let krate = def.module(db).krate; 915 let krate = def.module(db).krate;
916 let environment = TraitEnvironment::lower(db, &resolver); 916 let environment = TraitEnvironment::lower(db, &resolver);
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index a5bfef91f..e192c8f47 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -2,18 +2,15 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{GenericDefId, ImplId, LocalStructFieldId, TraitId, VariantId}; 5use hir_def::{DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, VariantId};
6use ra_arena::map::ArenaMap; 6use ra_arena::map::ArenaMap;
7use ra_db::{salsa, CrateId}; 7use ra_db::{salsa, CrateId};
8 8
9use crate::{ 9use crate::ty::{
10 ty::{ 10 method_resolution::CrateImplBlocks,
11 method_resolution::CrateImplBlocks, 11 traits::{AssocTyValue, Impl},
12 traits::{AssocTyValue, Impl}, 12 CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor,
13 CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor, 13 ValueTyDefId,
14 ValueTyDefId,
15 },
16 DefWithBody,
17}; 14};
18 15
19pub use hir_def::db::{ 16pub use hir_def::db::{
@@ -32,7 +29,7 @@ pub use hir_expand::db::{
32#[salsa::requires(salsa::Database)] 29#[salsa::requires(salsa::Database)]
33pub trait HirDatabase: DefDatabase { 30pub trait HirDatabase: DefDatabase {
34 #[salsa::invoke(crate::ty::infer_query)] 31 #[salsa::invoke(crate::ty::infer_query)]
35 fn infer(&self, def: DefWithBody) -> Arc<InferenceResult>; 32 fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
36 33
37 #[salsa::invoke(crate::ty::ty_query)] 34 #[salsa::invoke(crate::ty::ty_query)]
38 fn ty(&self, def: TyDefId) -> Ty; 35 fn ty(&self, def: TyDefId) -> Ty;
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 0de36abd1..c85e38a0d 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -168,7 +168,7 @@ impl SourceAnalyzer {
168 resolver, 168 resolver,
169 body_owner: Some(def), 169 body_owner: Some(def),
170 body_source_map: Some(source_map), 170 body_source_map: Some(source_map),
171 infer: Some(db.infer(def)), 171 infer: Some(db.infer(def.into())),
172 scopes: Some(scopes), 172 scopes: Some(scopes),
173 file_id: node.file_id, 173 file_id: node.file_id,
174 } 174 }
@@ -297,13 +297,13 @@ impl SourceAnalyzer {
297 if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { 297 if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
298 let expr_id = self.expr_id(&path_expr.into())?; 298 let expr_id = self.expr_id(&path_expr.into())?;
299 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) { 299 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
300 return Some(PathResolution::AssocItem(assoc)); 300 return Some(PathResolution::AssocItem(assoc.into()));
301 } 301 }
302 } 302 }
303 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) { 303 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
304 let pat_id = self.pat_id(&path_pat.into())?; 304 let pat_id = self.pat_id(&path_pat.into())?;
305 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) { 305 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
306 return Some(PathResolution::AssocItem(assoc)); 306 return Some(PathResolution::AssocItem(assoc.into()));
307 } 307 }
308 } 308 }
309 // This must be a normal source file rather than macro file. 309 // This must be a normal source file rather than macro file.
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 7b6dfd61b..1eca4883d 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -41,10 +41,7 @@ use super::{
41 ApplicationTy, InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeCtor, 41 ApplicationTy, InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeCtor,
42 TypeWalk, Uncertain, 42 TypeWalk, Uncertain,
43}; 43};
44use crate::{ 44use crate::{db::HirDatabase, ty::infer::diagnostics::InferenceDiagnostic, VariantDef};
45 db::HirDatabase, ty::infer::diagnostics::InferenceDiagnostic, AssocItem, DefWithBody,
46 VariantDef,
47};
48 45
49macro_rules! ty_app { 46macro_rules! ty_app {
50 ($ctor:pat, $param:pat) => { 47 ($ctor:pat, $param:pat) => {
@@ -62,15 +59,15 @@ mod pat;
62mod coerce; 59mod coerce;
63 60
64/// The entry point of type inference. 61/// The entry point of type inference.
65pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> { 62pub fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
66 let _p = profile("infer_query"); 63 let _p = profile("infer_query");
67 let resolver = DefWithBodyId::from(def).resolver(db); 64 let resolver = def.resolver(db);
68 let mut ctx = InferenceContext::new(db, def, resolver); 65 let mut ctx = InferenceContext::new(db, def, resolver);
69 66
70 match &def { 67 match def {
71 DefWithBody::Const(c) => ctx.collect_const(&db.const_data(c.id)), 68 DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)),
72 DefWithBody::Function(f) => ctx.collect_fn(&db.function_data(f.id)), 69 DefWithBodyId::FunctionId(f) => ctx.collect_fn(&db.function_data(f)),
73 DefWithBody::Static(s) => ctx.collect_const(&db.static_data(s.id)), 70 DefWithBodyId::StaticId(s) => ctx.collect_const(&db.static_data(s)),
74 } 71 }
75 72
76 ctx.infer_body(); 73 ctx.infer_body();
@@ -129,7 +126,7 @@ pub struct InferenceResult {
129 /// For each struct literal, records the variant it resolves to. 126 /// For each struct literal, records the variant it resolves to.
130 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>, 127 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>,
131 /// For each associated item record what it resolves to 128 /// For each associated item record what it resolves to
132 assoc_resolutions: FxHashMap<ExprOrPatId, AssocItem>, 129 assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>,
133 diagnostics: Vec<InferenceDiagnostic>, 130 diagnostics: Vec<InferenceDiagnostic>,
134 pub(super) type_of_expr: ArenaMap<ExprId, Ty>, 131 pub(super) type_of_expr: ArenaMap<ExprId, Ty>,
135 pub(super) type_of_pat: ArenaMap<PatId, Ty>, 132 pub(super) type_of_pat: ArenaMap<PatId, Ty>,
@@ -152,10 +149,10 @@ impl InferenceResult {
152 pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> { 149 pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> {
153 self.variant_resolutions.get(&id.into()).copied() 150 self.variant_resolutions.get(&id.into()).copied()
154 } 151 }
155 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<AssocItem> { 152 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<AssocItemId> {
156 self.assoc_resolutions.get(&id.into()).copied() 153 self.assoc_resolutions.get(&id.into()).copied()
157 } 154 }
158 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<AssocItem> { 155 pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<AssocItemId> {
159 self.assoc_resolutions.get(&id.into()).copied() 156 self.assoc_resolutions.get(&id.into()).copied()
160 } 157 }
161 pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> { 158 pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> {
@@ -191,7 +188,7 @@ impl Index<PatId> for InferenceResult {
191#[derive(Clone, Debug)] 188#[derive(Clone, Debug)]
192struct InferenceContext<'a, D: HirDatabase> { 189struct InferenceContext<'a, D: HirDatabase> {
193 db: &'a D, 190 db: &'a D,
194 owner: DefWithBody, 191 owner: DefWithBodyId,
195 body: Arc<Body>, 192 body: Arc<Body>,
196 resolver: Resolver, 193 resolver: Resolver,
197 var_unification_table: InPlaceUnificationTable<TypeVarId>, 194 var_unification_table: InPlaceUnificationTable<TypeVarId>,
@@ -209,7 +206,7 @@ struct InferenceContext<'a, D: HirDatabase> {
209} 206}
210 207
211impl<'a, D: HirDatabase> InferenceContext<'a, D> { 208impl<'a, D: HirDatabase> InferenceContext<'a, D> {
212 fn new(db: &'a D, owner: DefWithBody, resolver: Resolver) -> Self { 209 fn new(db: &'a D, owner: DefWithBodyId, resolver: Resolver) -> Self {
213 InferenceContext { 210 InferenceContext {
214 result: InferenceResult::default(), 211 result: InferenceResult::default(),
215 var_unification_table: InPlaceUnificationTable::new(), 212 var_unification_table: InPlaceUnificationTable::new(),