aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model_api.rs4
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs4
-rw-r--r--crates/ra_hir/src/ids.rs1
-rw-r--r--crates/ra_hir/src/nameres.rs30
-rw-r--r--crates/ra_hir/src/nameres/collector.rs22
-rw-r--r--crates/ra_hir/src/nameres/tests.rs2
-rw-r--r--crates/ra_hir/src/resolve.rs8
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs8
8 files changed, 40 insertions, 39 deletions
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::{
8 Name, ScopesWithSourceMap, Ty, HirFileId, 8 Name, ScopesWithSourceMap, Ty, HirFileId,
9 HirDatabase, PersistentHirDatabase, 9 HirDatabase, PersistentHirDatabase,
10 type_ref::TypeRef, 10 type_ref::TypeRef,
11 nameres::{ModuleScope, Namespace, ImportId, ModuleId}, 11 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
12 expr::{Body, BodySourceMap}, 12 expr::{Body, BodySourceMap},
13 ty::InferenceResult, 13 ty::InferenceResult,
14 adt::{EnumVariantId, StructFieldId, VariantDef}, 14 adt::{EnumVariantId, StructFieldId, VariantDef},
@@ -64,7 +64,7 @@ impl Crate {
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
65pub struct Module { 65pub struct Module {
66 pub(crate) krate: Crate, 66 pub(crate) krate: Crate,
67 pub(crate) module_id: ModuleId, 67 pub(crate) module_id: CrateModuleId,
68} 68}
69 69
70/// The defs which can be visible in the module. 70/// 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};
3 3
4use crate::{ 4use crate::{
5 Module, ModuleSource, Problem, Name, 5 Module, ModuleSource, Problem, Name,
6 nameres::{ModuleId, ImportId}, 6 nameres::{CrateModuleId, ImportId},
7 HirDatabase, PersistentHirDatabase, 7 HirDatabase, PersistentHirDatabase,
8 HirFileId, SourceItemId, 8 HirFileId, SourceItemId,
9}; 9};
@@ -31,7 +31,7 @@ impl ModuleSource {
31} 31}
32 32
33impl Module { 33impl Module {
34 fn with_module_id(&self, module_id: ModuleId) -> Module { 34 fn with_module_id(&self, module_id: CrateModuleId) -> Module {
35 Module { module_id, krate: self.krate } 35 Module { module_id, krate: self.krate }
36 } 36 }
37 37
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 {
373impl std::ops::Index<SourceFileItemId> for SourceFileItems { 373impl std::ops::Index<SourceFileItemId> for SourceFileItems {
374 type Output = SyntaxNodePtr; 374 type Output = SyntaxNodePtr;
375 fn index(&self, idx: SourceFileItemId) -> &SyntaxNodePtr { 375 fn index(&self, idx: SourceFileItemId) -> &SyntaxNodePtr {
376 eprintln!("invalid SourceFileItemId({:?}) for file({:?})", idx, self.file_id);
376 &self.arena[idx] 377 &self.arena[idx]
377 } 378 }
378} 379}
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 {
74 /// a dependency (`std` or `core`). 74 /// a dependency (`std` or `core`).
75 prelude: Option<Module>, 75 prelude: Option<Module>,
76 extern_prelude: FxHashMap<Name, ModuleDef>, 76 extern_prelude: FxHashMap<Name, ModuleDef>,
77 root: ModuleId, 77 root: CrateModuleId,
78 modules: Arena<ModuleId, ModuleData>, 78 modules: Arena<CrateModuleId, ModuleData>,
79 public_macros: FxHashMap<Name, mbe::MacroRules>, 79 public_macros: FxHashMap<Name, mbe::MacroRules>,
80 problems: CrateDefMapProblems, 80 problems: CrateDefMapProblems,
81} 81}
82 82
83impl std::ops::Index<ModuleId> for CrateDefMap { 83impl std::ops::Index<CrateModuleId> for CrateDefMap {
84 type Output = ModuleData; 84 type Output = ModuleData;
85 fn index(&self, id: ModuleId) -> &ModuleData { 85 fn index(&self, id: CrateModuleId) -> &ModuleData {
86 &self.modules[id] 86 &self.modules[id]
87 } 87 }
88} 88}
89 89
90/// An ID of a module, **local** to a specific crate 90/// An ID of a module, **local** to a specific crate
91#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 91#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
92pub(crate) struct ModuleId(RawId); 92struct CrateModuleId(RawId);
93impl_arena_id!(ModuleId); 93impl_arena_id!(CrateModuleId);
94 94
95#[derive(Default, Debug, PartialEq, Eq)] 95#[derive(Default, Debug, PartialEq, Eq)]
96pub(crate) struct ModuleData { 96pub(crate) struct ModuleData {
97 pub(crate) parent: Option<ModuleId>, 97 pub(crate) parent: Option<CrateModuleId>,
98 pub(crate) children: FxHashMap<Name, ModuleId>, 98 pub(crate) children: FxHashMap<Name, CrateModuleId>,
99 pub(crate) scope: ModuleScope, 99 pub(crate) scope: ModuleScope,
100 /// None for root 100 /// None for root
101 pub(crate) declaration: Option<SourceItemId>, 101 pub(crate) declaration: Option<SourceItemId>,
@@ -183,7 +183,7 @@ impl CrateDefMap {
183 let start = std::time::Instant::now(); 183 let start = std::time::Instant::now();
184 let def_map = { 184 let def_map = {
185 let edition = krate.edition(db); 185 let edition = krate.edition(db);
186 let mut modules: Arena<ModuleId, ModuleData> = Arena::default(); 186 let mut modules: Arena<CrateModuleId, ModuleData> = Arena::default();
187 let root = modules.alloc(ModuleData::default()); 187 let root = modules.alloc(ModuleData::default());
188 CrateDefMap { 188 CrateDefMap {
189 krate, 189 krate,
@@ -201,7 +201,7 @@ impl CrateDefMap {
201 Arc::new(def_map) 201 Arc::new(def_map)
202 } 202 }
203 203
204 pub(crate) fn root(&self) -> ModuleId { 204 pub(crate) fn root(&self) -> CrateModuleId {
205 self.root 205 self.root
206 } 206 }
207 207
@@ -209,7 +209,7 @@ impl CrateDefMap {
209 &self.problems 209 &self.problems
210 } 210 }
211 211
212 pub(crate) fn mk_module(&self, module_id: ModuleId) -> Module { 212 pub(crate) fn mk_module(&self, module_id: CrateModuleId) -> Module {
213 Module { krate: self.krate, module_id } 213 Module { krate: self.krate, module_id }
214 } 214 }
215 215
@@ -225,7 +225,7 @@ impl CrateDefMap {
225 &self, 225 &self,
226 file_id: HirFileId, 226 file_id: HirFileId,
227 decl_id: Option<SourceFileItemId>, 227 decl_id: Option<SourceFileItemId>,
228 ) -> Option<ModuleId> { 228 ) -> Option<CrateModuleId> {
229 let decl_id = decl_id.map(|it| it.with_file_id(file_id)); 229 let decl_id = decl_id.map(|it| it.with_file_id(file_id));
230 let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| { 230 let (module_id, _module_data) = self.modules.iter().find(|(_module_id, module_data)| {
231 if decl_id.is_some() { 231 if decl_id.is_some() {
@@ -240,7 +240,7 @@ impl CrateDefMap {
240 pub(crate) fn resolve_path( 240 pub(crate) fn resolve_path(
241 &self, 241 &self,
242 db: &impl PersistentHirDatabase, 242 db: &impl PersistentHirDatabase,
243 original_module: ModuleId, 243 original_module: CrateModuleId,
244 path: &Path, 244 path: &Path,
245 ) -> (PerNs<ModuleDef>, Option<usize>) { 245 ) -> (PerNs<ModuleDef>, Option<usize>) {
246 let res = self.resolve_path_fp(db, ResolveMode::Other, original_module, path); 246 let res = self.resolve_path_fp(db, ResolveMode::Other, original_module, path);
@@ -253,7 +253,7 @@ impl CrateDefMap {
253 &self, 253 &self,
254 db: &impl PersistentHirDatabase, 254 db: &impl PersistentHirDatabase,
255 mode: ResolveMode, 255 mode: ResolveMode,
256 original_module: ModuleId, 256 original_module: CrateModuleId,
257 path: &Path, 257 path: &Path,
258 ) -> ResolvePathResult { 258 ) -> ResolvePathResult {
259 let mut segments = path.segments.iter().enumerate(); 259 let mut segments = path.segments.iter().enumerate();
@@ -394,7 +394,7 @@ impl CrateDefMap {
394 pub(crate) fn resolve_name_in_module( 394 pub(crate) fn resolve_name_in_module(
395 &self, 395 &self,
396 db: &impl PersistentHirDatabase, 396 db: &impl PersistentHirDatabase,
397 module: ModuleId, 397 module: CrateModuleId,
398 name: &Name, 398 name: &Name,
399 ) -> PerNs<ModuleDef> { 399 ) -> PerNs<ModuleDef> {
400 // Resolve in: 400 // 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::{
12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId}, 12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId},
13}; 13};
14 14
15use super::{CrateDefMap, ModuleId, ModuleData}; 15use super::{CrateDefMap, CrateModuleId, ModuleData};
16 16
17pub(super) fn collect_defs( 17pub(super) fn collect_defs(
18 db: &impl PersistentHirDatabase, 18 db: &impl PersistentHirDatabase,
@@ -49,9 +49,9 @@ pub(super) fn collect_defs(
49struct DefCollector<DB> { 49struct DefCollector<DB> {
50 db: DB, 50 db: DB,
51 def_map: CrateDefMap, 51 def_map: CrateDefMap,
52 glob_imports: FxHashMap<ModuleId, Vec<(ModuleId, raw::ImportId)>>, 52 glob_imports: FxHashMap<CrateModuleId, Vec<(CrateModuleId, raw::ImportId)>>,
53 unresolved_imports: Vec<(ModuleId, raw::ImportId, raw::ImportData)>, 53 unresolved_imports: Vec<(CrateModuleId, raw::ImportId, raw::ImportData)>,
54 unexpanded_macros: Vec<(ModuleId, MacroCallId, Path, tt::Subtree)>, 54 unexpanded_macros: Vec<(CrateModuleId, MacroCallId, Path, tt::Subtree)>,
55 global_macro_scope: FxHashMap<Name, mbe::MacroRules>, 55 global_macro_scope: FxHashMap<Name, mbe::MacroRules>,
56} 56}
57 57
@@ -124,7 +124,7 @@ where
124 124
125 fn resolve_import( 125 fn resolve_import(
126 &mut self, 126 &mut self,
127 module_id: ModuleId, 127 module_id: CrateModuleId,
128 import: &raw::ImportData, 128 import: &raw::ImportData,
129 ) -> (PerNs<ModuleDef>, ReachedFixedPoint) { 129 ) -> (PerNs<ModuleDef>, ReachedFixedPoint) {
130 log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition); 130 log::debug!("resolving import: {:?} ({:?})", import, self.def_map.edition);
@@ -147,7 +147,7 @@ where
147 147
148 fn record_resolved_import( 148 fn record_resolved_import(
149 &mut self, 149 &mut self,
150 module_id: ModuleId, 150 module_id: CrateModuleId,
151 def: PerNs<ModuleDef>, 151 def: PerNs<ModuleDef>,
152 import_id: raw::ImportId, 152 import_id: raw::ImportId,
153 import: &raw::ImportData, 153 import: &raw::ImportData,
@@ -234,7 +234,7 @@ where
234 234
235 fn update( 235 fn update(
236 &mut self, 236 &mut self,
237 module_id: ModuleId, 237 module_id: CrateModuleId,
238 import: Option<raw::ImportId>, 238 import: Option<raw::ImportId>,
239 resolutions: &[(Name, Resolution)], 239 resolutions: &[(Name, Resolution)],
240 ) { 240 ) {
@@ -243,7 +243,7 @@ where
243 243
244 fn update_recursive( 244 fn update_recursive(
245 &mut self, 245 &mut self,
246 module_id: ModuleId, 246 module_id: CrateModuleId,
247 import: Option<raw::ImportId>, 247 import: Option<raw::ImportId>,
248 resolutions: &[(Name, Resolution)], 248 resolutions: &[(Name, Resolution)],
249 depth: usize, 249 depth: usize,
@@ -327,7 +327,7 @@ where
327 327
328 fn collect_macro_expansion( 328 fn collect_macro_expansion(
329 &mut self, 329 &mut self,
330 module_id: ModuleId, 330 module_id: CrateModuleId,
331 macro_call_id: MacroCallId, 331 macro_call_id: MacroCallId,
332 expansion: tt::Subtree, 332 expansion: tt::Subtree,
333 ) { 333 ) {
@@ -353,7 +353,7 @@ where
353/// Walks a single module, populating defs, imports and macros 353/// Walks a single module, populating defs, imports and macros
354struct ModCollector<'a, D> { 354struct ModCollector<'a, D> {
355 def_collector: D, 355 def_collector: D,
356 module_id: ModuleId, 356 module_id: CrateModuleId,
357 file_id: HirFileId, 357 file_id: HirFileId,
358 raw_items: &'a raw::RawItems, 358 raw_items: &'a raw::RawItems,
359} 359}
@@ -426,7 +426,7 @@ where
426 name: Name, 426 name: Name,
427 declaration: SourceItemId, 427 declaration: SourceItemId,
428 definition: Option<FileId>, 428 definition: Option<FileId>,
429 ) -> ModuleId { 429 ) -> CrateModuleId {
430 let modules = &mut self.def_collector.def_map.modules; 430 let modules = &mut self.def_collector.def_map.modules;
431 let res = modules.alloc(ModuleData::default()); 431 let res = modules.alloc(ModuleData::default());
432 modules[res].parent = Some(self.module_id); 432 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 {
27 go(&mut buf, map, "\ncrate", map.root); 27 go(&mut buf, map, "\ncrate", map.root);
28 return buf; 28 return buf;
29 29
30 fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: ModuleId) { 30 fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) {
31 *buf += path; 31 *buf += path;
32 *buf += "\n"; 32 *buf += "\n";
33 for (name, res) in map.modules[module].scope.items.iter() { 33 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::{
7 ModuleDef, 7 ModuleDef,
8 db::HirDatabase, 8 db::HirDatabase,
9 name::{Name, KnownName}, 9 name::{Name, KnownName},
10 nameres::{PerNs, CrateDefMap, ModuleId}, 10 nameres::{PerNs, CrateDefMap, CrateModuleId},
11 generics::GenericParams, 11 generics::GenericParams,
12 expr::{scope::{ExprScopes, ScopeId}, PatId, Body}, 12 expr::{scope::{ExprScopes, ScopeId}, PatId, Body},
13 impl_block::ImplBlock, 13 impl_block::ImplBlock,
@@ -23,7 +23,7 @@ pub struct Resolver {
23#[derive(Debug, Clone)] 23#[derive(Debug, Clone)]
24pub(crate) struct ModuleItemMap { 24pub(crate) struct ModuleItemMap {
25 crate_def_map: Arc<CrateDefMap>, 25 crate_def_map: Arc<CrateDefMap>,
26 module_id: ModuleId, 26 module_id: CrateModuleId,
27} 27}
28 28
29#[derive(Debug, Clone)] 29#[derive(Debug, Clone)]
@@ -175,7 +175,7 @@ impl Resolver {
175 names 175 names
176 } 176 }
177 177
178 fn module(&self) -> Option<(&CrateDefMap, ModuleId)> { 178 fn module(&self) -> Option<(&CrateDefMap, CrateModuleId)> {
179 self.scopes.iter().rev().find_map(|scope| match scope { 179 self.scopes.iter().rev().find_map(|scope| match scope {
180 Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)), 180 Scope::ModuleScope(m) => Some((&*m.crate_def_map, m.module_id)),
181 181
@@ -209,7 +209,7 @@ impl Resolver {
209 pub(crate) fn push_module_scope( 209 pub(crate) fn push_module_scope(
210 self, 210 self,
211 crate_def_map: Arc<CrateDefMap>, 211 crate_def_map: Arc<CrateDefMap>,
212 module_id: ModuleId, 212 module_id: CrateModuleId,
213 ) -> Resolver { 213 ) -> Resolver {
214 self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id })) 214 self.push_scope(Scope::ModuleScope(ModuleItemMap { crate_def_map, module_id }))
215 } 215 }
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::{
11 ids::TraitId, 11 ids::TraitId,
12 impl_block::{ImplId, ImplBlock, ImplItem}, 12 impl_block::{ImplId, ImplBlock, ImplItem},
13 ty::{AdtDef, Ty}, 13 ty::{AdtDef, Ty},
14 nameres::ModuleId, 14 nameres::CrateModuleId,
15 15
16}; 16};
17 17
@@ -35,10 +35,10 @@ impl TyFingerprint {
35 35
36#[derive(Debug, PartialEq, Eq)] 36#[derive(Debug, PartialEq, Eq)]
37pub struct CrateImplBlocks { 37pub struct CrateImplBlocks {
38 /// To make sense of the ModuleIds, we need the source root. 38 /// To make sense of the CrateModuleIds, we need the source root.
39 krate: Crate, 39 krate: Crate,
40 impls: FxHashMap<TyFingerprint, Vec<(ModuleId, ImplId)>>, 40 impls: FxHashMap<TyFingerprint, Vec<(CrateModuleId, ImplId)>>,
41 impls_by_trait: FxHashMap<TraitId, Vec<(ModuleId, ImplId)>>, 41 impls_by_trait: FxHashMap<TraitId, Vec<(CrateModuleId, ImplId)>>,
42} 42}
43 43
44impl CrateImplBlocks { 44impl CrateImplBlocks {