Use ItemPtr for id

This commit is contained in:
Aleksey Kladov 2018-11-28 02:13:52 +03:00
parent 3922503205
commit c2abd17f57
4 changed files with 12 additions and 18 deletions

View file

@ -11,8 +11,8 @@ use ra_syntax::{
};
use crate::{
hir::HirDatabase,
syntax_ptr::SyntaxPtr, FileId,
hir::{HirDatabase, SourceItemId},
FileId,
};
pub(crate) use self::scope::FnScopes;
@ -20,8 +20,10 @@ pub(crate) use crate::loc2id::FnId;
impl FnId {
pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId {
let ptr = SyntaxPtr::new(file_id, fn_def.syntax());
db.id_maps().fn_id(ptr)
let file_items = db.file_items(file_id);
let item_id = file_items.id_of(fn_def.syntax());
let item_id = SourceItemId { file_id, item_id };
db.id_maps().fn_id(item_id)
}
}

View file

@ -26,8 +26,8 @@ use crate::{
/// Resolve `FnId` to the corresponding `SyntaxNode`
pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode {
let ptr = db.id_maps().fn_ptr(fn_id);
let syntax = db.resolve_syntax_ptr(ptr);
let item_id = db.id_maps().fn_item_id(fn_id);
let syntax = db.file_item(item_id);
FnDef::cast(syntax.borrowed()).unwrap().owned()
}

View file

@ -9,7 +9,6 @@ use rustc_hash::FxHashMap;
use crate::{
hir::{SourceItemId, ModuleId},
syntax_ptr::SyntaxPtr,
input::SourceRootId,
};
@ -112,10 +111,10 @@ pub(crate) struct IdMaps {
}
impl IdMaps {
pub(crate) fn fn_id(&self, ptr: SyntaxPtr) -> FnId {
self.inner.fns.lock().loc2id(&ptr)
pub(crate) fn fn_id(&self, item_id: SourceItemId) -> FnId {
self.inner.fns.lock().loc2id(&item_id)
}
pub(crate) fn fn_ptr(&self, fn_id: FnId) -> SyntaxPtr {
pub(crate) fn fn_item_id(&self, fn_id: FnId) -> SourceItemId {
self.inner.fns.lock().id2loc(fn_id)
}
@ -129,6 +128,6 @@ impl IdMaps {
#[derive(Debug, Default)]
struct IdMapsInner {
fns: Mutex<Loc2IdMap<SyntaxPtr, FnId>>,
fns: Mutex<Loc2IdMap<SourceItemId, FnId>>,
defs: Mutex<Loc2IdMap<DefLoc, DefId>>,
}

View file

@ -17,13 +17,6 @@ pub(crate) struct SyntaxPtr {
local: LocalSyntaxPtr,
}
impl SyntaxPtr {
pub(crate) fn new(file_id: FileId, node: SyntaxNodeRef) -> SyntaxPtr {
let local = LocalSyntaxPtr::new(node);
SyntaxPtr { file_id, local }
}
}
/// A pionter to a syntax node inside a file.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct LocalSyntaxPtr {