diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2022-03-09 00:19:53 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2022-03-09 00:19:53 +0100 |
| commit | 55ec93a3370d4c801a74272128e6d696108e9cb1 (patch) | |
| tree | 3429f370c90c1ed242080f6d45f4572ece43e00e | |
| parent | dbada38b617b114a575c7a06dd69c2617d6af651 (diff) | |
| download | rust-55ec93a3370d4c801a74272128e6d696108e9cb1.tar.gz rust-55ec93a3370d4c801a74272128e6d696108e9cb1.zip | |
Remove unnecessary macro_declarations from ItemScope
| -rw-r--r-- | crates/hir/src/lib.rs | 12 | ||||
| -rw-r--r-- | crates/hir/src/symbols.rs | 30 | ||||
| -rw-r--r-- | crates/hir_def/src/db.rs | 1 | ||||
| -rw-r--r-- | crates/hir_def/src/item_scope.rs | 11 | ||||
| -rw-r--r-- | crates/hir_def/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 26 |
6 files changed, 25 insertions, 57 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 76bbe80e1f7..25138fcabcb 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1767,11 +1767,13 @@ impl Macro { } pub fn name(self, _db: &dyn HirDatabase) -> Option<Name> { - match self.id { - MacroId::Macro2Id(_id) => todo!(), - MacroId::MacroRulesId(_id) => todo!(), - MacroId::ProcMacroId(_id) => todo!(), - } + // match self.id { + // MacroId::Macro2Id(id) => db.macro2_data(id).name.clone(), + // MacroId::MacroRulesId(id) => db.macro_rules_data(id).name.clone(), + // MacroId::ProcMacroId(id) => db.proc_macro_data(id).name.clone(), + // } + // FIXME + None } pub fn kind(&self, db: &dyn HirDatabase) -> MacroKind { diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs index 11dccbe8a6d..a84ca0e0a17 100644 --- a/crates/hir/src/symbols.rs +++ b/crates/hir/src/symbols.rs @@ -1,7 +1,6 @@ //! File symbol extraction. use base_db::FileRange; -use either::Either; use hir_def::{ item_tree::ItemTreeNode, src::HasSource, AdtId, AssocItemId, AssocItemLoc, DefWithBodyId, ImplId, ItemContainerId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, @@ -10,7 +9,7 @@ use hir_expand::{HirFileId, InFile}; use hir_ty::db::HirDatabase; use syntax::{ast::HasName, AstNode, SmolStr, SyntaxNode, SyntaxNodePtr}; -use crate::{HasSource as _, Macro, Module, Semantics}; +use crate::{Module, Semantics}; /// The actual data that is stored in the index. It should be as compact as /// possible. @@ -175,10 +174,6 @@ impl<'a> SymbolCollector<'a> { for const_id in scope.unnamed_consts() { self.collect_from_body(const_id); } - - for macro_def_id in scope.macro_declarations() { - self.push_decl_macro(macro_def_id.into()); - } } fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>) { @@ -333,29 +328,6 @@ impl<'a> SymbolCollector<'a> { }) } - fn push_decl_macro(&mut self, macro_def: Macro) { - self.push_file_symbol(|s| { - let name = macro_def.name(s.db)?.as_text()?; - let source = macro_def.source(s.db)?; - - let (ptr, name_ptr) = match source.value { - Either::Left(m) => { - (SyntaxNodePtr::new(m.syntax()), SyntaxNodePtr::new(m.name()?.syntax())) - } - Either::Right(f) => { - (SyntaxNodePtr::new(f.syntax()), SyntaxNodePtr::new(f.name()?.syntax())) - } - }; - - Some(FileSymbol { - name, - kind: FileSymbolKind::Macro, - container_name: s.current_container_name(), - loc: DeclarationLocation { hir_file_id: source.file_id, name_ptr, ptr }, - }) - }) - } - fn push_file_symbol(&mut self, f: impl FnOnce(&Self) -> Option<FileSymbol>) { if let Some(file_symbol) = f(self) { self.symbols.push(file_symbol); diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs index 830ef776923..e31517551a9 100644 --- a/crates/hir_def/src/db.rs +++ b/crates/hir_def/src/db.rs @@ -93,6 +93,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { #[salsa::invoke(StructData::struct_data_query)] fn struct_data(&self, id: StructId) -> Arc<StructData>; + #[salsa::invoke(StructData::union_data_query)] fn union_data(&self, id: UnionId) -> Arc<StructData>; diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index 1293319561b..dea3b36e6c8 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -45,7 +45,6 @@ pub struct ItemScope { /// The defs declared in this scope. Each def has a single scope where it is /// declared. declarations: Vec<ModuleDefId>, - macro_declarations: Vec<MacroId>, impls: Vec<ImplId>, unnamed_consts: Vec<ConstId>, @@ -109,10 +108,6 @@ impl ItemScope { self.declarations.iter().copied() } - pub fn macro_declarations(&self) -> impl Iterator<Item = MacroId> + '_ { - self.macro_declarations.iter().copied() - } - pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ { self.impls.iter().copied() } @@ -177,10 +172,6 @@ impl ItemScope { self.declarations.push(def) } - pub(crate) fn declare_macro(&mut self, def: MacroId) { - self.macro_declarations.push(def); - } - pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroRulesId> { self.legacy_macros.get(name).copied() } @@ -380,7 +371,6 @@ impl ItemScope { macros, unresolved, declarations, - macro_declarations, impls, unnamed_consts, unnamed_trait_imports, @@ -393,7 +383,6 @@ impl ItemScope { macros.shrink_to_fit(); unresolved.shrink_to_fit(); declarations.shrink_to_fit(); - macro_declarations.shrink_to_fit(); impls.shrink_to_fit(); unnamed_consts.shrink_to_fit(); unnamed_trait_imports.shrink_to_fit(); diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index c2e2de309e8..065922841a2 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs @@ -448,7 +448,7 @@ pub enum ModuleDefId { MacroId(MacroId), } impl_from!( - MacroId, + MacroId(Macro2Id, MacroRulesId, ProcMacroId), ModuleId, FunctionId, AdtId(StructId, EnumId, UnionId), diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 897e72b6986..59ed617888c 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -606,16 +606,16 @@ impl DefCollector<'_> { ) { // Textual scoping self.define_legacy_macro(module_id, name.clone(), macro_); - let macro_ = macro_.into(); - self.def_map.modules[module_id].scope.declare_macro(macro_); // Module scoping // In Rust, `#[macro_export]` macros are unconditionally visible at the // crate root, even if the parent modules is **not** visible. if export { + let module_id = self.def_map.root; + self.def_map.modules[module_id].scope.declare(macro_.into()); self.update( - self.def_map.root, - &[(Some(name), PerNs::macros(macro_, Visibility::Public))], + module_id, + &[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))], Visibility::Public, ImportType::Named, ); @@ -646,9 +646,13 @@ impl DefCollector<'_> { ) { let vis = self.def_map.resolve_visibility(self.db, module_id, vis).unwrap_or(Visibility::Public); - let macro_ = macro_.into(); - self.def_map.modules[module_id].scope.declare_macro(macro_); - self.update(module_id, &[(Some(name), PerNs::macros(macro_, vis))], vis, ImportType::Named); + self.def_map.modules[module_id].scope.declare(macro_.into()); + self.update( + module_id, + &[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))], + vis, + ImportType::Named, + ); } /// Define a proc macro @@ -656,11 +660,11 @@ impl DefCollector<'_> { /// A proc macro is similar to normal macro scope, but it would not visible in legacy textual scoped. /// And unconditionally exported. fn define_proc_macro(&mut self, name: Name, macro_: ProcMacroId) { - let macro_ = macro_.into(); - self.def_map.modules[self.def_map.root].scope.declare_macro(macro_); + let module_id = self.def_map.root; + self.def_map.modules[module_id].scope.declare(macro_.into()); self.update( - self.def_map.root, - &[(Some(name), PerNs::macros(macro_, Visibility::Public))], + module_id, + &[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))], Visibility::Public, ImportType::Named, ); |
