aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/db.rs10
-rw-r--r--crates/ra_hir/src/ids.rs34
-rw-r--r--crates/ra_hir/src/impl_block.rs6
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs27
5 files changed, 35 insertions, 44 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index f383701d7..cc03da1e2 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -1,10 +1,10 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; 3use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
4use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, salsa}; 4use ra_db::{SourceRootId, SyntaxDatabase, salsa};
5 5
6use crate::{ 6use crate::{
7 DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId, 7 HirInterner, DefId, MacroCallId, Name, HirFileId,
8 SourceFileItems, SourceItemId, Crate, 8 SourceFileItems, SourceItemId, Crate,
9 query_definitions, 9 query_definitions,
10 FnSignature, FnScopes, 10 FnSignature, FnScopes,
@@ -18,11 +18,7 @@ use crate::{
18}; 18};
19 19
20#[salsa::query_group] 20#[salsa::query_group]
21pub trait HirDatabase: 21pub trait HirDatabase: SyntaxDatabase + AsRef<HirInterner> {
22 SyntaxDatabase
23 + AsRef<LocationIntener<DefLoc, DefId>>
24 + AsRef<LocationIntener<MacroCallLoc, MacroCallId>>
25{
26 #[salsa::invoke(HirFileId::hir_source_file)] 22 #[salsa::invoke(HirFileId::hir_source_file)]
27 fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>; 23 fn hir_source_file(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
28 24
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index b93b7f397..43f0e81f9 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -8,6 +8,18 @@ use crate::{
8 module_tree::ModuleId, 8 module_tree::ModuleId,
9}; 9};
10 10
11#[derive(Debug, Default)]
12pub struct HirInterner {
13 defs: LocationIntener<DefLoc, DefId>,
14 macros: LocationIntener<MacroCallLoc, MacroCallId>,
15}
16
17impl HirInterner {
18 pub fn len(&self) -> usize {
19 self.defs.len() + self.macros.len()
20 }
21}
22
11/// hir makes heavy use of ids: integer (u32) handlers to various things. You 23/// hir makes heavy use of ids: integer (u32) handlers to various things. You
12/// can think of id as a pointer (but without a lifetime) or a file descriptor 24/// can think of id as a pointer (but without a lifetime) or a file descriptor
13/// (but for hir objects). 25/// (but for hir objects).
@@ -106,21 +118,15 @@ pub struct MacroCallLoc {
106} 118}
107 119
108impl MacroCallId { 120impl MacroCallId {
109 pub(crate) fn loc( 121 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> MacroCallLoc {
110 self, 122 db.as_ref().macros.id2loc(self)
111 db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>,
112 ) -> MacroCallLoc {
113 db.as_ref().id2loc(self)
114 } 123 }
115} 124}
116 125
117impl MacroCallLoc { 126impl MacroCallLoc {
118 #[allow(unused)] 127 #[allow(unused)]
119 pub(crate) fn id( 128 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> MacroCallId {
120 &self, 129 db.as_ref().macros.loc2id(&self)
121 db: &impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>>,
122 ) -> MacroCallId {
123 db.as_ref().loc2id(&self)
124 } 130 }
125} 131}
126 132
@@ -164,8 +170,8 @@ pub(crate) enum DefKind {
164} 170}
165 171
166impl DefId { 172impl DefId {
167 pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { 173 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc {
168 db.as_ref().id2loc(self) 174 db.as_ref().defs.id2loc(self)
169 } 175 }
170 176
171 pub fn resolve(self, db: &impl HirDatabase) -> Def { 177 pub fn resolve(self, db: &impl HirDatabase) -> Def {
@@ -233,8 +239,8 @@ impl DefId {
233} 239}
234 240
235impl DefLoc { 241impl DefLoc {
236 pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { 242 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> DefId {
237 db.as_ref().loc2id(&self) 243 db.as_ref().defs.loc2id(&self)
238 } 244 }
239} 245}
240 246
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index ab996a12c..551d0d149 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -3,11 +3,11 @@ use rustc_hash::FxHashMap;
3 3
4use ra_arena::{Arena, RawId, impl_arena_id}; 4use ra_arena::{Arena, RawId, impl_arena_id};
5use ra_syntax::ast::{self, AstNode}; 5use ra_syntax::ast::{self, AstNode};
6use ra_db::{LocationIntener, SourceRootId}; 6use ra_db::{SourceRootId};
7 7
8use crate::{ 8use crate::{
9 DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, 9 DefId, DefLoc, DefKind, SourceItemId, SourceFileItems,
10 Function, 10 Function, HirInterner,
11 db::HirDatabase, 11 db::HirDatabase,
12 type_ref::TypeRef, 12 type_ref::TypeRef,
13 module_tree::ModuleId, 13 module_tree::ModuleId,
@@ -66,7 +66,7 @@ pub struct ImplData {
66 66
67impl ImplData { 67impl ImplData {
68 pub(crate) fn from_ast( 68 pub(crate) fn from_ast(
69 db: &impl AsRef<LocationIntener<DefLoc, DefId>>, 69 db: &impl AsRef<HirInterner>,
70 file_items: &SourceFileItems, 70 file_items: &SourceFileItems,
71 module: &Module, 71 module: &Module,
72 node: &ast::ImplBlock, 72 node: &ast::ImplBlock,
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index f517f71e0..87b5a8b8a 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -40,7 +40,7 @@ use crate::{
40pub use self::{ 40pub use self::{
41 path::{Path, PathKind}, 41 path::{Path, PathKind},
42 name::Name, 42 name::Name,
43 ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc}, 43 ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc, HirInterner},
44 macros::{MacroDef, MacroInput, MacroExpansion}, 44 macros::{MacroDef, MacroInput, MacroExpansion},
45 nameres::{ItemMap, PerNs, Namespace, Resolution}, 45 nameres::{ItemMap, PerNs, Namespace, Resolution},
46 ty::Ty, 46 ty::Ty,
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 6e6f2f04b..4145c8048 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -2,13 +2,13 @@ use std::{sync::Arc, panic};
2 2
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use ra_db::{ 4use ra_db::{
5 LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, 5 BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId,
6 salsa::{self, Database}, 6 salsa::{self, Database},
7}; 7};
8use relative_path::RelativePathBuf; 8use relative_path::RelativePathBuf;
9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; 9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
10 10
11use crate::{db, DefId, DefLoc, MacroCallId, MacroCallLoc}; 11use crate::{db, HirInterner};
12 12
13pub const WORKSPACE: SourceRootId = SourceRootId(0); 13pub const WORKSPACE: SourceRootId = SourceRootId(0);
14 14
@@ -16,7 +16,7 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
16pub(crate) struct MockDatabase { 16pub(crate) struct MockDatabase {
17 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 17 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
18 runtime: salsa::Runtime<MockDatabase>, 18 runtime: salsa::Runtime<MockDatabase>,
19 id_maps: Arc<IdMaps>, 19 interner: Arc<HirInterner>,
20 file_counter: u32, 20 file_counter: u32,
21} 21}
22 22
@@ -123,12 +123,6 @@ impl MockDatabase {
123 } 123 }
124} 124}
125 125
126#[derive(Debug, Default)]
127struct IdMaps {
128 defs: LocationIntener<DefLoc, DefId>,
129 macros: LocationIntener<MacroCallLoc, MacroCallId>,
130}
131
132impl salsa::Database for MockDatabase { 126impl salsa::Database for MockDatabase {
133 fn salsa_runtime(&self) -> &salsa::Runtime<MockDatabase> { 127 fn salsa_runtime(&self) -> &salsa::Runtime<MockDatabase> {
134 &self.runtime 128 &self.runtime
@@ -147,7 +141,7 @@ impl Default for MockDatabase {
147 let mut db = MockDatabase { 141 let mut db = MockDatabase {
148 events: Default::default(), 142 events: Default::default(),
149 runtime: salsa::Runtime::default(), 143 runtime: salsa::Runtime::default(),
150 id_maps: Default::default(), 144 interner: Default::default(),
151 file_counter: 0, 145 file_counter: 0,
152 }; 146 };
153 db.query_mut(ra_db::CrateGraphQuery) 147 db.query_mut(ra_db::CrateGraphQuery)
@@ -165,7 +159,7 @@ impl salsa::ParallelDatabase for MockDatabase {
165 salsa::Snapshot::new(MockDatabase { 159 salsa::Snapshot::new(MockDatabase {
166 events: Default::default(), 160 events: Default::default(),
167 runtime: self.runtime.snapshot(self), 161 runtime: self.runtime.snapshot(self),
168 id_maps: self.id_maps.clone(), 162 interner: Arc::clone(&self.interner),
169 file_counter: self.file_counter, 163 file_counter: self.file_counter,
170 }) 164 })
171 } 165 }
@@ -173,14 +167,9 @@ impl salsa::ParallelDatabase for MockDatabase {
173 167
174impl BaseDatabase for MockDatabase {} 168impl BaseDatabase for MockDatabase {}
175 169
176impl AsRef<LocationIntener<DefLoc, DefId>> for MockDatabase { 170impl AsRef<HirInterner> for MockDatabase {
177 fn as_ref(&self) -> &LocationIntener<DefLoc, DefId> { 171 fn as_ref(&self) -> &HirInterner {
178 &self.id_maps.defs 172 &self.interner
179 }
180}
181impl AsRef<LocationIntener<MacroCallLoc, MacroCallId>> for MockDatabase {
182 fn as_ref(&self) -> &LocationIntener<MacroCallLoc, MacroCallId> {
183 &self.id_maps.macros
184 } 173 }
185} 174}
186 175