diff options
author | Jonas Schievink <[email protected]> | 2020-12-16 23:26:01 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-16 23:26:01 +0000 |
commit | 21b68a328ca1f8e926f0364727ed105310a573b5 (patch) | |
tree | 94159153e6f1b26bc7f1b888aeee698ab182ed98 /crates/hir_def/src | |
parent | 785860bd171da1a18aed78a5020732831596cd78 (diff) |
Remove `module_lang_items`
It isn't used anywhere except in `crate_lang_items`. Remove it to
slightly reduce memory usage and simplify the code.
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/db.rs | 7 | ||||
-rw-r--r-- | crates/hir_def/src/lang_item.rs | 77 |
2 files changed, 30 insertions, 54 deletions
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, |