From f5e0a31eaf9ddd7788e6261d49f4d18e8463a719 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 18:05:12 +0300 Subject: Cleanup nameres --- crates/ra_hir_def/src/lang_item.rs | 5 +++-- crates/ra_hir_def/src/nameres.rs | 32 ++++++------------------------ crates/ra_hir_def/src/nameres/collector.rs | 5 ++++- crates/ra_hir_def/src/resolver.rs | 8 ++++---- 4 files changed, 17 insertions(+), 33 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index 3b9fb0328..f15c23db9 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs @@ -39,8 +39,9 @@ impl LangItems { let crate_def_map = db.crate_def_map(krate); crate_def_map - .modules() - .filter_map(|module_id| db.module_lang_items(ModuleId { krate, module_id })) + .modules + .iter() + .filter_map(|(module_id, _)| db.module_lang_items(ModuleId { krate, module_id })) .for_each(|it| lang_items.items.extend(it.items.iter().map(|(k, v)| (k.clone(), *v)))); Arc::new(lang_items) diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 5919771b0..9476fb1ad 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -80,16 +80,16 @@ use crate::{ /// Contains all top-level defs from a macro-expanded crate #[derive(Debug, PartialEq, Eq)] pub struct CrateDefMap { - krate: CrateId, - edition: Edition, + pub root: LocalModuleId, + pub(crate) krate: CrateId, /// The prelude module for this crate. This either comes from an import /// marked with the `prelude_import` attribute, or (in the normal case) from /// a dependency (`std` or `core`). - prelude: Option, - extern_prelude: FxHashMap, - root: LocalModuleId, - modules: Arena, + pub(crate) prelude: Option, + pub(crate) extern_prelude: FxHashMap, + pub(crate) modules: Arena, + edition: Edition, diagnostics: Vec, } @@ -229,22 +229,6 @@ impl CrateDefMap { Arc::new(def_map) } - pub fn krate(&self) -> CrateId { - self.krate - } - - pub fn root(&self) -> LocalModuleId { - self.root - } - - pub fn prelude(&self) -> Option { - self.prelude - } - - pub fn extern_prelude(&self) -> &FxHashMap { - &self.extern_prelude - } - pub fn add_diagnostics( &self, db: &impl DefDatabase, @@ -254,10 +238,6 @@ impl CrateDefMap { self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) } - pub fn modules(&self) -> impl Iterator + '_ { - self.modules.iter().map(|(id, _data)| id) - } - pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator + '_ { self.modules .iter() diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index df01a20e1..41becf8df 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -1,4 +1,7 @@ -//! FIXME: write short doc here +//! The core of the module-level name resolution algorithm. +//! +//! `DefCollector::collect` contains the fixed-point iteration loop which +//! resolves imports and expands macros. use hir_expand::{ builtin_macro::find_builtin_macro, diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 7182b8a4d..c24a9b165 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -321,7 +321,7 @@ impl Resolver { let mut traits = FxHashSet::default(); for scope in &self.scopes { if let Scope::ModuleScope(m) = scope { - if let Some(prelude) = m.crate_def_map.prelude() { + if let Some(prelude) = m.crate_def_map.prelude { let prelude_def_map = db.crate_def_map(prelude.krate); traits.extend(prelude_def_map[prelude.module_id].scope.traits()); } @@ -340,7 +340,7 @@ impl Resolver { } pub fn krate(&self) -> Option { - self.module().map(|t| t.0.krate()) + self.module().map(|t| t.0.krate) } pub fn where_predicates_in_scope<'a>( @@ -395,10 +395,10 @@ impl Scope { m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_))); }); - m.crate_def_map.extern_prelude().iter().for_each(|(name, &def)| { + m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into()))); }); - if let Some(prelude) = m.crate_def_map.prelude() { + if let Some(prelude) = m.crate_def_map.prelude { let prelude_def_map = db.crate_def_map(prelude.krate); prelude_def_map[prelude.module_id].scope.entries().for_each(|(name, res)| { f(name.clone(), ScopeDef::PerNs(res.def)); -- cgit v1.2.3