diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/db.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 145 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 11 |
5 files changed, 106 insertions, 86 deletions
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 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{SyntaxNode, TreeArc, SourceFile}; | 3 | use ra_syntax::{SyntaxNode, TreeArc, SourceFile, ast}; |
4 | use ra_db::{SourceDatabase, salsa}; | 4 | use ra_db::{SourceDatabase, salsa}; |
5 | 5 | ||
6 | use crate::{ | 6 | use 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)] |
22 | pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> { | 23 | pub 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)] |
296 | mod tests { | 296 | mod 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 | ||
6 | use ra_db::{LocationInterner, FileId}; | 6 | use ra_db::{FileId, salsa}; |
7 | use ra_syntax::{TreeArc, SourceFile, AstNode, ast}; | 7 | use ra_syntax::{TreeArc, SourceFile, AstNode, ast}; |
8 | use ra_arena::{RawId, ArenaId, impl_arena_id}; | ||
9 | use mbe::MacroRules; | 8 | use mbe::MacroRules; |
10 | 9 | ||
11 | use crate::{ | 10 | use crate::{ |
12 | Module, DefDatabase, AstId, FileAstId, | 11 | Module, DefDatabase, AstId, FileAstId, |
13 | }; | 12 | }; |
14 | 13 | ||
15 | #[derive(Debug, Default)] | ||
16 | pub 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 | |||
27 | impl 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 | ||
112 | macro_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)] |
141 | pub struct MacroCallId(RawId); | 128 | pub struct MacroCallId(salsa::InternId); |
142 | impl_arena_id!(MacroCallId); | 129 | impl_intern_key!(MacroCallId); |
143 | 130 | ||
144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 131 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
145 | pub struct MacroCallLoc { | 132 | pub struct MacroCallLoc { |
@@ -148,14 +135,14 @@ pub struct MacroCallLoc { | |||
148 | } | 135 | } |
149 | 136 | ||
150 | impl MacroCallId { | 137 | impl 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 | ||
156 | impl MacroCallLoc { | 143 | impl 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 | ||
207 | pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | 194 | pub(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)] |
232 | pub(crate) struct FunctionId(RawId); | 219 | pub struct FunctionId(salsa::InternId); |
233 | impl_arena_id!(FunctionId); | 220 | impl_intern_key!(FunctionId); |
221 | |||
234 | impl AstItemDef<ast::FnDef> for FunctionId { | 222 | impl 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)] |
241 | pub(crate) struct StructId(RawId); | 232 | pub struct StructId(salsa::InternId); |
242 | impl_arena_id!(StructId); | 233 | impl_intern_key!(StructId); |
243 | impl AstItemDef<ast::StructDef> for StructId { | 234 | impl 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)] |
250 | pub(crate) struct EnumId(RawId); | 244 | pub struct EnumId(salsa::InternId); |
251 | impl_arena_id!(EnumId); | 245 | impl_intern_key!(EnumId); |
252 | impl AstItemDef<ast::EnumDef> for EnumId { | 246 | impl 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)] |
259 | pub(crate) struct ConstId(RawId); | 256 | pub struct ConstId(salsa::InternId); |
260 | impl_arena_id!(ConstId); | 257 | impl_intern_key!(ConstId); |
261 | impl AstItemDef<ast::ConstDef> for ConstId { | 258 | impl 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)] |
268 | pub(crate) struct StaticId(RawId); | 268 | pub struct StaticId(salsa::InternId); |
269 | impl_arena_id!(StaticId); | 269 | impl_intern_key!(StaticId); |
270 | impl AstItemDef<ast::StaticDef> for StaticId { | 270 | impl 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)] |
277 | pub(crate) struct TraitId(RawId); | 280 | pub struct TraitId(salsa::InternId); |
278 | impl_arena_id!(TraitId); | 281 | impl_intern_key!(TraitId); |
279 | impl AstItemDef<ast::TraitDef> for TraitId { | 282 | impl 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)] |
286 | pub(crate) struct TypeAliasId(RawId); | 292 | pub struct TypeAliasId(salsa::InternId); |
287 | impl_arena_id!(TypeAliasId); | 293 | impl_intern_key!(TypeAliasId); |
288 | impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { | 294 | impl 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; | |||
9 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; | 9 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; |
10 | use rustc_hash::FxHashMap; | 10 | use rustc_hash::FxHashMap; |
11 | 11 | ||
12 | use crate::{db, HirInterner, diagnostics::DiagnosticSink}; | 12 | use crate::{db, diagnostics::DiagnosticSink}; |
13 | 13 | ||
14 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 14 | pub const WORKSPACE: SourceRootId = SourceRootId(0); |
15 | 15 | ||
@@ -18,7 +18,6 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0); | |||
18 | pub struct MockDatabase { | 18 | pub 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 | ||
218 | impl AsRef<HirInterner> for MockDatabase { | ||
219 | fn as_ref(&self) -> &HirInterner { | ||
220 | &self.interner | ||
221 | } | ||
222 | } | ||
223 | |||
224 | impl MockDatabase { | 215 | impl 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()); |