diff options
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 50 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 1 |
3 files changed, 34 insertions, 29 deletions
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 3ea6e10c9..9dee4f43d 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs | |||
@@ -82,8 +82,8 @@ impl ItemTree { | |||
82 | 82 | ||
83 | /// Returns an iterator over all items located at the top level of the `HirFileId` this | 83 | /// Returns an iterator over all items located at the top level of the `HirFileId` this |
84 | /// `ItemTree` was created from. | 84 | /// `ItemTree` was created from. |
85 | pub fn top_level_items(&self) -> impl Iterator<Item = ModItem> + '_ { | 85 | pub fn top_level_items(&self) -> &[ModItem] { |
86 | self.top_level.iter().copied() | 86 | &self.top_level |
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
@@ -120,7 +120,7 @@ impl_index!( | |||
120 | ); | 120 | ); |
121 | 121 | ||
122 | /// A desugared `extern crate` or `use` import. | 122 | /// A desugared `extern crate` or `use` import. |
123 | #[derive(Debug, Eq, PartialEq)] | 123 | #[derive(Debug, Clone, Eq, PartialEq)] |
124 | pub struct Import { | 124 | pub struct Import { |
125 | pub path: ModPath, | 125 | pub path: ModPath, |
126 | pub alias: Option<ImportAlias>, | 126 | pub alias: Option<ImportAlias>, |
@@ -220,6 +220,12 @@ pub struct Mod { | |||
220 | pub items: Vec<ModItem>, | 220 | pub items: Vec<ModItem>, |
221 | } | 221 | } |
222 | 222 | ||
223 | pub enum ModKind { | ||
224 | Inline { items: Vec<ModItem> }, | ||
225 | |||
226 | Outline {}, | ||
227 | } | ||
228 | |||
223 | #[derive(Debug, Eq, PartialEq)] | 229 | #[derive(Debug, Eq, PartialEq)] |
224 | pub struct MacroCall { | 230 | pub struct MacroCall { |
225 | pub name: Option<Name>, | 231 | pub name: Option<Name>, |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index cbce04315..034f27410 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -19,9 +19,10 @@ use test_utils::mark; | |||
19 | use crate::{ | 19 | use crate::{ |
20 | attr::Attrs, | 20 | attr::Attrs, |
21 | db::DefDatabase, | 21 | db::DefDatabase, |
22 | item_tree::{Import, ItemTree, Mod, ModItem}, | ||
22 | nameres::{ | 23 | nameres::{ |
23 | diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, | 24 | diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, |
24 | raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode, | 25 | BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode, |
25 | }, | 26 | }, |
26 | path::{ImportAlias, ModPath, PathKind}, | 27 | path::{ImportAlias, ModPath, PathKind}, |
27 | per_ns::PerNs, | 28 | per_ns::PerNs, |
@@ -30,6 +31,7 @@ use crate::{ | |||
30 | FunctionLoc, ImplLoc, Intern, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, | 31 | FunctionLoc, ImplLoc, Intern, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, |
31 | TraitLoc, TypeAliasLoc, UnionLoc, | 32 | TraitLoc, TypeAliasLoc, UnionLoc, |
32 | }; | 33 | }; |
34 | use ra_arena::Idx; | ||
33 | 35 | ||
34 | pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 36 | pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
35 | let crate_graph = db.crate_graph(); | 37 | let crate_graph = db.crate_graph(); |
@@ -104,8 +106,8 @@ impl PartialResolvedImport { | |||
104 | #[derive(Clone, Debug, Eq, PartialEq)] | 106 | #[derive(Clone, Debug, Eq, PartialEq)] |
105 | struct ImportDirective { | 107 | struct ImportDirective { |
106 | module_id: LocalModuleId, | 108 | module_id: LocalModuleId, |
107 | import_id: raw::Import, | 109 | import_id: Idx<Import>, |
108 | import: raw::ImportData, | 110 | import: Import, |
109 | status: PartialResolvedImport, | 111 | status: PartialResolvedImport, |
110 | } | 112 | } |
111 | 113 | ||
@@ -140,7 +142,7 @@ struct DefCollector<'a> { | |||
140 | impl DefCollector<'_> { | 142 | impl DefCollector<'_> { |
141 | fn collect(&mut self) { | 143 | fn collect(&mut self) { |
142 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; | 144 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; |
143 | let raw_items = self.db.raw_items(file_id.into()); | 145 | let item_tree = self.db.item_tree(file_id.into()); |
144 | let module_id = self.def_map.root; | 146 | let module_id = self.def_map.root; |
145 | self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; | 147 | self.def_map.modules[module_id].origin = ModuleOrigin::CrateRoot { definition: file_id }; |
146 | ModCollector { | 148 | ModCollector { |
@@ -148,10 +150,10 @@ impl DefCollector<'_> { | |||
148 | macro_depth: 0, | 150 | macro_depth: 0, |
149 | module_id, | 151 | module_id, |
150 | file_id: file_id.into(), | 152 | file_id: file_id.into(), |
151 | raw_items: &raw_items, | 153 | item_tree: &item_tree, |
152 | mod_dir: ModDir::root(), | 154 | mod_dir: ModDir::root(), |
153 | } | 155 | } |
154 | .collect(raw_items.items()); | 156 | .collect(item_tree.top_level_items()); |
155 | 157 | ||
156 | // main name resolution fixed-point loop. | 158 | // main name resolution fixed-point loop. |
157 | let mut i = 0; | 159 | let mut i = 0; |
@@ -286,7 +288,7 @@ impl DefCollector<'_> { | |||
286 | fn import_macros_from_extern_crate( | 288 | fn import_macros_from_extern_crate( |
287 | &mut self, | 289 | &mut self, |
288 | current_module_id: LocalModuleId, | 290 | current_module_id: LocalModuleId, |
289 | import: &raw::ImportData, | 291 | import: &Import, |
290 | ) { | 292 | ) { |
291 | log::debug!( | 293 | log::debug!( |
292 | "importing macros from extern crate: {:?} ({:?})", | 294 | "importing macros from extern crate: {:?} ({:?})", |
@@ -352,11 +354,7 @@ impl DefCollector<'_> { | |||
352 | } | 354 | } |
353 | } | 355 | } |
354 | 356 | ||
355 | fn resolve_import( | 357 | fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialResolvedImport { |
356 | &self, | ||
357 | module_id: LocalModuleId, | ||
358 | import: &raw::ImportData, | ||
359 | ) -> PartialResolvedImport { | ||
360 | log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition); | 358 | log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition); |
361 | if import.is_extern_crate { | 359 | if import.is_extern_crate { |
362 | let res = self.def_map.resolve_name_in_extern_prelude( | 360 | let res = self.def_map.resolve_name_in_extern_prelude( |
@@ -649,17 +647,17 @@ impl DefCollector<'_> { | |||
649 | depth: usize, | 647 | depth: usize, |
650 | ) { | 648 | ) { |
651 | let file_id: HirFileId = macro_call_id.as_file(); | 649 | let file_id: HirFileId = macro_call_id.as_file(); |
652 | let raw_items = self.db.raw_items(file_id); | 650 | let item_tree = self.db.item_tree(file_id); |
653 | let mod_dir = self.mod_dirs[&module_id].clone(); | 651 | let mod_dir = self.mod_dirs[&module_id].clone(); |
654 | ModCollector { | 652 | ModCollector { |
655 | def_collector: &mut *self, | 653 | def_collector: &mut *self, |
656 | macro_depth: depth, | 654 | macro_depth: depth, |
657 | file_id, | 655 | file_id, |
658 | module_id, | 656 | module_id, |
659 | raw_items: &raw_items, | 657 | item_tree: &item_tree, |
660 | mod_dir, | 658 | mod_dir, |
661 | } | 659 | } |
662 | .collect(raw_items.items()); | 660 | .collect(item_tree.top_level_items()); |
663 | } | 661 | } |
664 | 662 | ||
665 | fn finish(self) -> CrateDefMap { | 663 | fn finish(self) -> CrateDefMap { |
@@ -673,12 +671,12 @@ struct ModCollector<'a, 'b> { | |||
673 | macro_depth: usize, | 671 | macro_depth: usize, |
674 | module_id: LocalModuleId, | 672 | module_id: LocalModuleId, |
675 | file_id: HirFileId, | 673 | file_id: HirFileId, |
676 | raw_items: &'a raw::RawItems, | 674 | item_tree: &'a ItemTree, |
677 | mod_dir: ModDir, | 675 | mod_dir: ModDir, |
678 | } | 676 | } |
679 | 677 | ||
680 | impl ModCollector<'_, '_> { | 678 | impl ModCollector<'_, '_> { |
681 | fn collect(&mut self, items: &[raw::RawItem]) { | 679 | fn collect(&mut self, items: &[ModItem]) { |
682 | // Note: don't assert that inserted value is fresh: it's simply not true | 680 | // Note: don't assert that inserted value is fresh: it's simply not true |
683 | // for macros. | 681 | // for macros. |
684 | self.def_collector.mod_dirs.insert(self.module_id, self.mod_dir.clone()); | 682 | self.def_collector.mod_dirs.insert(self.module_id, self.mod_dir.clone()); |
@@ -697,7 +695,7 @@ impl ModCollector<'_, '_> { | |||
697 | for item in items { | 695 | for item in items { |
698 | if self.is_cfg_enabled(&item.attrs) { | 696 | if self.is_cfg_enabled(&item.attrs) { |
699 | if let raw::RawItemKind::Import(import_id) = item.kind { | 697 | if let raw::RawItemKind::Import(import_id) = item.kind { |
700 | let import = self.raw_items[import_id].clone(); | 698 | let import = self.item_tree[import_id].clone(); |
701 | if import.is_extern_crate && import.is_macro_use { | 699 | if import.is_extern_crate && import.is_macro_use { |
702 | self.def_collector.import_macros_from_extern_crate(self.module_id, &import); | 700 | self.def_collector.import_macros_from_extern_crate(self.module_id, &import); |
703 | } | 701 | } |
@@ -709,27 +707,27 @@ impl ModCollector<'_, '_> { | |||
709 | if self.is_cfg_enabled(&item.attrs) { | 707 | if self.is_cfg_enabled(&item.attrs) { |
710 | match item.kind { | 708 | match item.kind { |
711 | raw::RawItemKind::Module(m) => { | 709 | raw::RawItemKind::Module(m) => { |
712 | self.collect_module(&self.raw_items[m], &item.attrs) | 710 | self.collect_module(&self.item_tree[m], &item.attrs) |
713 | } | 711 | } |
714 | raw::RawItemKind::Import(import_id) => { | 712 | raw::RawItemKind::Import(import_id) => { |
715 | self.def_collector.unresolved_imports.push(ImportDirective { | 713 | self.def_collector.unresolved_imports.push(ImportDirective { |
716 | module_id: self.module_id, | 714 | module_id: self.module_id, |
717 | import_id, | 715 | import_id, |
718 | import: self.raw_items[import_id].clone(), | 716 | import: self.item_tree[import_id].clone(), |
719 | status: PartialResolvedImport::Unresolved, | 717 | status: PartialResolvedImport::Unresolved, |
720 | }) | 718 | }) |
721 | } | 719 | } |
722 | raw::RawItemKind::Def(def) => { | 720 | raw::RawItemKind::Def(def) => { |
723 | self.define_def(&self.raw_items[def], &item.attrs) | 721 | self.define_def(&self.item_tree[def], &item.attrs) |
724 | } | 722 | } |
725 | raw::RawItemKind::Macro(mac) => self.collect_macro(&self.raw_items[mac]), | 723 | raw::RawItemKind::Macro(mac) => self.collect_macro(&self.item_tree[mac]), |
726 | raw::RawItemKind::Impl(imp) => { | 724 | raw::RawItemKind::Impl(imp) => { |
727 | let module = ModuleId { | 725 | let module = ModuleId { |
728 | krate: self.def_collector.def_map.krate, | 726 | krate: self.def_collector.def_map.krate, |
729 | local_id: self.module_id, | 727 | local_id: self.module_id, |
730 | }; | 728 | }; |
731 | let container = ContainerId::ModuleId(module); | 729 | let container = ContainerId::ModuleId(module); |
732 | let ast_id = self.raw_items[imp].ast_id; | 730 | let ast_id = self.item_tree[imp].ast_id; |
733 | let impl_id = | 731 | let impl_id = |
734 | ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) } | 732 | ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
735 | .intern(self.def_collector.db); | 733 | .intern(self.def_collector.db); |
@@ -742,7 +740,7 @@ impl ModCollector<'_, '_> { | |||
742 | } | 740 | } |
743 | } | 741 | } |
744 | 742 | ||
745 | fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) { | 743 | fn collect_module(&mut self, module: &Mod, attrs: &Attrs) { |
746 | let path_attr = attrs.by_key("path").string_value(); | 744 | let path_attr = attrs.by_key("path").string_value(); |
747 | let is_macro_use = attrs.by_key("macro_use").exists(); | 745 | let is_macro_use = attrs.by_key("macro_use").exists(); |
748 | match module { | 746 | match module { |
@@ -760,7 +758,7 @@ impl ModCollector<'_, '_> { | |||
760 | macro_depth: self.macro_depth, | 758 | macro_depth: self.macro_depth, |
761 | module_id, | 759 | module_id, |
762 | file_id: self.file_id, | 760 | file_id: self.file_id, |
763 | raw_items: self.raw_items, | 761 | item_tree: self.item_tree, |
764 | mod_dir: self.mod_dir.descend_into_definition(name, path_attr), | 762 | mod_dir: self.mod_dir.descend_into_definition(name, path_attr), |
765 | } | 763 | } |
766 | .collect(&*items); | 764 | .collect(&*items); |
@@ -790,7 +788,7 @@ impl ModCollector<'_, '_> { | |||
790 | macro_depth: self.macro_depth, | 788 | macro_depth: self.macro_depth, |
791 | module_id, | 789 | module_id, |
792 | file_id: file_id.into(), | 790 | file_id: file_id.into(), |
793 | raw_items: &raw_items, | 791 | item_tree: &raw_items, |
794 | mod_dir, | 792 | mod_dir, |
795 | } | 793 | } |
796 | .collect(raw_items.items()); | 794 | .collect(raw_items.items()); |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index f44baa579..d83a5b2b5 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -46,6 +46,7 @@ pub struct RawItems { | |||
46 | impl RawItems { | 46 | impl RawItems { |
47 | pub(crate) fn raw_items_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<RawItems> { | 47 | pub(crate) fn raw_items_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<RawItems> { |
48 | let _p = profile("raw_items_query"); | 48 | let _p = profile("raw_items_query"); |
49 | db.item_tree(file_id); | ||
49 | let mut collector = RawItemsCollector { | 50 | let mut collector = RawItemsCollector { |
50 | raw_items: RawItems::default(), | 51 | raw_items: RawItems::default(), |
51 | source_ast_id_map: db.ast_id_map(file_id), | 52 | source_ast_id_map: db.ast_id_map(file_id), |