mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Move generic_params query to HIR
This commit is contained in:
parent
c51dcb1c4b
commit
cb642fc578
4 changed files with 37 additions and 27 deletions
|
@ -8,7 +8,7 @@ use ra_syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
debug::HirDebugDatabase,
|
debug::HirDebugDatabase,
|
||||||
generics::{GenericDef, GenericParams},
|
generics::GenericDef,
|
||||||
ids,
|
ids,
|
||||||
lang_item::{LangItemTarget, LangItems},
|
lang_item::{LangItemTarget, LangItems},
|
||||||
ty::{
|
ty::{
|
||||||
|
@ -24,8 +24,9 @@ use crate::{
|
||||||
|
|
||||||
pub use hir_def::db::{
|
pub use hir_def::db::{
|
||||||
BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
|
BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
|
||||||
EnumDataQuery, ExprScopesQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
|
EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase,
|
||||||
RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, TraitDataQuery,
|
InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery,
|
||||||
|
TraitDataQuery,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||||
|
@ -36,9 +37,6 @@ pub use hir_expand::db::{
|
||||||
#[salsa::query_group(DefDatabaseStorage)]
|
#[salsa::query_group(DefDatabaseStorage)]
|
||||||
#[salsa::requires(AstDatabase)]
|
#[salsa::requires(AstDatabase)]
|
||||||
pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
|
pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
|
||||||
#[salsa::invoke(crate::generics::generic_params_query)]
|
|
||||||
fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
|
|
||||||
|
|
||||||
#[salsa::invoke(FnData::fn_data_query)]
|
#[salsa::invoke(FnData::fn_data_query)]
|
||||||
fn fn_data(&self, func: Function) -> Arc<FnData>;
|
fn fn_data(&self, func: Function) -> Arc<FnData>;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
db::{DefDatabase, HirDatabase},
|
||||||
Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, TypeAlias, Union,
|
Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait, TypeAlias, Union,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,21 +31,6 @@ impl_froms!(
|
||||||
Const
|
Const
|
||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) fn generic_params_query(
|
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
def: GenericDef,
|
|
||||||
) -> Arc<GenericParams> {
|
|
||||||
let parent = match def {
|
|
||||||
GenericDef::Function(it) => it.container(db).map(GenericDef::from),
|
|
||||||
GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
|
|
||||||
GenericDef::Const(it) => it.container(db).map(GenericDef::from),
|
|
||||||
GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
|
|
||||||
GenericDef::Adt(_) | GenericDef::Trait(_) => None,
|
|
||||||
GenericDef::ImplBlock(_) => None,
|
|
||||||
};
|
|
||||||
Arc::new(GenericParams::new(db, def.into(), parent.map(|it| db.generic_params(it))))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GenericDef {
|
impl GenericDef {
|
||||||
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver {
|
||||||
match self {
|
match self {
|
||||||
|
@ -78,6 +63,6 @@ where
|
||||||
T: Into<GenericDef> + Copy,
|
T: Into<GenericDef> + Copy,
|
||||||
{
|
{
|
||||||
fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams> {
|
fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams> {
|
||||||
db.generic_params(self.into())
|
db.generic_params(self.into().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,14 @@ use ra_syntax::ast;
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::{EnumData, StructData},
|
adt::{EnumData, StructData},
|
||||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||||
|
generics::GenericParams,
|
||||||
impls::ImplData,
|
impls::ImplData,
|
||||||
nameres::{
|
nameres::{
|
||||||
raw::{ImportSourceMap, RawItems},
|
raw::{ImportSourceMap, RawItems},
|
||||||
CrateDefMap,
|
CrateDefMap,
|
||||||
},
|
},
|
||||||
traits::TraitData,
|
traits::TraitData,
|
||||||
DefWithBodyId, EnumId, ImplId, ItemLoc, StructOrUnionId, TraitId,
|
DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group(InternDatabaseStorage)]
|
#[salsa::query_group(InternDatabaseStorage)]
|
||||||
|
@ -71,4 +72,7 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
|
||||||
|
|
||||||
#[salsa::invoke(ExprScopes::expr_scopes_query)]
|
#[salsa::invoke(ExprScopes::expr_scopes_query)]
|
||||||
fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
|
fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>;
|
||||||
|
|
||||||
|
#[salsa::invoke(GenericParams::generic_params_query)]
|
||||||
|
fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_expand::name::{self, AsName, Name};
|
use hir_expand::name::{self, AsName, Name};
|
||||||
|
|
||||||
use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
|
use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase2,
|
db::DefDatabase2,
|
||||||
type_ref::{TypeBound, TypeRef},
|
type_ref::{TypeBound, TypeRef},
|
||||||
AdtId, AstItemDef, GenericDefId, HasSource, Lookup,
|
AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||||
|
@ -43,7 +42,15 @@ pub struct WherePredicate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GenericParams {
|
impl GenericParams {
|
||||||
pub fn new(
|
pub(crate) fn generic_params_query(
|
||||||
|
db: &impl DefDatabase2,
|
||||||
|
def: GenericDefId,
|
||||||
|
) -> Arc<GenericParams> {
|
||||||
|
let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it));
|
||||||
|
Arc::new(GenericParams::new(db, def.into(), parent_generics))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new(
|
||||||
db: &impl DefDatabase2,
|
db: &impl DefDatabase2,
|
||||||
def: GenericDefId,
|
def: GenericDefId,
|
||||||
parent_params: Option<Arc<GenericParams>>,
|
parent_params: Option<Arc<GenericParams>>,
|
||||||
|
@ -161,3 +168,19 @@ impl GenericParams {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parent_generic_def(db: &impl DefDatabase2, def: GenericDefId) -> Option<GenericDefId> {
|
||||||
|
let container = match def {
|
||||||
|
GenericDefId::FunctionId(it) => it.lookup(db).container,
|
||||||
|
GenericDefId::TypeAliasId(it) => it.lookup(db).container,
|
||||||
|
GenericDefId::ConstId(it) => it.lookup(db).container,
|
||||||
|
GenericDefId::EnumVariantId(it) => return Some(it.parent.into()),
|
||||||
|
GenericDefId::AdtId(_) | GenericDefId::TraitId(_) | GenericDefId::ImplId(_) => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
match container {
|
||||||
|
ContainerId::ImplId(it) => Some(it.into()),
|
||||||
|
ContainerId::TraitId(it) => Some(it.into()),
|
||||||
|
ContainerId::ModuleId(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue