From 57a82fb05b46fd028c0b971dc6ce317db3682146 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 18 Jan 2021 20:18:05 +0100 Subject: Rename `CrateDefMap` to `DefMap` --- crates/hir_def/src/body.rs | 4 ++-- crates/hir_def/src/db.rs | 10 +++++----- crates/hir_def/src/find_path.rs | 4 ++-- crates/hir_def/src/nameres.rs | 12 ++++++------ crates/hir_def/src/nameres/collector.rs | 14 +++++++------- crates/hir_def/src/nameres/path_resolution.rs | 4 ++-- crates/hir_def/src/nameres/tests.rs | 2 +- crates/hir_def/src/resolver.rs | 12 ++++-------- crates/hir_def/src/visibility.rs | 6 +++--- 9 files changed, 32 insertions(+), 36 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 344f0b6c0..3b2dd0f6e 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -29,7 +29,7 @@ use crate::{ 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, @@ -45,7 +45,7 @@ pub(crate) struct CfgExpander { pub(crate) struct Expander { cfg_expander: CfgExpander, - crate_def_map: Arc, + crate_def_map: Arc, current_file_id: HirFileId, ast_id_map: Arc, module: ModuleId, diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs index 6ef9fe790..91c8d45cd 100644 --- a/crates/hir_def/src/db.rs +++ b/crates/hir_def/src/db.rs @@ -15,7 +15,7 @@ use crate::{ 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, @@ -50,10 +50,10 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast { #[salsa::invoke(crate_def_map_wait)] #[salsa::transparent] - fn crate_def_map(&self, krate: CrateId) -> Arc; + fn crate_def_map(&self, krate: CrateId) -> Arc; - #[salsa::invoke(CrateDefMap::crate_def_map_query)] - fn crate_def_map_query(&self, krate: CrateId) -> Arc; + #[salsa::invoke(DefMap::crate_def_map_query)] + fn crate_def_map_query(&self, krate: CrateId) -> Arc; #[salsa::invoke(StructData::struct_data_query)] fn struct_data(&self, id: StructId) -> Arc; @@ -112,7 +112,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast { fn import_map(&self, krate: CrateId) -> Arc; } -fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc { +fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc { let _p = profile::span("crate_def_map:wait"); db.crate_def_map_query(krate) } diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs index 4a212d291..422a6eeb4 100644 --- a/crates/hir_def/src/find_path.rs +++ b/crates/hir_def/src/find_path.rs @@ -4,7 +4,7 @@ use hir_expand::name::{known, AsName, Name}; use rustc_hash::FxHashSet; use test_utils::mark; -use crate::nameres::CrateDefMap; +use crate::nameres::DefMap; use crate::{ db::DefDatabase, item_scope::ItemInNs, @@ -47,7 +47,7 @@ impl ModPath { } } -fn check_self_super(def_map: &CrateDefMap, item: ItemInNs, from: ModuleId) -> Option { +fn check_self_super(def_map: &DefMap, item: ItemInNs, from: ModuleId) -> Option { 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())) diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 50acc3f54..769a557ad 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -74,7 +74,7 @@ use crate::{ /// 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, pub(crate) krate: CrateId, @@ -88,7 +88,7 @@ pub struct CrateDefMap { diagnostics: Vec, } -impl std::ops::Index for CrateDefMap { +impl std::ops::Index for DefMap { type Output = ModuleData; fn index(&self, id: LocalModuleId) -> &ModuleData { &self.modules[id] @@ -169,8 +169,8 @@ pub struct ModuleData { pub origin: ModuleOrigin, } -impl CrateDefMap { - pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc { +impl DefMap { + pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc { let _p = profile::span("crate_def_map_query").detail(|| { 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 mut modules: Arena = Arena::default(); let root = modules.alloc(ModuleData::default()); - CrateDefMap { + DefMap { krate, edition, extern_prelude: FxHashMap::default(), @@ -227,7 +227,7 @@ impl CrateDefMap { 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(); diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 0cd61698c..61da56340 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -31,7 +31,7 @@ use crate::{ }, 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, @@ -45,7 +45,7 @@ const GLOB_RECURSION_LIMIT: usize = 100; 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 @@ -210,7 +210,7 @@ struct DefData<'a> { /// Walks the tree of module recursively struct DefCollector<'a> { db: &'a dyn DefDatabase, - def_map: CrateDefMap, + def_map: DefMap, glob_imports: FxHashMap>, unresolved_imports: Vec, resolved_imports: Vec, @@ -859,7 +859,7 @@ impl DefCollector<'_> { .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 { @@ -1474,7 +1474,7 @@ mod tests { 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, @@ -1493,7 +1493,7 @@ mod tests { 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(); @@ -1501,7 +1501,7 @@ mod tests { let edition = db.crate_graph()[krate].edition; let mut modules: Arena = Arena::default(); let root = modules.alloc(ModuleData::default()); - CrateDefMap { + DefMap { krate, edition, extern_prelude: FxHashMap::default(), diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 88e10574e..096a7d0ac 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -19,7 +19,7 @@ use test_utils::mark; use crate::{ db::DefDatabase, item_scope::BUILTIN_SCOPE, - nameres::{BuiltinShadowMode, CrateDefMap}, + nameres::{BuiltinShadowMode, DefMap}, path::{ModPath, PathKind}, per_ns::PerNs, 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 { self.extern_prelude .get(name) diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs index c459fa66d..723481c36 100644 --- a/crates/hir_def/src/nameres/tests.rs +++ b/crates/hir_def/src/nameres/tests.rs @@ -13,7 +13,7 @@ use test_utils::mark; use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; -fn compute_crate_def_map(ra_fixture: &str) -> Arc { +fn compute_crate_def_map(ra_fixture: &str) -> Arc { let db = TestDB::with_files(ra_fixture); let krate = db.crate_graph().iter().next().unwrap(); db.crate_def_map(krate) diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index 85ddc2c47..e7e92c72d 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -16,7 +16,7 @@ use crate::{ expr::{ExprId, PatId}, generics::GenericParams, item_scope::{BuiltinShadowMode, BUILTIN_SCOPE}, - nameres::CrateDefMap, + nameres::DefMap, path::{ModPath, PathKind}, per_ns::PerNs, visibility::{RawVisibility, Visibility}, @@ -34,7 +34,7 @@ pub struct Resolver { // FIXME how to store these best #[derive(Debug, Clone)] struct ModuleItemMap { - crate_def_map: Arc, + crate_def_map: Arc, module_id: LocalModuleId, } @@ -425,7 +425,7 @@ impl Resolver { 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)), @@ -588,11 +588,7 @@ impl Resolver { self.push_scope(Scope::ImplDefScope(impl_def)) } - fn push_module_scope( - self, - crate_def_map: Arc, - module_id: LocalModuleId, - ) -> Resolver { + fn push_module_scope(self, crate_def_map: Arc, module_id: LocalModuleId) -> Resolver { self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) } diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs index f3bc9d680..3134fa43d 100644 --- a/crates/hir_def/src/visibility.rs +++ b/crates/hir_def/src/visibility.rs @@ -5,7 +5,7 @@ use syntax::ast; use crate::{ db::DefDatabase, - nameres::CrateDefMap, + nameres::DefMap, path::{ModPath, PathKind}, ModuleId, }; @@ -116,7 +116,7 @@ impl Visibility { 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 { @@ -135,7 +135,7 @@ impl Visibility { /// /// 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 { + pub(crate) fn max(self, other: Visibility, def_map: &DefMap) -> Option { match (self, other) { (Visibility::Module(_), Visibility::Public) | (Visibility::Public, Visibility::Module(_)) -- cgit v1.2.3