aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-09 20:51:22 +0100
committerAleksey Kladov <[email protected]>2019-04-09 20:51:22 +0100
commit6b993a97602da5ddee4033d4d76a68471f8d1ee1 (patch)
tree7789a282bbdf26119e3a05370040c3e14bdadc1b /crates
parent2fc2d4373b2c4e96bebf320a84270eee3afe34aa (diff)
migrate to salsas interning
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_batch/src/lib.rs12
-rw-r--r--crates/ra_hir/src/db.rs26
-rw-r--r--crates/ra_hir/src/expr/scope.rs8
-rw-r--r--crates/ra_hir/src/ids.rs145
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs11
-rw-r--r--crates/ra_ide_api/src/db.rs9
-rw-r--r--crates/ra_ide_api/src/status.rs7
8 files changed, 109 insertions, 111 deletions
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs
index 5bb47afb2..0cafe617d 100644
--- a/crates/ra_batch/src/lib.rs
+++ b/crates/ra_batch/src/lib.rs
@@ -9,7 +9,7 @@ use rustc_hash::FxHashMap;
9use ra_db::{ 9use ra_db::{
10 CrateGraph, FileId, SourceRoot, SourceRootId, SourceDatabase, salsa, 10 CrateGraph, FileId, SourceRoot, SourceRootId, SourceDatabase, salsa,
11}; 11};
12use ra_hir::{db, HirInterner}; 12use ra_hir::db;
13use ra_project_model::ProjectWorkspace; 13use ra_project_model::ProjectWorkspace;
14use ra_vfs::{Vfs, VfsChange}; 14use ra_vfs::{Vfs, VfsChange};
15use vfs_filter::IncludeRustFiles; 15use vfs_filter::IncludeRustFiles;
@@ -20,7 +20,6 @@ type Result<T> = std::result::Result<T, failure::Error>;
20#[derive(Debug)] 20#[derive(Debug)]
21pub struct BatchDatabase { 21pub struct BatchDatabase {
22 runtime: salsa::Runtime<BatchDatabase>, 22 runtime: salsa::Runtime<BatchDatabase>,
23 interner: Arc<HirInterner>,
24} 23}
25 24
26impl salsa::Database for BatchDatabase { 25impl salsa::Database for BatchDatabase {
@@ -29,12 +28,6 @@ impl salsa::Database for BatchDatabase {
29 } 28 }
30} 29}
31 30
32impl AsRef<HirInterner> for BatchDatabase {
33 fn as_ref(&self) -> &HirInterner {
34 &self.interner
35 }
36}
37
38fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { 31fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId {
39 FileId(f.0.into()) 32 FileId(f.0.into())
40} 33}
@@ -44,8 +37,7 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
44 37
45impl BatchDatabase { 38impl BatchDatabase {
46 pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { 39 pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase {
47 let mut db = 40 let mut db = BatchDatabase { runtime: salsa::Runtime::default() };
48 BatchDatabase { runtime: salsa::Runtime::default(), interner: Default::default() };
49 db.set_crate_graph(Arc::new(crate_graph)); 41 db.set_crate_graph(Arc::new(crate_graph));
50 42
51 // wait until Vfs has loaded all roots 43 // wait until Vfs has loaded all roots
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index be8a8c98b..e23e2bb2b 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, ast};
4use ra_db::{SourceDatabase, salsa}; 4use ra_db::{SourceDatabase, salsa};
5 5
6use crate::{ 6use crate::{
7 HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, HirInterner, 7 HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc,
8 Function, FnSignature, ExprScopes, TypeAlias, 8 Function, FnSignature, ExprScopes, TypeAlias,
9 Struct, Enum, StructField, 9 Struct, Enum, StructField,
10 Const, ConstSignature, Static, 10 Const, ConstSignature, Static,
@@ -15,11 +15,29 @@ use crate::{
15 impl_block::{ModuleImplBlocks, ImplSourceMap}, 15 impl_block::{ModuleImplBlocks, ImplSourceMap},
16 generics::{GenericParams, GenericDef}, 16 generics::{GenericParams, GenericDef},
17 type_ref::TypeRef, 17 type_ref::TypeRef,
18 traits::TraitData, Trait, ty::TraitRef 18 traits::TraitData, Trait, ty::TraitRef,
19 ids
19}; 20};
20 21
21#[salsa::query_group(DefDatabaseStorage)] 22#[salsa::query_group(DefDatabaseStorage)]
22pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> { 23pub trait DefDatabase: SourceDatabase {
24 #[salsa::interned]
25 fn intern_macro(&self, macro_call: MacroCallLoc) -> ids::MacroCallId;
26 #[salsa::interned]
27 fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
28 #[salsa::interned]
29 fn intern_struct(&self, loc: ids::ItemLoc<ast::StructDef>) -> ids::StructId;
30 #[salsa::interned]
31 fn intern_enum(&self, loc: ids::ItemLoc<ast::EnumDef>) -> ids::EnumId;
32 #[salsa::interned]
33 fn intern_const(&self, loc: ids::ItemLoc<ast::ConstDef>) -> ids::ConstId;
34 #[salsa::interned]
35 fn intern_static(&self, loc: ids::ItemLoc<ast::StaticDef>) -> ids::StaticId;
36 #[salsa::interned]
37 fn intern_trait(&self, loc: ids::ItemLoc<ast::TraitDef>) -> ids::TraitId;
38 #[salsa::interned]
39 fn intern_type_alias(&self, loc: ids::ItemLoc<ast::TypeAliasDef>) -> ids::TypeAliasId;
40
23 #[salsa::invoke(crate::ids::macro_def_query)] 41 #[salsa::invoke(crate::ids::macro_def_query)]
24 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; 42 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
25 43
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index 48283907b..f1e6e0f02 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -294,9 +294,9 @@ pub struct ReferenceDescriptor {
294 294
295#[cfg(test)] 295#[cfg(test)]
296mod tests { 296mod tests {
297 use ra_db::salsa::InternKey;
297 use ra_syntax::{SourceFile, algo::find_node_at_offset}; 298 use ra_syntax::{SourceFile, algo::find_node_at_offset};
298 use test_utils::{extract_offset, assert_eq_text}; 299 use test_utils::{extract_offset, assert_eq_text};
299 use ra_arena::ArenaId;
300 use crate::Function; 300 use crate::Function;
301 301
302 use crate::expr::{ExprCollector}; 302 use crate::expr::{ExprCollector};
@@ -316,7 +316,8 @@ mod tests {
316 let file = SourceFile::parse(&code); 316 let file = SourceFile::parse(&code);
317 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); 317 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
318 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 318 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
319 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; 319 let irrelevant_function =
320 Function { id: crate::ids::FunctionId::from_intern_id(0u32.into()) };
320 let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def); 321 let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def);
321 let scopes = ExprScopes::new(Arc::new(body)); 322 let scopes = ExprScopes::new(Arc::new(body));
322 let scopes = 323 let scopes =
@@ -421,7 +422,8 @@ mod tests {
421 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 422 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
422 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); 423 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
423 424
424 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; 425 let irrelevant_function =
426 Function { id: crate::ids::FunctionId::from_intern_id(0u32.into()) };
425 let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def); 427 let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def);
426 let scopes = ExprScopes::new(Arc::new(body)); 428 let scopes = ExprScopes::new(Arc::new(body));
427 let scopes = 429 let scopes =
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index eb9939df7..141c9072f 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -3,40 +3,14 @@ use std::{
3 sync::Arc, 3 sync::Arc,
4}; 4};
5 5
6use ra_db::{LocationInterner, FileId}; 6use ra_db::{FileId, salsa};
7use ra_syntax::{TreeArc, SourceFile, AstNode, ast}; 7use ra_syntax::{TreeArc, SourceFile, AstNode, ast};
8use ra_arena::{RawId, ArenaId, impl_arena_id};
9use mbe::MacroRules; 8use mbe::MacroRules;
10 9
11use crate::{ 10use crate::{
12 Module, DefDatabase, AstId, FileAstId, 11 Module, DefDatabase, AstId, FileAstId,
13}; 12};
14 13
15#[derive(Debug, Default)]
16pub struct HirInterner {
17 macros: LocationInterner<MacroCallLoc, MacroCallId>,
18 fns: LocationInterner<ItemLoc<ast::FnDef>, FunctionId>,
19 structs: LocationInterner<ItemLoc<ast::StructDef>, StructId>,
20 enums: LocationInterner<ItemLoc<ast::EnumDef>, EnumId>,
21 consts: LocationInterner<ItemLoc<ast::ConstDef>, ConstId>,
22 statics: LocationInterner<ItemLoc<ast::StaticDef>, StaticId>,
23 traits: LocationInterner<ItemLoc<ast::TraitDef>, TraitId>,
24 types: LocationInterner<ItemLoc<ast::TypeAliasDef>, TypeAliasId>,
25}
26
27impl HirInterner {
28 pub fn len(&self) -> usize {
29 self.macros.len()
30 + self.fns.len()
31 + self.structs.len()
32 + self.enums.len()
33 + self.consts.len()
34 + self.statics.len()
35 + self.traits.len()
36 + self.types.len()
37 }
38}
39
40/// hir makes heavy use of ids: integer (u32) handlers to various things. You 14/// hir makes heavy use of ids: integer (u32) handlers to various things. You
41/// can think of id as a pointer (but without a lifetime) or a file descriptor 15/// can think of id as a pointer (but without a lifetime) or a file descriptor
42/// (but for hir objects). 16/// (but for hir objects).
@@ -135,11 +109,24 @@ pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<A
135 Some(Arc::new(rules)) 109 Some(Arc::new(rules))
136} 110}
137 111
112macro_rules! impl_intern_key {
113 ($name:ident) => {
114 impl salsa::InternKey for $name {
115 fn from_intern_id(v: salsa::InternId) -> Self {
116 $name(v)
117 }
118 fn as_intern_id(&self) -> salsa::InternId {
119 self.0
120 }
121 }
122 };
123}
124
138/// `MacroCallId` identifies a particular macro invocation, like 125/// `MacroCallId` identifies a particular macro invocation, like
139/// `println!("Hello, {}", world)`. 126/// `println!("Hello, {}", world)`.
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 127#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
141pub struct MacroCallId(RawId); 128pub struct MacroCallId(salsa::InternId);
142impl_arena_id!(MacroCallId); 129impl_intern_key!(MacroCallId);
143 130
144#[derive(Debug, Clone, PartialEq, Eq, Hash)] 131#[derive(Debug, Clone, PartialEq, Eq, Hash)]
145pub struct MacroCallLoc { 132pub struct MacroCallLoc {
@@ -148,14 +135,14 @@ pub struct MacroCallLoc {
148} 135}
149 136
150impl MacroCallId { 137impl MacroCallId {
151 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> MacroCallLoc { 138 pub(crate) fn loc(self, db: &impl DefDatabase) -> MacroCallLoc {
152 db.as_ref().macros.id2loc(self) 139 db.lookup_intern_macro(self)
153 } 140 }
154} 141}
155 142
156impl MacroCallLoc { 143impl MacroCallLoc {
157 pub(crate) fn id(&self, db: &impl AsRef<HirInterner>) -> MacroCallId { 144 pub(crate) fn id(self, db: &impl DefDatabase) -> MacroCallId {
158 db.as_ref().macros.loc2id(&self) 145 db.intern_macro(self)
159 } 146 }
160} 147}
161 148
@@ -204,8 +191,10 @@ impl<'a, DB: DefDatabase> LocationCtx<&'a DB> {
204 } 191 }
205} 192}
206 193
207pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { 194pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
208 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>; 195 fn intern(db: &impl DefDatabase, loc: ItemLoc<N>) -> Self;
196 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<N>;
197
209 fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self { 198 fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self {
210 let items = ctx.db.ast_id_map(ctx.file_id); 199 let items = ctx.db.ast_id_map(ctx.file_id);
211 let item_id = items.ast_id(ast); 200 let item_id = items.ast_id(ast);
@@ -213,80 +202,100 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
213 } 202 }
214 fn from_ast_id(ctx: LocationCtx<&impl DefDatabase>, ast_id: FileAstId<N>) -> Self { 203 fn from_ast_id(ctx: LocationCtx<&impl DefDatabase>, ast_id: FileAstId<N>) -> Self {
215 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) }; 204 let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
216 Self::interner(ctx.db.as_ref()).loc2id(&loc) 205 Self::intern(ctx.db, loc)
217 } 206 }
218 fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) { 207 fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) {
219 let int = Self::interner(db.as_ref()); 208 let loc = self.lookup_intern(db);
220 let loc = int.id2loc(self);
221 let ast = loc.ast_id.to_node(db); 209 let ast = loc.ast_id.to_node(db);
222 (loc.ast_id.file_id(), ast) 210 (loc.ast_id.file_id(), ast)
223 } 211 }
224 fn module(self, db: &impl DefDatabase) -> Module { 212 fn module(self, db: &impl DefDatabase) -> Module {
225 let int = Self::interner(db.as_ref()); 213 let loc = self.lookup_intern(db);
226 let loc = int.id2loc(self);
227 loc.module 214 loc.module
228 } 215 }
229} 216}
230 217
231#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 218#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
232pub(crate) struct FunctionId(RawId); 219pub struct FunctionId(salsa::InternId);
233impl_arena_id!(FunctionId); 220impl_intern_key!(FunctionId);
221
234impl AstItemDef<ast::FnDef> for FunctionId { 222impl AstItemDef<ast::FnDef> for FunctionId {
235 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::FnDef>, Self> { 223 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::FnDef>) -> Self {
236 &interner.fns 224 db.intern_function(loc)
225 }
226 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::FnDef> {
227 db.lookup_intern_function(self)
237 } 228 }
238} 229}
239 230
240#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 231#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
241pub(crate) struct StructId(RawId); 232pub struct StructId(salsa::InternId);
242impl_arena_id!(StructId); 233impl_intern_key!(StructId);
243impl AstItemDef<ast::StructDef> for StructId { 234impl AstItemDef<ast::StructDef> for StructId {
244 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::StructDef>, Self> { 235 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::StructDef>) -> Self {
245 &interner.structs 236 db.intern_struct(loc)
237 }
238 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::StructDef> {
239 db.lookup_intern_struct(self)
246 } 240 }
247} 241}
248 242
249#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 243#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
250pub(crate) struct EnumId(RawId); 244pub struct EnumId(salsa::InternId);
251impl_arena_id!(EnumId); 245impl_intern_key!(EnumId);
252impl AstItemDef<ast::EnumDef> for EnumId { 246impl AstItemDef<ast::EnumDef> for EnumId {
253 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::EnumDef>, Self> { 247 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::EnumDef>) -> Self {
254 &interner.enums 248 db.intern_enum(loc)
249 }
250 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::EnumDef> {
251 db.lookup_intern_enum(self)
255 } 252 }
256} 253}
257 254
258#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 255#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
259pub(crate) struct ConstId(RawId); 256pub struct ConstId(salsa::InternId);
260impl_arena_id!(ConstId); 257impl_intern_key!(ConstId);
261impl AstItemDef<ast::ConstDef> for ConstId { 258impl AstItemDef<ast::ConstDef> for ConstId {
262 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::ConstDef>, Self> { 259 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::ConstDef>) -> Self {
263 &interner.consts 260 db.intern_const(loc)
261 }
262 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::ConstDef> {
263 db.lookup_intern_const(self)
264 } 264 }
265} 265}
266 266
267#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 267#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
268pub(crate) struct StaticId(RawId); 268pub struct StaticId(salsa::InternId);
269impl_arena_id!(StaticId); 269impl_intern_key!(StaticId);
270impl AstItemDef<ast::StaticDef> for StaticId { 270impl AstItemDef<ast::StaticDef> for StaticId {
271 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::StaticDef>, Self> { 271 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::StaticDef>) -> Self {
272 &interner.statics 272 db.intern_static(loc)
273 }
274 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::StaticDef> {
275 db.lookup_intern_static(self)
273 } 276 }
274} 277}
275 278
276#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 279#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
277pub(crate) struct TraitId(RawId); 280pub struct TraitId(salsa::InternId);
278impl_arena_id!(TraitId); 281impl_intern_key!(TraitId);
279impl AstItemDef<ast::TraitDef> for TraitId { 282impl AstItemDef<ast::TraitDef> for TraitId {
280 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::TraitDef>, Self> { 283 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::TraitDef>) -> Self {
281 &interner.traits 284 db.intern_trait(loc)
285 }
286 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::TraitDef> {
287 db.lookup_intern_trait(self)
282 } 288 }
283} 289}
284 290
285#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 291#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
286pub(crate) struct TypeAliasId(RawId); 292pub struct TypeAliasId(salsa::InternId);
287impl_arena_id!(TypeAliasId); 293impl_intern_key!(TypeAliasId);
288impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { 294impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
289 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<ast::TypeAliasDef>, Self> { 295 fn intern(db: &impl DefDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self {
290 &interner.types 296 db.intern_type_alias(loc)
297 }
298 fn lookup_intern(self, db: &impl DefDatabase) -> ItemLoc<ast::TypeAliasDef> {
299 db.lookup_intern_type_alias(self)
291 } 300 }
292} 301}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index c19450f39..4d337d2e3 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -55,7 +55,7 @@ pub use self::{
55 path::{Path, PathKind}, 55 path::{Path, PathKind},
56 name::Name, 56 name::Name,
57 source_id::{AstIdMap, ErasedFileAstId}, 57 source_id::{AstIdMap, ErasedFileAstId},
58 ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, HirInterner}, 58 ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc},
59 nameres::{PerNs, Namespace, ImportId, ImportSource}, 59 nameres::{PerNs, Namespace, ImportId, ImportSource},
60 ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay}, 60 ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay},
61 impl_block::{ImplBlock, ImplItem}, 61 impl_block::{ImplBlock, ImplItem},
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index aeab6b180..fa5882dea 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -9,7 +9,7 @@ use relative_path::RelativePathBuf;
9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; 9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
10use rustc_hash::FxHashMap; 10use rustc_hash::FxHashMap;
11 11
12use crate::{db, HirInterner, diagnostics::DiagnosticSink}; 12use crate::{db, diagnostics::DiagnosticSink};
13 13
14pub const WORKSPACE: SourceRootId = SourceRootId(0); 14pub const WORKSPACE: SourceRootId = SourceRootId(0);
15 15
@@ -18,7 +18,6 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
18pub struct MockDatabase { 18pub struct MockDatabase {
19 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 19 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
20 runtime: salsa::Runtime<MockDatabase>, 20 runtime: salsa::Runtime<MockDatabase>,
21 interner: Arc<HirInterner>,
22 files: FxHashMap<String, FileId>, 21 files: FxHashMap<String, FileId>,
23} 22}
24 23
@@ -195,7 +194,6 @@ impl Default for MockDatabase {
195 let mut db = MockDatabase { 194 let mut db = MockDatabase {
196 events: Default::default(), 195 events: Default::default(),
197 runtime: salsa::Runtime::default(), 196 runtime: salsa::Runtime::default(),
198 interner: Default::default(),
199 files: FxHashMap::default(), 197 files: FxHashMap::default(),
200 }; 198 };
201 db.set_crate_graph(Default::default()); 199 db.set_crate_graph(Default::default());
@@ -208,19 +206,12 @@ impl salsa::ParallelDatabase for MockDatabase {
208 salsa::Snapshot::new(MockDatabase { 206 salsa::Snapshot::new(MockDatabase {
209 events: Default::default(), 207 events: Default::default(),
210 runtime: self.runtime.snapshot(self), 208 runtime: self.runtime.snapshot(self),
211 interner: Arc::clone(&self.interner),
212 // only the root database can be used to get file_id by path. 209 // only the root database can be used to get file_id by path.
213 files: FxHashMap::default(), 210 files: FxHashMap::default(),
214 }) 211 })
215 } 212 }
216} 213}
217 214
218impl AsRef<HirInterner> for MockDatabase {
219 fn as_ref(&self) -> &HirInterner {
220 &self.interner
221 }
222}
223
224impl MockDatabase { 215impl MockDatabase {
225 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> { 216 pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> {
226 *self.events.lock() = Some(Vec::new()); 217 *self.events.lock() = Some(Vec::new());
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index ea4255d35..33d3903bb 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -20,7 +20,6 @@ use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
20#[derive(Debug)] 20#[derive(Debug)]
21pub(crate) struct RootDatabase { 21pub(crate) struct RootDatabase {
22 runtime: salsa::Runtime<RootDatabase>, 22 runtime: salsa::Runtime<RootDatabase>,
23 interner: Arc<hir::HirInterner>,
24 pub(crate) last_gc: time::Instant, 23 pub(crate) last_gc: time::Instant,
25 pub(crate) last_gc_check: time::Instant, 24 pub(crate) last_gc_check: time::Instant,
26} 25}
@@ -38,7 +37,6 @@ impl Default for RootDatabase {
38 fn default() -> RootDatabase { 37 fn default() -> RootDatabase {
39 let mut db = RootDatabase { 38 let mut db = RootDatabase {
40 runtime: salsa::Runtime::default(), 39 runtime: salsa::Runtime::default(),
41 interner: Default::default(),
42 last_gc: time::Instant::now(), 40 last_gc: time::Instant::now(),
43 last_gc_check: time::Instant::now(), 41 last_gc_check: time::Instant::now(),
44 }; 42 };
@@ -53,19 +51,12 @@ impl salsa::ParallelDatabase for RootDatabase {
53 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { 51 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
54 salsa::Snapshot::new(RootDatabase { 52 salsa::Snapshot::new(RootDatabase {
55 runtime: self.runtime.snapshot(self), 53 runtime: self.runtime.snapshot(self),
56 interner: Arc::clone(&self.interner),
57 last_gc: self.last_gc.clone(), 54 last_gc: self.last_gc.clone(),
58 last_gc_check: self.last_gc_check.clone(), 55 last_gc_check: self.last_gc_check.clone(),
59 }) 56 })
60 } 57 }
61} 58}
62 59
63impl AsRef<hir::HirInterner> for RootDatabase {
64 fn as_ref(&self) -> &hir::HirInterner {
65 &self.interner
66 }
67}
68
69#[salsa::query_group(LineIndexDatabaseStorage)] 60#[salsa::query_group(LineIndexDatabaseStorage)]
70pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { 61pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
71 fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; 62 fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
index e0fc1c123..d99a4e750 100644
--- a/crates/ra_ide_api/src/status.rs
+++ b/crates/ra_ide_api/src/status.rs
@@ -23,16 +23,11 @@ pub(crate) fn status(db: &RootDatabase) -> String {
23 let files_stats = db.query(FileTextQuery).entries::<FilesStats>(); 23 let files_stats = db.query(FileTextQuery).entries::<FilesStats>();
24 let syntax_tree_stats = syntax_tree_stats(db); 24 let syntax_tree_stats = syntax_tree_stats(db);
25 let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>(); 25 let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>();
26 let n_defs = {
27 let interner: &hir::HirInterner = db.as_ref();
28 interner.len()
29 };
30 format!( 26 format!(
31 "{}\n{}\n{}\n{} defs\n\nmemory:\n{}\ngc {:?} seconds ago", 27 "{}\n{}\n{}\n\n\nmemory:\n{}\ngc {:?} seconds ago",
32 files_stats, 28 files_stats,
33 symbols_stats, 29 symbols_stats,
34 syntax_tree_stats, 30 syntax_tree_stats,
35 n_defs,
36 MemoryStats::current(), 31 MemoryStats::current(),
37 db.last_gc.elapsed().as_secs(), 32 db.last_gc.elapsed().as_secs(),
38 ) 33 )