From d3353118939d5ab77a63218db6ef542843256aac Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 12:44:28 +0100 Subject: Remove import source map --- crates/ra_hir_def/src/db.rs | 11 +------ crates/ra_hir_def/src/nameres/raw.rs | 62 +++++++----------------------------- crates/ra_hir_def/src/trace.rs | 8 ----- 3 files changed, 13 insertions(+), 68 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 98bff6cb7..c55fd4111 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs @@ -13,10 +13,7 @@ use crate::{ docs::Documentation, generics::GenericParams, lang_item::{LangItemTarget, LangItems}, - nameres::{ - raw::{ImportSourceMap, RawItems}, - CrateDefMap, - }, + nameres::{raw::RawItems, CrateDefMap}, AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, @@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase { #[salsa::query_group(DefDatabaseStorage)] pub trait DefDatabase: InternDatabase + AstDatabase { - #[salsa::invoke(RawItems::raw_items_with_source_map_query)] - fn raw_items_with_source_map( - &self, - file_id: HirFileId, - ) -> (Arc, Arc); - #[salsa::invoke(RawItems::raw_items_query)] fn raw_items(&self, file_id: HirFileId) -> Arc; diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index ecb4d7c03..73e57f1e5 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -7,23 +7,21 @@ use std::{ops::Index, sync::Arc}; -use either::Either; use hir_expand::{ ast_id_map::AstIdMap, db::AstDatabase, hygiene::Hygiene, name::{AsName, Name}, }; -use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; +use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::{ ast::{self, AttrsOwner, NameOwner}, - AstNode, AstPtr, + AstNode, }; use test_utils::tested_by; use crate::{ - attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile, - LocalImportId, + attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId, }; /// `RawItems` is a set of top-level items in a file (except for impls). @@ -41,35 +39,14 @@ pub struct RawItems { items: Vec, } -#[derive(Debug, Default, PartialEq, Eq)] -pub struct ImportSourceMap { - map: ArenaMap, -} - -type ImportSourcePtr = Either, AstPtr>; - -impl ImportSourceMap { - pub fn get(&self, import: LocalImportId) -> ImportSourcePtr { - self.map[import].clone() - } -} - impl RawItems { pub(crate) fn raw_items_query( db: &(impl DefDatabase + AstDatabase), 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 + AstDatabase), - file_id: HirFileId, - ) -> (Arc, Arc) { let mut collector = RawItemsCollector { raw_items: RawItems::default(), source_ast_id_map: db.ast_id_map(file_id), - imports: Trace::new(), file_id, hygiene: Hygiene::new(db, file_id), }; @@ -80,11 +57,8 @@ impl RawItems { collector.process_module(None, item_list); } } - let mut raw_items = collector.raw_items; - let (arena, map) = collector.imports.into_arena_and_map(); - raw_items.imports = arena; - let source_map = ImportSourceMap { map }; - (Arc::new(raw_items), Arc::new(source_map)) + let raw_items = collector.raw_items; + Arc::new(raw_items) } pub(super) fn items(&self) -> &[RawItem] { @@ -223,7 +197,6 @@ pub(super) struct ImplData { struct RawItemsCollector { raw_items: RawItems, - imports: Trace, source_ast_id_map: Arc, file_id: HirFileId, hygiene: Hygiene, @@ -330,7 +303,7 @@ impl RawItemsCollector { ModPath::expand_use_item( InFile { value: use_item, file_id: self.file_id }, &self.hygiene, - |path, use_tree, is_glob, alias| { + |path, _use_tree, is_glob, alias| { let import_data = ImportData { path, alias, @@ -339,11 +312,11 @@ impl RawItemsCollector { is_extern_crate: false, is_macro_use: false, }; - buf.push((import_data, Either::Left(AstPtr::new(use_tree)))); + buf.push(import_data); }, ); - for (import_data, ptr) in buf { - self.push_import(current_module, attrs.clone(), import_data, ptr); + for import_data in buf { + self.push_import(current_module, attrs.clone(), import_data); } } @@ -366,12 +339,7 @@ impl RawItemsCollector { is_extern_crate: true, is_macro_use, }; - self.push_import( - current_module, - attrs, - import_data, - Either::Right(AstPtr::new(&extern_crate)), - ); + self.push_import(current_module, attrs, import_data); } } @@ -402,14 +370,8 @@ impl RawItemsCollector { self.push_item(current_module, attrs, RawItemKind::Impl(imp)) } - fn push_import( - &mut self, - current_module: Option, - attrs: Attrs, - data: ImportData, - source: ImportSourcePtr, - ) { - let import = self.imports.alloc(|| source, || data); + fn push_import(&mut self, current_module: Option, attrs: Attrs, data: ImportData) { + let import = self.raw_items.imports.alloc(data); self.push_item(current_module, attrs, RawItemKind::Import(import)) } diff --git a/crates/ra_hir_def/src/trace.rs b/crates/ra_hir_def/src/trace.rs index 2bcd707bc..9769e88df 100644 --- a/crates/ra_hir_def/src/trace.rs +++ b/crates/ra_hir_def/src/trace.rs @@ -18,10 +18,6 @@ pub(crate) struct Trace { } impl Trace { - pub(crate) fn new() -> Trace { - Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 } - } - pub(crate) fn new_for_arena() -> Trace { Trace { arena: Some(Arena::default()), map: None, len: 0 } } @@ -52,8 +48,4 @@ impl Trace { pub(crate) fn into_map(mut self) -> ArenaMap { self.map.take().unwrap() } - - pub(crate) fn into_arena_and_map(mut self) -> (Arena, ArenaMap) { - (self.arena.take().unwrap(), self.map.take().unwrap()) - } } -- cgit v1.2.3