Cleanup nameres

This commit is contained in:
Aleksey Kladov 2019-11-24 18:05:12 +03:00
parent 855a629b14
commit f5e0a31eaf
5 changed files with 19 additions and 35 deletions

View File

@ -62,7 +62,7 @@ impl Crate {
}
pub fn root_module(self, db: &impl DefDatabase) -> Option<Module> {
let module_id = db.crate_def_map(self.crate_id).root();
let module_id = db.crate_def_map(self.crate_id).root;
Some(Module::new(self, module_id))
}
@ -195,7 +195,7 @@ impl Module {
/// in the module tree of any target in `Cargo.toml`.
pub fn crate_root(self, db: &impl DefDatabase) -> Module {
let def_map = db.crate_def_map(self.id.krate);
self.with_module_id(def_map.root())
self.with_module_id(def_map.root)
}
/// Finds a child module with the specified name.

View File

@ -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)

View File

@ -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<ModuleId>,
extern_prelude: FxHashMap<Name, ModuleDefId>,
root: LocalModuleId,
modules: Arena<LocalModuleId, ModuleData>,
pub(crate) prelude: Option<ModuleId>,
pub(crate) extern_prelude: FxHashMap<Name, ModuleDefId>,
pub(crate) modules: Arena<LocalModuleId, ModuleData>,
edition: Edition,
diagnostics: Vec<DefDiagnostic>,
}
@ -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<ModuleId> {
self.prelude
}
pub fn extern_prelude(&self) -> &FxHashMap<Name, ModuleDefId> {
&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<Item = LocalModuleId> + '_ {
self.modules.iter().map(|(id, _data)| id)
}
pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator<Item = LocalModuleId> + '_ {
self.modules
.iter()

View File

@ -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,

View File

@ -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<CrateId> {
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));