aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-27 23:49:28 +0000
committerAleksey Kladov <[email protected]>2018-11-27 23:49:28 +0000
commitb2de95879a8d48cc4077895376b0aaed1e972169 (patch)
tree32b7ae7146237d3f861cf58c1dac70ed0d462059 /crates/ra_analysis/src/hir
parentec45dfea1e37ba40ea3e2c8c6df0991a3d49213f (diff)
generalize location interner
Diffstat (limited to 'crates/ra_analysis/src/hir')
-rw-r--r--crates/ra_analysis/src/hir/db.rs18
-rw-r--r--crates/ra_analysis/src/hir/function/mod.rs2
-rw-r--r--crates/ra_analysis/src/hir/mod.rs2
-rw-r--r--crates/ra_analysis/src/hir/module/mod.rs4
-rw-r--r--crates/ra_analysis/src/hir/module/nameres.rs6
-rw-r--r--crates/ra_analysis/src/hir/query_definitions.rs2
6 files changed, 19 insertions, 15 deletions
diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs
index 0998295f5..bf0dc393a 100644
--- a/crates/ra_analysis/src/hir/db.rs
+++ b/crates/ra_analysis/src/hir/db.rs
@@ -8,20 +8,24 @@ use ra_syntax::{
8use crate::{ 8use crate::{
9 FileId, 9 FileId,
10 db::SyntaxDatabase, 10 db::SyntaxDatabase,
11 hir::{SourceFileItems, SourceItemId}, 11 hir::{
12 hir::query_definitions, 12 SourceFileItems, SourceItemId,
13 hir::function::{FnId, FnScopes}, 13 query_definitions,
14 hir::module::{ 14 function::{FnScopes},
15 ModuleId, ModuleTree, ModuleSource, 15 module::{ModuleId, ModuleTree, ModuleSource,
16 nameres::{ItemMap, InputModuleItems} 16 nameres::{ItemMap, InputModuleItems}},
17 }, 17 },
18 input::SourceRootId, 18 input::SourceRootId,
19 loc2id::{DefLoc, DefId, FnId, LocationIntener},
19 Cancelable, 20 Cancelable,
20}; 21};
21 22
22salsa::query_group! { 23salsa::query_group! {
23 24
24pub(crate) trait HirDatabase: SyntaxDatabase { 25pub(crate) trait HirDatabase: SyntaxDatabase
26 + AsRef<LocationIntener<DefLoc, DefId>>
27 + AsRef<LocationIntener<SourceItemId, FnId>>
28{
25 fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> { 29 fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> {
26 type FnScopesQuery; 30 type FnScopesQuery;
27 use fn query_definitions::fn_scopes; 31 use fn query_definitions::fn_scopes;
diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs
index 280218fd4..e64a9f045 100644
--- a/crates/ra_analysis/src/hir/function/mod.rs
+++ b/crates/ra_analysis/src/hir/function/mod.rs
@@ -23,7 +23,7 @@ impl FnId {
23 let file_items = db.file_items(file_id); 23 let file_items = db.file_items(file_id);
24 let item_id = file_items.id_of(fn_def.syntax()); 24 let item_id = file_items.id_of(fn_def.syntax());
25 let item_id = SourceItemId { file_id, item_id }; 25 let item_id = SourceItemId { file_id, item_id };
26 db.id_maps().fn_id(item_id) 26 FnId::from_loc(db, &item_id)
27 } 27 }
28} 28}
29 29
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index 9527cc33f..61e6c9913 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -38,7 +38,7 @@ pub(crate) enum Def {
38 38
39impl DefId { 39impl DefId {
40 pub(crate) fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> { 40 pub(crate) fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> {
41 let loc = db.id_maps().def_loc(self); 41 let loc = self.loc(db);
42 let res = match loc { 42 let res = match loc {
43 DefLoc::Module { id, source_root } => { 43 DefLoc::Module { id, source_root } => {
44 let descr = Module::new(db, source_root, id)?; 44 let descr = Module::new(db, source_root, id)?;
diff --git a/crates/ra_analysis/src/hir/module/mod.rs b/crates/ra_analysis/src/hir/module/mod.rs
index 83f176b32..893ec3a10 100644
--- a/crates/ra_analysis/src/hir/module/mod.rs
+++ b/crates/ra_analysis/src/hir/module/mod.rs
@@ -134,7 +134,7 @@ impl Module {
134 id: self.module_id, 134 id: self.module_id,
135 source_root: self.source_root_id, 135 source_root: self.source_root_id,
136 }; 136 };
137 db.id_maps().def_id(def_loc) 137 def_loc.id(db)
138 } 138 }
139 139
140 /// Finds a child module with the specified name. 140 /// Finds a child module with the specified name.
@@ -167,7 +167,7 @@ impl Module {
167 167
168 let segments = path.segments; 168 let segments = path.segments;
169 for name in segments.iter() { 169 for name in segments.iter() {
170 let module = match db.id_maps().def_loc(curr) { 170 let module = match curr.loc(db) {
171 DefLoc::Module { id, source_root } => Module::new(db, source_root, id)?, 171 DefLoc::Module { id, source_root } => Module::new(db, source_root, id)?,
172 _ => return Ok(None), 172 _ => return Ok(None),
173 }; 173 };
diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs
index f22832eda..f48f51c8d 100644
--- a/crates/ra_analysis/src/hir/module/nameres.rs
+++ b/crates/ra_analysis/src/hir/module/nameres.rs
@@ -256,7 +256,7 @@ where
256 item_id: item.id, 256 item_id: item.id,
257 }, 257 },
258 }; 258 };
259 let def_id = self.db.id_maps().def_id(def_loc); 259 let def_id = def_loc.id(self.db);
260 let resolution = Resolution { 260 let resolution = Resolution {
261 def_id: Some(def_id), 261 def_id: Some(def_id),
262 import: None, 262 import: None,
@@ -269,7 +269,7 @@ where
269 id: mod_id, 269 id: mod_id,
270 source_root: self.source_root, 270 source_root: self.source_root,
271 }; 271 };
272 let def_id = self.db.id_maps().def_id(def_loc); 272 let def_id = def_loc.id(self.db);
273 let resolution = Resolution { 273 let resolution = Resolution {
274 def_id: Some(def_id), 274 def_id: Some(def_id),
275 import: None, 275 import: None,
@@ -318,7 +318,7 @@ where
318 }; 318 };
319 319
320 if !is_last { 320 if !is_last {
321 curr = match self.db.id_maps().def_loc(def_id) { 321 curr = match def_id.loc(self.db) {
322 DefLoc::Module { id, .. } => id, 322 DefLoc::Module { id, .. } => id,
323 _ => return, 323 _ => return,
324 } 324 }
diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs
index e7fba5d72..6570ca994 100644
--- a/crates/ra_analysis/src/hir/query_definitions.rs
+++ b/crates/ra_analysis/src/hir/query_definitions.rs
@@ -26,7 +26,7 @@ use crate::{
26 26
27/// Resolve `FnId` to the corresponding `SyntaxNode` 27/// Resolve `FnId` to the corresponding `SyntaxNode`
28pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { 28pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode {
29 let item_id = db.id_maps().fn_item_id(fn_id); 29 let item_id = fn_id.loc(db);
30 let syntax = db.file_item(item_id); 30 let syntax = db.file_item(item_id);
31 FnDef::cast(syntax.borrowed()).unwrap().owned() 31 FnDef::cast(syntax.borrowed()).unwrap().owned()
32} 32}