From f66e5b6e6b6f7b2b899ef4207dfe46655d77334c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 03:31:50 +0300 Subject: move ids to HIR --- crates/ra_analysis/src/db.rs | 9 +++- crates/ra_analysis/src/hir/db.rs | 2 +- crates/ra_analysis/src/hir/function/mod.rs | 3 +- crates/ra_analysis/src/hir/mod.rs | 45 +++++++++++++++- crates/ra_analysis/src/hir/module/mod.rs | 3 +- crates/ra_analysis/src/hir/module/nameres.rs | 2 +- crates/ra_analysis/src/hir/query_definitions.rs | 3 +- crates/ra_analysis/src/lib.rs | 1 - crates/ra_analysis/src/loc2id.rs | 69 ------------------------- 9 files changed, 57 insertions(+), 80 deletions(-) delete mode 100644 crates/ra_analysis/src/loc2id.rs (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 1b2dd4b3d..2bc1c8f8f 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -5,9 +5,8 @@ use salsa::{self, Database}; use ra_db::{LocationIntener, BaseDatabase}; use crate::{ - hir, + hir::{self, DefId, DefLoc, FnId, SourceItemId}, symbol_index, - loc2id::{IdMaps, DefId, DefLoc, FnId}, }; #[derive(Debug)] @@ -21,6 +20,12 @@ pub(crate) struct RootDatabase { id_maps: Arc, } +#[derive(Debug, Default)] +struct IdMaps { + fns: LocationIntener, + defs: LocationIntener, +} + impl salsa::Database for RootDatabase { fn salsa_runtime(&self) -> &salsa::Runtime { &self.runtime diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs index 0ae2086ff..c8ae551c5 100644 --- a/crates/ra_analysis/src/hir/db.rs +++ b/crates/ra_analysis/src/hir/db.rs @@ -9,13 +9,13 @@ use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase}; use crate::{ FileId, hir::{ + DefLoc, DefId, FnId, SourceFileItems, SourceItemId, query_definitions, function::{FnScopes}, module::{ModuleId, ModuleTree, ModuleSource, nameres::{ItemMap, InputModuleItems}}, }, - loc2id::{DefLoc, DefId, FnId}, Cancelable, }; diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs index e64a9f045..a399d2a9e 100644 --- a/crates/ra_analysis/src/hir/function/mod.rs +++ b/crates/ra_analysis/src/hir/function/mod.rs @@ -11,12 +11,11 @@ use ra_syntax::{ }; use crate::{ - hir::{HirDatabase, SourceItemId}, + hir::{FnId, HirDatabase, SourceItemId}, FileId, }; pub(crate) use self::scope::FnScopes; -pub(crate) use crate::loc2id::FnId; impl FnId { pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId { diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs index 61e6c9913..83131384d 100644 --- a/crates/ra_analysis/src/hir/mod.rs +++ b/crates/ra_analysis/src/hir/mod.rs @@ -14,11 +14,11 @@ mod path; use std::ops::Index; use ra_syntax::{SyntaxNodeRef, SyntaxNode}; +use ra_db::{LocationIntener, SourceRootId}; use crate::{ FileId, hir::db::HirDatabase, - loc2id::{DefId, DefLoc}, Cancelable, arena::{Arena, Id}, }; @@ -31,6 +31,49 @@ pub(crate) use self::{ pub use self::function::FnSignatureInfo; +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) struct FnId(u32); +ra_db::impl_numeric_id!(FnId); + +impl FnId { + pub(crate) fn from_loc( + db: &impl AsRef>, + loc: &SourceItemId, + ) -> FnId { + db.as_ref().loc2id(loc) + } + pub(crate) fn loc(self, db: &impl AsRef>) -> SourceItemId { + db.as_ref().id2loc(self) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) struct DefId(u32); +ra_db::impl_numeric_id!(DefId); + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub(crate) enum DefLoc { + Module { + id: ModuleId, + source_root: SourceRootId, + }, + Item { + source_item_id: SourceItemId, + }, +} + +impl DefId { + pub(crate) fn loc(self, db: &impl AsRef>) -> DefLoc { + db.as_ref().id2loc(self) + } +} + +impl DefLoc { + pub(crate) fn id(&self, db: &impl AsRef>) -> DefId { + db.as_ref().loc2id(&self) + } +} + pub(crate) enum Def { Module(Module), Item, diff --git a/crates/ra_analysis/src/hir/module/mod.rs b/crates/ra_analysis/src/hir/module/mod.rs index 683cb5d4c..d2096b01e 100644 --- a/crates/ra_analysis/src/hir/module/mod.rs +++ b/crates/ra_analysis/src/hir/module/mod.rs @@ -15,9 +15,8 @@ use relative_path::RelativePathBuf; use crate::{ FileId, FilePosition, Cancelable, - hir::{Path, PathKind, HirDatabase, SourceItemId}, + hir::{DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId}, arena::{Arena, Id}, - loc2id::{DefLoc, DefId}, }; pub(crate) use self::nameres::ModuleScope; diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs index 5c87e7af2..d4ecc010b 100644 --- a/crates/ra_analysis/src/hir/module/nameres.rs +++ b/crates/ra_analysis/src/hir/module/nameres.rs @@ -28,8 +28,8 @@ use ra_db::SourceRootId; use crate::{ Cancelable, FileId, - loc2id::{DefId, DefLoc}, hir::{ + DefId, DefLoc, SourceItemId, SourceFileItemId, SourceFileItems, Path, PathKind, HirDatabase, diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs index fbdf8eb67..00237b633 100644 --- a/crates/ra_analysis/src/hir/query_definitions.rs +++ b/crates/ra_analysis/src/hir/query_definitions.rs @@ -13,9 +13,10 @@ use ra_db::SourceRootId; use crate::{ FileId, Cancelable, hir::{ + FnId, SourceFileItems, SourceItemId, db::HirDatabase, - function::{FnId, FnScopes}, + function::FnScopes, module::{ ModuleSource, ModuleSourceNode, ModuleId, imp::Submodule, diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 012d36b8e..5b6e4df8c 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -20,7 +20,6 @@ macro_rules! ctry { mod arena; mod db; -mod loc2id; mod imp; mod completion; mod hir; diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs deleted file mode 100644 index 7956431ab..000000000 --- a/crates/ra_analysis/src/loc2id.rs +++ /dev/null @@ -1,69 +0,0 @@ -use ra_db::SourceRootId; - -use crate::{ - hir::{SourceItemId, ModuleId}, -}; - -use ra_db::{NumericId, LocationIntener}; - -macro_rules! impl_numeric_id { - ($id:ident) => { - impl NumericId for $id { - fn from_u32(id: u32) -> Self { - $id(id) - } - fn to_u32(self) -> u32 { - self.0 - } - } - }; -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct FnId(u32); -impl_numeric_id!(FnId); - -impl FnId { - pub(crate) fn from_loc( - db: &impl AsRef>, - loc: &SourceItemId, - ) -> FnId { - db.as_ref().loc2id(loc) - } - pub(crate) fn loc(self, db: &impl AsRef>) -> SourceItemId { - db.as_ref().id2loc(self) - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct DefId(u32); -impl_numeric_id!(DefId); - -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub(crate) enum DefLoc { - Module { - id: ModuleId, - source_root: SourceRootId, - }, - Item { - source_item_id: SourceItemId, - }, -} - -impl DefId { - pub(crate) fn loc(self, db: &impl AsRef>) -> DefLoc { - db.as_ref().id2loc(self) - } -} - -impl DefLoc { - pub(crate) fn id(&self, db: &impl AsRef>) -> DefId { - db.as_ref().loc2id(&self) - } -} - -#[derive(Debug, Default)] -pub(crate) struct IdMaps { - pub(crate) fns: LocationIntener, - pub(crate) defs: LocationIntener, -} -- cgit v1.2.3