diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 70 | ||||
-rw-r--r-- | crates/ra_hir_def/src/trace.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/change.rs | 2 |
8 files changed, 43 insertions, 107 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index bfae3660b..f5ffd64fa 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -4,8 +4,8 @@ pub use hir_def::db::{ | |||
4 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, | 4 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, |
5 | DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, | 5 | DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, |
6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, | 6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, |
7 | LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, | 7 | LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery, |
8 | StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery, | 8 | TraitDataQuery, TypeAliasDataQuery, |
9 | }; | 9 | }; |
10 | pub use hir_expand::db::{ | 10 | pub use hir_expand::db::{ |
11 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 11 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 98bff6cb7..c55fd4111 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -13,10 +13,7 @@ use crate::{ | |||
13 | docs::Documentation, | 13 | docs::Documentation, |
14 | generics::GenericParams, | 14 | generics::GenericParams, |
15 | lang_item::{LangItemTarget, LangItems}, | 15 | lang_item::{LangItemTarget, LangItems}, |
16 | nameres::{ | 16 | nameres::{raw::RawItems, CrateDefMap}, |
17 | raw::{ImportSourceMap, RawItems}, | ||
18 | CrateDefMap, | ||
19 | }, | ||
20 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, | 17 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, |
21 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, | 18 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, |
22 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, | 19 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, |
@@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase { | |||
46 | 43 | ||
47 | #[salsa::query_group(DefDatabaseStorage)] | 44 | #[salsa::query_group(DefDatabaseStorage)] |
48 | pub trait DefDatabase: InternDatabase + AstDatabase { | 45 | pub trait DefDatabase: InternDatabase + AstDatabase { |
49 | #[salsa::invoke(RawItems::raw_items_with_source_map_query)] | ||
50 | fn raw_items_with_source_map( | ||
51 | &self, | ||
52 | file_id: HirFileId, | ||
53 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>); | ||
54 | |||
55 | #[salsa::invoke(RawItems::raw_items_query)] | 46 | #[salsa::invoke(RawItems::raw_items_query)] |
56 | fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; | 47 | fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; |
57 | 48 | ||
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index ad104bb3d..9e082c5f7 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -5,7 +5,7 @@ use hir_expand::name::Name; | |||
5 | use once_cell::sync::Lazy; | 5 | use once_cell::sync::Lazy; |
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId}; | 8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId}; |
9 | 9 | ||
10 | #[derive(Debug, Default, PartialEq, Eq)] | 10 | #[derive(Debug, Default, PartialEq, Eq)] |
11 | pub struct ItemScope { | 11 | pub struct ItemScope { |
@@ -30,7 +30,7 @@ static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { | |||
30 | BuiltinType::ALL | 30 | BuiltinType::ALL |
31 | .iter() | 31 | .iter() |
32 | .map(|(name, ty)| { | 32 | .map(|(name, ty)| { |
33 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None }) | 33 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: false }) |
34 | }) | 34 | }) |
35 | .collect() | 35 | .collect() |
36 | }); | 36 | }); |
@@ -54,7 +54,7 @@ impl ItemScope { | |||
54 | 54 | ||
55 | pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { | 55 | pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { |
56 | self.entries() | 56 | self.entries() |
57 | .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None }) | 57 | .filter_map(|(_name, res)| if !res.import { Some(res.def) } else { None }) |
58 | .flat_map(|per_ns| { | 58 | .flat_map(|per_ns| { |
59 | per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) | 59 | per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) |
60 | }) | 60 | }) |
@@ -112,36 +112,27 @@ impl ItemScope { | |||
112 | self.legacy_macros.insert(name, mac); | 112 | self.legacy_macros.insert(name, mac); |
113 | } | 113 | } |
114 | 114 | ||
115 | pub(crate) fn push_res( | 115 | pub(crate) fn push_res(&mut self, name: Name, res: &Resolution, import: bool) -> bool { |
116 | &mut self, | ||
117 | name: Name, | ||
118 | res: &Resolution, | ||
119 | import: Option<LocalImportId>, | ||
120 | ) -> bool { | ||
121 | let mut changed = false; | 116 | let mut changed = false; |
122 | let existing = self.items.entry(name.clone()).or_default(); | 117 | let existing = self.items.entry(name.clone()).or_default(); |
123 | 118 | ||
124 | if existing.def.types.is_none() && res.def.types.is_some() { | 119 | if existing.def.types.is_none() && res.def.types.is_some() { |
125 | existing.def.types = res.def.types; | 120 | existing.def.types = res.def.types; |
126 | existing.import = import.or(res.import); | 121 | existing.import = import || res.import; |
127 | changed = true; | 122 | changed = true; |
128 | } | 123 | } |
129 | if existing.def.values.is_none() && res.def.values.is_some() { | 124 | if existing.def.values.is_none() && res.def.values.is_some() { |
130 | existing.def.values = res.def.values; | 125 | existing.def.values = res.def.values; |
131 | existing.import = import.or(res.import); | 126 | existing.import = import || res.import; |
132 | changed = true; | 127 | changed = true; |
133 | } | 128 | } |
134 | if existing.def.macros.is_none() && res.def.macros.is_some() { | 129 | if existing.def.macros.is_none() && res.def.macros.is_some() { |
135 | existing.def.macros = res.def.macros; | 130 | existing.def.macros = res.def.macros; |
136 | existing.import = import.or(res.import); | 131 | existing.import = import || res.import; |
137 | changed = true; | 132 | changed = true; |
138 | } | 133 | } |
139 | 134 | ||
140 | if existing.def.is_none() | 135 | if existing.def.is_none() && res.def.is_none() && !existing.import && res.import { |
141 | && res.def.is_none() | ||
142 | && existing.import.is_none() | ||
143 | && res.import.is_some() | ||
144 | { | ||
145 | existing.import = res.import; | 136 | existing.import = res.import; |
146 | } | 137 | } |
147 | changed | 138 | changed |
@@ -160,6 +151,5 @@ impl ItemScope { | |||
160 | pub struct Resolution { | 151 | pub struct Resolution { |
161 | /// None for unresolved | 152 | /// None for unresolved |
162 | pub def: PerNs, | 153 | pub def: PerNs, |
163 | /// ident by which this is imported into local scope. | 154 | pub(crate) import: bool, |
164 | pub(crate) import: Option<LocalImportId>, | ||
165 | } | 155 | } |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 8cb5ab8d0..f6c7f38d1 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -52,10 +52,6 @@ use crate::body::Expander; | |||
52 | use crate::builtin_type::BuiltinType; | 52 | use crate::builtin_type::BuiltinType; |
53 | 53 | ||
54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
55 | pub(crate) struct LocalImportId(RawId); | ||
56 | impl_arena_id!(LocalImportId); | ||
57 | |||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
59 | pub struct ModuleId { | 55 | pub struct ModuleId { |
60 | pub krate: CrateId, | 56 | pub krate: CrateId, |
61 | pub local_id: LocalModuleId, | 57 | pub local_id: LocalModuleId, |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 45199fa11..2b194f488 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -26,8 +26,7 @@ use crate::{ | |||
26 | path::{ModPath, PathKind}, | 26 | path::{ModPath, PathKind}, |
27 | per_ns::PerNs, | 27 | per_ns::PerNs, |
28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, | 28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, |
29 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, | 29 | LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, |
30 | TypeAliasLoc, UnionLoc, | ||
31 | }; | 30 | }; |
32 | 31 | ||
33 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 32 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -93,7 +92,7 @@ impl PartialResolvedImport { | |||
93 | #[derive(Clone, Debug, Eq, PartialEq)] | 92 | #[derive(Clone, Debug, Eq, PartialEq)] |
94 | struct ImportDirective { | 93 | struct ImportDirective { |
95 | module_id: LocalModuleId, | 94 | module_id: LocalModuleId, |
96 | import_id: LocalImportId, | 95 | import_id: raw::Import, |
97 | import: raw::ImportData, | 96 | import: raw::ImportData, |
98 | status: PartialResolvedImport, | 97 | status: PartialResolvedImport, |
99 | } | 98 | } |
@@ -110,7 +109,7 @@ struct MacroDirective { | |||
110 | struct DefCollector<'a, DB> { | 109 | struct DefCollector<'a, DB> { |
111 | db: &'a DB, | 110 | db: &'a DB, |
112 | def_map: CrateDefMap, | 111 | def_map: CrateDefMap, |
113 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, LocalImportId)>>, | 112 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, raw::Import)>>, |
114 | unresolved_imports: Vec<ImportDirective>, | 113 | unresolved_imports: Vec<ImportDirective>, |
115 | resolved_imports: Vec<ImportDirective>, | 114 | resolved_imports: Vec<ImportDirective>, |
116 | unexpanded_macros: Vec<MacroDirective>, | 115 | unexpanded_macros: Vec<MacroDirective>, |
@@ -219,7 +218,7 @@ where | |||
219 | self.update( | 218 | self.update( |
220 | self.def_map.root, | 219 | self.def_map.root, |
221 | None, | 220 | None, |
222 | &[(name, Resolution { def: PerNs::macros(macro_), import: None })], | 221 | &[(name, Resolution { def: PerNs::macros(macro_), import: false })], |
223 | ); | 222 | ); |
224 | } | 223 | } |
225 | } | 224 | } |
@@ -404,7 +403,7 @@ where | |||
404 | let variant = EnumVariantId { parent: e, local_id }; | 403 | let variant = EnumVariantId { parent: e, local_id }; |
405 | let res = Resolution { | 404 | let res = Resolution { |
406 | def: PerNs::both(variant.into(), variant.into()), | 405 | def: PerNs::both(variant.into(), variant.into()), |
407 | import: Some(import_id), | 406 | import: true, |
408 | }; | 407 | }; |
409 | (name, res) | 408 | (name, res) |
410 | }) | 409 | }) |
@@ -431,7 +430,7 @@ where | |||
431 | } | 430 | } |
432 | } | 431 | } |
433 | 432 | ||
434 | let resolution = Resolution { def, import: Some(import_id) }; | 433 | let resolution = Resolution { def, import: true }; |
435 | self.update(module_id, Some(import_id), &[(name, resolution)]); | 434 | self.update(module_id, Some(import_id), &[(name, resolution)]); |
436 | } | 435 | } |
437 | None => tested_by!(bogus_paths), | 436 | None => tested_by!(bogus_paths), |
@@ -442,7 +441,7 @@ where | |||
442 | fn update( | 441 | fn update( |
443 | &mut self, | 442 | &mut self, |
444 | module_id: LocalModuleId, | 443 | module_id: LocalModuleId, |
445 | import: Option<LocalImportId>, | 444 | import: Option<raw::Import>, |
446 | resolutions: &[(Name, Resolution)], | 445 | resolutions: &[(Name, Resolution)], |
447 | ) { | 446 | ) { |
448 | self.update_recursive(module_id, import, resolutions, 0) | 447 | self.update_recursive(module_id, import, resolutions, 0) |
@@ -451,7 +450,7 @@ where | |||
451 | fn update_recursive( | 450 | fn update_recursive( |
452 | &mut self, | 451 | &mut self, |
453 | module_id: LocalModuleId, | 452 | module_id: LocalModuleId, |
454 | import: Option<LocalImportId>, | 453 | import: Option<raw::Import>, |
455 | resolutions: &[(Name, Resolution)], | 454 | resolutions: &[(Name, Resolution)], |
456 | depth: usize, | 455 | depth: usize, |
457 | ) { | 456 | ) { |
@@ -462,7 +461,7 @@ where | |||
462 | let scope = &mut self.def_map.modules[module_id].scope; | 461 | let scope = &mut self.def_map.modules[module_id].scope; |
463 | let mut changed = false; | 462 | let mut changed = false; |
464 | for (name, res) in resolutions { | 463 | for (name, res) in resolutions { |
465 | changed |= scope.push_res(name.clone(), res, import); | 464 | changed |= scope.push_res(name.clone(), res, import.is_some()); |
466 | } | 465 | } |
467 | 466 | ||
468 | if !changed { | 467 | if !changed { |
@@ -719,7 +718,7 @@ where | |||
719 | def: PerNs::types( | 718 | def: PerNs::types( |
720 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), | 719 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), |
721 | ), | 720 | ), |
722 | import: None, | 721 | import: false, |
723 | }; | 722 | }; |
724 | self.def_collector.update(self.module_id, None, &[(name, resolution)]); | 723 | self.def_collector.update(self.module_id, None, &[(name, resolution)]); |
725 | res | 724 | res |
@@ -791,7 +790,7 @@ where | |||
791 | PerNs::types(def.into()) | 790 | PerNs::types(def.into()) |
792 | } | 791 | } |
793 | }; | 792 | }; |
794 | let resolution = Resolution { def, import: None }; | 793 | let resolution = Resolution { def, import: false }; |
795 | self.def_collector.update(self.module_id, None, &[(name, resolution)]) | 794 | self.def_collector.update(self.module_id, None, &[(name, resolution)]) |
796 | } | 795 | } |
797 | 796 | ||
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index df5dac88a..1b83b2247 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -7,24 +7,20 @@ | |||
7 | 7 | ||
8 | use std::{ops::Index, sync::Arc}; | 8 | use std::{ops::Index, sync::Arc}; |
9 | 9 | ||
10 | use either::Either; | ||
11 | use hir_expand::{ | 10 | use hir_expand::{ |
12 | ast_id_map::AstIdMap, | 11 | ast_id_map::AstIdMap, |
13 | db::AstDatabase, | 12 | db::AstDatabase, |
14 | hygiene::Hygiene, | 13 | hygiene::Hygiene, |
15 | name::{AsName, Name}, | 14 | name::{AsName, Name}, |
16 | }; | 15 | }; |
17 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 16 | use ra_arena::{impl_arena_id, Arena, RawId}; |
18 | use ra_syntax::{ | 17 | use ra_syntax::{ |
19 | ast::{self, AttrsOwner, NameOwner}, | 18 | ast::{self, AttrsOwner, NameOwner}, |
20 | AstNode, AstPtr, | 19 | AstNode, |
21 | }; | 20 | }; |
22 | use test_utils::tested_by; | 21 | use test_utils::tested_by; |
23 | 22 | ||
24 | use crate::{ | 23 | use crate::{attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile}; |
25 | attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile, | ||
26 | LocalImportId, | ||
27 | }; | ||
28 | 24 | ||
29 | /// `RawItems` is a set of top-level items in a file (except for impls). | 25 | /// `RawItems` is a set of top-level items in a file (except for impls). |
30 | /// | 26 | /// |
@@ -33,7 +29,7 @@ use crate::{ | |||
33 | #[derive(Debug, Default, PartialEq, Eq)] | 29 | #[derive(Debug, Default, PartialEq, Eq)] |
34 | pub struct RawItems { | 30 | pub struct RawItems { |
35 | modules: Arena<Module, ModuleData>, | 31 | modules: Arena<Module, ModuleData>, |
36 | imports: Arena<LocalImportId, ImportData>, | 32 | imports: Arena<Import, ImportData>, |
37 | defs: Arena<Def, DefData>, | 33 | defs: Arena<Def, DefData>, |
38 | macros: Arena<Macro, MacroData>, | 34 | macros: Arena<Macro, MacroData>, |
39 | impls: Arena<Impl, ImplData>, | 35 | impls: Arena<Impl, ImplData>, |
@@ -41,29 +37,14 @@ pub struct RawItems { | |||
41 | items: Vec<RawItem>, | 37 | items: Vec<RawItem>, |
42 | } | 38 | } |
43 | 39 | ||
44 | #[derive(Debug, Default, PartialEq, Eq)] | ||
45 | pub struct ImportSourceMap { | ||
46 | map: ArenaMap<LocalImportId, ImportSourcePtr>, | ||
47 | } | ||
48 | |||
49 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | ||
50 | |||
51 | impl RawItems { | 40 | impl RawItems { |
52 | pub(crate) fn raw_items_query( | 41 | pub(crate) fn raw_items_query( |
53 | db: &(impl DefDatabase + AstDatabase), | 42 | db: &(impl DefDatabase + AstDatabase), |
54 | file_id: HirFileId, | 43 | file_id: HirFileId, |
55 | ) -> Arc<RawItems> { | 44 | ) -> Arc<RawItems> { |
56 | db.raw_items_with_source_map(file_id).0 | ||
57 | } | ||
58 | |||
59 | pub(crate) fn raw_items_with_source_map_query( | ||
60 | db: &(impl DefDatabase + AstDatabase), | ||
61 | file_id: HirFileId, | ||
62 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { | ||
63 | let mut collector = RawItemsCollector { | 45 | let mut collector = RawItemsCollector { |
64 | raw_items: RawItems::default(), | 46 | raw_items: RawItems::default(), |
65 | source_ast_id_map: db.ast_id_map(file_id), | 47 | source_ast_id_map: db.ast_id_map(file_id), |
66 | imports: Trace::new(), | ||
67 | file_id, | 48 | file_id, |
68 | hygiene: Hygiene::new(db, file_id), | 49 | hygiene: Hygiene::new(db, file_id), |
69 | }; | 50 | }; |
@@ -74,11 +55,8 @@ impl RawItems { | |||
74 | collector.process_module(None, item_list); | 55 | collector.process_module(None, item_list); |
75 | } | 56 | } |
76 | } | 57 | } |
77 | let mut raw_items = collector.raw_items; | 58 | let raw_items = collector.raw_items; |
78 | let (arena, map) = collector.imports.into_arena_and_map(); | 59 | Arc::new(raw_items) |
79 | raw_items.imports = arena; | ||
80 | let source_map = ImportSourceMap { map }; | ||
81 | (Arc::new(raw_items), Arc::new(source_map)) | ||
82 | } | 60 | } |
83 | 61 | ||
84 | pub(super) fn items(&self) -> &[RawItem] { | 62 | pub(super) fn items(&self) -> &[RawItem] { |
@@ -93,9 +71,9 @@ impl Index<Module> for RawItems { | |||
93 | } | 71 | } |
94 | } | 72 | } |
95 | 73 | ||
96 | impl Index<LocalImportId> for RawItems { | 74 | impl Index<Import> for RawItems { |
97 | type Output = ImportData; | 75 | type Output = ImportData; |
98 | fn index(&self, idx: LocalImportId) -> &ImportData { | 76 | fn index(&self, idx: Import) -> &ImportData { |
99 | &self.imports[idx] | 77 | &self.imports[idx] |
100 | } | 78 | } |
101 | } | 79 | } |
@@ -130,7 +108,7 @@ pub(super) struct RawItem { | |||
130 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 108 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
131 | pub(super) enum RawItemKind { | 109 | pub(super) enum RawItemKind { |
132 | Module(Module), | 110 | Module(Module), |
133 | Import(LocalImportId), | 111 | Import(Import), |
134 | Def(Def), | 112 | Def(Def), |
135 | Macro(Macro), | 113 | Macro(Macro), |
136 | Impl(Impl), | 114 | Impl(Impl), |
@@ -146,6 +124,10 @@ pub(super) enum ModuleData { | |||
146 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, | 124 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
147 | } | 125 | } |
148 | 126 | ||
127 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
128 | pub(crate) struct Import(RawId); | ||
129 | impl_arena_id!(Import); | ||
130 | |||
149 | #[derive(Debug, Clone, PartialEq, Eq)] | 131 | #[derive(Debug, Clone, PartialEq, Eq)] |
150 | pub struct ImportData { | 132 | pub struct ImportData { |
151 | pub(super) path: ModPath, | 133 | pub(super) path: ModPath, |
@@ -217,7 +199,6 @@ pub(super) struct ImplData { | |||
217 | 199 | ||
218 | struct RawItemsCollector { | 200 | struct RawItemsCollector { |
219 | raw_items: RawItems, | 201 | raw_items: RawItems, |
220 | imports: Trace<LocalImportId, ImportData, ImportSourcePtr>, | ||
221 | source_ast_id_map: Arc<AstIdMap>, | 202 | source_ast_id_map: Arc<AstIdMap>, |
222 | file_id: HirFileId, | 203 | file_id: HirFileId, |
223 | hygiene: Hygiene, | 204 | hygiene: Hygiene, |
@@ -324,7 +305,7 @@ impl RawItemsCollector { | |||
324 | ModPath::expand_use_item( | 305 | ModPath::expand_use_item( |
325 | InFile { value: use_item, file_id: self.file_id }, | 306 | InFile { value: use_item, file_id: self.file_id }, |
326 | &self.hygiene, | 307 | &self.hygiene, |
327 | |path, use_tree, is_glob, alias| { | 308 | |path, _use_tree, is_glob, alias| { |
328 | let import_data = ImportData { | 309 | let import_data = ImportData { |
329 | path, | 310 | path, |
330 | alias, | 311 | alias, |
@@ -333,11 +314,11 @@ impl RawItemsCollector { | |||
333 | is_extern_crate: false, | 314 | is_extern_crate: false, |
334 | is_macro_use: false, | 315 | is_macro_use: false, |
335 | }; | 316 | }; |
336 | buf.push((import_data, Either::Left(AstPtr::new(use_tree)))); | 317 | buf.push(import_data); |
337 | }, | 318 | }, |
338 | ); | 319 | ); |
339 | for (import_data, ptr) in buf { | 320 | for import_data in buf { |
340 | self.push_import(current_module, attrs.clone(), import_data, ptr); | 321 | self.push_import(current_module, attrs.clone(), import_data); |
341 | } | 322 | } |
342 | } | 323 | } |
343 | 324 | ||
@@ -360,12 +341,7 @@ impl RawItemsCollector { | |||
360 | is_extern_crate: true, | 341 | is_extern_crate: true, |
361 | is_macro_use, | 342 | is_macro_use, |
362 | }; | 343 | }; |
363 | self.push_import( | 344 | self.push_import(current_module, attrs, import_data); |
364 | current_module, | ||
365 | attrs, | ||
366 | import_data, | ||
367 | Either::Right(AstPtr::new(&extern_crate)), | ||
368 | ); | ||
369 | } | 345 | } |
370 | } | 346 | } |
371 | 347 | ||
@@ -396,14 +372,8 @@ impl RawItemsCollector { | |||
396 | self.push_item(current_module, attrs, RawItemKind::Impl(imp)) | 372 | self.push_item(current_module, attrs, RawItemKind::Impl(imp)) |
397 | } | 373 | } |
398 | 374 | ||
399 | fn push_import( | 375 | fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) { |
400 | &mut self, | 376 | let import = self.raw_items.imports.alloc(data); |
401 | current_module: Option<Module>, | ||
402 | attrs: Attrs, | ||
403 | data: ImportData, | ||
404 | source: ImportSourcePtr, | ||
405 | ) { | ||
406 | let import = self.imports.alloc(|| source, || data); | ||
407 | self.push_item(current_module, attrs, RawItemKind::Import(import)) | 377 | self.push_item(current_module, attrs, RawItemKind::Import(import)) |
408 | } | 378 | } |
409 | 379 | ||
diff --git a/crates/ra_hir_def/src/trace.rs b/crates/ra_hir_def/src/trace.rs index 2bcd707bc..9769e88df 100644 --- a/crates/ra_hir_def/src/trace.rs +++ b/crates/ra_hir_def/src/trace.rs | |||
@@ -18,10 +18,6 @@ pub(crate) struct Trace<ID: ArenaId, T, V> { | |||
18 | } | 18 | } |
19 | 19 | ||
20 | impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { | 20 | impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { |
21 | pub(crate) fn new() -> Trace<ID, T, V> { | ||
22 | Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 } | ||
23 | } | ||
24 | |||
25 | pub(crate) fn new_for_arena() -> Trace<ID, T, V> { | 21 | pub(crate) fn new_for_arena() -> Trace<ID, T, V> { |
26 | Trace { arena: Some(Arena::default()), map: None, len: 0 } | 22 | Trace { arena: Some(Arena::default()), map: None, len: 0 } |
27 | } | 23 | } |
@@ -52,8 +48,4 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { | |||
52 | pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { | 48 | pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { |
53 | self.map.take().unwrap() | 49 | self.map.take().unwrap() |
54 | } | 50 | } |
55 | |||
56 | pub(crate) fn into_arena_and_map(mut self) -> (Arena<ID, T>, ArenaMap<ID, V>) { | ||
57 | (self.arena.take().unwrap(), self.map.take().unwrap()) | ||
58 | } | ||
59 | } | 51 | } |
diff --git a/crates/ra_ide/src/change.rs b/crates/ra_ide/src/change.rs index 4a76d1dd8..387a9cafb 100644 --- a/crates/ra_ide/src/change.rs +++ b/crates/ra_ide/src/change.rs | |||
@@ -270,7 +270,6 @@ impl RootDatabase { | |||
270 | 270 | ||
271 | self.query(hir::db::AstIdMapQuery).sweep(sweep); | 271 | self.query(hir::db::AstIdMapQuery).sweep(sweep); |
272 | 272 | ||
273 | self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); | ||
274 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); | 273 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); |
275 | 274 | ||
276 | self.query(hir::db::ExprScopesQuery).sweep(sweep); | 275 | self.query(hir::db::ExprScopesQuery).sweep(sweep); |
@@ -309,7 +308,6 @@ impl RootDatabase { | |||
309 | hir::db::StructDataQuery | 308 | hir::db::StructDataQuery |
310 | hir::db::EnumDataQuery | 309 | hir::db::EnumDataQuery |
311 | hir::db::TraitDataQuery | 310 | hir::db::TraitDataQuery |
312 | hir::db::RawItemsWithSourceMapQuery | ||
313 | hir::db::RawItemsQuery | 311 | hir::db::RawItemsQuery |
314 | hir::db::CrateDefMapQuery | 312 | hir::db::CrateDefMapQuery |
315 | hir::db::GenericParamsQuery | 313 | hir::db::GenericParamsQuery |