Rename CrateDefMap to DefMap

This commit is contained in:
Jonas Schievink 2021-01-18 20:18:05 +01:00
parent 08efb8a943
commit 57a82fb05b
10 changed files with 35 additions and 39 deletions

View file

@ -29,7 +29,7 @@ use crate::{
expr::{Expr, ExprId, Label, LabelId, Pat, PatId}, expr::{Expr, ExprId, Label, LabelId, Pat, PatId},
item_scope::BuiltinShadowMode, item_scope::BuiltinShadowMode,
item_scope::ItemScope, item_scope::ItemScope,
nameres::CrateDefMap, nameres::DefMap,
path::{ModPath, Path}, path::{ModPath, Path},
src::HasSource, src::HasSource,
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId,
@ -45,7 +45,7 @@ pub(crate) struct CfgExpander {
pub(crate) struct Expander { pub(crate) struct Expander {
cfg_expander: CfgExpander, cfg_expander: CfgExpander,
crate_def_map: Arc<CrateDefMap>, crate_def_map: Arc<DefMap>,
current_file_id: HirFileId, current_file_id: HirFileId,
ast_id_map: Arc<AstIdMap>, ast_id_map: Arc<AstIdMap>,
module: ModuleId, module: ModuleId,

View file

@ -15,7 +15,7 @@ use crate::{
import_map::ImportMap, import_map::ImportMap,
item_tree::ItemTree, item_tree::ItemTree,
lang_item::{LangItemTarget, LangItems}, lang_item::{LangItemTarget, LangItems},
nameres::CrateDefMap, nameres::DefMap,
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
GenericDefId, ImplId, ImplLoc, LocalEnumVariantId, LocalFieldId, StaticId, StaticLoc, StructId, GenericDefId, ImplId, ImplLoc, LocalEnumVariantId, LocalFieldId, StaticId, StaticLoc, StructId,
StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
@ -50,10 +50,10 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
#[salsa::invoke(crate_def_map_wait)] #[salsa::invoke(crate_def_map_wait)]
#[salsa::transparent] #[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)] #[salsa::invoke(DefMap::crate_def_map_query)]
fn crate_def_map_query(&self, krate: CrateId) -> Arc<CrateDefMap>; fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
#[salsa::invoke(StructData::struct_data_query)] #[salsa::invoke(StructData::struct_data_query)]
fn struct_data(&self, id: StructId) -> Arc<StructData>; fn struct_data(&self, id: StructId) -> Arc<StructData>;
@ -112,7 +112,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>; 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"); let _p = profile::span("crate_def_map:wait");
db.crate_def_map_query(krate) db.crate_def_map_query(krate)
} }

View file

@ -4,7 +4,7 @@ use hir_expand::name::{known, AsName, Name};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use test_utils::mark; use test_utils::mark;
use crate::nameres::CrateDefMap; use crate::nameres::DefMap;
use crate::{ use crate::{
db::DefDatabase, db::DefDatabase,
item_scope::ItemInNs, item_scope::ItemInNs,
@ -47,7 +47,7 @@ impl ModPath {
} }
} }
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 item == ItemInNs::Types(from.into()) {
// - if the item is the module we're in, use `self` // - if the item is the module we're in, use `self`
Some(ModPath::from_segments(PathKind::Super(0), Vec::new())) Some(ModPath::from_segments(PathKind::Super(0), Vec::new()))

View file

@ -74,7 +74,7 @@ use crate::{
/// Contains all top-level defs from a macro-expanded crate /// Contains all top-level defs from a macro-expanded crate
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct CrateDefMap { pub struct DefMap {
pub root: LocalModuleId, pub root: LocalModuleId,
pub modules: Arena<ModuleData>, pub modules: Arena<ModuleData>,
pub(crate) krate: CrateId, pub(crate) krate: CrateId,
@ -88,7 +88,7 @@ pub struct CrateDefMap {
diagnostics: Vec<DefDiagnostic>, diagnostics: Vec<DefDiagnostic>,
} }
impl std::ops::Index<LocalModuleId> for CrateDefMap { impl std::ops::Index<LocalModuleId> for DefMap {
type Output = ModuleData; type Output = ModuleData;
fn index(&self, id: LocalModuleId) -> &ModuleData { fn index(&self, id: LocalModuleId) -> &ModuleData {
&self.modules[id] &self.modules[id]
@ -169,8 +169,8 @@ pub struct ModuleData {
pub origin: ModuleOrigin, pub origin: ModuleOrigin,
} }
impl CrateDefMap { impl DefMap {
pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
let _p = profile::span("crate_def_map_query").detail(|| { let _p = profile::span("crate_def_map_query").detail(|| {
db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string() db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string()
}); });
@ -178,7 +178,7 @@ impl CrateDefMap {
let edition = db.crate_graph()[krate].edition; let edition = db.crate_graph()[krate].edition;
let mut modules: Arena<ModuleData> = Arena::default(); let mut modules: Arena<ModuleData> = Arena::default();
let root = modules.alloc(ModuleData::default()); let root = modules.alloc(ModuleData::default());
CrateDefMap { DefMap {
krate, krate,
edition, edition,
extern_prelude: FxHashMap::default(), extern_prelude: FxHashMap::default(),
@ -227,7 +227,7 @@ impl CrateDefMap {
go(&mut buf, self, "crate", self.root); go(&mut buf, self, "crate", self.root);
return buf; 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); format_to!(buf, "{}\n", path);
let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect(); let mut entries: Vec<_> = map.modules[module].scope.resolutions().collect();

View file

@ -31,7 +31,7 @@ use crate::{
}, },
nameres::{ nameres::{
diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode, BuiltinShadowMode, DefMap, ModuleData, ModuleOrigin, ResolveMode,
}, },
path::{ImportAlias, ModPath, PathKind}, path::{ImportAlias, ModPath, PathKind},
per_ns::PerNs, per_ns::PerNs,
@ -45,7 +45,7 @@ const GLOB_RECURSION_LIMIT: usize = 100;
const EXPANSION_DEPTH_LIMIT: usize = 128; const EXPANSION_DEPTH_LIMIT: usize = 128;
const FIXED_POINT_LIMIT: usize = 8192; 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(); let crate_graph = db.crate_graph();
// populate external prelude // populate external prelude
@ -210,7 +210,7 @@ struct DefData<'a> {
/// Walks the tree of module recursively /// Walks the tree of module recursively
struct DefCollector<'a> { struct DefCollector<'a> {
db: &'a dyn DefDatabase, db: &'a dyn DefDatabase,
def_map: CrateDefMap, def_map: DefMap,
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>, glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
unresolved_imports: Vec<ImportDirective>, unresolved_imports: Vec<ImportDirective>,
resolved_imports: Vec<ImportDirective>, resolved_imports: Vec<ImportDirective>,
@ -859,7 +859,7 @@ impl DefCollector<'_> {
.collect(item_tree.top_level_items()); .collect(item_tree.top_level_items());
} }
fn finish(mut self) -> CrateDefMap { fn finish(mut self) -> DefMap {
// Emit diagnostics for all remaining unexpanded macros. // Emit diagnostics for all remaining unexpanded macros.
for directive in &self.unexpanded_macros { for directive in &self.unexpanded_macros {
@ -1474,7 +1474,7 @@ mod tests {
use super::*; 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 { let mut collector = DefCollector {
db, db,
def_map, def_map,
@ -1493,7 +1493,7 @@ mod tests {
collector.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 (db, _file_id) = TestDB::with_single_file(&code);
let krate = db.test_crate(); let krate = db.test_crate();
@ -1501,7 +1501,7 @@ mod tests {
let edition = db.crate_graph()[krate].edition; let edition = db.crate_graph()[krate].edition;
let mut modules: Arena<ModuleData> = Arena::default(); let mut modules: Arena<ModuleData> = Arena::default();
let root = modules.alloc(ModuleData::default()); let root = modules.alloc(ModuleData::default());
CrateDefMap { DefMap {
krate, krate,
edition, edition,
extern_prelude: FxHashMap::default(), extern_prelude: FxHashMap::default(),

View file

@ -19,7 +19,7 @@ use test_utils::mark;
use crate::{ use crate::{
db::DefDatabase, db::DefDatabase,
item_scope::BUILTIN_SCOPE, item_scope::BUILTIN_SCOPE,
nameres::{BuiltinShadowMode, CrateDefMap}, nameres::{BuiltinShadowMode, DefMap},
path::{ModPath, PathKind}, path::{ModPath, PathKind},
per_ns::PerNs, per_ns::PerNs,
visibility::{RawVisibility, Visibility}, visibility::{RawVisibility, Visibility},
@ -61,7 +61,7 @@ impl ResolvePathResult {
} }
} }
impl CrateDefMap { impl DefMap {
pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs {
self.extern_prelude self.extern_prelude
.get(name) .get(name)

View file

@ -13,7 +13,7 @@ use test_utils::mark;
use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; 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 db = TestDB::with_files(ra_fixture);
let krate = db.crate_graph().iter().next().unwrap(); let krate = db.crate_graph().iter().next().unwrap();
db.crate_def_map(krate) db.crate_def_map(krate)

View file

@ -16,7 +16,7 @@ use crate::{
expr::{ExprId, PatId}, expr::{ExprId, PatId},
generics::GenericParams, generics::GenericParams,
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE}, item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
nameres::CrateDefMap, nameres::DefMap,
path::{ModPath, PathKind}, path::{ModPath, PathKind},
per_ns::PerNs, per_ns::PerNs,
visibility::{RawVisibility, Visibility}, visibility::{RawVisibility, Visibility},
@ -34,7 +34,7 @@ pub struct Resolver {
// FIXME how to store these best // FIXME how to store these best
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct ModuleItemMap { struct ModuleItemMap {
crate_def_map: Arc<CrateDefMap>, crate_def_map: Arc<DefMap>,
module_id: LocalModuleId, module_id: LocalModuleId,
} }
@ -425,7 +425,7 @@ impl Resolver {
traits traits
} }
fn module_scope(&self) -> Option<(&CrateDefMap, LocalModuleId)> { fn module_scope(&self) -> Option<(&DefMap, LocalModuleId)> {
self.scopes.iter().rev().find_map(|scope| match scope { self.scopes.iter().rev().find_map(|scope| match scope {
Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
@ -588,11 +588,7 @@ impl Resolver {
self.push_scope(Scope::ImplDefScope(impl_def)) self.push_scope(Scope::ImplDefScope(impl_def))
} }
fn push_module_scope( fn push_module_scope(self, crate_def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
self,
crate_def_map: Arc<CrateDefMap>,
module_id: LocalModuleId,
) -> Resolver {
self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
} }

View file

@ -5,7 +5,7 @@ use syntax::ast;
use crate::{ use crate::{
db::DefDatabase, db::DefDatabase,
nameres::CrateDefMap, nameres::DefMap,
path::{ModPath, PathKind}, path::{ModPath, PathKind},
ModuleId, ModuleId,
}; };
@ -116,7 +116,7 @@ impl Visibility {
pub(crate) fn is_visible_from_def_map( pub(crate) fn is_visible_from_def_map(
self, self,
def_map: &CrateDefMap, def_map: &DefMap,
from_module: crate::LocalModuleId, from_module: crate::LocalModuleId,
) -> bool { ) -> bool {
let to_module = match self { let to_module = match self {
@ -135,7 +135,7 @@ impl Visibility {
/// ///
/// If there is no subset relation between `self` and `other`, returns `None` (ie. they're only /// If there is no subset relation between `self` and `other`, returns `None` (ie. they're only
/// visible in unrelated modules). /// 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) { match (self, other) {
(Visibility::Module(_), Visibility::Public) (Visibility::Module(_), Visibility::Public)
| (Visibility::Public, Visibility::Module(_)) | (Visibility::Public, Visibility::Module(_))

View file

@ -18,7 +18,7 @@ use hir_def::{
db::DefDatabase, db::DefDatabase,
item_scope::ItemScope, item_scope::ItemScope,
keys, keys,
nameres::CrateDefMap, nameres::DefMap,
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
}; };
use hir_expand::{db::AstDatabase, InFile}; use hir_expand::{db::AstDatabase, InFile};
@ -221,7 +221,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
fn visit_module( fn visit_module(
db: &TestDB, db: &TestDB,
crate_def_map: &CrateDefMap, crate_def_map: &DefMap,
module_id: LocalModuleId, module_id: LocalModuleId,
cb: &mut dyn FnMut(DefWithBodyId), cb: &mut dyn FnMut(DefWithBodyId),
) { ) {
@ -249,7 +249,7 @@ fn visit_module(
fn visit_scope( fn visit_scope(
db: &TestDB, db: &TestDB,
crate_def_map: &CrateDefMap, crate_def_map: &DefMap,
scope: &ItemScope, scope: &ItemScope,
cb: &mut dyn FnMut(DefWithBodyId), cb: &mut dyn FnMut(DefWithBodyId),
) { ) {