From 5270bca5f72fa65f0515be776e06d3d6a4d1efca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Mar 2019 13:09:39 +0300 Subject: store macro def inside macro id This solves the problem of "macro expansion can't call into name resolution, because name resolution calls back into macro expansion" Because we store macro def as a part of call id, macro expansion just knows the def! --- crates/ra_hir/src/nameres/raw.rs | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) (limited to 'crates/ra_hir/src/nameres/raw.rs') diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index f8ba398ec..7a516e556 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -4,7 +4,6 @@ use std::{ }; use test_utils::tested_by; -use ra_db::FileId; use ra_arena::{Arena, impl_arena_id, RawId, map::ArenaMap}; use ra_syntax::{ AstNode, SourceFile, AstPtr, TreeArc, @@ -47,20 +46,20 @@ impl ImportSourceMap { } impl RawItems { - pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: FileId) -> Arc { + pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: HirFileId) -> Arc { db.raw_items_with_source_map(file_id).0 } pub(crate) fn raw_items_with_source_map_query( db: &impl DefDatabase, - file_id: FileId, + file_id: HirFileId, ) -> (Arc, Arc) { let mut collector = RawItemsCollector { raw_items: RawItems::default(), source_file_items: db.file_items(file_id.into()), source_map: ImportSourceMap::default(), }; - let source_file = db.parse(file_id); + let source_file = db.hir_parse(file_id); collector.process_module(None, &*source_file); (Arc::new(collector.raw_items), Arc::new(collector.source_map)) } @@ -68,19 +67,6 @@ impl RawItems { pub(crate) fn items(&self) -> &[RawItem] { &self.items } - - // We can't use queries during name resolution for fear of cycles, so this - // is a query-less variant of the above function. - pub(crate) fn from_source_file(source_file: &SourceFile, file_id: HirFileId) -> RawItems { - let source_file_items = SourceFileItems::from_source_file(source_file, file_id); - let mut collector = RawItemsCollector { - raw_items: RawItems::default(), - source_file_items: Arc::new(source_file_items), - source_map: ImportSourceMap::default(), - }; - collector.process_module(None, &*source_file); - collector.raw_items - } } impl Index for RawItems { @@ -173,7 +159,6 @@ pub(crate) struct MacroData { pub(crate) source_item_id: SourceFileItemId, pub(crate) path: Path, pub(crate) name: Option, - pub(crate) arg: tt::Subtree, pub(crate) export: bool, } @@ -291,18 +276,15 @@ impl RawItemsCollector { } fn add_macro(&mut self, current_module: Option, m: &ast::MacroCall) { - let (path, arg) = match ( - m.path().and_then(Path::from_ast), - m.token_tree().and_then(mbe::ast_to_token_tree), - ) { - (Some(path), Some((token_tree, _token_map))) => (path, token_tree), + let path = match m.path().and_then(Path::from_ast) { + Some(it) => it, _ => return, }; let name = m.name().map(|it| it.as_name()); let source_item_id = self.source_file_items.id_of_unchecked(m.syntax()); let export = m.has_atom_attr("macro_export"); - let m = self.raw_items.macros.alloc(MacroData { source_item_id, path, arg, name, export }); + let m = self.raw_items.macros.alloc(MacroData { source_item_id, path, name, export }); self.push_item(current_module, RawItem::Macro(m)); } -- cgit v1.2.3