]> git.lizzy.rs Git - rust.git/commitdiff
rename LoweredImport -> ImportId
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 18 Jan 2019 13:56:02 +0000 (16:56 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 19 Jan 2019 12:37:25 +0000 (15:37 +0300)
crates/ra_hir/src/code_model_api.rs
crates/ra_hir/src/code_model_impl/module.rs
crates/ra_hir/src/db.rs
crates/ra_hir/src/lib.rs
crates/ra_hir/src/nameres.rs
crates/ra_hir/src/nameres/lower.rs
crates/ra_hir/src/source_binder.rs
crates/ra_ide_api/src/db.rs

index 865e5e80929505390c9f9ea1d5ec0c803f885ea5..860fd75395b1cf3b9c416dae7203c99f8d6df5e7 100644 (file)
@@ -7,7 +7,7 @@
 use crate::{
     Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId,
     type_ref::TypeRef,
-    nameres::{ModuleScope, lower::LoweredImport},
+    nameres::{ModuleScope, lower::ImportId},
     db::HirDatabase,
     expr::BodySyntaxMapping,
     ty::InferenceResult,
@@ -100,7 +100,7 @@ pub fn declaration_source(
     pub fn import_source(
         &self,
         db: &impl HirDatabase,
-        import: LoweredImport,
+        import: ImportId,
     ) -> TreeArc<ast::PathSegment> {
         self.import_source_impl(db, import)
     }
index f110548c645f069eca7fea5113f9655a51810298..e5394d440e1a7087dc1bbaa157706c911131cb73 100644 (file)
@@ -5,7 +5,7 @@
     Module, ModuleSource, Problem,
     Crate, DefId, DefLoc, DefKind, Name, Path, PathKind, PerNs, Def,
     module_tree::ModuleId,
-    nameres::{ModuleScope, lower::LoweredImport},
+    nameres::{ModuleScope, lower::ImportId},
     db::HirDatabase,
 };
 
@@ -69,7 +69,7 @@ pub(crate) fn declaration_source_impl(
     pub(crate) fn import_source_impl(
         &self,
         db: &impl HirDatabase,
-        import: LoweredImport,
+        import: ImportId,
     ) -> TreeArc<ast::PathSegment> {
         let loc = self.def_id.loc(db);
         let source_map = db.lower_module_source_map(loc.source_root_id, loc.module_id);
index ccc53c454ce172ae9019a78a85770b34015a368c..60065cf6a55a83888af6c65b2ab5ca737eff9652 100644 (file)
@@ -10,7 +10,7 @@
     FnSignature, FnScopes,
     macros::MacroExpansion,
     module_tree::{ModuleId, ModuleTree},
-    nameres::{ItemMap, lower::{InputModuleItems, LoweredModule, ImportSourceMap}},
+    nameres::{ItemMap, lower::{LoweredModule, ImportSourceMap}},
     ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks},
     adt::{StructData, EnumData, EnumVariantData},
     impl_block::ModuleImplBlocks,
@@ -58,13 +58,6 @@ pub trait HirDatabase:
     #[salsa::invoke(crate::module_tree::Submodule::submodules_query)]
     fn submodules(&self, source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>>;
 
-    #[salsa::invoke(crate::nameres::lower::InputModuleItems::input_module_items_query)]
-    fn input_module_items(
-        &self,
-        source_root_id: SourceRootId,
-        module_id: ModuleId,
-    ) -> Arc<InputModuleItems>;
-
     #[salsa::invoke(crate::nameres::lower::LoweredModule::lower_module_query)]
     fn lower_module(
         &self,
index ef7d049eeeb1812f2b554fc9d5733a248df03bfd..75b9c6b4300d8e9b40b49e7ebe4430d65097eb7f 100644 (file)
@@ -31,7 +31,7 @@
 use crate::{
     db::HirDatabase,
     name::{AsName, KnownName},
-    ids::{DefKind, SourceItemId, SourceFileItemId, SourceFileItems},
+    ids::{DefKind, SourceItemId, SourceFileItems},
 };
 
 pub use self::{
index ab0a9041da67f2d6ab0a58b71f3e0637a167295b..4efafd4092791a780ae3f990115567dd8fb09503 100644 (file)
@@ -60,7 +60,7 @@ pub struct Resolution {
     /// None for unresolved
     pub def_id: PerNs<DefId>,
     /// ident by whitch this is imported into local scope.
-    pub import: Option<LoweredImport>,
+    pub import: Option<ImportId>,
 }
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -154,7 +154,7 @@ pub(crate) struct Resolver<'a, DB> {
     input: &'a FxHashMap<ModuleId, Arc<LoweredModule>>,
     source_root: SourceRootId,
     module_tree: Arc<ModuleTree>,
-    processed_imports: FxHashSet<(ModuleId, LoweredImport)>,
+    processed_imports: FxHashSet<(ModuleId, ImportId)>,
     result: ItemMap,
 }
 
@@ -296,7 +296,7 @@ fn resolve_imports(&mut self, module_id: ModuleId) {
     fn resolve_import(
         &mut self,
         module_id: ModuleId,
-        import_id: LoweredImport,
+        import_id: ImportId,
         import: &ImportData,
     ) -> bool {
         log::debug!("resolving import: {:?}", import);
index 6bca1444429d50ac31e3463636fc512899dc7542..52448644cdce54f1eb8377c94ffa8310f54a9848 100644 (file)
 use std::sync::Arc;
 
 use ra_syntax::{
-    TextRange, SyntaxKind, AstNode, SourceFile, TreeArc,
+    SyntaxKind, AstNode, SourceFile, TreeArc,
     ast::{self, ModuleItemOwner},
 };
 use ra_db::{SourceRootId, LocalSyntaxPtr};
 use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
 
 use crate::{
-    SourceItemId, SourceFileItemId, Path, ModuleSource, HirDatabase, Name, SourceFileItems,
+    SourceItemId, Path, ModuleSource, HirDatabase, Name, SourceFileItems,
     HirFileId, MacroCallLoc, AsName,
     module_tree::ModuleId
 };
-/// A set of items and imports declared inside a module, without relation to
-/// other modules.
-///
-/// This sits in-between raw syntax and name resolution and allows us to avoid
-/// recomputing name res: if two instance of `InputModuleItems` are the same, we
-/// can avoid redoing name resolution.
-#[derive(Debug, Default, PartialEq, Eq)]
-pub struct InputModuleItems {
-    pub(crate) items: Vec<ModuleItem>,
-    pub(super) imports: Vec<Import>,
-}
-
-impl InputModuleItems {
-    pub(crate) fn input_module_items_query(
-        db: &impl HirDatabase,
-        source_root_id: SourceRootId,
-        module_id: ModuleId,
-    ) -> Arc<InputModuleItems> {
-        let module_tree = db.module_tree(source_root_id);
-        let source = module_id.source(&module_tree);
-        let file_id = source.file_id;
-        let source = ModuleSource::from_source_item_id(db, source);
-        let mut res = InputModuleItems::default();
-        match source {
-            ModuleSource::SourceFile(it) => res.fill(
-                db,
-                source_root_id,
-                module_id,
-                file_id,
-                &mut it.items_with_macros(),
-            ),
-            ModuleSource::Module(it) => {
-                if let Some(item_list) = it.item_list() {
-                    res.fill(
-                        db,
-                        source_root_id,
-                        module_id,
-                        file_id,
-                        &mut item_list.items_with_macros(),
-                    )
-                }
-            }
-        };
-        Arc::new(res)
-    }
-
-    fn fill(
-        &mut self,
-        db: &impl HirDatabase,
-        source_root_id: SourceRootId,
-        module_id: ModuleId,
-        file_id: HirFileId,
-        items: &mut Iterator<Item = ast::ItemOrMacro>,
-    ) {
-        let file_items = db.file_items(file_id);
-
-        for item in items {
-            match item {
-                ast::ItemOrMacro::Item(it) => {
-                    self.add_item(file_id, &file_items, it);
-                }
-                ast::ItemOrMacro::Macro(macro_call) => {
-                    let item_id = file_items.id_of_unchecked(macro_call.syntax());
-                    let loc = MacroCallLoc {
-                        source_root_id,
-                        module_id,
-                        source_item_id: SourceItemId {
-                            file_id,
-                            item_id: Some(item_id),
-                        },
-                    };
-                    let id = loc.id(db);
-                    let file_id = HirFileId::from(id);
-                    let file_items = db.file_items(file_id);
-                    //FIXME: expand recursively
-                    for item in db.hir_source_file(file_id).items() {
-                        self.add_item(file_id, &file_items, item);
-                    }
-                }
-            }
-        }
-    }
-
-    fn add_item(
-        &mut self,
-        file_id: HirFileId,
-        file_items: &SourceFileItems,
-        item: &ast::ModuleItem,
-    ) -> Option<()> {
-        match item.kind() {
-            ast::ModuleItemKind::StructDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::EnumDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::FnDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::TraitDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::TypeDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::ImplBlock(_) => {
-                // impls don't define items
-            }
-            ast::ModuleItemKind::UseItem(it) => self.add_use_item(file_items, it),
-            ast::ModuleItemKind::ExternCrateItem(_) => {
-                // TODO
-            }
-            ast::ModuleItemKind::ConstDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::StaticDef(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-            ast::ModuleItemKind::Module(it) => {
-                self.items.push(ModuleItem::new(file_id, file_items, it)?)
-            }
-        }
-        Some(())
-    }
-
-    fn add_use_item(&mut self, file_items: &SourceFileItems, item: &ast::UseItem) {
-        let file_item_id = file_items.id_of_unchecked(item.syntax());
-        let start_offset = item.syntax().range().start();
-        Path::expand_use_item(item, |path, segment| {
-            let kind = match segment {
-                None => ImportKind::Glob,
-                Some(segment) => ImportKind::Named(NamedImport {
-                    file_item_id,
-                    relative_range: segment.syntax().range() - start_offset,
-                }),
-            };
-            self.imports.push(Import { kind, path })
-        })
-    }
-}
 
 #[derive(Debug, PartialEq, Eq)]
 pub(super) enum Vis {
@@ -188,27 +48,9 @@ fn new(
     }
 }
 
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub(super) struct Import {
-    pub(super) path: Path,
-    pub(super) kind: ImportKind,
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct NamedImport {
-    pub file_item_id: SourceFileItemId,
-    pub relative_range: TextRange,
-}
-
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub(super) enum ImportKind {
-    Glob,
-    Named(NamedImport),
-}
-
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub struct LoweredImport(RawId);
-impl_arena_id!(LoweredImport);
+pub struct ImportId(RawId);
+impl_arena_id!(ImportId);
 
 #[derive(Debug, PartialEq, Eq)]
 pub(super) struct ImportData {
@@ -216,24 +58,30 @@ pub(super) struct ImportData {
     pub(super) is_glob: bool,
 }
 
+/// A set of items and imports declared inside a module, without relation to
+/// other modules.
+///
+/// This sits in-between raw syntax and name resolution and allows us to avoid
+/// recomputing name res: if two instance of `InputModuleItems` are the same, we
+/// can avoid redoing name resolution.
 #[derive(Debug, Default, PartialEq, Eq)]
 pub struct LoweredModule {
-    pub(super) items: Vec<ModuleItem>,
-    pub(super) imports: Arena<LoweredImport, ImportData>,
+    pub(crate) items: Vec<ModuleItem>,
+    pub(super) imports: Arena<ImportId, ImportData>,
 }
 
 #[derive(Debug, Default, PartialEq, Eq)]
 pub struct ImportSourceMap {
-    map: ArenaMap<LoweredImport, LocalSyntaxPtr>,
+    map: ArenaMap<ImportId, LocalSyntaxPtr>,
 }
 
 impl ImportSourceMap {
-    fn insert(&mut self, import: LoweredImport, segment: &ast::PathSegment) {
+    fn insert(&mut self, import: ImportId, segment: &ast::PathSegment) {
         self.map
             .insert(import, LocalSyntaxPtr::new(segment.syntax()))
     }
 
-    pub fn get(&self, source: &ModuleSource, import: LoweredImport) -> TreeArc<ast::PathSegment> {
+    pub fn get(&self, source: &ModuleSource, import: ImportId) -> TreeArc<ast::PathSegment> {
         let file = match source {
             ModuleSource::SourceFile(file) => &*file,
             ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
index be82d804a5c77c37776a96f120b3749e1d61dec0..2fe354b0419dd4ff50fea08680befff095d08986 100644 (file)
@@ -142,7 +142,7 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te
         None => return Vec::new(),
     };
     let loc = module.def_id.loc(db);
-    let items = db.input_module_items(loc.source_root_id, loc.module_id);
+    let items = db.lower_module_module(loc.source_root_id, loc.module_id);
     let mut res = Vec::new();
 
     for macro_call_id in items
index a1d3333b2cb744e83fc66390e5f06b0e6b6e56ea..c2978f909733d1c17db0f0d07f06f2e39a53e7eb 100644 (file)
@@ -113,7 +113,6 @@ impl hir::db::HirDatabase {
             fn fn_scopes() for hir::db::FnScopesQuery;
             fn file_items() for hir::db::FileItemsQuery;
             fn file_item() for hir::db::FileItemQuery;
-            fn input_module_items() for hir::db::InputModuleItemsQuery;
             fn lower_module() for hir::db::LowerModuleQuery;
             fn lower_module_module() for hir::db::LowerModuleModuleQuery;
             fn lower_module_source_map() for hir::db::LowerModuleSourceMapQuery;