aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/db.rs11
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs56
-rw-r--r--crates/ra_hir_def/src/trace.rs8
3 files changed, 13 insertions, 62 deletions
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::{
13 docs::Documentation, 13 docs::Documentation,
14 generics::GenericParams, 14 generics::GenericParams,
15 lang_item::{LangItemTarget, LangItems}, 15 lang_item::{LangItemTarget, LangItems},
16 nameres::{ 16 nameres::{raw::RawItems, CrateDefMap},
17 raw::{ImportSourceMap, RawItems},
18 CrateDefMap,
19 },
20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, 17 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
21 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, 18 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
22 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, 19 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
@@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase {
46 43
47#[salsa::query_group(DefDatabaseStorage)] 44#[salsa::query_group(DefDatabaseStorage)]
48pub trait DefDatabase: InternDatabase + AstDatabase { 45pub trait DefDatabase: InternDatabase + AstDatabase {
49 #[salsa::invoke(RawItems::raw_items_with_source_map_query)]
50 fn raw_items_with_source_map(
51 &self,
52 file_id: HirFileId,
53 ) -> (Arc<RawItems>, Arc<ImportSourceMap>);
54
55 #[salsa::invoke(RawItems::raw_items_query)] 46 #[salsa::invoke(RawItems::raw_items_query)]
56 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; 47 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
57 48
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index df5dac88a..73e57f1e5 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -7,23 +7,21 @@
7 7
8use std::{ops::Index, sync::Arc}; 8use std::{ops::Index, sync::Arc};
9 9
10use either::Either;
11use hir_expand::{ 10use hir_expand::{
12 ast_id_map::AstIdMap, 11 ast_id_map::AstIdMap,
13 db::AstDatabase, 12 db::AstDatabase,
14 hygiene::Hygiene, 13 hygiene::Hygiene,
15 name::{AsName, Name}, 14 name::{AsName, Name},
16}; 15};
17use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 16use ra_arena::{impl_arena_id, Arena, RawId};
18use ra_syntax::{ 17use ra_syntax::{
19 ast::{self, AttrsOwner, NameOwner}, 18 ast::{self, AttrsOwner, NameOwner},
20 AstNode, AstPtr, 19 AstNode,
21}; 20};
22use test_utils::tested_by; 21use test_utils::tested_by;
23 22
24use crate::{ 23use crate::{
25 attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile, 24 attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId,
26 LocalImportId,
27}; 25};
28 26
29/// `RawItems` is a set of top-level items in a file (except for impls). 27/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -41,29 +39,14 @@ pub struct RawItems {
41 items: Vec<RawItem>, 39 items: Vec<RawItem>,
42} 40}
43 41
44#[derive(Debug, Default, PartialEq, Eq)]
45pub struct ImportSourceMap {
46 map: ArenaMap<LocalImportId, ImportSourcePtr>,
47}
48
49type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
50
51impl RawItems { 42impl RawItems {
52 pub(crate) fn raw_items_query( 43 pub(crate) fn raw_items_query(
53 db: &(impl DefDatabase + AstDatabase), 44 db: &(impl DefDatabase + AstDatabase),
54 file_id: HirFileId, 45 file_id: HirFileId,
55 ) -> Arc<RawItems> { 46 ) -> Arc<RawItems> {
56 db.raw_items_with_source_map(file_id).0
57 }
58
59 pub(crate) fn raw_items_with_source_map_query(
60 db: &(impl DefDatabase + AstDatabase),
61 file_id: HirFileId,
62 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
63 let mut collector = RawItemsCollector { 47 let mut collector = RawItemsCollector {
64 raw_items: RawItems::default(), 48 raw_items: RawItems::default(),
65 source_ast_id_map: db.ast_id_map(file_id), 49 source_ast_id_map: db.ast_id_map(file_id),
66 imports: Trace::new(),
67 file_id, 50 file_id,
68 hygiene: Hygiene::new(db, file_id), 51 hygiene: Hygiene::new(db, file_id),
69 }; 52 };
@@ -74,11 +57,8 @@ impl RawItems {
74 collector.process_module(None, item_list); 57 collector.process_module(None, item_list);
75 } 58 }
76 } 59 }
77 let mut raw_items = collector.raw_items; 60 let raw_items = collector.raw_items;
78 let (arena, map) = collector.imports.into_arena_and_map(); 61 Arc::new(raw_items)
79 raw_items.imports = arena;
80 let source_map = ImportSourceMap { map };
81 (Arc::new(raw_items), Arc::new(source_map))
82 } 62 }
83 63
84 pub(super) fn items(&self) -> &[RawItem] { 64 pub(super) fn items(&self) -> &[RawItem] {
@@ -217,7 +197,6 @@ pub(super) struct ImplData {
217 197
218struct RawItemsCollector { 198struct RawItemsCollector {
219 raw_items: RawItems, 199 raw_items: RawItems,
220 imports: Trace<LocalImportId, ImportData, ImportSourcePtr>,
221 source_ast_id_map: Arc<AstIdMap>, 200 source_ast_id_map: Arc<AstIdMap>,
222 file_id: HirFileId, 201 file_id: HirFileId,
223 hygiene: Hygiene, 202 hygiene: Hygiene,
@@ -324,7 +303,7 @@ impl RawItemsCollector {
324 ModPath::expand_use_item( 303 ModPath::expand_use_item(
325 InFile { value: use_item, file_id: self.file_id }, 304 InFile { value: use_item, file_id: self.file_id },
326 &self.hygiene, 305 &self.hygiene,
327 |path, use_tree, is_glob, alias| { 306 |path, _use_tree, is_glob, alias| {
328 let import_data = ImportData { 307 let import_data = ImportData {
329 path, 308 path,
330 alias, 309 alias,
@@ -333,11 +312,11 @@ impl RawItemsCollector {
333 is_extern_crate: false, 312 is_extern_crate: false,
334 is_macro_use: false, 313 is_macro_use: false,
335 }; 314 };
336 buf.push((import_data, Either::Left(AstPtr::new(use_tree)))); 315 buf.push(import_data);
337 }, 316 },
338 ); 317 );
339 for (import_data, ptr) in buf { 318 for import_data in buf {
340 self.push_import(current_module, attrs.clone(), import_data, ptr); 319 self.push_import(current_module, attrs.clone(), import_data);
341 } 320 }
342 } 321 }
343 322
@@ -360,12 +339,7 @@ impl RawItemsCollector {
360 is_extern_crate: true, 339 is_extern_crate: true,
361 is_macro_use, 340 is_macro_use,
362 }; 341 };
363 self.push_import( 342 self.push_import(current_module, attrs, import_data);
364 current_module,
365 attrs,
366 import_data,
367 Either::Right(AstPtr::new(&extern_crate)),
368 );
369 } 343 }
370 } 344 }
371 345
@@ -396,14 +370,8 @@ impl RawItemsCollector {
396 self.push_item(current_module, attrs, RawItemKind::Impl(imp)) 370 self.push_item(current_module, attrs, RawItemKind::Impl(imp))
397 } 371 }
398 372
399 fn push_import( 373 fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) {
400 &mut self, 374 let import = self.raw_items.imports.alloc(data);
401 current_module: Option<Module>,
402 attrs: Attrs,
403 data: ImportData,
404 source: ImportSourcePtr,
405 ) {
406 let import = self.imports.alloc(|| source, || data);
407 self.push_item(current_module, attrs, RawItemKind::Import(import)) 375 self.push_item(current_module, attrs, RawItemKind::Import(import))
408 } 376 }
409 377
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<ID: ArenaId, T, V> {
18} 18}
19 19
20impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { 20impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
21 pub(crate) fn new() -> Trace<ID, T, V> {
22 Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 }
23 }
24
25 pub(crate) fn new_for_arena() -> Trace<ID, T, V> { 21 pub(crate) fn new_for_arena() -> Trace<ID, T, V> {
26 Trace { arena: Some(Arena::default()), map: None, len: 0 } 22 Trace { arena: Some(Arena::default()), map: None, len: 0 }
27 } 23 }
@@ -52,8 +48,4 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
52 pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { 48 pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> {
53 self.map.take().unwrap() 49 self.map.take().unwrap()
54 } 50 }
55
56 pub(crate) fn into_arena_and_map(mut self) -> (Arena<ID, T>, ArenaMap<ID, V>) {
57 (self.arena.take().unwrap(), self.map.take().unwrap())
58 }
59} 51}