aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 22:41:36 +0000
committerAleksey Kladov <[email protected]>2019-01-24 22:41:36 +0000
commita03c109f50a01d646cd2e63c190b0bb08760dcd8 (patch)
tree3ad27bf06b5a1cee19b643a3317d340eae6859f0
parent1ccf73c836d8a70d6f04b621bd6461f133669131 (diff)
Kill DefId
-rw-r--r--crates/ra_hir/src/ids.rs40
-rw-r--r--crates/ra_hir/src/lib.rs2
2 files changed, 11 insertions, 31 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index cbe31f830..b125a1518 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -8,13 +8,12 @@ use ra_syntax::{TreeArc, SyntaxNode, SourceFile, AstNode, ast};
8use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; 8use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
9 9
10use crate::{ 10use crate::{
11 HirDatabase, Def, 11 HirDatabase,
12 Module, 12 Module,
13}; 13};
14 14
15#[derive(Debug, Default)] 15#[derive(Debug, Default)]
16pub struct HirInterner { 16pub struct HirInterner {
17 defs: LocationIntener<DefLoc, DefId>,
18 macros: LocationIntener<MacroCallLoc, MacroCallId>, 17 macros: LocationIntener<MacroCallLoc, MacroCallId>,
19 fns: LocationIntener<ItemLoc<ast::FnDef>, FunctionId>, 18 fns: LocationIntener<ItemLoc<ast::FnDef>, FunctionId>,
20 structs: LocationIntener<ItemLoc<ast::StructDef>, StructId>, 19 structs: LocationIntener<ItemLoc<ast::StructDef>, StructId>,
@@ -28,7 +27,15 @@ pub struct HirInterner {
28 27
29impl HirInterner { 28impl HirInterner {
30 pub fn len(&self) -> usize { 29 pub fn len(&self) -> usize {
31 self.defs.len() + self.macros.len() 30 self.macros.len()
31 + self.fns.len()
32 + self.structs.len()
33 + self.enums.len()
34 + self.enum_variants.len()
35 + self.consts.len()
36 + self.statics.len()
37 + self.traits.len()
38 + self.types.len()
32 } 39 }
33} 40}
34 41
@@ -299,33 +306,6 @@ impl AstItemDef<ast::TypeDef> for TypeId {
299 } 306 }
300} 307}
301 308
302/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
303/// in a specific module.
304#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
305pub struct DefId(RawId);
306impl_arena_id!(DefId);
307
308#[derive(Clone, Debug, PartialEq, Eq, Hash)]
309pub struct DefLoc {
310 pub(crate) kind: DefKind,
311 pub(crate) module: Module,
312 pub(crate) source_item_id: SourceItemId,
313}
314
315#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
316pub(crate) enum DefKind {}
317
318impl DefId {
319 pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc {
320 db.as_ref().defs.id2loc(self)
321 }
322
323 pub fn resolve(self, db: &impl HirDatabase) -> Def {
324 let loc = self.loc(db);
325 match loc.kind {}
326 }
327}
328
329/// Identifier of item within a specific file. This is stable over reparses, so 309/// Identifier of item within a specific file. This is stable over reparses, so
330/// it's OK to use it as a salsa key/value. 310/// it's OK to use it as a salsa key/value.
331#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 311#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 6cbece95e..644affd44 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -52,7 +52,7 @@ use crate::{
52pub use self::{ 52pub use self::{
53 path::{Path, PathKind}, 53 path::{Path, PathKind},
54 name::Name, 54 name::Name,
55 ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc, HirInterner}, 55 ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner},
56 macros::{MacroDef, MacroInput, MacroExpansion}, 56 macros::{MacroDef, MacroInput, MacroExpansion},
57 nameres::{ItemMap, PerNs, Namespace, Resolution}, 57 nameres::{ItemMap, PerNs, Namespace, Resolution},
58 ty::{Ty, AdtDef}, 58 ty::{Ty, AdtDef},