Remove import source map
This commit is contained in:
parent
ec56f59ac1
commit
02f79e37ca
5 changed files with 15 additions and 66 deletions
|
@ -4,8 +4,8 @@ pub use hir_def::db::{
|
||||||
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
|
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
|
||||||
DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
|
DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
|
||||||
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
|
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
|
||||||
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery,
|
LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery,
|
||||||
StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
|
TraitDataQuery, TypeAliasDataQuery,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||||
|
|
|
@ -13,10 +13,7 @@ use crate::{
|
||||||
docs::Documentation,
|
docs::Documentation,
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
lang_item::{LangItemTarget, LangItems},
|
lang_item::{LangItemTarget, LangItems},
|
||||||
nameres::{
|
nameres::{raw::RawItems, CrateDefMap},
|
||||||
raw::{ImportSourceMap, RawItems},
|
|
||||||
CrateDefMap,
|
|
||||||
},
|
|
||||||
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
|
||||||
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
|
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
|
||||||
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
|
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
|
||||||
|
@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase {
|
||||||
|
|
||||||
#[salsa::query_group(DefDatabaseStorage)]
|
#[salsa::query_group(DefDatabaseStorage)]
|
||||||
pub trait DefDatabase: InternDatabase + AstDatabase {
|
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)]
|
#[salsa::invoke(RawItems::raw_items_query)]
|
||||||
fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
|
fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
|
||||||
|
|
||||||
|
|
|
@ -7,23 +7,21 @@
|
||||||
|
|
||||||
use std::{ops::Index, sync::Arc};
|
use std::{ops::Index, sync::Arc};
|
||||||
|
|
||||||
use either::Either;
|
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
ast_id_map::AstIdMap,
|
ast_id_map::AstIdMap,
|
||||||
db::AstDatabase,
|
db::AstDatabase,
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene,
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
};
|
};
|
||||||
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
|
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, AttrsOwner, NameOwner},
|
ast::{self, AttrsOwner, NameOwner},
|
||||||
AstNode, AstPtr,
|
AstNode,
|
||||||
};
|
};
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile,
|
attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId,
|
||||||
LocalImportId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// `RawItems` is a set of top-level items in a file (except for impls).
|
/// `RawItems` is a set of top-level items in a file (except for impls).
|
||||||
|
@ -41,29 +39,14 @@ pub struct RawItems {
|
||||||
items: Vec<RawItem>,
|
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 RawItems {
|
impl RawItems {
|
||||||
pub(crate) fn raw_items_query(
|
pub(crate) fn raw_items_query(
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
) -> Arc<RawItems> {
|
) -> 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 {
|
let mut collector = RawItemsCollector {
|
||||||
raw_items: RawItems::default(),
|
raw_items: RawItems::default(),
|
||||||
source_ast_id_map: db.ast_id_map(file_id),
|
source_ast_id_map: db.ast_id_map(file_id),
|
||||||
imports: Trace::new(),
|
|
||||||
file_id,
|
file_id,
|
||||||
hygiene: Hygiene::new(db, file_id),
|
hygiene: Hygiene::new(db, file_id),
|
||||||
};
|
};
|
||||||
|
@ -74,11 +57,8 @@ impl RawItems {
|
||||||
collector.process_module(None, item_list);
|
collector.process_module(None, item_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut raw_items = collector.raw_items;
|
let raw_items = collector.raw_items;
|
||||||
let (arena, map) = collector.imports.into_arena_and_map();
|
Arc::new(raw_items)
|
||||||
raw_items.imports = arena;
|
|
||||||
let source_map = ImportSourceMap { map };
|
|
||||||
(Arc::new(raw_items), Arc::new(source_map))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn items(&self) -> &[RawItem] {
|
pub(super) fn items(&self) -> &[RawItem] {
|
||||||
|
@ -217,7 +197,6 @@ pub(super) struct ImplData {
|
||||||
|
|
||||||
struct RawItemsCollector {
|
struct RawItemsCollector {
|
||||||
raw_items: RawItems,
|
raw_items: RawItems,
|
||||||
imports: Trace<LocalImportId, ImportData, ImportSourcePtr>,
|
|
||||||
source_ast_id_map: Arc<AstIdMap>,
|
source_ast_id_map: Arc<AstIdMap>,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
hygiene: Hygiene,
|
hygiene: Hygiene,
|
||||||
|
@ -324,7 +303,7 @@ impl RawItemsCollector {
|
||||||
ModPath::expand_use_item(
|
ModPath::expand_use_item(
|
||||||
InFile { value: use_item, file_id: self.file_id },
|
InFile { value: use_item, file_id: self.file_id },
|
||||||
&self.hygiene,
|
&self.hygiene,
|
||||||
|path, use_tree, is_glob, alias| {
|
|path, _use_tree, is_glob, alias| {
|
||||||
let import_data = ImportData {
|
let import_data = ImportData {
|
||||||
path,
|
path,
|
||||||
alias,
|
alias,
|
||||||
|
@ -333,11 +312,11 @@ impl RawItemsCollector {
|
||||||
is_extern_crate: false,
|
is_extern_crate: false,
|
||||||
is_macro_use: 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 {
|
for import_data in buf {
|
||||||
self.push_import(current_module, attrs.clone(), import_data, ptr);
|
self.push_import(current_module, attrs.clone(), import_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,12 +339,7 @@ impl RawItemsCollector {
|
||||||
is_extern_crate: true,
|
is_extern_crate: true,
|
||||||
is_macro_use,
|
is_macro_use,
|
||||||
};
|
};
|
||||||
self.push_import(
|
self.push_import(current_module, attrs, import_data);
|
||||||
current_module,
|
|
||||||
attrs,
|
|
||||||
import_data,
|
|
||||||
Either::Right(AstPtr::new(&extern_crate)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,14 +370,8 @@ impl RawItemsCollector {
|
||||||
self.push_item(current_module, attrs, RawItemKind::Impl(imp))
|
self.push_item(current_module, attrs, RawItemKind::Impl(imp))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_import(
|
fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) {
|
||||||
&mut self,
|
let import = self.raw_items.imports.alloc(data);
|
||||||
current_module: Option<Module>,
|
|
||||||
attrs: Attrs,
|
|
||||||
data: ImportData,
|
|
||||||
source: ImportSourcePtr,
|
|
||||||
) {
|
|
||||||
let import = self.imports.alloc(|| source, || data);
|
|
||||||
self.push_item(current_module, attrs, RawItemKind::Import(import))
|
self.push_item(current_module, attrs, RawItemKind::Import(import))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,6 @@ pub(crate) struct Trace<ID: ArenaId, T, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, 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> {
|
pub(crate) fn new_for_arena() -> Trace<ID, T, V> {
|
||||||
Trace { arena: Some(Arena::default()), map: None, len: 0 }
|
Trace { arena: Some(Arena::default()), map: None, len: 0 }
|
||||||
}
|
}
|
||||||
|
@ -52,8 +48,4 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
|
||||||
pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> {
|
pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> {
|
||||||
self.map.take().unwrap()
|
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,6 @@ impl RootDatabase {
|
||||||
|
|
||||||
self.query(hir::db::AstIdMapQuery).sweep(sweep);
|
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::BodyWithSourceMapQuery).sweep(sweep);
|
||||||
|
|
||||||
self.query(hir::db::ExprScopesQuery).sweep(sweep);
|
self.query(hir::db::ExprScopesQuery).sweep(sweep);
|
||||||
|
@ -309,7 +308,6 @@ impl RootDatabase {
|
||||||
hir::db::StructDataQuery
|
hir::db::StructDataQuery
|
||||||
hir::db::EnumDataQuery
|
hir::db::EnumDataQuery
|
||||||
hir::db::TraitDataQuery
|
hir::db::TraitDataQuery
|
||||||
hir::db::RawItemsWithSourceMapQuery
|
|
||||||
hir::db::RawItemsQuery
|
hir::db::RawItemsQuery
|
||||||
hir::db::CrateDefMapQuery
|
hir::db::CrateDefMapQuery
|
||||||
hir::db::GenericParamsQuery
|
hir::db::GenericParamsQuery
|
||||||
|
|
Loading…
Add table
Reference in a new issue