aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/body.rs4
-rw-r--r--crates/hir_def/src/child_by_source.rs4
-rw-r--r--crates/hir_def/src/import_map.rs95
-rw-r--r--crates/hir_def/src/resolver.rs24
4 files changed, 65 insertions, 62 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs
index ff4b4a0cf..16e1bac40 100644
--- a/crates/hir_def/src/body.rs
+++ b/crates/hir_def/src/body.rs
@@ -87,11 +87,11 @@ impl Expander {
87 module: ModuleId, 87 module: ModuleId,
88 ) -> Expander { 88 ) -> Expander {
89 let cfg_expander = CfgExpander::new(db, current_file_id, module.krate); 89 let cfg_expander = CfgExpander::new(db, current_file_id, module.krate);
90 let crate_def_map = module.def_map(db); 90 let def_map = module.def_map(db);
91 let ast_id_map = db.ast_id_map(current_file_id); 91 let ast_id_map = db.ast_id_map(current_file_id);
92 Expander { 92 Expander {
93 cfg_expander, 93 cfg_expander,
94 def_map: crate_def_map, 94 def_map,
95 current_file_id, 95 current_file_id,
96 ast_id_map, 96 ast_id_map,
97 module: module.local_id, 97 module: module.local_id,
diff --git a/crates/hir_def/src/child_by_source.rs b/crates/hir_def/src/child_by_source.rs
index 65d85c86a..75c2d756b 100644
--- a/crates/hir_def/src/child_by_source.rs
+++ b/crates/hir_def/src/child_by_source.rs
@@ -74,8 +74,8 @@ impl ChildBySource for ImplId {
74 74
75impl ChildBySource for ModuleId { 75impl ChildBySource for ModuleId {
76 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap { 76 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
77 let crate_def_map = self.def_map(db); 77 let def_map = self.def_map(db);
78 let module_data = &crate_def_map[self.local_id]; 78 let module_data = &def_map[self.local_id];
79 module_data.scope.child_by_source(db) 79 module_data.scope.child_by_source(db)
80 } 80 }
81} 81}
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index 0a3dc7956..e1c28bc83 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -388,7 +388,7 @@ pub fn search_dependencies<'a>(
388 db: &'a dyn DefDatabase, 388 db: &'a dyn DefDatabase,
389 krate: CrateId, 389 krate: CrateId,
390 query: Query, 390 query: Query,
391) -> Vec<ItemInNs> { 391) -> FxHashSet<ItemInNs> {
392 let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query)); 392 let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query));
393 393
394 let graph = db.crate_graph(); 394 let graph = db.crate_graph();
@@ -403,41 +403,42 @@ pub fn search_dependencies<'a>(
403 } 403 }
404 404
405 let mut stream = op.union(); 405 let mut stream = op.union();
406 let mut res = Vec::new(); 406
407 let mut all_indexed_values = FxHashSet::default();
407 while let Some((_, indexed_values)) = stream.next() { 408 while let Some((_, indexed_values)) = stream.next() {
408 for indexed_value in indexed_values { 409 all_indexed_values.extend(indexed_values.iter().copied());
409 let import_map = &import_maps[indexed_value.index]; 410 }
410 let importables = &import_map.importables[indexed_value.value as usize..];
411 411
412 let common_importable_data = &import_map.map[&importables[0]]; 412 let mut res = FxHashSet::default();
413 if !query.import_matches(common_importable_data, true) { 413 for indexed_value in all_indexed_values {
414 continue; 414 let import_map = &import_maps[indexed_value.index];
415 } 415 let importables = &import_map.importables[indexed_value.value as usize..];
416 416
417 // Path shared by the importable items in this group. 417 let common_importable_data = &import_map.map[&importables[0]];
418 let common_importables_path_fst = fst_path(&common_importable_data.path); 418 if !query.import_matches(common_importable_data, true) {
419 // Add the items from this `ModPath` group. Those are all subsequent items in 419 continue;
420 // `importables` whose paths match `path`. 420 }
421 let iter = importables 421
422 .iter() 422 // Path shared by the importable items in this group.
423 .copied() 423 let common_importables_path_fst = fst_path(&common_importable_data.path);
424 .take_while(|item| { 424 // Add the items from this `ModPath` group. Those are all subsequent items in
425 common_importables_path_fst == fst_path(&import_map.map[item].path) 425 // `importables` whose paths match `path`.
426 }) 426 let iter = importables
427 .filter(|&item| match item_import_kind(item) { 427 .iter()
428 Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), 428 .copied()
429 None => true, 429 .take_while(|item| common_importables_path_fst == fst_path(&import_map.map[item].path))
430 }) 430 .filter(|&item| match item_import_kind(item) {
431 .filter(|item| { 431 Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind),
432 !query.case_sensitive // we've already checked the common importables path case-insensitively 432 None => true,
433 })
434 .filter(|item| {
435 !query.case_sensitive // we've already checked the common importables path case-insensitively
433 || query.import_matches(&import_map.map[item], false) 436 || query.import_matches(&import_map.map[item], false)
434 }); 437 });
435 res.extend(iter); 438 res.extend(iter);
436 439
437 if res.len() >= query.limit { 440 if res.len() >= query.limit {
438 res.truncate(query.limit); 441 return res;
439 return res;
440 }
441 } 442 }
442 } 443 }
443 444
@@ -821,10 +822,10 @@ mod tests {
821 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), 822 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
822 expect![[r#" 823 expect![[r#"
823 dep::fmt (t) 824 dep::fmt (t)
825 dep::fmt::Display::format_method (a)
824 dep::fmt::Display (t) 826 dep::fmt::Display (t)
825 dep::fmt::Display::FMT_CONST (a) 827 dep::fmt::Display::FMT_CONST (a)
826 dep::fmt::Display::format_function (a) 828 dep::fmt::Display::format_function (a)
827 dep::fmt::Display::format_method (a)
828 "#]], 829 "#]],
829 ); 830 );
830 } 831 }
@@ -850,9 +851,9 @@ mod tests {
850 "main", 851 "main",
851 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(), 852 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(),
852 expect![[r#" 853 expect![[r#"
854 dep::fmt::Display::format_method (a)
853 dep::fmt::Display::FMT_CONST (a) 855 dep::fmt::Display::FMT_CONST (a)
854 dep::fmt::Display::format_function (a) 856 dep::fmt::Display::format_function (a)
855 dep::fmt::Display::format_method (a)
856 "#]], 857 "#]],
857 ); 858 );
858 859
@@ -911,12 +912,12 @@ mod tests {
911 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), 912 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
912 expect![[r#" 913 expect![[r#"
913 dep::fmt (t) 914 dep::fmt (t)
914 dep::Fmt (t) 915 dep::format (f)
915 dep::Fmt (v) 916 dep::Fmt (v)
916 dep::Fmt (m)
917 dep::fmt::Display (t) 917 dep::fmt::Display (t)
918 dep::Fmt (t)
918 dep::fmt::Display::fmt (a) 919 dep::fmt::Display::fmt (a)
919 dep::format (f) 920 dep::Fmt (m)
920 "#]], 921 "#]],
921 ); 922 );
922 923
@@ -926,10 +927,10 @@ mod tests {
926 Query::new("fmt".to_string()).search_mode(SearchMode::Equals), 927 Query::new("fmt".to_string()).search_mode(SearchMode::Equals),
927 expect![[r#" 928 expect![[r#"
928 dep::fmt (t) 929 dep::fmt (t)
929 dep::Fmt (t)
930 dep::Fmt (v) 930 dep::Fmt (v)
931 dep::Fmt (m) 931 dep::Fmt (t)
932 dep::fmt::Display::fmt (a) 932 dep::fmt::Display::fmt (a)
933 dep::Fmt (m)
933 "#]], 934 "#]],
934 ); 935 );
935 936
@@ -939,11 +940,11 @@ mod tests {
939 Query::new("fmt".to_string()).search_mode(SearchMode::Contains), 940 Query::new("fmt".to_string()).search_mode(SearchMode::Contains),
940 expect![[r#" 941 expect![[r#"
941 dep::fmt (t) 942 dep::fmt (t)
942 dep::Fmt (t)
943 dep::Fmt (v) 943 dep::Fmt (v)
944 dep::Fmt (m)
945 dep::fmt::Display (t) 944 dep::fmt::Display (t)
945 dep::Fmt (t)
946 dep::fmt::Display::fmt (a) 946 dep::fmt::Display::fmt (a)
947 dep::Fmt (m)
947 "#]], 948 "#]],
948 ); 949 );
949 } 950 }
@@ -980,11 +981,11 @@ mod tests {
980 Query::new("fmt".to_string()), 981 Query::new("fmt".to_string()),
981 expect![[r#" 982 expect![[r#"
982 dep::fmt (t) 983 dep::fmt (t)
983 dep::Fmt (t)
984 dep::Fmt (v) 984 dep::Fmt (v)
985 dep::Fmt (m)
986 dep::fmt::Display (t) 985 dep::fmt::Display (t)
986 dep::Fmt (t)
987 dep::fmt::Display::fmt (a) 987 dep::fmt::Display::fmt (a)
988 dep::Fmt (m)
988 "#]], 989 "#]],
989 ); 990 );
990 991
@@ -994,10 +995,10 @@ mod tests {
994 Query::new("fmt".to_string()).name_only(), 995 Query::new("fmt".to_string()).name_only(),
995 expect![[r#" 996 expect![[r#"
996 dep::fmt (t) 997 dep::fmt (t)
997 dep::Fmt (t)
998 dep::Fmt (v) 998 dep::Fmt (v)
999 dep::Fmt (m) 999 dep::Fmt (t)
1000 dep::fmt::Display::fmt (a) 1000 dep::fmt::Display::fmt (a)
1001 dep::Fmt (m)
1001 "#]], 1002 "#]],
1002 ); 1003 );
1003 } 1004 }
@@ -1018,9 +1019,9 @@ mod tests {
1018 Query::new("FMT".to_string()), 1019 Query::new("FMT".to_string()),
1019 expect![[r#" 1020 expect![[r#"
1020 dep::fmt (t) 1021 dep::fmt (t)
1022 dep::FMT (v)
1021 dep::fmt (v) 1023 dep::fmt (v)
1022 dep::FMT (t) 1024 dep::FMT (t)
1023 dep::FMT (v)
1024 "#]], 1025 "#]],
1025 ); 1026 );
1026 1027
@@ -1060,6 +1061,8 @@ mod tests {
1060 expect![[r#" 1061 expect![[r#"
1061 dep::fmt (t) 1062 dep::fmt (t)
1062 dep::Fmt (t) 1063 dep::Fmt (t)
1064 dep::Fmt (m)
1065 dep::Fmt (v)
1063 "#]], 1066 "#]],
1064 ); 1067 );
1065 } 1068 }
@@ -1080,9 +1083,9 @@ mod tests {
1080 Query::new("FMT".to_string()), 1083 Query::new("FMT".to_string()),
1081 expect![[r#" 1084 expect![[r#"
1082 dep::fmt (t) 1085 dep::fmt (t)
1086 dep::FMT (v)
1083 dep::fmt (v) 1087 dep::fmt (v)
1084 dep::FMT (t) 1088 dep::FMT (t)
1085 dep::FMT (v)
1086 "#]], 1089 "#]],
1087 ); 1090 );
1088 1091
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index e85f85e49..77ff21739 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -34,7 +34,7 @@ pub struct Resolver {
34// FIXME how to store these best 34// FIXME how to store these best
35#[derive(Debug, Clone)] 35#[derive(Debug, Clone)]
36struct ModuleItemMap { 36struct ModuleItemMap {
37 crate_def_map: Arc<DefMap>, 37 def_map: Arc<DefMap>,
38 module_id: LocalModuleId, 38 module_id: LocalModuleId,
39} 39}
40 40
@@ -337,11 +337,11 @@ impl Resolver {
337 let mut traits = FxHashSet::default(); 337 let mut traits = FxHashSet::default();
338 for scope in &self.scopes { 338 for scope in &self.scopes {
339 if let Scope::ModuleScope(m) = scope { 339 if let Scope::ModuleScope(m) = scope {
340 if let Some(prelude) = m.crate_def_map.prelude() { 340 if let Some(prelude) = m.def_map.prelude() {
341 let prelude_def_map = prelude.def_map(db); 341 let prelude_def_map = prelude.def_map(db);
342 traits.extend(prelude_def_map[prelude.local_id].scope.traits()); 342 traits.extend(prelude_def_map[prelude.local_id].scope.traits());
343 } 343 }
344 traits.extend(m.crate_def_map[m.module_id].scope.traits()); 344 traits.extend(m.def_map[m.module_id].scope.traits());
345 } 345 }
346 } 346 }
347 traits 347 traits
@@ -349,7 +349,7 @@ impl Resolver {
349 349
350 fn module_scope(&self) -> Option<(&DefMap, LocalModuleId)> { 350 fn module_scope(&self) -> Option<(&DefMap, LocalModuleId)> {
351 self.scopes.iter().rev().find_map(|scope| match scope { 351 self.scopes.iter().rev().find_map(|scope| match scope {
352 Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), 352 Scope::ModuleScope(m) => Some((&*m.def_map, m.module_id)),
353 353
354 _ => None, 354 _ => None,
355 }) 355 })
@@ -413,21 +413,21 @@ impl Scope {
413 // def: m.module.into(), 413 // def: m.module.into(),
414 // }), 414 // }),
415 // ); 415 // );
416 m.crate_def_map[m.module_id].scope.entries().for_each(|(name, def)| { 416 m.def_map[m.module_id].scope.entries().for_each(|(name, def)| {
417 f(name.clone(), ScopeDef::PerNs(def)); 417 f(name.clone(), ScopeDef::PerNs(def));
418 }); 418 });
419 m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { 419 m.def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| {
420 let scope = PerNs::macros(macro_, Visibility::Public); 420 let scope = PerNs::macros(macro_, Visibility::Public);
421 seen.insert((name.clone(), scope)); 421 seen.insert((name.clone(), scope));
422 f(name.clone(), ScopeDef::PerNs(scope)); 422 f(name.clone(), ScopeDef::PerNs(scope));
423 }); 423 });
424 m.crate_def_map.extern_prelude().for_each(|(name, &def)| { 424 m.def_map.extern_prelude().for_each(|(name, &def)| {
425 f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); 425 f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public)));
426 }); 426 });
427 BUILTIN_SCOPE.iter().for_each(|(name, &def)| { 427 BUILTIN_SCOPE.iter().for_each(|(name, &def)| {
428 f(name.clone(), ScopeDef::PerNs(def)); 428 f(name.clone(), ScopeDef::PerNs(def));
429 }); 429 });
430 if let Some(prelude) = m.crate_def_map.prelude() { 430 if let Some(prelude) = m.def_map.prelude() {
431 let prelude_def_map = prelude.def_map(db); 431 let prelude_def_map = prelude.def_map(db);
432 prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { 432 prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| {
433 let seen_tuple = (name.clone(), def); 433 let seen_tuple = (name.clone(), def);
@@ -513,8 +513,8 @@ impl Resolver {
513 self.push_scope(Scope::ImplDefScope(impl_def)) 513 self.push_scope(Scope::ImplDefScope(impl_def))
514 } 514 }
515 515
516 fn push_module_scope(self, crate_def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver { 516 fn push_module_scope(self, def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
517 self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) 517 self.push_scope(Scope::ModuleScope(ModuleItemMap { def_map, module_id }))
518 } 518 }
519 519
520 fn push_expr_scope( 520 fn push_expr_scope(
@@ -534,7 +534,7 @@ impl ModuleItemMap {
534 path: &ModPath, 534 path: &ModPath,
535 ) -> Option<ResolveValueResult> { 535 ) -> Option<ResolveValueResult> {
536 let (module_def, idx) = 536 let (module_def, idx) =
537 self.crate_def_map.resolve_path(db, self.module_id, &path, BuiltinShadowMode::Other); 537 self.def_map.resolve_path(db, self.module_id, &path, BuiltinShadowMode::Other);
538 match idx { 538 match idx {
539 None => { 539 None => {
540 let value = to_value_ns(module_def)?; 540 let value = to_value_ns(module_def)?;
@@ -564,7 +564,7 @@ impl ModuleItemMap {
564 path: &ModPath, 564 path: &ModPath,
565 ) -> Option<(TypeNs, Option<usize>)> { 565 ) -> Option<(TypeNs, Option<usize>)> {
566 let (module_def, idx) = 566 let (module_def, idx) =
567 self.crate_def_map.resolve_path(db, self.module_id, &path, BuiltinShadowMode::Other); 567 self.def_map.resolve_path(db, self.module_id, &path, BuiltinShadowMode::Other);
568 let res = to_type_ns(module_def)?; 568 let res = to_type_ns(module_def)?;
569 Some((res, idx)) 569 Some((res, idx))
570 } 570 }