From dddbac68779d068cabfa511bed4ba105bc43d194 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 23:51:44 +0300 Subject: remove FnId --- crates/ra_hir/src/db.rs | 10 ++-------- crates/ra_hir/src/function.rs | 23 +++++++++++------------ crates/ra_hir/src/mock.rs | 1 - crates/ra_hir/src/query_definitions.rs | 23 ++++++++--------------- 4 files changed, 21 insertions(+), 36 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index e7f9afa77..ba43a4502 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use ra_syntax::{ SmolStr, SyntaxNode, - ast::FnDefNode, }; use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable}; @@ -12,7 +11,6 @@ use crate::{ SourceFileItems, SourceItemId, query_definitions, FnScopes, - function::FnId, module::{ModuleId, ModuleTree, ModuleSource, nameres::{ItemMap, InputModuleItems}}, ty::{InferenceResult, Ty}, @@ -24,14 +22,10 @@ salsa::query_group! { pub trait HirDatabase: SyntaxDatabase + AsRef> { - fn fn_scopes(fn_id: FnId) -> Arc { + fn fn_scopes(def_id: DefId) -> Arc { type FnScopesQuery; use fn query_definitions::fn_scopes; } - fn fn_syntax(fn_id: FnId) -> FnDefNode { - type FnSyntaxQuery; - use fn query_definitions::fn_syntax; - } fn struct_data(def_id: DefId) -> Cancelable> { type StructDataQuery; @@ -43,7 +37,7 @@ pub trait HirDatabase: SyntaxDatabase use fn query_definitions::enum_data; } - fn infer(fn_id: FnId) -> Cancelable> { + fn infer(def_id: DefId) -> Cancelable> { type InferQuery; use fn query_definitions::infer; } diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs index d4159cee2..5a44132fc 100644 --- a/crates/ra_hir/src/function.rs +++ b/crates/ra_hir/src/function.rs @@ -11,43 +11,42 @@ use ra_syntax::{ ast::{self, AstNode, DocCommentsOwner, NameOwner}, }; -use crate::{ DefId, HirDatabase, ty::InferenceResult, Module }; +use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module}; pub use self::scope::FnScopes; -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub struct FnId(pub(crate) DefId); - #[derive(Debug)] pub struct Function { - pub(crate) fn_id: FnId, + def_id: DefId, } impl Function { pub(crate) fn new(def_id: DefId) -> Function { - let fn_id = FnId(def_id); - Function { fn_id } + Function { def_id } } pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { - db.fn_syntax(self.fn_id) + let def_loc = self.def_id.loc(db); + assert!(def_loc.kind == DefKind::Function); + let syntax = db.file_item(def_loc.source_item_id); + ast::FnDef::cast(syntax.borrowed()).unwrap().owned() } pub fn scopes(&self, db: &impl HirDatabase) -> Arc { - db.fn_scopes(self.fn_id) + db.fn_scopes(self.def_id) } pub fn signature_info(&self, db: &impl HirDatabase) -> Option { - let syntax = db.fn_syntax(self.fn_id); + let syntax = self.syntax(db); FnSignatureInfo::new(syntax.borrowed()) } pub fn infer(&self, db: &impl HirDatabase) -> Cancelable> { - db.infer(self.fn_id) + db.infer(self.def_id) } pub fn module(&self, db: &impl HirDatabase) -> Cancelable { - self.fn_id.0.module(db) + self.def_id.module(db) } } diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index f6882cb77..a2507c9b5 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -189,7 +189,6 @@ salsa::database_storage! { fn file_item() for db::FileItemQuery; fn input_module_items() for db::InputModuleItemsQuery; fn item_map() for db::ItemMapQuery; - fn fn_syntax() for db::FnSyntaxQuery; fn submodules() for db::SubmodulesQuery; fn infer() for db::InferQuery; fn type_for_def() for db::TypeForDefQuery; diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index e6241342a..56e3f7e9d 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -5,15 +5,15 @@ use std::{ use rustc_hash::FxHashMap; use ra_syntax::{ - AstNode, SyntaxNode, SmolStr, - ast::{self, FnDef, FnDefNode, NameOwner, ModuleItemOwner} + AstNode, SyntaxNode, SmolStr, + ast::{self, NameOwner, ModuleItemOwner} }; use ra_db::{SourceRootId, FileId, Cancelable,}; use crate::{ SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, db::HirDatabase, - function::{FnScopes, FnId}, + function::FnScopes, module::{ ModuleSource, ModuleSourceNode, ModuleId, imp::Submodule, @@ -23,22 +23,15 @@ use crate::{ adt::{StructData, EnumData}, }; -/// Resolve `FnId` to the corresponding `SyntaxNode` -pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { - let def_loc = fn_id.0.loc(db); - assert!(def_loc.kind == DefKind::Function); - let syntax = db.file_item(def_loc.source_item_id); - FnDef::cast(syntax.borrowed()).unwrap().owned() -} - -pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc { - let syntax = db.fn_syntax(fn_id); +pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc { + let function = Function::new(def_id); + let syntax = function.syntax(db); let res = FnScopes::new(syntax.borrowed()); Arc::new(res) } -pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable> { - let function = Function { fn_id }; +pub(super) fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable> { + let function = Function::new(def_id); ty::infer(db, function).map(Arc::new) } -- cgit v1.2.3