aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-20 17:39:00 +0000
committerGitHub <[email protected]>2019-11-20 17:39:00 +0000
commit7a5fd1f3f3c4a8f64407f9bd08a3d5e7f79417e0 (patch)
tree5a16aa6fbc213909a5d7be3c852fa2a6b9c62299
parentc51dcb1c4bdd71f9f17de508bd0d47e3c06ae1d5 (diff)
parentcb642fc578100c0945088accb85acb8f03d2e1fd (diff)
Merge #2328
2328: Move generic_params query to HIR r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_hir/src/db.rs10
-rw-r--r--crates/ra_hir/src/generics.rs19
-rw-r--r--crates/ra_hir_def/src/db.rs6
-rw-r--r--crates/ra_hir_def/src/generics.rs29
4 files changed, 37 insertions, 27 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 5bb7961b3..a9982a70f 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -8,7 +8,7 @@ use ra_syntax::SmolStr;
8 8
9use crate::{ 9use crate::{
10 debug::HirDebugDatabase, 10 debug::HirDebugDatabase,
11 generics::{GenericDef, GenericParams}, 11 generics::GenericDef,
12 ids, 12 ids,
13 lang_item::{LangItemTarget, LangItems}, 13 lang_item::{LangItemTarget, LangItems},
14 ty::{ 14 ty::{
@@ -24,8 +24,9 @@ use crate::{
24 24
25pub use hir_def::db::{ 25pub use hir_def::db::{
26 BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, 26 BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
27 EnumDataQuery, ExprScopesQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, 27 EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase,
28 RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, TraitDataQuery, 28 InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery,
29 TraitDataQuery,
29}; 30};
30pub use hir_expand::db::{ 31pub use hir_expand::db::{
31 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, 32 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
@@ -36,9 +37,6 @@ pub use hir_expand::db::{
36#[salsa::query_group(DefDatabaseStorage)] 37#[salsa::query_group(DefDatabaseStorage)]
37#[salsa::requires(AstDatabase)] 38#[salsa::requires(AstDatabase)]
38pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { 39pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
39 #[salsa::invoke(crate::generics::generic_params_query)]
40 fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
41
42 #[salsa::invoke(FnData::fn_data_query)] 40 #[salsa::invoke(FnData::fn_data_query)]
43 fn fn_data(&self, func: Function) -> Arc<FnData>; 41 fn fn_data(&self, func: Function) -> Arc<FnData>;
44 42
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index caedb90e6..54ed03642 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -2,7 +2,7 @@
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use crate::{ 4use crate::{
5 db::{AstDatabase, DefDatabase, HirDatabase}, 5 db::{DefDatabase, HirDatabase},
6 Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, TypeAlias, Union, 6 Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, TypeAlias, Union,
7}; 7};
8 8
@@ -31,21 +31,6 @@ impl_froms!(
31 Const 31 Const
32); 32);
33 33
34pub(crate) fn generic_params_query(
35 db: &(impl DefDatabase + AstDatabase),
36 def: GenericDef,
37) -> Arc<GenericParams> {
38 let parent = match def {
39 GenericDef::Function(it) => it.container(db).map(GenericDef::from),
40 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
41 GenericDef::Const(it) => it.container(db).map(GenericDef::from),
42 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
43 GenericDef::Adt(_) | GenericDef::Trait(_) => None,
44 GenericDef::ImplBlock(_) => None,
45 };
46 Arc::new(GenericParams::new(db, def.into(), parent.map(|it| db.generic_params(it))))
47}
48
49impl GenericDef { 34impl GenericDef {
50 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { 35 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver {
51 match self { 36 match self {
@@ -78,6 +63,6 @@ where
78 T: Into<GenericDef> + Copy, 63 T: Into<GenericDef> + Copy,
79{ 64{
80 fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams> { 65 fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams> {
81 db.generic_params(self.into()) 66 db.generic_params(self.into().into())
82 } 67 }
83} 68}
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index c6cd4369b..844f8bbe8 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -8,13 +8,14 @@ use ra_syntax::ast;
8use crate::{ 8use crate::{
9 adt::{EnumData, StructData}, 9 adt::{EnumData, StructData},
10 body::{scope::ExprScopes, Body, BodySourceMap}, 10 body::{scope::ExprScopes, Body, BodySourceMap},
11 generics::GenericParams,
11 impls::ImplData, 12 impls::ImplData,
12 nameres::{ 13 nameres::{
13 raw::{ImportSourceMap, RawItems}, 14 raw::{ImportSourceMap, RawItems},
14 CrateDefMap, 15 CrateDefMap,
15 }, 16 },
16 traits::TraitData, 17 traits::TraitData,
17 DefWithBodyId, EnumId, ImplId, ItemLoc, StructOrUnionId, TraitId, 18 DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId,
18}; 19};
19 20
20#[salsa::query_group(InternDatabaseStorage)] 21#[salsa::query_group(InternDatabaseStorage)]
@@ -71,4 +72,7 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
71 72
72 #[salsa::invoke(ExprScopes::expr_scopes_query)] 73 #[salsa::invoke(ExprScopes::expr_scopes_query)]
73 fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>; 74 fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
75
76 #[salsa::invoke(GenericParams::generic_params_query)]
77 fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>;
74} 78}
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 17a5d5f43..f794eefbc 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -5,13 +5,12 @@
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use hir_expand::name::{self, AsName, Name}; 7use hir_expand::name::{self, AsName, Name};
8
9use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
10 9
11use crate::{ 10use crate::{
12 db::DefDatabase2, 11 db::DefDatabase2,
13 type_ref::{TypeBound, TypeRef}, 12 type_ref::{TypeBound, TypeRef},
14 AdtId, AstItemDef, GenericDefId, HasSource, Lookup, 13 AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
15}; 14};
16 15
17/// Data about a generic parameter (to a function, struct, impl, ...). 16/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -43,7 +42,15 @@ pub struct WherePredicate {
43} 42}
44 43
45impl GenericParams { 44impl GenericParams {
46 pub fn new( 45 pub(crate) fn generic_params_query(
46 db: &impl DefDatabase2,
47 def: GenericDefId,
48 ) -> Arc<GenericParams> {
49 let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it));
50 Arc::new(GenericParams::new(db, def.into(), parent_generics))
51 }
52
53 fn new(
47 db: &impl DefDatabase2, 54 db: &impl DefDatabase2,
48 def: GenericDefId, 55 def: GenericDefId,
49 parent_params: Option<Arc<GenericParams>>, 56 parent_params: Option<Arc<GenericParams>>,
@@ -161,3 +168,19 @@ impl GenericParams {
161 vec 168 vec
162 } 169 }
163} 170}
171
172fn parent_generic_def(db: &impl DefDatabase2, def: GenericDefId) -> Option<GenericDefId> {
173 let container = match def {
174 GenericDefId::FunctionId(it) => it.lookup(db).container,
175 GenericDefId::TypeAliasId(it) => it.lookup(db).container,
176 GenericDefId::ConstId(it) => it.lookup(db).container,
177 GenericDefId::EnumVariantId(it) => return Some(it.parent.into()),
178 GenericDefId::AdtId(_) | GenericDefId::TraitId(_) | GenericDefId::ImplId(_) => return None,
179 };
180
181 match container {
182 ContainerId::ImplId(it) => Some(it.into()),
183 ContainerId::TraitId(it) => Some(it.into()),
184 ContainerId::ModuleId(_) => None,
185 }
186}