diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/db.rs | 7 | ||||
-rw-r--r-- | crates/hir_def/src/lang_item.rs | 77 | ||||
-rw-r--r-- | crates/ide_db/src/apply_change.rs | 1 |
4 files changed, 32 insertions, 57 deletions
diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs index 8d949b264..d01e1b33d 100644 --- a/crates/hir/src/db.rs +++ b/crates/hir/src/db.rs | |||
@@ -6,8 +6,8 @@ pub use hir_def::db::{ | |||
6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, InternConstQuery, | 6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, InternConstQuery, |
7 | InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, InternImplQuery, | 7 | InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, InternImplQuery, |
8 | InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery, | 8 | InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery, |
9 | ItemTreeQuery, LangItemQuery, ModuleLangItemsQuery, StaticDataQuery, StructDataQuery, | 9 | ItemTreeQuery, LangItemQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, |
10 | TraitDataQuery, TypeAliasDataQuery, UnionDataQuery, | 10 | TypeAliasDataQuery, UnionDataQuery, |
11 | }; | 11 | }; |
12 | pub use hir_expand::db::{ | 12 | pub use hir_expand::db::{ |
13 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery, | 13 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery, |
diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs index 7f250da33..d1a459066 100644 --- a/crates/hir_def/src/db.rs +++ b/crates/hir_def/src/db.rs | |||
@@ -16,8 +16,8 @@ use crate::{ | |||
16 | lang_item::{LangItemTarget, LangItems}, | 16 | lang_item::{LangItemTarget, LangItems}, |
17 | nameres::CrateDefMap, | 17 | nameres::CrateDefMap, |
18 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, | 18 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, |
19 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, | 19 | GenericDefId, ImplId, ImplLoc, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, |
20 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, | 20 | TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | #[salsa::query_group(InternDatabaseStorage)] | 23 | #[salsa::query_group(InternDatabaseStorage)] |
@@ -95,9 +95,6 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { | |||
95 | #[salsa::invoke(Attrs::attrs_query)] | 95 | #[salsa::invoke(Attrs::attrs_query)] |
96 | fn attrs(&self, def: AttrDefId) -> Attrs; | 96 | fn attrs(&self, def: AttrDefId) -> Attrs; |
97 | 97 | ||
98 | #[salsa::invoke(LangItems::module_lang_items_query)] | ||
99 | fn module_lang_items(&self, module: ModuleId) -> Option<Arc<LangItems>>; | ||
100 | |||
101 | #[salsa::invoke(LangItems::crate_lang_items_query)] | 98 | #[salsa::invoke(LangItems::crate_lang_items_query)] |
102 | fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>; | 99 | fn crate_lang_items(&self, krate: CrateId) -> Arc<LangItems>; |
103 | 100 | ||
diff --git a/crates/hir_def/src/lang_item.rs b/crates/hir_def/src/lang_item.rs index 063eadccb..30188b740 100644 --- a/crates/hir_def/src/lang_item.rs +++ b/crates/hir_def/src/lang_item.rs | |||
@@ -8,8 +8,8 @@ use rustc_hash::FxHashMap; | |||
8 | use syntax::SmolStr; | 8 | use syntax::SmolStr; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId, | 11 | db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, StaticId, |
12 | StaticId, StructId, TraitId, | 12 | StructId, TraitId, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 15 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -84,27 +84,34 @@ impl LangItems { | |||
84 | 84 | ||
85 | let crate_def_map = db.crate_def_map(krate); | 85 | let crate_def_map = db.crate_def_map(krate); |
86 | 86 | ||
87 | crate_def_map | 87 | for (_, module_data) in crate_def_map.modules.iter() { |
88 | .modules | 88 | for impl_def in module_data.scope.impls() { |
89 | .iter() | 89 | lang_items.collect_lang_item(db, impl_def, LangItemTarget::ImplDefId) |
90 | .filter_map(|(local_id, _)| db.module_lang_items(ModuleId { krate, local_id })) | 90 | } |
91 | .for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v)))); | ||
92 | |||
93 | Arc::new(lang_items) | ||
94 | } | ||
95 | 91 | ||
96 | pub(crate) fn module_lang_items_query( | 92 | for def in module_data.scope.declarations() { |
97 | db: &dyn DefDatabase, | 93 | match def { |
98 | module: ModuleId, | 94 | ModuleDefId::TraitId(trait_) => { |
99 | ) -> Option<Arc<LangItems>> { | 95 | lang_items.collect_lang_item(db, trait_, LangItemTarget::TraitId) |
100 | let _p = profile::span("module_lang_items_query"); | 96 | } |
101 | let mut lang_items = LangItems::default(); | 97 | ModuleDefId::AdtId(AdtId::EnumId(e)) => { |
102 | lang_items.collect_lang_items(db, module); | 98 | lang_items.collect_lang_item(db, e, LangItemTarget::EnumId) |
103 | if lang_items.items.is_empty() { | 99 | } |
104 | None | 100 | ModuleDefId::AdtId(AdtId::StructId(s)) => { |
105 | } else { | 101 | lang_items.collect_lang_item(db, s, LangItemTarget::StructId) |
106 | Some(Arc::new(lang_items)) | 102 | } |
103 | ModuleDefId::FunctionId(f) => { | ||
104 | lang_items.collect_lang_item(db, f, LangItemTarget::FunctionId) | ||
105 | } | ||
106 | ModuleDefId::StaticId(s) => { | ||
107 | lang_items.collect_lang_item(db, s, LangItemTarget::StaticId) | ||
108 | } | ||
109 | _ => {} | ||
110 | } | ||
111 | } | ||
107 | } | 112 | } |
113 | |||
114 | Arc::new(lang_items) | ||
108 | } | 115 | } |
109 | 116 | ||
110 | /// Salsa query. Look for a lang item, starting from the specified crate and recursively | 117 | /// Salsa query. Look for a lang item, starting from the specified crate and recursively |
@@ -126,34 +133,6 @@ impl LangItems { | |||
126 | .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) | 133 | .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) |
127 | } | 134 | } |
128 | 135 | ||
129 | fn collect_lang_items(&mut self, db: &dyn DefDatabase, module: ModuleId) { | ||
130 | // Look for impl targets | ||
131 | let def_map = db.crate_def_map(module.krate); | ||
132 | let module_data = &def_map[module.local_id]; | ||
133 | for impl_def in module_data.scope.impls() { | ||
134 | self.collect_lang_item(db, impl_def, LangItemTarget::ImplDefId) | ||
135 | } | ||
136 | |||
137 | for def in module_data.scope.declarations() { | ||
138 | match def { | ||
139 | ModuleDefId::TraitId(trait_) => { | ||
140 | self.collect_lang_item(db, trait_, LangItemTarget::TraitId) | ||
141 | } | ||
142 | ModuleDefId::AdtId(AdtId::EnumId(e)) => { | ||
143 | self.collect_lang_item(db, e, LangItemTarget::EnumId) | ||
144 | } | ||
145 | ModuleDefId::AdtId(AdtId::StructId(s)) => { | ||
146 | self.collect_lang_item(db, s, LangItemTarget::StructId) | ||
147 | } | ||
148 | ModuleDefId::FunctionId(f) => { | ||
149 | self.collect_lang_item(db, f, LangItemTarget::FunctionId) | ||
150 | } | ||
151 | ModuleDefId::StaticId(s) => self.collect_lang_item(db, s, LangItemTarget::StaticId), | ||
152 | _ => {} | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | |||
157 | fn collect_lang_item<T>( | 136 | fn collect_lang_item<T>( |
158 | &mut self, | 137 | &mut self, |
159 | db: &dyn DefDatabase, | 138 | db: &dyn DefDatabase, |
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs index e2251f2b7..71c19ed13 100644 --- a/crates/ide_db/src/apply_change.rs +++ b/crates/ide_db/src/apply_change.rs | |||
@@ -163,7 +163,6 @@ impl RootDatabase { | |||
163 | hir::db::ExprScopesQuery | 163 | hir::db::ExprScopesQuery |
164 | hir::db::GenericParamsQuery | 164 | hir::db::GenericParamsQuery |
165 | hir::db::AttrsQuery | 165 | hir::db::AttrsQuery |
166 | hir::db::ModuleLangItemsQuery | ||
167 | hir::db::CrateLangItemsQuery | 166 | hir::db::CrateLangItemsQuery |
168 | hir::db::LangItemQuery | 167 | hir::db::LangItemQuery |
169 | hir::db::ImportMapQuery | 168 | hir::db::ImportMapQuery |