diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests.rs | 2 |
3 files changed, 15 insertions, 12 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index df01a20e1..41becf8df 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! The core of the module-level name resolution algorithm. |
2 | //! | ||
3 | //! `DefCollector::collect` contains the fixed-point iteration loop which | ||
4 | //! resolves imports and expands macros. | ||
2 | 5 | ||
3 | use hir_expand::{ | 6 | use hir_expand::{ |
4 | builtin_macro::find_builtin_macro, | 7 | builtin_macro::find_builtin_macro, |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 2ec84f2cc..401af031c 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -22,7 +22,8 @@ use ra_syntax::{ | |||
22 | use test_utils::tested_by; | 22 | use test_utils::tested_by; |
23 | 23 | ||
24 | use crate::{ | 24 | use crate::{ |
25 | attr::Attrs, db::DefDatabase, path::Path, FileAstId, HirFileId, LocalImportId, Source, | 25 | attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, LocalImportId, |
26 | Source, | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | /// `RawItems` is a set of top-level items in a file (except for impls). | 29 | /// `RawItems` is a set of top-level items in a file (except for impls). |
@@ -48,10 +49,6 @@ pub struct ImportSourceMap { | |||
48 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | 49 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
49 | 50 | ||
50 | impl ImportSourceMap { | 51 | impl ImportSourceMap { |
51 | fn insert(&mut self, import: LocalImportId, ptr: ImportSourcePtr) { | ||
52 | self.map.insert(import, ptr) | ||
53 | } | ||
54 | |||
55 | pub fn get(&self, import: LocalImportId) -> ImportSourcePtr { | 52 | pub fn get(&self, import: LocalImportId) -> ImportSourcePtr { |
56 | self.map[import].clone() | 53 | self.map[import].clone() |
57 | } | 54 | } |
@@ -72,7 +69,7 @@ impl RawItems { | |||
72 | let mut collector = RawItemsCollector { | 69 | let mut collector = RawItemsCollector { |
73 | raw_items: RawItems::default(), | 70 | raw_items: RawItems::default(), |
74 | source_ast_id_map: db.ast_id_map(file_id), | 71 | source_ast_id_map: db.ast_id_map(file_id), |
75 | source_map: ImportSourceMap::default(), | 72 | imports: Trace::new(), |
76 | file_id, | 73 | file_id, |
77 | hygiene: Hygiene::new(db, file_id), | 74 | hygiene: Hygiene::new(db, file_id), |
78 | }; | 75 | }; |
@@ -83,7 +80,11 @@ impl RawItems { | |||
83 | collector.process_module(None, item_list); | 80 | collector.process_module(None, item_list); |
84 | } | 81 | } |
85 | } | 82 | } |
86 | (Arc::new(collector.raw_items), Arc::new(collector.source_map)) | 83 | let mut raw_items = collector.raw_items; |
84 | let (arena, map) = collector.imports.into_arena_and_map(); | ||
85 | raw_items.imports = arena; | ||
86 | let source_map = ImportSourceMap { map }; | ||
87 | (Arc::new(raw_items), Arc::new(source_map)) | ||
87 | } | 88 | } |
88 | 89 | ||
89 | pub(super) fn items(&self) -> &[RawItem] { | 90 | pub(super) fn items(&self) -> &[RawItem] { |
@@ -207,8 +208,8 @@ pub(super) struct ImplData { | |||
207 | 208 | ||
208 | struct RawItemsCollector { | 209 | struct RawItemsCollector { |
209 | raw_items: RawItems, | 210 | raw_items: RawItems, |
211 | imports: Trace<LocalImportId, ImportData, ImportSourcePtr>, | ||
210 | source_ast_id_map: Arc<AstIdMap>, | 212 | source_ast_id_map: Arc<AstIdMap>, |
211 | source_map: ImportSourceMap, | ||
212 | file_id: HirFileId, | 213 | file_id: HirFileId, |
213 | hygiene: Hygiene, | 214 | hygiene: Hygiene, |
214 | } | 215 | } |
@@ -392,8 +393,7 @@ impl RawItemsCollector { | |||
392 | data: ImportData, | 393 | data: ImportData, |
393 | source: ImportSourcePtr, | 394 | source: ImportSourcePtr, |
394 | ) { | 395 | ) { |
395 | let import = self.raw_items.imports.alloc(data); | 396 | let import = self.imports.alloc(|| source, || data); |
396 | self.source_map.insert(import, source); | ||
397 | self.push_item(current_module, attrs, RawItemKind::Import(import)) | 397 | self.push_item(current_module, attrs, RawItemKind::Import(import)) |
398 | } | 398 | } |
399 | 399 | ||
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index f0b86af7c..f502f1cb3 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs | |||
@@ -25,7 +25,7 @@ fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> { | |||
25 | 25 | ||
26 | fn render_crate_def_map(map: &CrateDefMap) -> String { | 26 | fn render_crate_def_map(map: &CrateDefMap) -> String { |
27 | let mut buf = String::new(); | 27 | let mut buf = String::new(); |
28 | go(&mut buf, map, "\ncrate", map.root()); | 28 | go(&mut buf, map, "\ncrate", map.root); |
29 | return buf.trim().to_string(); | 29 | return buf.trim().to_string(); |
30 | 30 | ||
31 | fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) { | 31 | fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) { |