Kill DefId

This commit is contained in:
Aleksey Kladov 2019-01-25 01:41:36 +03:00
parent 1ccf73c836
commit a03c109f50
2 changed files with 11 additions and 31 deletions

View File

@ -8,13 +8,12 @@ use ra_syntax::{TreeArc, SyntaxNode, SourceFile, AstNode, ast};
use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
use crate::{
HirDatabase, Def,
HirDatabase,
Module,
};
#[derive(Debug, Default)]
pub struct HirInterner {
defs: LocationIntener<DefLoc, DefId>,
macros: LocationIntener<MacroCallLoc, MacroCallId>,
fns: LocationIntener<ItemLoc<ast::FnDef>, FunctionId>,
structs: LocationIntener<ItemLoc<ast::StructDef>, StructId>,
@ -28,7 +27,15 @@ pub struct HirInterner {
impl HirInterner {
pub fn len(&self) -> usize {
self.defs.len() + self.macros.len()
self.macros.len()
+ self.fns.len()
+ self.structs.len()
+ self.enums.len()
+ self.enum_variants.len()
+ self.consts.len()
+ self.statics.len()
+ self.traits.len()
+ self.types.len()
}
}
@ -299,33 +306,6 @@ impl AstItemDef<ast::TypeDef> for TypeId {
}
}
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
/// in a specific module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DefId(RawId);
impl_arena_id!(DefId);
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct DefLoc {
pub(crate) kind: DefKind,
pub(crate) module: Module,
pub(crate) source_item_id: SourceItemId,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum DefKind {}
impl DefId {
pub(crate) fn loc(self, db: &impl AsRef<HirInterner>) -> DefLoc {
db.as_ref().defs.id2loc(self)
}
pub fn resolve(self, db: &impl HirDatabase) -> Def {
let loc = self.loc(db);
match loc.kind {}
}
}
/// Identifier of item within a specific file. This is stable over reparses, so
/// it's OK to use it as a salsa key/value.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]

View File

@ -52,7 +52,7 @@ use crate::{
pub use self::{
path::{Path, PathKind},
name::Name,
ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc, HirInterner},
ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner},
macros::{MacroDef, MacroInput, MacroExpansion},
nameres::{ItemMap, PerNs, Namespace, Resolution},
ty::{Ty, AdtDef},