aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-18 20:12:11 +0000
committerGitHub <[email protected]>2021-01-18 20:12:11 +0000
commit0791c8e44c6fd1e7519df003dcb8c9e156916f46 (patch)
tree28468414f1ba4183859ebdf78c31f23b87ebda96 /crates/hir_def/src/nameres.rs
parent8164e2ea31ed0c169bc295acb6e13650576e5366 (diff)
parent57a82fb05b46fd028c0b971dc6ce317db3682146 (diff)
Merge #7336
7336: Rename `CrateDefMap` to `DefMap` r=matklad a=jonas-schievink I propose handling local items by computing a `DefMap` for every block expression, using the regular (early) name resolution algorithm. The result of that will be a `DefMap` that has a reference to the parent `DefMap`, which is either the one computed for the containing block expression, or the crate's root `DefMap`. Name resolution will fall back to a name in the parent `DefMap` if it cannot be resolved in the inner block. The `DefMap`s computed for block expressions will go through a separate query that can be garbage-collected much more aggressively, since these `DefMap`s should be cheap to compute and are never part of a crate's public API. The first step towards that is to make `CrateDefMap` not specific to crates anymore, hence this rename (if this plans sounds reasonable). cc https://github.com/rust-analyzer/rust-analyzer/issues/7325 and https://github.com/rust-analyzer/rust-analyzer/issues/1165 Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/nameres.rs')
-rw-r--r--crates/hir_def/src/nameres.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index 50acc3f54..769a557ad 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -74,7 +74,7 @@ use crate::{
74 74
75/// Contains all top-level defs from a macro-expanded crate 75/// Contains all top-level defs from a macro-expanded crate
76#[derive(Debug, PartialEq, Eq)] 76#[derive(Debug, PartialEq, Eq)]
77pub struct CrateDefMap { 77pub struct DefMap {
78 pub root: LocalModuleId, 78 pub root: LocalModuleId,
79 pub modules: Arena<ModuleData>, 79 pub modules: Arena<ModuleData>,
80 pub(crate) krate: CrateId, 80 pub(crate) krate: CrateId,
@@ -88,7 +88,7 @@ pub struct CrateDefMap {
88 diagnostics: Vec<DefDiagnostic>, 88 diagnostics: Vec<DefDiagnostic>,
89} 89}
90 90
91impl std::ops::Index<LocalModuleId> for CrateDefMap { 91impl std::ops::Index<LocalModuleId> for DefMap {
92 type Output = ModuleData; 92 type Output = ModuleData;
93 fn index(&self, id: LocalModuleId) -> &ModuleData { 93 fn index(&self, id: LocalModuleId) -> &ModuleData {
94 &self.modules[id] 94 &self.modules[id]
@@ -169,8 +169,8 @@ pub struct ModuleData {
169 pub origin: ModuleOrigin, 169 pub origin: ModuleOrigin,
170} 170}
171 171
172impl CrateDefMap { 172impl DefMap {
173 pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 173 pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
174 let _p = profile::span("crate_def_map_query").detail(|| { 174 let _p = profile::span("crate_def_map_query").detail(|| {
175 db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string() 175 db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string()
176 }); 176 });
@@ -178,7 +178,7 @@ impl CrateDefMap {
178 let edition = db.crate_graph()[krate].edition; 178 let edition = db.crate_graph()[krate].edition;
179 let mut modules: Arena<ModuleData> = Arena::default(); 179 let mut modules: Arena<ModuleData> = Arena::default();
180 let root = modules.alloc(ModuleData::default()); 180 let root = modules.alloc(ModuleData::default());
181 CrateDefMap { 181 DefMap {
182 krate, 182 krate,
183 edition, 183 edition,
184 extern_prelude: FxHashMap::default(), 184 extern_prelude: FxHashMap::default(),
@@ -227,7 +227,7 @@ impl CrateDefMap {
227 go(&mut buf, self, "crate", self.root); 227 go(&mut buf, self, "crate", self.root);
228 return buf; 228 return buf;
229 229
230 fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) { 230 fn go(buf: &mut String, map: &DefMap, path: &str, module: LocalModuleId) {
231 format_to!(buf, "{}\n", path); 231 format_to!(buf, "{}\n", path);
232 232
233 let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect(); 233 let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();