From 77f90caf2deeb6a2d2c8196399fbba61bf0c461d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 29 Oct 2019 11:15:51 +0300 Subject: start ra_hir_def crate --- crates/ra_hir/src/nameres/collector.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index b5fe16bfa..4f363df36 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -567,7 +567,7 @@ where // inline module, just recurse raw::ModuleData::Definition { name, items, ast_id } => { let module_id = - self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None); + self.push_child_module(name.clone(), AstId::new(self.file_id, *ast_id), None); ModCollector { def_collector: &mut *self.def_collector, @@ -583,7 +583,7 @@ where } // out of line module, resolve, parse and recurse raw::ModuleData::Declaration { name, ast_id } => { - let ast_id = ast_id.with_file_id(self.file_id); + let ast_id = AstId::new(self.file_id, *ast_id); match self.mod_dir.resolve_declaration( self.def_collector.db, self.file_id, @@ -671,21 +671,18 @@ where } fn collect_macro(&mut self, mac: &raw::MacroData) { + let ast_id = AstId::new(self.file_id, mac.ast_id); + // Case 1: macro rules, define a macro in crate-global mutable scope if is_macro_rules(&mac.path) { if let Some(name) = &mac.name { - let macro_id = MacroDefId { - ast_id: mac.ast_id.with_file_id(self.file_id), - krate: self.def_collector.def_map.krate, - }; + let macro_id = MacroDefId { ast_id, krate: self.def_collector.def_map.krate }; let macro_ = MacroDef { id: macro_id }; self.def_collector.define_macro(self.module_id, name.clone(), macro_, mac.export); } return; } - let ast_id = mac.ast_id.with_file_id(self.file_id); - // Case 2: try to resolve in legacy scope and expand macro_rules, triggering // recursive item collection. if let Some(macro_def) = mac.path.as_ident().and_then(|name| { -- cgit v1.2.3 From 541387564483ee3a42a1969fd048f94e57599ca4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 29 Oct 2019 14:55:39 +0300 Subject: move expansion-related code to a separate crate --- crates/ra_hir/src/nameres/collector.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 4f363df36..885ea57a1 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -676,7 +676,8 @@ where // Case 1: macro rules, define a macro in crate-global mutable scope if is_macro_rules(&mac.path) { if let Some(name) = &mac.name { - let macro_id = MacroDefId { ast_id, krate: self.def_collector.def_map.krate }; + let macro_id = + MacroDefId { ast_id, krate: self.def_collector.def_map.krate.crate_id }; let macro_ = MacroDef { id: macro_id }; self.def_collector.define_macro(self.module_id, name.clone(), macro_, mac.export); } -- cgit v1.2.3 From 7de6eaa58ae994a5c5d39a66253e347fb039fa94 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 29 Oct 2019 16:01:14 +0300 Subject: remove not that useful indirection --- crates/ra_hir/src/nameres/collector.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 885ea57a1..dc591e8d3 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -448,7 +448,7 @@ where ); if let Some(def) = resolved_res.resolved_def.get_macros() { - let call_id = MacroCallLoc { def: def.id, ast_id: *ast_id }.id(self.db); + let call_id = self.db.intern_macro(MacroCallLoc { def: def.id, ast_id: *ast_id }); resolved.push((*module_id, call_id, def.id)); res = ReachedFixedPoint::No; return false; @@ -690,7 +690,7 @@ where self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) }) { let def = macro_def.id; - let macro_call_id = MacroCallLoc { def, ast_id }.id(self.def_collector.db); + let macro_call_id = self.def_collector.db.intern_macro(MacroCallLoc { def, ast_id }); self.def_collector.collect_macro_expansion(self.module_id, macro_call_id, def); return; -- cgit v1.2.3 From a136cc0653d2b4133fb6387009cfdbaf3e2cf275 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 12:27:54 +0300 Subject: introduce ra_hir_def --- crates/ra_hir/src/nameres/collector.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index dc591e8d3..dd5f9d4ba 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -212,7 +212,7 @@ where if let Some(ModuleDef::Module(m)) = res.take_types() { tested_by!(macro_rules_from_other_crates_are_visible_with_macro_use); - self.import_all_macros_exported(current_module_id, m.krate); + self.import_all_macros_exported(current_module_id, m.krate()); } } @@ -289,11 +289,11 @@ where if import.is_prelude { tested_by!(std_prelude); self.def_map.prelude = Some(m); - } else if m.krate != self.def_map.krate { + } else if m.krate() != self.def_map.krate { tested_by!(glob_across_crates); // glob import from other crate => we can just import everything once - let item_map = self.db.crate_def_map(m.krate); - let scope = &item_map[m.module_id].scope; + let item_map = self.db.crate_def_map(m.krate()); + let scope = &item_map[m.id.module_id].scope; // Module scoped macros is included let items = scope @@ -307,7 +307,7 @@ where // glob import from same crate => we do an initial // import, and then need to propagate any further // additions - let scope = &self.def_map[m.module_id].scope; + let scope = &self.def_map[m.id.module_id].scope; // Module scoped macros is included let items = scope @@ -319,7 +319,7 @@ where self.update(module_id, Some(import_id), &items); // record the glob import in case we add further items self.glob_imports - .entry(m.module_id) + .entry(m.id.module_id) .or_default() .push((module_id, import_id)); } @@ -523,9 +523,10 @@ where // Prelude module is always considered to be `#[macro_use]`. if let Some(prelude_module) = self.def_collector.def_map.prelude { - if prelude_module.krate != self.def_collector.def_map.krate { + if prelude_module.krate() != self.def_collector.def_map.krate { tested_by!(prelude_is_macro_use); - self.def_collector.import_all_macros_exported(self.module_id, prelude_module.krate); + self.def_collector + .import_all_macros_exported(self.module_id, prelude_module.krate()); } } @@ -631,9 +632,7 @@ where modules[res].scope.legacy_macros = modules[self.module_id].scope.legacy_macros.clone(); modules[self.module_id].children.insert(name.clone(), res); let resolution = Resolution { - def: PerNs::types( - Module { krate: self.def_collector.def_map.krate, module_id: res }.into(), - ), + def: PerNs::types(Module::new(self.def_collector.def_map.krate, res).into()), import: None, }; self.def_collector.update(self.module_id, None, &[(name, resolution)]); @@ -641,7 +640,7 @@ where } fn define_def(&mut self, def: &raw::DefData) { - let module = Module { krate: self.def_collector.def_map.krate, module_id: self.module_id }; + let module = Module::new(self.def_collector.def_map.krate, self.module_id); let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); macro_rules! def { -- cgit v1.2.3 From c9cd6aa370667783292de3bc580e0503a409e453 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 13:10:38 +0300 Subject: Move ids to hir_def crate --- crates/ra_hir/src/nameres/collector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index dd5f9d4ba..a94a0554c 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -641,7 +641,7 @@ where fn define_def(&mut self, def: &raw::DefData) { let module = Module::new(self.def_collector.def_map.krate, self.module_id); - let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); + let ctx = LocationCtx::new(self.def_collector.db, module.id, self.file_id); macro_rules! def { ($kind:ident, $ast_id:ident) => { -- cgit v1.2.3 From 16e620c052016010b2f17070a98bdc1e7e849ab3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 16:12:55 +0300 Subject: move raw_items to hir_def --- crates/ra_hir/src/nameres/collector.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index a94a0554c..2dd0a5877 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,5 +1,6 @@ //! FIXME: write short doc here +use hir_def::nameres::raw; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -12,7 +13,7 @@ use crate::{ ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, name::MACRO_RULES, nameres::{ - diagnostics::DefDiagnostic, mod_resolution::ModDir, raw, Crate, CrateDefMap, CrateModuleId, + diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, }, Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, -- cgit v1.2.3 From f8ddef875af08f6c67fe69f7803f3926bc6f66bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 17:19:30 +0300 Subject: remove forward pointer for name --- crates/ra_hir/src/nameres/collector.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 2dd0a5877..1f3849dc7 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir_def::nameres::raw; +use hir_def::{name, nameres::raw}; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -11,7 +11,6 @@ use crate::{ attr::Attr, db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, - name::MACRO_RULES, nameres::{ diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, @@ -726,7 +725,7 @@ where } fn is_macro_rules(path: &Path) -> bool { - path.as_ident() == Some(&MACRO_RULES) + path.as_ident() == Some(&name::MACRO_RULES) } #[cfg(test)] -- cgit v1.2.3 From e34e71c62d9b4cf0ab237969e03ecde893ab347b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 18:06:08 +0300 Subject: remove forward pointer for attrs --- crates/ra_hir/src/nameres/collector.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 1f3849dc7..2f342870b 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir_def::{name, nameres::raw}; +use hir_def::{attr::Attr, name, nameres::raw}; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -8,7 +8,6 @@ use rustc_hash::FxHashMap; use test_utils::tested_by; use crate::{ - attr::Attr, db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, nameres::{ -- cgit v1.2.3 From 872ac566bfc6cf43ac55354cf5223b962dbc1d92 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 18:56:20 +0300 Subject: push name down to hir_expand --- crates/ra_hir/src/nameres/collector.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 2f342870b..e2e13805a 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,7 @@ //! FIXME: write short doc here -use hir_def::{attr::Attr, name, nameres::raw}; +use hir_def::{attr::Attr, nameres::raw}; +use hir_expand::name; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; -- cgit v1.2.3 From 6f4d5f7339395d854e4ba2af227de851246e528f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Oct 2019 10:31:29 +0300 Subject: move mod_resolution to hir_def --- crates/ra_hir/src/nameres/collector.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/nameres/collector.rs') diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index e2e13805a..ee0a4c99f 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,9 @@ //! FIXME: write short doc here -use hir_def::{attr::Attr, nameres::raw}; +use hir_def::{ + attr::Attr, + nameres::{mod_resolution::ModDir, raw}, +}; use hir_expand::name; use ra_cfg::CfgOptions; use ra_db::FileId; @@ -12,8 +15,8 @@ use crate::{ db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, nameres::{ - diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, - ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, + diagnostics::DefDiagnostic, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, + PerNs, ReachedFixedPoint, Resolution, ResolveMode, }, Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, Struct, Trait, TypeAlias, Union, -- cgit v1.2.3