From ee3cf6172b29a1dc0973800b5a4f97afa5eefd90 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Mar 2019 18:57:53 +0300 Subject: rename ModuleId -> CrateModuleId --- crates/ra_hir/src/code_model_api.rs | 4 ++-- crates/ra_hir/src/code_model_impl/module.rs | 4 ++-- crates/ra_hir/src/ids.rs | 1 + crates/ra_hir/src/nameres.rs | 30 ++++++++++++++--------------- crates/ra_hir/src/nameres/collector.rs | 22 ++++++++++----------- crates/ra_hir/src/nameres/tests.rs | 2 +- crates/ra_hir/src/resolve.rs | 8 ++++---- crates/ra_hir/src/ty/method_resolution.rs | 8 ++++---- 8 files changed, 40 insertions(+), 39 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index c3124480b..b00481cd5 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -8,7 +8,7 @@ use crate::{ Name, ScopesWithSourceMap, Ty, HirFileId, HirDatabase, PersistentHirDatabase, type_ref::TypeRef, - nameres::{ModuleScope, Namespace, ImportId, ModuleId}, + nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, expr::{Body, BodySourceMap}, ty::InferenceResult, adt::{EnumVariantId, StructFieldId, VariantDef}, @@ -64,7 +64,7 @@ impl Crate { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Module { pub(crate) krate: Crate, - pub(crate) module_id: ModuleId, + pub(crate) module_id: CrateModuleId, } /// The defs which can be visible in the module. diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 9f4448475..f7d15c55e 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -3,7 +3,7 @@ use ra_syntax::{ast, SyntaxNode, TreeArc, AstNode}; use crate::{ Module, ModuleSource, Problem, Name, - nameres::{ModuleId, ImportId}, + nameres::{CrateModuleId, ImportId}, HirDatabase, PersistentHirDatabase, HirFileId, SourceItemId, }; @@ -31,7 +31,7 @@ impl ModuleSource { } impl Module { - fn with_module_id(&self, module_id: ModuleId) -> Module { + fn with_module_id(&self, module_id: CrateModuleId) -> Module { Module { module_id, krate: self.krate } } diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 2bd617436..a144e4a1e 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -373,6 +373,7 @@ impl SourceFileItems { impl std::ops::Index for SourceFileItems { type Output = SyntaxNodePtr; fn index(&self, idx: SourceFileItemId) -> &SyntaxNodePtr { + eprintln!("invalid SourceFileItemId({:?}) for file({:?})", idx, self.file_id); &self.arena[idx] } } diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 4ff81af7f..eabaa5691 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -74,28 +74,28 @@ pub struct CrateDefMap { /// a dependency (`std` or `core`). prelude: Option, extern_prelude: FxHashMap, - root: ModuleId, - modules: Arena, + root: CrateModuleId, + modules: Arena, public_macros: FxHashMap, problems: CrateDefMapProblems, } -impl std::ops::Index for CrateDefMap { +impl std::ops::Index for CrateDefMap { type Output = ModuleData; - fn index(&self, id: ModuleId) -> &ModuleData { + fn index(&self, id: CrateModuleId) -> &ModuleData { &self.modules[id] } } /// An ID of a module, **local** to a specific crate #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub(crate) struct ModuleId(RawId); -impl_arena_id!(ModuleId); +struct CrateModuleId(RawId); +impl_arena_id!(CrateModuleId); #[derive(Default, Debug, PartialEq, Eq)] pub(crate) struct ModuleData { - pub(crate) parent: Option, - pub(crate) children: FxHashMap, + pub(crate) parent: Option, + pub(crate) children: FxHashMap, pub(crate) scope: ModuleScope, /// None for root pub(crate) declaration: Option, @@ -183,7 +183,7 @@ impl CrateDefMap { let start = std::time::Instant::now(); let def_map = { let edition = krate.edition(db); - let mut modules: Arena = Arena::default(); + let mut modules: Arena = Arena::default(); let root = modules.alloc(ModuleData::default()); CrateDefMap { krate, @@ -201,7 +201,7 @@ impl CrateDefMap { Arc::new(def_map) } - pub(crate) fn root(&self) -> ModuleId { + pub(crate) fn root(&self) -> CrateModuleId { self.root } @@ -209,7 +209,7 @@ impl CrateDefMap { &self.problems } - pub(crate) fn mk_module(&self, module_id: ModuleId) -> Module { + pub(crate) fn mk_module(&self, module_id: CrateModuleId) -> Module { Module { krate: self.krate, module_id } } @@ -225,7 +225,7 @@ impl CrateDefMap { &self, file_id: HirFileId, decl_id: Option, - ) -> Option { + ) -> Option { let decl_id = decl_id.map(|it| it.with_file_id(file_id)); let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| { if decl_id.is_some() { @@ -240,7 +240,7 @@ impl CrateDefMap { pub(crate) fn resolve_path( &self, db: &impl PersistentHirDatabase, - original_module: ModuleId, + original_module: CrateModuleId, path: &Path, ) -> (PerNs, Option) { let res = self.resolve_path_fp(db, ResolveMode::Other, original_module, path); @@ -253,7 +253,7 @@ impl CrateDefMap { &self, db: &impl PersistentHirDatabase, mode: ResolveMode, - original_module: ModuleId, + original_module: CrateModuleId, path: &Path, ) -> ResolvePathResult { let mut segments = path.segments.iter().enumerate(); @@ -394,7 +394,7 @@ impl CrateDefMap { pub(crate) fn resolve_name_in_module( &self, db: &impl PersistentHirDatabase, - module: ModuleId, + module: CrateModuleId, name: &Name, ) -> PerNs { // Resolve in: diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index e7afc34c9..f2336c271 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -12,7 +12,7 @@ use crate::{ ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId}, }; -use super::{CrateDefMap, ModuleId, ModuleData}; +use super::{CrateDefMap, CrateModuleId, ModuleData}; pub(super) fn collect_defs( db: &impl PersistentHirDatabase, @@ -49,9 +49,9 @@ pub(super) fn collect_defs( struct DefCollector { db: DB, def_map: CrateDefMap, - glob_imports: FxHashMap>, - unresolved_imports: Vec<(ModuleId, raw::ImportId, raw::ImportData)>, - unexpanded_macros: Vec<(ModuleId, MacroCallId, Path, tt::Subtree)>, + glob_imports: FxHashMap>, + unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>, + unexpanded_macros: Vec<(CrateModuleId, MacroCallId, Path, tt::Subtree)>, global_macro_scope: FxHashMap, } @@ -124,7 +124,7 @@ where fn resolve_import( &mut self, - module_id: ModuleId, + module_id: CrateModuleId, import: &raw::ImportData, ) -> (PerNs, ReachedFixedPoint) { log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition); @@ -147,7 +147,7 @@ where fn record_resolved_import( &mut self, - module_id: ModuleId, + module_id: CrateModuleId, def: PerNs, import_id: raw::ImportId, import: &raw::ImportData, @@ -234,7 +234,7 @@ where fn update( &mut self, - module_id: ModuleId, + module_id: CrateModuleId, import: Option, resolutions: &[(Name, Resolution)], ) { @@ -243,7 +243,7 @@ where fn update_recursive( &mut self, - module_id: ModuleId, + module_id: CrateModuleId, import: Option, resolutions: &[(Name, Resolution)], depth: usize, @@ -327,7 +327,7 @@ where fn collect_macro_expansion( &mut self, - module_id: ModuleId, + module_id: CrateModuleId, macro_call_id: MacroCallId, expansion: tt::Subtree, ) { @@ -353,7 +353,7 @@ where /// Walks a single module, populating defs, imports and macros struct ModCollector<'a, D> { def_collector: D, - module_id: ModuleId, + module_id: CrateModuleId, file_id: HirFileId, raw_items: &'a raw::RawItems, } @@ -426,7 +426,7 @@ where name: Name, declaration: SourceItemId, definition: Option, - ) -> ModuleId { + ) -> CrateModuleId { let modules = &mut self.def_collector.def_map.modules; let res = modules.alloc(ModuleData::default()); modules[res].parent = Some(self.module_id); diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index f73f9d8a6..ac9b88520 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -27,7 +27,7 @@ fn render_crate_def_map(map: &CrateDefMap) -> String { go(&mut buf, map, "\ncrate", map.root); return buf; - fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: ModuleId) { + fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) { *buf += path; *buf += "\n"; for (name, res) in map.modules[module].scope.items.iter() { diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index e85447eeb..59af4ec60 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -7,7 +7,7 @@ use crate::{ ModuleDef, db::HirDatabase, name::{Name, KnownName}, - nameres::{PerNs, CrateDefMap, ModuleId}, + nameres::{PerNs, CrateDefMap, CrateModuleId}, generics::GenericParams, expr::{scope::{ExprScopes, ScopeId}, PatId, Body}, impl_block::ImplBlock, @@ -23,7 +23,7 @@ pub struct Resolver { #[derive(Debug, Clone)] pub(crate) struct ModuleItemMap { crate_def_map: Arc, - module_id: ModuleId, + module_id: CrateModuleId, } #[derive(Debug, Clone)] @@ -175,7 +175,7 @@ impl Resolver { names } - fn module(&self) -> Option<(&CrateDefMap, ModuleId)> { + fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> { self.scopes.iter().rev().find_map(|scope| match scope { Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), @@ -209,7 +209,7 @@ impl Resolver { pub(crate) fn push_module_scope( self, crate_def_map: Arc, - module_id: ModuleId, + module_id: CrateModuleId, ) -> Resolver { self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) } diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 1adf9eef9..804824868 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -11,7 +11,7 @@ use crate::{ ids::TraitId, impl_block::{ImplId, ImplBlock, ImplItem}, ty::{AdtDef, Ty}, - nameres::ModuleId, + nameres::CrateModuleId, }; @@ -35,10 +35,10 @@ impl TyFingerprint { #[derive(Debug, PartialEq, Eq)] pub struct CrateImplBlocks { - /// To make sense of the ModuleIds, we need the source root. + /// To make sense of the CrateModuleIds, we need the source root. krate: Crate, - impls: FxHashMap>, - impls_by_trait: FxHashMap>, + impls: FxHashMap>, + impls_by_trait: FxHashMap>, } impl CrateImplBlocks { -- cgit v1.2.3