aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--crates/ra_analysis/src/db.rs1
-rw-r--r--crates/ra_analysis/src/imp.rs3
-rw-r--r--crates/ra_hir/src/db.rs10
-rw-r--r--crates/ra_hir/src/function.rs23
-rw-r--r--crates/ra_hir/src/mock.rs1
-rw-r--r--crates/ra_hir/src/query_definitions.rs23
7 files changed, 26 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0b05ba962..92c1cd683 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -688,7 +688,7 @@ dependencies = [
688 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 688 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
689 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 689 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
690 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 690 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
691 "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)", 691 "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)",
692 "test_utils 0.1.0", 692 "test_utils 0.1.0",
693] 693]
694 694
@@ -714,7 +714,7 @@ dependencies = [
714 "ra_syntax 0.1.0", 714 "ra_syntax 0.1.0",
715 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 715 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
716 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 716 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
717 "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)", 717 "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)",
718 "test_utils 0.1.0", 718 "test_utils 0.1.0",
719] 719]
720 720
@@ -746,7 +746,7 @@ dependencies = [
746 "ra_syntax 0.1.0", 746 "ra_syntax 0.1.0",
747 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 747 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
748 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 748 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
749 "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)", 749 "salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)",
750 "test_utils 0.1.0", 750 "test_utils 0.1.0",
751] 751]
752 752
@@ -1050,7 +1050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1050[[package]] 1050[[package]]
1051name = "salsa" 1051name = "salsa"
1052version = "0.8.0" 1052version = "0.8.0"
1053source = "git+https://github.com/matklad/salsa?branch=no-upgrade#1a7ae719af1601fda81186fb48bd100edd9cfb7f" 1053source = "git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe#9f15af718f58c76a1280d457a113106baf7c20c5"
1054dependencies = [ 1054dependencies = [
1055 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", 1055 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
1056 "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1056 "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"
1621"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" 1621"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
1622"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" 1622"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
1623"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" 1623"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
1624"checksum salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)" = "<none>" 1624"checksum salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)" = "<none>"
1625"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" 1625"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
1626"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 1626"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
1627"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1627"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 036e284bf..b072a5eba 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -91,7 +91,6 @@ salsa::database_storage! {
91 fn file_item() for hir::db::FileItemQuery; 91 fn file_item() for hir::db::FileItemQuery;
92 fn input_module_items() for hir::db::InputModuleItemsQuery; 92 fn input_module_items() for hir::db::InputModuleItemsQuery;
93 fn item_map() for hir::db::ItemMapQuery; 93 fn item_map() for hir::db::ItemMapQuery;
94 fn fn_syntax() for hir::db::FnSyntaxQuery;
95 fn submodules() for hir::db::SubmodulesQuery; 94 fn submodules() for hir::db::SubmodulesQuery;
96 fn infer() for hir::db::InferQuery; 95 fn infer() for hir::db::InferQuery;
97 fn type_for_def() for hir::db::TypeForDefQuery; 96 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 0471a2fca..14c8d58f1 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -123,9 +123,6 @@ impl AnalysisHostImpl {
123 .query(ra_db::SourceFileQuery) 123 .query(ra_db::SourceFileQuery)
124 .sweep(salsa::SweepStrategy::default().discard_values()); 124 .sweep(salsa::SweepStrategy::default().discard_values());
125 self.db 125 self.db
126 .query(hir::db::FnSyntaxQuery)
127 .sweep(salsa::SweepStrategy::default().discard_values());
128 self.db
129 .query(hir::db::SourceFileItemsQuery) 126 .query(hir::db::SourceFileItemsQuery)
130 .sweep(salsa::SweepStrategy::default().discard_values()); 127 .sweep(salsa::SweepStrategy::default().discard_values());
131 self.db 128 self.db
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;
3use ra_syntax::{ 3use ra_syntax::{
4 SmolStr, 4 SmolStr,
5 SyntaxNode, 5 SyntaxNode,
6 ast::FnDefNode,
7}; 6};
8use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable}; 7use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable};
9 8
@@ -12,7 +11,6 @@ use crate::{
12 SourceFileItems, SourceItemId, 11 SourceFileItems, SourceItemId,
13 query_definitions, 12 query_definitions,
14 FnScopes, 13 FnScopes,
15 function::FnId,
16 module::{ModuleId, ModuleTree, ModuleSource, 14 module::{ModuleId, ModuleTree, ModuleSource,
17 nameres::{ItemMap, InputModuleItems}}, 15 nameres::{ItemMap, InputModuleItems}},
18 ty::{InferenceResult, Ty}, 16 ty::{InferenceResult, Ty},
@@ -24,14 +22,10 @@ salsa::query_group! {
24pub trait HirDatabase: SyntaxDatabase 22pub trait HirDatabase: SyntaxDatabase
25 + AsRef<LocationIntener<DefLoc, DefId>> 23 + AsRef<LocationIntener<DefLoc, DefId>>
26{ 24{
27 fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> { 25 fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
28 type FnScopesQuery; 26 type FnScopesQuery;
29 use fn query_definitions::fn_scopes; 27 use fn query_definitions::fn_scopes;
30 } 28 }
31 fn fn_syntax(fn_id: FnId) -> FnDefNode {
32 type FnSyntaxQuery;
33 use fn query_definitions::fn_syntax;
34 }
35 29
36 fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> { 30 fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> {
37 type StructDataQuery; 31 type StructDataQuery;
@@ -43,7 +37,7 @@ pub trait HirDatabase: SyntaxDatabase
43 use fn query_definitions::enum_data; 37 use fn query_definitions::enum_data;
44 } 38 }
45 39
46 fn infer(fn_id: FnId) -> Cancelable<Arc<InferenceResult>> { 40 fn infer(def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
47 type InferQuery; 41 type InferQuery;
48 use fn query_definitions::infer; 42 use fn query_definitions::infer;
49 } 43 }
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::{
11 ast::{self, AstNode, DocCommentsOwner, NameOwner}, 11 ast::{self, AstNode, DocCommentsOwner, NameOwner},
12}; 12};
13 13
14use crate::{ DefId, HirDatabase, ty::InferenceResult, Module }; 14use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module};
15 15
16pub use self::scope::FnScopes; 16pub use self::scope::FnScopes;
17 17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
19pub struct FnId(pub(crate) DefId);
20
21#[derive(Debug)] 18#[derive(Debug)]
22pub struct Function { 19pub struct Function {
23 pub(crate) fn_id: FnId, 20 def_id: DefId,
24} 21}
25 22
26impl Function { 23impl Function {
27 pub(crate) fn new(def_id: DefId) -> Function { 24 pub(crate) fn new(def_id: DefId) -> Function {
28 let fn_id = FnId(def_id); 25 Function { def_id }
29 Function { fn_id }
30 } 26 }
31 27
32 pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { 28 pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode {
33 db.fn_syntax(self.fn_id) 29 let def_loc = self.def_id.loc(db);
30 assert!(def_loc.kind == DefKind::Function);
31 let syntax = db.file_item(def_loc.source_item_id);
32 ast::FnDef::cast(syntax.borrowed()).unwrap().owned()
34 } 33 }
35 34
36 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> { 35 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
37 db.fn_scopes(self.fn_id) 36 db.fn_scopes(self.def_id)
38 } 37 }
39 38
40 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { 39 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
41 let syntax = db.fn_syntax(self.fn_id); 40 let syntax = self.syntax(db);
42 FnSignatureInfo::new(syntax.borrowed()) 41 FnSignatureInfo::new(syntax.borrowed())
43 } 42 }
44 43
45 pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { 44 pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> {
46 db.infer(self.fn_id) 45 db.infer(self.def_id)
47 } 46 }
48 47
49 pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> { 48 pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
50 self.fn_id.0.module(db) 49 self.def_id.module(db)
51 } 50 }
52} 51}
53 52
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! {
189 fn file_item() for db::FileItemQuery; 189 fn file_item() for db::FileItemQuery;
190 fn input_module_items() for db::InputModuleItemsQuery; 190 fn input_module_items() for db::InputModuleItemsQuery;
191 fn item_map() for db::ItemMapQuery; 191 fn item_map() for db::ItemMapQuery;
192 fn fn_syntax() for db::FnSyntaxQuery;
193 fn submodules() for db::SubmodulesQuery; 192 fn submodules() for db::SubmodulesQuery;
194 fn infer() for db::InferQuery; 193 fn infer() for db::InferQuery;
195 fn type_for_def() for db::TypeForDefQuery; 194 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::{
5 5
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use ra_syntax::{ 7use ra_syntax::{
8 AstNode, SyntaxNode, SmolStr, 8 AstNode, SyntaxNode, SmolStr,
9 ast::{self, FnDef, FnDefNode, NameOwner, ModuleItemOwner} 9 ast::{self, NameOwner, ModuleItemOwner}
10}; 10};
11use ra_db::{SourceRootId, FileId, Cancelable,}; 11use ra_db::{SourceRootId, FileId, Cancelable,};
12 12
13use crate::{ 13use crate::{
14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, 14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName,
15 db::HirDatabase, 15 db::HirDatabase,
16 function::{FnScopes, FnId}, 16 function::FnScopes,
17 module::{ 17 module::{
18 ModuleSource, ModuleSourceNode, ModuleId, 18 ModuleSource, ModuleSourceNode, ModuleId,
19 imp::Submodule, 19 imp::Submodule,
@@ -23,22 +23,15 @@ use crate::{
23 adt::{StructData, EnumData}, 23 adt::{StructData, EnumData},
24}; 24};
25 25
26/// Resolve `FnId` to the corresponding `SyntaxNode` 26pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
27pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { 27 let function = Function::new(def_id);
28 let def_loc = fn_id.0.loc(db); 28 let syntax = function.syntax(db);
29 assert!(def_loc.kind == DefKind::Function);
30 let syntax = db.file_item(def_loc.source_item_id);
31 FnDef::cast(syntax.borrowed()).unwrap().owned()
32}
33
34pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
35 let syntax = db.fn_syntax(fn_id);
36 let res = FnScopes::new(syntax.borrowed()); 29 let res = FnScopes::new(syntax.borrowed());
37 Arc::new(res) 30 Arc::new(res)
38} 31}
39 32
40pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable<Arc<InferenceResult>> { 33pub(super) fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
41 let function = Function { fn_id }; 34 let function = Function::new(def_id);
42 ty::infer(db, function).map(Arc::new) 35 ty::infer(db, function).map(Arc::new)
43} 36}
44 37