mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
use loc2id for FnIds
This commit is contained in:
parent
cb22a799d6
commit
4e48917c00
6 changed files with 70 additions and 22 deletions
|
@ -1,7 +1,16 @@
|
|||
use std::hash::Hash;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use std::{
|
||||
hash::Hash,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
syntax_ptr::SyntaxPtr,
|
||||
};
|
||||
|
||||
/// There are two principle ways to refer to things:
|
||||
/// - by their locatinon (module in foo/bar/baz.rs at line 42)
|
||||
/// - by their numeric id (module `ModuleId(42)`)
|
||||
|
@ -53,8 +62,8 @@ where
|
|||
id
|
||||
}
|
||||
|
||||
pub fn id2loc(&self, id: &ID) -> L {
|
||||
self.id2loc[id].clone()
|
||||
pub fn id2loc(&self, id: ID) -> L {
|
||||
self.id2loc[&id].clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,3 +71,38 @@ pub(crate) trait NumericId: Clone + Eq + Hash {
|
|||
fn from_u32(id: u32) -> Self;
|
||||
fn to_u32(self) -> u32;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct FnId(u32);
|
||||
|
||||
impl NumericId for FnId {
|
||||
fn from_u32(id: u32) -> FnId {
|
||||
FnId(id)
|
||||
}
|
||||
fn to_u32(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait IdDatabase: salsa::Database {
|
||||
fn id_maps(&self) -> &IdMaps;
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub(crate) struct IdMaps {
|
||||
inner: Arc<IdMapsInner>,
|
||||
}
|
||||
|
||||
impl IdMaps {
|
||||
pub(crate) fn fn_id(&self, ptr: SyntaxPtr) -> FnId {
|
||||
self.inner.fns.lock().loc2id(&ptr)
|
||||
}
|
||||
pub(crate) fn fn_ptr(&self, fn_id: FnId) -> SyntaxPtr {
|
||||
self.inner.fns.lock().id2loc(fn_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct IdMapsInner {
|
||||
fns: Mutex<Loc2IdMap<SyntaxPtr, FnId>>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue