diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-30 19:37:48 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-30 19:37:48 +0000 |
commit | c65e6cdcb3d603ce7c0943785f7140662022c54a (patch) | |
tree | b92e52aed2a5b22d73cbebccd08f2870c8212b16 /crates/ra_hir/src/nameres.rs | |
parent | b704ce803b99f0c69bbcd3d4ab531d2604de8594 (diff) | |
parent | ef7eb8c2576963a9a2df405feff354d36366b202 (diff) |
Merge #709
709: Use Crate instead of CrateId r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 97ce6c946..4573a72ba 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -16,9 +16,8 @@ | |||
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; | ||
22 | use ra_arena::map::ArenaMap; | 21 | use ra_arena::map::ArenaMap; |
23 | use test_utils::tested_by; | 22 | use test_utils::tested_by; |
24 | use rustc_hash::{FxHashMap, FxHashSet}; | 23 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -156,10 +155,10 @@ impl<T> PerNs<T> { | |||
156 | } | 155 | } |
157 | } | 156 | } |
158 | 157 | ||
159 | pub(crate) struct Resolver<'a, DB> { | 158 | struct Resolver<'a, DB> { |
160 | db: &'a DB, | 159 | db: &'a DB, |
161 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, | 160 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, |
162 | krate: CrateId, | 161 | krate: Crate, |
163 | module_tree: Arc<ModuleTree>, | 162 | module_tree: Arc<ModuleTree>, |
164 | processed_imports: FxHashSet<(ModuleId, ImportId)>, | 163 | processed_imports: FxHashSet<(ModuleId, ImportId)>, |
165 | result: ItemMap, | 164 | result: ItemMap, |
@@ -169,10 +168,10 @@ impl<'a, DB> Resolver<'a, DB> | |||
169 | where | 168 | where |
170 | DB: HirDatabase, | 169 | DB: HirDatabase, |
171 | { | 170 | { |
172 | pub(crate) fn new( | 171 | fn new( |
173 | db: &'a DB, | 172 | db: &'a DB, |
174 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, | 173 | input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>, |
175 | krate: CrateId, | 174 | krate: Crate, |
176 | ) -> Resolver<'a, DB> { | 175 | ) -> Resolver<'a, DB> { |
177 | let module_tree = db.module_tree(krate); | 176 | let module_tree = db.module_tree(krate); |
178 | Resolver { | 177 | Resolver { |
@@ -219,7 +218,7 @@ where | |||
219 | let crate_graph = self.db.crate_graph(); | 218 | let crate_graph = self.db.crate_graph(); |
220 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file()) | 219 | if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file()) |
221 | { | 220 | { |
222 | let krate = Crate::new(crate_id); | 221 | let krate = Crate { crate_id }; |
223 | for dep in krate.dependencies(self.db) { | 222 | for dep in krate.dependencies(self.db) { |
224 | if let Some(module) = dep.krate.root_module(self.db) { | 223 | if let Some(module) = dep.krate.root_module(self.db) { |
225 | let def = module.into(); | 224 | let def = module.into(); |
@@ -331,6 +330,26 @@ enum ReachedFixedPoint { | |||
331 | } | 330 | } |
332 | 331 | ||
333 | impl ItemMap { | 332 | impl ItemMap { |
333 | pub(crate) fn item_map_query(db: &impl HirDatabase, krate: Crate) -> Arc<ItemMap> { | ||
334 | let start = time::Instant::now(); | ||
335 | let module_tree = db.module_tree(krate); | ||
336 | let input = module_tree | ||
337 | .modules() | ||
338 | .map(|module_id| { | ||
339 | ( | ||
340 | module_id, | ||
341 | db.lower_module_module(Module { krate, module_id }), | ||
342 | ) | ||
343 | }) | ||
344 | .collect::<FxHashMap<_, _>>(); | ||
345 | |||
346 | let resolver = Resolver::new(db, &input, krate); | ||
347 | let res = resolver.resolve(); | ||
348 | let elapsed = start.elapsed(); | ||
349 | log::info!("item_map: {:?}", elapsed); | ||
350 | Arc::new(res) | ||
351 | } | ||
352 | |||
334 | pub(crate) fn resolve_path( | 353 | pub(crate) fn resolve_path( |
335 | &self, | 354 | &self, |
336 | db: &impl HirDatabase, | 355 | db: &impl HirDatabase, |