aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres
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
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')
-rw-r--r--crates/hir_def/src/nameres/collector.rs14
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs4
-rw-r--r--crates/hir_def/src/nameres/tests.rs2
3 files changed, 10 insertions, 10 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 0cd61698c..61da56340 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -31,7 +31,7 @@ use crate::{
31 }, 31 },
32 nameres::{ 32 nameres::{
33 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, 33 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
34 BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode, 34 BuiltinShadowMode, DefMap, ModuleData, ModuleOrigin, ResolveMode,
35 }, 35 },
36 path::{ImportAlias, ModPath, PathKind}, 36 path::{ImportAlias, ModPath, PathKind},
37 per_ns::PerNs, 37 per_ns::PerNs,
@@ -45,7 +45,7 @@ const GLOB_RECURSION_LIMIT: usize = 100;
45const EXPANSION_DEPTH_LIMIT: usize = 128; 45const EXPANSION_DEPTH_LIMIT: usize = 128;
46const FIXED_POINT_LIMIT: usize = 8192; 46const FIXED_POINT_LIMIT: usize = 8192;
47 47
48pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 48pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap) -> DefMap {
49 let crate_graph = db.crate_graph(); 49 let crate_graph = db.crate_graph();
50 50
51 // populate external prelude 51 // populate external prelude
@@ -210,7 +210,7 @@ struct DefData<'a> {
210/// Walks the tree of module recursively 210/// Walks the tree of module recursively
211struct DefCollector<'a> { 211struct DefCollector<'a> {
212 db: &'a dyn DefDatabase, 212 db: &'a dyn DefDatabase,
213 def_map: CrateDefMap, 213 def_map: DefMap,
214 glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>, 214 glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
215 unresolved_imports: Vec<ImportDirective>, 215 unresolved_imports: Vec<ImportDirective>,
216 resolved_imports: Vec<ImportDirective>, 216 resolved_imports: Vec<ImportDirective>,
@@ -859,7 +859,7 @@ impl DefCollector<'_> {
859 .collect(item_tree.top_level_items()); 859 .collect(item_tree.top_level_items());
860 } 860 }
861 861
862 fn finish(mut self) -> CrateDefMap { 862 fn finish(mut self) -> DefMap {
863 // Emit diagnostics for all remaining unexpanded macros. 863 // Emit diagnostics for all remaining unexpanded macros.
864 864
865 for directive in &self.unexpanded_macros { 865 for directive in &self.unexpanded_macros {
@@ -1474,7 +1474,7 @@ mod tests {
1474 1474
1475 use super::*; 1475 use super::*;
1476 1476
1477 fn do_collect_defs(db: &dyn DefDatabase, def_map: CrateDefMap) -> CrateDefMap { 1477 fn do_collect_defs(db: &dyn DefDatabase, def_map: DefMap) -> DefMap {
1478 let mut collector = DefCollector { 1478 let mut collector = DefCollector {
1479 db, 1479 db,
1480 def_map, 1480 def_map,
@@ -1493,7 +1493,7 @@ mod tests {
1493 collector.def_map 1493 collector.def_map
1494 } 1494 }
1495 1495
1496 fn do_resolve(code: &str) -> CrateDefMap { 1496 fn do_resolve(code: &str) -> DefMap {
1497 let (db, _file_id) = TestDB::with_single_file(&code); 1497 let (db, _file_id) = TestDB::with_single_file(&code);
1498 let krate = db.test_crate(); 1498 let krate = db.test_crate();
1499 1499
@@ -1501,7 +1501,7 @@ mod tests {
1501 let edition = db.crate_graph()[krate].edition; 1501 let edition = db.crate_graph()[krate].edition;
1502 let mut modules: Arena<ModuleData> = Arena::default(); 1502 let mut modules: Arena<ModuleData> = Arena::default();
1503 let root = modules.alloc(ModuleData::default()); 1503 let root = modules.alloc(ModuleData::default());
1504 CrateDefMap { 1504 DefMap {
1505 krate, 1505 krate,
1506 edition, 1506 edition,
1507 extern_prelude: FxHashMap::default(), 1507 extern_prelude: FxHashMap::default(),
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 88e10574e..096a7d0ac 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -19,7 +19,7 @@ use test_utils::mark;
19use crate::{ 19use crate::{
20 db::DefDatabase, 20 db::DefDatabase,
21 item_scope::BUILTIN_SCOPE, 21 item_scope::BUILTIN_SCOPE,
22 nameres::{BuiltinShadowMode, CrateDefMap}, 22 nameres::{BuiltinShadowMode, DefMap},
23 path::{ModPath, PathKind}, 23 path::{ModPath, PathKind},
24 per_ns::PerNs, 24 per_ns::PerNs,
25 visibility::{RawVisibility, Visibility}, 25 visibility::{RawVisibility, Visibility},
@@ -61,7 +61,7 @@ impl ResolvePathResult {
61 } 61 }
62} 62}
63 63
64impl CrateDefMap { 64impl DefMap {
65 pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { 65 pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
66 self.extern_prelude 66 self.extern_prelude
67 .get(name) 67 .get(name)
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs
index c459fa66d..723481c36 100644
--- a/crates/hir_def/src/nameres/tests.rs
+++ b/crates/hir_def/src/nameres/tests.rs
@@ -13,7 +13,7 @@ use test_utils::mark;
13 13
14use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; 14use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
15 15
16fn compute_crate_def_map(ra_fixture: &str) -> Arc<CrateDefMap> { 16fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> {
17 let db = TestDB::with_files(ra_fixture); 17 let db = TestDB::with_files(ra_fixture);
18 let krate = db.crate_graph().iter().next().unwrap(); 18 let krate = db.crate_graph().iter().next().unwrap();
19 db.crate_def_map(krate) 19 db.crate_def_map(krate)