diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/krate.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/module_tree.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 2 |
9 files changed, 36 insertions, 45 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 53e84429c..c59b7fbc5 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -52,7 +52,7 @@ pub enum Def { | |||
52 | 52 | ||
53 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 53 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
54 | pub struct Module { | 54 | pub struct Module { |
55 | pub(crate) krate: CrateId, | 55 | pub(crate) krate: Crate, |
56 | pub(crate) module_id: ModuleId, | 56 | pub(crate) module_id: ModuleId, |
57 | } | 57 | } |
58 | 58 | ||
@@ -133,8 +133,8 @@ impl Module { | |||
133 | } | 133 | } |
134 | 134 | ||
135 | /// Returns the crate this module is part of. | 135 | /// Returns the crate this module is part of. |
136 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { | 136 | pub fn krate(&self, _db: &impl HirDatabase) -> Option<Crate> { |
137 | self.krate_impl(db) | 137 | Some(self.krate) |
138 | } | 138 | } |
139 | 139 | ||
140 | /// Topmost parent of this module. Every module has a `crate_root`, but some | 140 | /// Topmost parent of this module. Every module has a `crate_root`, but some |
diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs index cdd30b402..86f29d959 100644 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ b/crates/ra_hir/src/code_model_impl/krate.rs | |||
@@ -1,31 +1,28 @@ | |||
1 | use ra_db::CrateId; | ||
2 | |||
3 | use crate::{ | 1 | use crate::{ |
4 | Crate, CrateDependency, AsName, Module, | 2 | Crate, CrateDependency, AsName, Module, |
5 | db::HirDatabase, | 3 | db::HirDatabase, |
6 | }; | 4 | }; |
7 | 5 | ||
8 | impl Crate { | 6 | impl Crate { |
9 | pub(crate) fn new(crate_id: CrateId) -> Crate { | ||
10 | Crate { crate_id } | ||
11 | } | ||
12 | pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { | 7 | pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { |
13 | let crate_graph = db.crate_graph(); | 8 | let crate_graph = db.crate_graph(); |
14 | crate_graph | 9 | crate_graph |
15 | .dependencies(self.crate_id) | 10 | .dependencies(self.crate_id) |
16 | .map(|dep| { | 11 | .map(|dep| { |
17 | let krate = Crate::new(dep.crate_id()); | 12 | let krate = Crate { |
13 | crate_id: dep.crate_id(), | ||
14 | }; | ||
18 | let name = dep.as_name(); | 15 | let name = dep.as_name(); |
19 | CrateDependency { krate, name } | 16 | CrateDependency { krate, name } |
20 | }) | 17 | }) |
21 | .collect() | 18 | .collect() |
22 | } | 19 | } |
23 | pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option<Module> { | 20 | pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option<Module> { |
24 | let module_tree = db.module_tree(self.crate_id); | 21 | let module_tree = db.module_tree(*self); |
25 | let module_id = module_tree.modules().next()?; | 22 | let module_id = module_tree.modules().next()?; |
26 | 23 | ||
27 | let module = Module { | 24 | let module = Module { |
28 | krate: self.crate_id, | 25 | krate: *self, |
29 | module_id, | 26 | module_id, |
30 | }; | 27 | }; |
31 | Some(module) | 28 | Some(module) |
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index c6f85ac82..4a3901b8b 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -3,7 +3,7 @@ use ra_syntax::{ast, SyntaxNode, TreeArc}; | |||
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | Module, ModuleSource, Problem, | 5 | Module, ModuleSource, Problem, |
6 | Crate, Name, | 6 | Name, |
7 | module_tree::ModuleId, | 7 | module_tree::ModuleId, |
8 | impl_block::ImplId, | 8 | impl_block::ImplId, |
9 | nameres::{lower::ImportId}, | 9 | nameres::{lower::ImportId}, |
@@ -67,10 +67,6 @@ impl Module { | |||
67 | source_map.get(&source, impl_id) | 67 | source_map.get(&source, impl_id) |
68 | } | 68 | } |
69 | 69 | ||
70 | pub(crate) fn krate_impl(&self, _db: &impl HirDatabase) -> Option<Crate> { | ||
71 | Some(Crate::new(self.krate)) | ||
72 | } | ||
73 | |||
74 | pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module { | 70 | pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module { |
75 | let module_tree = db.module_tree(self.krate); | 71 | let module_tree = db.module_tree(self.krate); |
76 | let module_id = self.module_id.crate_root(&module_tree); | 72 | let module_id = self.module_id.crate_root(&module_tree); |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index e7c5d1436..16d5a7877 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; | 3 | use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; |
4 | use ra_db::{SourceDatabase, CrateId, salsa}; | 4 | use ra_db::{SourceDatabase, salsa}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | MacroCallId, HirFileId, | 7 | MacroCallId, HirFileId, |
@@ -68,10 +68,10 @@ pub trait HirDatabase: SourceDatabase + AsRef<HirInterner> { | |||
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(crate::nameres::ItemMap::item_map_query)] | 70 | #[salsa::invoke(crate::nameres::ItemMap::item_map_query)] |
71 | fn item_map(&self, crate_id: CrateId) -> Arc<ItemMap>; | 71 | fn item_map(&self, krate: Crate) -> Arc<ItemMap>; |
72 | 72 | ||
73 | #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] | 73 | #[salsa::invoke(crate::module_tree::ModuleTree::module_tree_query)] |
74 | fn module_tree(&self, crate_id: CrateId) -> Arc<ModuleTree>; | 74 | fn module_tree(&self, krate: Crate) -> Arc<ModuleTree>; |
75 | 75 | ||
76 | #[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)] | 76 | #[salsa::invoke(crate::impl_block::impls_in_module_with_source_map_query)] |
77 | fn impls_in_module_with_source_map( | 77 | fn impls_in_module_with_source_map( |
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index 893c375b5..1f327eeb2 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs | |||
@@ -2,7 +2,7 @@ use std::sync::Arc; | |||
2 | 2 | ||
3 | use arrayvec::ArrayVec; | 3 | use arrayvec::ArrayVec; |
4 | use relative_path::RelativePathBuf; | 4 | use relative_path::RelativePathBuf; |
5 | use ra_db::{FileId, SourceRoot, CrateId}; | 5 | use ra_db::{FileId, SourceRoot}; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | SyntaxNode, TreeArc, | 7 | SyntaxNode, TreeArc, |
8 | algo::generate, | 8 | algo::generate, |
@@ -13,6 +13,7 @@ use test_utils::tested_by; | |||
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
15 | Name, AsName, HirDatabase, SourceItemId, HirFileId, Problem, SourceFileItems, ModuleSource, | 15 | Name, AsName, HirDatabase, SourceItemId, HirFileId, Problem, SourceFileItems, ModuleSource, |
16 | Crate, | ||
16 | ids::SourceFileItemId, | 17 | ids::SourceFileItemId, |
17 | }; | 18 | }; |
18 | 19 | ||
@@ -132,10 +133,10 @@ struct LinkData { | |||
132 | } | 133 | } |
133 | 134 | ||
134 | impl ModuleTree { | 135 | impl ModuleTree { |
135 | pub(crate) fn module_tree_query(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ModuleTree> { | 136 | pub(crate) fn module_tree_query(db: &impl HirDatabase, krate: Crate) -> Arc<ModuleTree> { |
136 | db.check_canceled(); | 137 | db.check_canceled(); |
137 | let mut res = ModuleTree::default(); | 138 | let mut res = ModuleTree::default(); |
138 | res.init_crate(db, crate_id); | 139 | res.init_crate(db, krate); |
139 | Arc::new(res) | 140 | Arc::new(res) |
140 | } | 141 | } |
141 | 142 | ||
@@ -155,9 +156,9 @@ impl ModuleTree { | |||
155 | Some(res) | 156 | Some(res) |
156 | } | 157 | } |
157 | 158 | ||
158 | fn init_crate(&mut self, db: &impl HirDatabase, crate_id: CrateId) { | 159 | fn init_crate(&mut self, db: &impl HirDatabase, krate: Crate) { |
159 | let crate_graph = db.crate_graph(); | 160 | let crate_graph = db.crate_graph(); |
160 | let file_id = crate_graph.crate_root(crate_id); | 161 | let file_id = crate_graph.crate_root(krate.crate_id); |
161 | let source_root_id = db.file_source_root(file_id); | 162 | let source_root_id = db.file_source_root(file_id); |
162 | 163 | ||
163 | let source_root = db.source_root(source_root_id); | 164 | let source_root = db.source_root(source_root_id); |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index d06cd5c69..4573a72ba 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -18,7 +18,6 @@ pub(crate) mod lower; | |||
18 | 18 | ||
19 | use std::{time, 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}; |
@@ -159,7 +158,7 @@ impl<T> PerNs<T> { | |||
159 | 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, |
@@ -172,7 +171,7 @@ where | |||
172 | 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,23 +330,20 @@ enum ReachedFixedPoint { | |||
331 | } | 330 | } |
332 | 331 | ||
333 | impl ItemMap { | 332 | impl ItemMap { |
334 | pub(crate) fn item_map_query(db: &impl HirDatabase, crate_id: CrateId) -> Arc<ItemMap> { | 333 | pub(crate) fn item_map_query(db: &impl HirDatabase, krate: Crate) -> Arc<ItemMap> { |
335 | let start = time::Instant::now(); | 334 | let start = time::Instant::now(); |
336 | let module_tree = db.module_tree(crate_id); | 335 | let module_tree = db.module_tree(krate); |
337 | let input = module_tree | 336 | let input = module_tree |
338 | .modules() | 337 | .modules() |
339 | .map(|module_id| { | 338 | .map(|module_id| { |
340 | ( | 339 | ( |
341 | module_id, | 340 | module_id, |
342 | db.lower_module_module(Module { | 341 | db.lower_module_module(Module { krate, module_id }), |
343 | krate: crate_id, | ||
344 | module_id, | ||
345 | }), | ||
346 | ) | 342 | ) |
347 | }) | 343 | }) |
348 | .collect::<FxHashMap<_, _>>(); | 344 | .collect::<FxHashMap<_, _>>(); |
349 | 345 | ||
350 | let resolver = Resolver::new(db, &input, crate_id); | 346 | let resolver = Resolver::new(db, &input, krate); |
351 | let res = resolver.resolve(); | 347 | let res = resolver.resolve(); |
352 | let elapsed = start.elapsed(); | 348 | let elapsed = start.elapsed(); |
353 | log::info!("item_map: {:?}", elapsed); | 349 | log::info!("item_map: {:?}", elapsed); |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 3d420467c..9c5ca097e 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -16,7 +16,7 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { | |||
16 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); | 16 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); |
17 | let krate = module.krate(&db).unwrap(); | 17 | let krate = module.krate(&db).unwrap(); |
18 | let module_id = module.module_id; | 18 | let module_id = module.module_id; |
19 | (db.item_map(krate.crate_id), module_id) | 19 | (db.item_map(krate), module_id) |
20 | } | 20 | } |
21 | 21 | ||
22 | /// Sets the crate root to the file of the cursor marker | 22 | /// Sets the crate root to the file of the cursor marker |
@@ -30,7 +30,7 @@ fn item_map_custom_crate_root(fixture: &str) -> (Arc<ItemMap>, ModuleId) { | |||
30 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); | 30 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); |
31 | let krate = module.krate(&db).unwrap(); | 31 | let krate = module.krate(&db).unwrap(); |
32 | let module_id = module.module_id; | 32 | let module_id = module.module_id; |
33 | (db.item_map(krate.crate_id), module_id) | 33 | (db.item_map(krate), module_id) |
34 | } | 34 | } |
35 | 35 | ||
36 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { | 36 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { |
@@ -297,7 +297,7 @@ fn item_map_across_crates() { | |||
297 | 297 | ||
298 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 298 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
299 | let krate = module.krate(&db).unwrap(); | 299 | let krate = module.krate(&db).unwrap(); |
300 | let item_map = db.item_map(krate.crate_id); | 300 | let item_map = db.item_map(krate); |
301 | 301 | ||
302 | check_module_item_map( | 302 | check_module_item_map( |
303 | &item_map, | 303 | &item_map, |
@@ -349,7 +349,7 @@ fn import_across_source_roots() { | |||
349 | 349 | ||
350 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 350 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
351 | let krate = module.krate(&db).unwrap(); | 351 | let krate = module.krate(&db).unwrap(); |
352 | let item_map = db.item_map(krate.crate_id); | 352 | let item_map = db.item_map(krate); |
353 | 353 | ||
354 | check_module_item_map( | 354 | check_module_item_map( |
355 | &item_map, | 355 | &item_map, |
@@ -391,7 +391,7 @@ fn reexport_across_crates() { | |||
391 | 391 | ||
392 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 392 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
393 | let krate = module.krate(&db).unwrap(); | 393 | let krate = module.krate(&db).unwrap(); |
394 | let item_map = db.item_map(krate.crate_id); | 394 | let item_map = db.item_map(krate); |
395 | 395 | ||
396 | check_module_item_map( | 396 | check_module_item_map( |
397 | &item_map, | 397 | &item_map, |
@@ -409,7 +409,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
409 | let krate = module.krate(&db).unwrap(); | 409 | let krate = module.krate(&db).unwrap(); |
410 | { | 410 | { |
411 | let events = db.log_executed(|| { | 411 | let events = db.log_executed(|| { |
412 | db.item_map(krate.crate_id); | 412 | db.item_map(krate); |
413 | }); | 413 | }); |
414 | assert!(format!("{:?}", events).contains("item_map")) | 414 | assert!(format!("{:?}", events).contains("item_map")) |
415 | } | 415 | } |
@@ -417,7 +417,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
417 | 417 | ||
418 | { | 418 | { |
419 | let events = db.log_executed(|| { | 419 | let events = db.log_executed(|| { |
420 | db.item_map(krate.crate_id); | 420 | db.item_map(krate); |
421 | }); | 421 | }); |
422 | assert!( | 422 | assert!( |
423 | !format!("{:?}", events).contains("item_map"), | 423 | !format!("{:?}", events).contains("item_map"), |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 589efd023..d1eaccf23 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -14,7 +14,7 @@ use ra_syntax::{ | |||
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | HirDatabase, Function, ModuleDef, Struct, Enum, | 16 | HirDatabase, Function, ModuleDef, Struct, Enum, |
17 | AsName, Module, HirFileId, | 17 | AsName, Module, HirFileId, Crate, |
18 | ids::{LocationCtx, SourceFileItemId}, | 18 | ids::{LocationCtx, SourceFileItemId}, |
19 | }; | 19 | }; |
20 | 20 | ||
@@ -83,7 +83,8 @@ fn module_from_source( | |||
83 | let source_root_id = db.file_source_root(file_id.as_original_file()); | 83 | let source_root_id = db.file_source_root(file_id.as_original_file()); |
84 | db.source_root_crates(source_root_id) | 84 | db.source_root_crates(source_root_id) |
85 | .iter() | 85 | .iter() |
86 | .find_map(|&krate| { | 86 | .map(|&crate_id| Crate { crate_id }) |
87 | .find_map(|krate| { | ||
87 | let module_tree = db.module_tree(krate); | 88 | let module_tree = db.module_tree(krate); |
88 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; | 89 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; |
89 | Some(Module { krate, module_id }) | 90 | Some(Module { krate, module_id }) |
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index d70a24582..37bc3f38c 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -52,7 +52,7 @@ impl CrateImplBlocks { | |||
52 | .flat_map(|i| i.iter()) | 52 | .flat_map(|i| i.iter()) |
53 | .map(move |(module_id, impl_id)| { | 53 | .map(move |(module_id, impl_id)| { |
54 | let module = Module { | 54 | let module = Module { |
55 | krate: self.krate.crate_id, | 55 | krate: self.krate, |
56 | module_id: *module_id, | 56 | module_id: *module_id, |
57 | }; | 57 | }; |
58 | let module_impl_blocks = db.impls_in_module(module); | 58 | let module_impl_blocks = db.impls_in_module(module); |