Remove import source map

This commit is contained in:
Aleksey Kladov 2019-12-21 12:44:28 +01:00
parent ab7a70fb14
commit d335311893
5 changed files with 15 additions and 72 deletions

View File

@ -4,8 +4,8 @@
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery,
StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery,
TraitDataQuery, TypeAliasDataQuery,
};
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,

View File

@ -13,10 +13,7 @@
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<RawItems>, Arc<ImportSourceMap>);
#[salsa::invoke(RawItems::raw_items_query)]
fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;

View File

@ -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<RawItem>,
}
#[derive(Debug, Default, PartialEq, Eq)]
pub struct ImportSourceMap {
map: ArenaMap<LocalImportId, ImportSourcePtr>,
}
type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
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<RawItems> {
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<RawItems>, Arc<ImportSourceMap>) {
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 @@ pub(crate) fn raw_items_with_source_map_query(
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<LocalImportId, ImportData, ImportSourcePtr>,
source_ast_id_map: Arc<AstIdMap>,
file_id: HirFileId,
hygiene: Hygiene,
@ -330,7 +303,7 @@ fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseIte
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 @@ fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseIte
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 @@ fn add_extern_crate_item(
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 @@ fn add_impl(&mut self, current_module: Option<Module>, imp: ast::ImplBlock) {
self.push_item(current_module, attrs, RawItemKind::Impl(imp))
}
fn push_import(
&mut self,
current_module: Option<Module>,
attrs: Attrs,
data: ImportData,
source: ImportSourcePtr,
) {
let import = self.imports.alloc(|| source, || data);
fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) {
let import = self.raw_items.imports.alloc(data);
self.push_item(current_module, attrs, RawItemKind::Import(import))
}

View File

@ -18,10 +18,6 @@ pub(crate) struct Trace<ID: ArenaId, T, V> {
}
impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
pub(crate) fn new() -> Trace<ID, T, V> {
Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 }
}
pub(crate) fn new_for_arena() -> Trace<ID, T, V> {
Trace { arena: Some(Arena::default()), map: None, len: 0 }
}
@ -52,8 +48,4 @@ pub(crate) fn into_arena(mut self) -> Arena<ID, T> {
pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> {
self.map.take().unwrap()
}
pub(crate) fn into_arena_and_map(mut self) -> (Arena<ID, T>, ArenaMap<ID, V>) {
(self.arena.take().unwrap(), self.map.take().unwrap())
}
}

View File

@ -270,7 +270,6 @@ pub(crate) fn collect_garbage(&mut self) {
self.query(hir::db::AstIdMapQuery).sweep(sweep);
self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep);
self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep);
self.query(hir::db::ExprScopesQuery).sweep(sweep);
@ -309,7 +308,6 @@ macro_rules! sweep_each_query {
hir::db::StructDataQuery
hir::db::EnumDataQuery
hir::db::TraitDataQuery
hir::db::RawItemsWithSourceMapQuery
hir::db::RawItemsQuery
hir::db::CrateDefMapQuery
hir::db::GenericParamsQuery