diff --git a/Cargo.lock b/Cargo.lock index 0b05ba96203..92c1cd6832a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -688,7 +688,7 @@ dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)", + "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)", "test_utils 0.1.0", ] @@ -714,7 +714,7 @@ dependencies = [ "ra_syntax 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)", + "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)", "test_utils 0.1.0", ] @@ -746,7 +746,7 @@ dependencies = [ "ra_syntax 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)", + "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)", "test_utils 0.1.0", ] @@ -1050,7 +1050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "salsa" version = "0.8.0" -source = "git+https://github.com/matklad/salsa?branch=no-upgrade#1a7ae719af1601fda81186fb48bd100edd9cfb7f" +source = "git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe#9f15af718f58c76a1280d457a113106baf7c20c5" dependencies = [ "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1621,7 +1621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" -"checksum salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)" = "" +"checksum salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)" = "" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 036e284bfbb..b072a5eba0b 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -91,7 +91,6 @@ salsa::database_storage! { fn file_item() for hir::db::FileItemQuery; fn input_module_items() for hir::db::InputModuleItemsQuery; fn item_map() for hir::db::ItemMapQuery; - fn fn_syntax() for hir::db::FnSyntaxQuery; fn submodules() for hir::db::SubmodulesQuery; fn infer() for hir::db::InferQuery; fn type_for_def() for hir::db::TypeForDefQuery; diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 0471a2fca56..14c8d58f101 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -122,9 +122,6 @@ impl AnalysisHostImpl { self.db .query(ra_db::SourceFileQuery) .sweep(salsa::SweepStrategy::default().discard_values()); - self.db - .query(hir::db::FnSyntaxQuery) - .sweep(salsa::SweepStrategy::default().discard_values()); self.db .query(hir::db::SourceFileItemsQuery) .sweep(salsa::SweepStrategy::default().discard_values()); diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index e7f9afa77d5..ba43a4502c4 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 d4159cee23d..5a44132fcca 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 f6882cb7719..a2507c9b52f 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 e6241342acd..56e3f7e9dd8 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) }