diff options
author | Aleksey Kladov <[email protected]> | 2019-01-30 19:18:17 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-30 19:36:22 +0000 |
commit | 95aa7e46fc69b5279a1af74dfa7008396a4455a5 (patch) | |
tree | e7439a2b29197ae3d202a66d50f737a7f45e40e5 /crates/ra_hir/src | |
parent | b704ce803b99f0c69bbcd3d4ab531d2604de8594 (diff) |
move item_map_query
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/db.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 29 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 33 |
3 files changed, 29 insertions, 35 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 70d9de212..e7c5d1436 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -67,7 +67,7 @@ pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> { | |||
67 | #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_source_map_query)] | 67 | #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_source_map_query)] |
68 | fn lower_module_source_map(&self, module: Module) -> Arc<ImportSourceMap>; | 68 | fn lower_module_source_map(&self, module: Module) -> Arc<ImportSourceMap>; |
69 | 69 | ||
70 | #[salsa::invoke(query_definitions::item_map)] | 70 | #[salsa::invoke(crate::nameres::ItemMap::item_map_query)] |
71 | fn item_map(&self, crate_id: CrateId) -> Arc<ItemMap>; | 71 | fn item_map(&self, crate_id: CrateId) -> Arc<ItemMap>; |
72 | 72 | ||
73 | #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] | 73 | #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 97ce6c946..d06cd5c69 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -16,7 +16,7 @@ | |||
16 | //! structure itself is modified. | 16 | //! structure itself is modified. |
17 | pub(crate) mod lower; | 17 | pub(crate) mod lower; |
18 | 18 | ||
19 | use std::sync::Arc; | 19 | use std::{time, sync::Arc}; |
20 | 20 | ||
21 | use ra_db::CrateId; | 21 | use ra_db::CrateId; |
22 | use ra_arena::map::ArenaMap; | 22 | use ra_arena::map::ArenaMap; |
@@ -156,7 +156,7 @@ impl<T> PerNs<T> { | |||
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | pub(crate) struct Resolver<'a, DB> { | 159 | struct Resolver<'a, DB> { |
160 | db: &'a DB, | 160 | db: &'a DB, |
161 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, | 161 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, |
162 | krate: CrateId, | 162 | krate: CrateId, |
@@ -169,7 +169,7 @@ impl<'a, DB> Resolver<'a, DB> | |||
169 | where | 169 | where |
170 | DB: HirDatabase, | 170 | DB: HirDatabase, |
171 | { | 171 | { |
172 | pub(crate) fn new( | 172 | fn new( |
173 | db: &'a DB, | 173 | db: &'a DB, |
174 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, | 174 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, |
175 | krate: CrateId, | 175 | krate: CrateId, |
@@ -331,6 +331,29 @@ enum ReachedFixedPoint { | |||
331 | } | 331 | } |
332 | 332 | ||
333 | impl ItemMap { | 333 | impl ItemMap { |
334 | pub(crate) fn item_map_query(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ItemMap> { | ||
335 | let start = time::Instant::now(); | ||
336 | let module_tree = db.module_tree(crate_id); | ||
337 | let input = module_tree | ||
338 | .modules() | ||
339 | .map(|module_id| { | ||
340 | ( | ||
341 | module_id, | ||
342 | db.lower_module_module(Module { | ||
343 | krate: crate_id, | ||
344 | module_id, | ||
345 | }), | ||
346 | ) | ||
347 | }) | ||
348 | .collect::<FxHashMap<_, _>>(); | ||
349 | |||
350 | let resolver = Resolver::new(db, &input, crate_id); | ||
351 | let res = resolver.resolve(); | ||
352 | let elapsed = start.elapsed(); | ||
353 | log::info!("item_map: {:?}", elapsed); | ||
354 | Arc::new(res) | ||
355 | } | ||
356 | |||
334 | pub(crate) fn resolve_path( | 357 | pub(crate) fn resolve_path( |
335 | &self, | 358 | &self, |
336 | db: &impl HirDatabase, | 359 | db: &impl HirDatabase, |
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index bf9ac0dfb..6724649e1 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -1,17 +1,11 @@ | |||
1 | use std::{ | 1 | use std::sync::Arc; |
2 | sync::Arc, | ||
3 | time::Instant, | ||
4 | }; | ||
5 | 2 | ||
6 | use rustc_hash::FxHashMap; | ||
7 | use ra_syntax::{SyntaxNode, TreeArc}; | 3 | use ra_syntax::{SyntaxNode, TreeArc}; |
8 | use ra_db::{CrateId}; | ||
9 | 4 | ||
10 | use crate::{ | 5 | use crate::{ |
11 | SourceFileItems, SourceItemId, HirFileId, | 6 | SourceFileItems, SourceItemId, HirFileId, |
12 | Function, FnScopes, Module, | 7 | Function, FnScopes, |
13 | db::HirDatabase, | 8 | db::HirDatabase, |
14 | nameres::{ItemMap, Resolver}, | ||
15 | }; | 9 | }; |
16 | 10 | ||
17 | pub(super) fn fn_scopes(db: &impl HirDatabase, func: Function) -> Arc<FnScopes> { | 11 | pub(super) fn fn_scopes(db: &impl HirDatabase, func: Function) -> Arc<FnScopes> { |
@@ -35,26 +29,3 @@ pub(super) fn file_item( | |||
35 | .to_node(&source_file) | 29 | .to_node(&source_file) |
36 | .to_owned() | 30 | .to_owned() |
37 | } | 31 | } |
38 | |||
39 | pub(super) fn item_map(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ItemMap> { | ||
40 | let start = Instant::now(); | ||
41 | let module_tree = db.module_tree(crate_id); | ||
42 | let input = module_tree | ||
43 | .modules() | ||
44 | .map(|module_id| { | ||
45 | ( | ||
46 | module_id, | ||
47 | db.lower_module_module(Module { | ||
48 | krate: crate_id, | ||
49 | module_id, | ||
50 | }), | ||
51 | ) | ||
52 | }) | ||
53 | .collect::<FxHashMap<_, _>>(); | ||
54 | |||
55 | let resolver = Resolver::new(db, &input, crate_id); | ||
56 | let res = resolver.resolve(); | ||
57 | let elapsed = start.elapsed(); | ||
58 | log::info!("item_map: {:?}", elapsed); | ||
59 | Arc::new(res) | ||
60 | } | ||