expr::{Expr, ExprId, Label, LabelId, Pat, PatId},
item_scope::BuiltinShadowMode,
item_scope::ItemScope,
- nameres::CrateDefMap,
+ nameres::DefMap,
path::{ModPath, Path},
src::HasSource,
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId,
pub(crate) struct Expander {
cfg_expander: CfgExpander,
- crate_def_map: Arc<CrateDefMap>,
+ crate_def_map: Arc<DefMap>,
current_file_id: HirFileId,
ast_id_map: Arc<AstIdMap>,
module: ModuleId,
import_map::ImportMap,
item_tree::ItemTree,
lang_item::{LangItemTarget, LangItems},
- nameres::CrateDefMap,
+ nameres::DefMap,
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
GenericDefId, ImplId, ImplLoc, LocalEnumVariantId, LocalFieldId, StaticId, StaticLoc, StructId,
StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
#[salsa::invoke(crate_def_map_wait)]
#[salsa::transparent]
- fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>;
+ fn crate_def_map(&self, krate: CrateId) -> Arc<DefMap>;
- #[salsa::invoke(CrateDefMap::crate_def_map_query)]
- fn crate_def_map_query(&self, krate: CrateId) -> Arc<CrateDefMap>;
+ #[salsa::invoke(DefMap::crate_def_map_query)]
+ fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
#[salsa::invoke(StructData::struct_data_query)]
fn struct_data(&self, id: StructId) -> Arc<StructData>;
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
}
-fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
+fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<DefMap> {
let _p = profile::span("crate_def_map:wait");
db.crate_def_map_query(krate)
}
use rustc_hash::FxHashSet;
use test_utils::mark;
-use crate::nameres::CrateDefMap;
+use crate::nameres::DefMap;
use crate::{
db::DefDatabase,
item_scope::ItemInNs,
}
}
-fn check_self_super(def_map: &CrateDefMap, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
+fn check_self_super(def_map: &DefMap, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
if item == ItemInNs::Types(from.into()) {
// - if the item is the module we're in, use `self`
Some(ModPath::from_segments(PathKind::Super(0), Vec::new()))
/// Contains all top-level defs from a macro-expanded crate
#[derive(Debug, PartialEq, Eq)]
-pub struct CrateDefMap {
+pub struct DefMap {
pub root: LocalModuleId,
pub modules: Arena<ModuleData>,
pub(crate) krate: CrateId,
diagnostics: Vec<DefDiagnostic>,
}
-impl std::ops::Index<LocalModuleId> for CrateDefMap {
+impl std::ops::Index<LocalModuleId> for DefMap {
type Output = ModuleData;
fn index(&self, id: LocalModuleId) -> &ModuleData {
&self.modules[id]
pub origin: ModuleOrigin,
}
-impl CrateDefMap {
- pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
+impl DefMap {
+ pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
let _p = profile::span("crate_def_map_query").detail(|| {
db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string()
});
let edition = db.crate_graph()[krate].edition;
let mut modules: Arena<ModuleData> = Arena::default();
let root = modules.alloc(ModuleData::default());
- CrateDefMap {
+ DefMap {
krate,
edition,
extern_prelude: FxHashMap::default(),
go(&mut buf, self, "crate", self.root);
return buf;
- fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) {
+ fn go(buf: &mut String, map: &DefMap, path: &str, module: LocalModuleId) {
format_to!(buf, "{}\n", path);
let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();
},
nameres::{
diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
- BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode,
+ BuiltinShadowMode, DefMap, ModuleData, ModuleOrigin, ResolveMode,
},
path::{ImportAlias, ModPath, PathKind},
per_ns::PerNs,
const EXPANSION_DEPTH_LIMIT: usize = 128;
const FIXED_POINT_LIMIT: usize = 8192;
-pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
+pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap) -> DefMap {
let crate_graph = db.crate_graph();
// populate external prelude
/// Walks the tree of module recursively
struct DefCollector<'a> {
db: &'a dyn DefDatabase,
- def_map: CrateDefMap,
+ def_map: DefMap,
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
unresolved_imports: Vec<ImportDirective>,
resolved_imports: Vec<ImportDirective>,
.collect(item_tree.top_level_items());
}
- fn finish(mut self) -> CrateDefMap {
+ fn finish(mut self) -> DefMap {
// Emit diagnostics for all remaining unexpanded macros.
for directive in &self.unexpanded_macros {
use super::*;
- fn do_collect_defs(db: &dyn DefDatabase, def_map: CrateDefMap) -> CrateDefMap {
+ fn do_collect_defs(db: &dyn DefDatabase, def_map: DefMap) -> DefMap {
let mut collector = DefCollector {
db,
def_map,
collector.def_map
}
- fn do_resolve(code: &str) -> CrateDefMap {
+ fn do_resolve(code: &str) -> DefMap {
let (db, _file_id) = TestDB::with_single_file(&code);
let krate = db.test_crate();
let edition = db.crate_graph()[krate].edition;
let mut modules: Arena<ModuleData> = Arena::default();
let root = modules.alloc(ModuleData::default());
- CrateDefMap {
+ DefMap {
krate,
edition,
extern_prelude: FxHashMap::default(),
use crate::{
db::DefDatabase,
item_scope::BUILTIN_SCOPE,
- nameres::{BuiltinShadowMode, CrateDefMap},
+ nameres::{BuiltinShadowMode, DefMap},
path::{ModPath, PathKind},
per_ns::PerNs,
visibility::{RawVisibility, Visibility},
}
}
-impl CrateDefMap {
+impl DefMap {
pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
self.extern_prelude
.get(name)
use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
-fn compute_crate_def_map(ra_fixture: &str) -> Arc<CrateDefMap> {
+fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> {
let db = TestDB::with_files(ra_fixture);
let krate = db.crate_graph().iter().next().unwrap();
db.crate_def_map(krate)
expr::{ExprId, PatId},
generics::GenericParams,
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
- nameres::CrateDefMap,
+ nameres::DefMap,
path::{ModPath, PathKind},
per_ns::PerNs,
visibility::{RawVisibility, Visibility},
// FIXME how to store these best
#[derive(Debug, Clone)]
struct ModuleItemMap {
- crate_def_map: Arc<CrateDefMap>,
+ crate_def_map: Arc<DefMap>,
module_id: LocalModuleId,
}
traits
}
- fn module_scope(&self) -> Option<(&CrateDefMap, LocalModuleId)> {
+ fn module_scope(&self) -> Option<(&DefMap, LocalModuleId)> {
self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
self.push_scope(Scope::ImplDefScope(impl_def))
}
- fn push_module_scope(
- self,
- crate_def_map: Arc<CrateDefMap>,
- module_id: LocalModuleId,
- ) -> Resolver {
+ fn push_module_scope(self, crate_def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
}
use crate::{
db::DefDatabase,
- nameres::CrateDefMap,
+ nameres::DefMap,
path::{ModPath, PathKind},
ModuleId,
};
pub(crate) fn is_visible_from_def_map(
self,
- def_map: &CrateDefMap,
+ def_map: &DefMap,
from_module: crate::LocalModuleId,
) -> bool {
let to_module = match self {
///
/// If there is no subset relation between `self` and `other`, returns `None` (ie. they're only
/// visible in unrelated modules).
- pub(crate) fn max(self, other: Visibility, def_map: &CrateDefMap) -> Option<Visibility> {
+ pub(crate) fn max(self, other: Visibility, def_map: &DefMap) -> Option<Visibility> {
match (self, other) {
(Visibility::Module(_), Visibility::Public)
| (Visibility::Public, Visibility::Module(_))
db::DefDatabase,
item_scope::ItemScope,
keys,
- nameres::CrateDefMap,
+ nameres::DefMap,
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
};
use hir_expand::{db::AstDatabase, InFile};
fn visit_module(
db: &TestDB,
- crate_def_map: &CrateDefMap,
+ crate_def_map: &DefMap,
module_id: LocalModuleId,
cb: &mut dyn FnMut(DefWithBodyId),
) {
fn visit_scope(
db: &TestDB,
- crate_def_map: &CrateDefMap,
+ crate_def_map: &DefMap,
scope: &ItemScope,
cb: &mut dyn FnMut(DefWithBodyId),
) {