mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 04:45:05 +00:00
Move const&static date to hir_def
This commit is contained in:
parent
b841c53a0c
commit
d4f4ae0dd8
7 changed files with 58 additions and 72 deletions
|
@ -10,7 +10,7 @@ use hir_def::{
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
body::scope::ExprScopes,
|
body::scope::ExprScopes,
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
data::TraitData,
|
data::{ConstData, TraitData},
|
||||||
nameres::per_ns::PerNs,
|
nameres::per_ns::PerNs,
|
||||||
resolver::{HasResolver, TypeNs},
|
resolver::{HasResolver, TypeNs},
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
|
@ -22,10 +22,10 @@ use hir_expand::{
|
||||||
name::{self, AsName},
|
name::{self, AsName},
|
||||||
};
|
};
|
||||||
use ra_db::{CrateId, Edition};
|
use ra_db::{CrateId, Edition};
|
||||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
db::{DefDatabase, HirDatabase},
|
||||||
expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
|
expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
|
||||||
ids::{
|
ids::{
|
||||||
AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
|
AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
|
||||||
|
@ -645,11 +645,11 @@ impl Const {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
||||||
db.const_data(self)
|
db.const_data(self.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||||
self.data(db).name().cloned()
|
self.data(db).name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
||||||
|
@ -681,45 +681,6 @@ impl Const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub struct ConstData {
|
|
||||||
pub(crate) name: Option<Name>,
|
|
||||||
pub(crate) type_ref: TypeRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ConstData {
|
|
||||||
pub fn name(&self) -> Option<&Name> {
|
|
||||||
self.name.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn type_ref(&self) -> &TypeRef {
|
|
||||||
&self.type_ref
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn const_data_query(
|
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
konst: Const,
|
|
||||||
) -> Arc<ConstData> {
|
|
||||||
let node = konst.source(db).value;
|
|
||||||
const_data_for(&node)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn static_data_query(
|
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
konst: Static,
|
|
||||||
) -> Arc<ConstData> {
|
|
||||||
let node = konst.source(db).value;
|
|
||||||
const_data_for(&node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
|
|
||||||
let name = node.name().map(|n| n.as_name());
|
|
||||||
let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
|
|
||||||
let sig = ConstData { name, type_ref };
|
|
||||||
Arc::new(sig)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Static {
|
pub struct Static {
|
||||||
pub(crate) id: StaticId,
|
pub(crate) id: StaticId,
|
||||||
|
@ -735,7 +696,7 @@ impl Static {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
|
||||||
db.static_data(self)
|
db.static_data(self.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
||||||
|
|
|
@ -16,15 +16,15 @@ use crate::{
|
||||||
CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
|
CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef,
|
||||||
TypeCtor,
|
TypeCtor,
|
||||||
},
|
},
|
||||||
Const, ConstData, Crate, DefWithBody, GenericDef, ImplBlock, Module, Static, StructField,
|
Crate, DefWithBody, GenericDef, ImplBlock, Module, StructField, Trait,
|
||||||
Trait,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use hir_def::db::{
|
pub use hir_def::db::{
|
||||||
BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
|
BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, DefDatabase2,
|
||||||
EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery,
|
DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery,
|
||||||
InternDatabase, InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery,
|
ImplDataQuery, InternDatabase, InternDatabaseStorage, RawItemsQuery,
|
||||||
StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
|
RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery,
|
||||||
|
TypeAliasDataQuery,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
|
||||||
|
@ -35,12 +35,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(ConstData::const_data_query)]
|
|
||||||
fn const_data(&self, konst: Const) -> Arc<ConstData>;
|
|
||||||
|
|
||||||
#[salsa::invoke(ConstData::static_data_query)]
|
|
||||||
fn static_data(&self, konst: Static) -> Arc<ConstData>;
|
|
||||||
|
|
||||||
#[salsa::invoke(LangItems::module_lang_items_query)]
|
#[salsa::invoke(LangItems::module_lang_items_query)]
|
||||||
fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>;
|
fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>;
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,10 @@ pub use crate::{
|
||||||
attrs::{AttrDef, HasAttrs},
|
attrs::{AttrDef, HasAttrs},
|
||||||
docs::{DocDef, Docs, Documentation},
|
docs::{DocDef, Docs, Documentation},
|
||||||
src::{HasBodySource, HasSource},
|
src::{HasBodySource, HasSource},
|
||||||
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
Adt, AssocItem, Const, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant,
|
||||||
EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local,
|
FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local, MacroDef,
|
||||||
MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait,
|
Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, TypeAlias,
|
||||||
TypeAlias, Union, VariantDef,
|
Union, VariantDef,
|
||||||
},
|
},
|
||||||
expr::ExprScopes,
|
expr::ExprScopes,
|
||||||
from_source::FromSource,
|
from_source::FromSource,
|
||||||
|
|
|
@ -22,7 +22,7 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
data::FunctionData,
|
data::{ConstData, FunctionData},
|
||||||
path::known,
|
path::known,
|
||||||
resolver::{HasResolver, Resolver, TypeNs},
|
resolver::{HasResolver, Resolver, TypeNs},
|
||||||
type_ref::{Mutability, TypeRef},
|
type_ref::{Mutability, TypeRef},
|
||||||
|
@ -44,8 +44,8 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
expr::{BindingAnnotation, Body, ExprId, PatId},
|
expr::{BindingAnnotation, Body, ExprId, PatId},
|
||||||
ty::infer::diagnostics::InferenceDiagnostic,
|
ty::infer::diagnostics::InferenceDiagnostic,
|
||||||
Adt, AssocItem, ConstData, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField,
|
Adt, AssocItem, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField, Trait,
|
||||||
Trait, VariantDef,
|
VariantDef,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! ty_app {
|
macro_rules! ty_app {
|
||||||
|
@ -560,7 +560,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_const(&mut self, data: &ConstData) {
|
fn collect_const(&mut self, data: &ConstData) {
|
||||||
self.return_ty = self.make_ty(data.type_ref());
|
self.return_ty = self.make_ty(&data.type_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_fn(&mut self, data: &FunctionData) {
|
fn collect_fn(&mut self, data: &FunctionData) {
|
||||||
|
|
|
@ -642,7 +642,7 @@ fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty {
|
||||||
let data = def.data(db);
|
let data = def.data(db);
|
||||||
let resolver = def.id.resolver(db);
|
let resolver = def.id.resolver(db);
|
||||||
|
|
||||||
Ty::from_hir(db, &resolver, data.type_ref())
|
Ty::from_hir(db, &resolver, &data.type_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the declared type of a static.
|
/// Build the declared type of a static.
|
||||||
|
@ -650,7 +650,7 @@ fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty {
|
||||||
let data = def.data(db);
|
let data = def.data(db);
|
||||||
let resolver = def.id.resolver(db);
|
let resolver = def.id.resolver(db);
|
||||||
|
|
||||||
Ty::from_hir(db, &resolver, data.type_ref())
|
Ty::from_hir(db, &resolver, &data.type_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the declared type of a static.
|
/// Build the declared type of a static.
|
||||||
|
|
|
@ -11,8 +11,8 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase2,
|
db::DefDatabase2,
|
||||||
type_ref::{Mutability, TypeRef},
|
type_ref::{Mutability, TypeRef},
|
||||||
AssocItemId, AstItemDef, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, ImplId,
|
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource,
|
||||||
Intern, Lookup, TraitId, TypeAliasId, TypeAliasLoc,
|
ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -190,3 +190,28 @@ impl ImplData {
|
||||||
Arc::new(res)
|
Arc::new(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ConstData {
|
||||||
|
pub name: Option<Name>,
|
||||||
|
pub type_ref: TypeRef,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConstData {
|
||||||
|
pub(crate) fn const_data_query(db: &impl DefDatabase2, konst: ConstId) -> Arc<ConstData> {
|
||||||
|
let node = konst.lookup(db).source(db).value;
|
||||||
|
const_data_for(&node)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn static_data_query(db: &impl DefDatabase2, konst: StaticId) -> Arc<ConstData> {
|
||||||
|
let node = konst.source(db).value;
|
||||||
|
const_data_for(&node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> {
|
||||||
|
let name = node.name().map(|n| n.as_name());
|
||||||
|
let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
|
||||||
|
let sig = ConstData { name, type_ref };
|
||||||
|
Arc::new(sig)
|
||||||
|
}
|
||||||
|
|
|
@ -8,14 +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},
|
||||||
data::{FunctionData, ImplData, TraitData, TypeAliasData},
|
data::{ConstData, FunctionData, ImplData, TraitData, TypeAliasData},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
nameres::{
|
nameres::{
|
||||||
raw::{ImportSourceMap, RawItems},
|
raw::{ImportSourceMap, RawItems},
|
||||||
CrateDefMap,
|
CrateDefMap,
|
||||||
},
|
},
|
||||||
DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId,
|
ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, ImplId, ItemLoc, StaticId,
|
||||||
TypeAliasId,
|
StructOrUnionId, TraitId, TypeAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group(InternDatabaseStorage)]
|
#[salsa::query_group(InternDatabaseStorage)]
|
||||||
|
@ -70,6 +70,12 @@ pub trait DefDatabase2: InternDatabase + AstDatabase {
|
||||||
#[salsa::invoke(FunctionData::fn_data_query)]
|
#[salsa::invoke(FunctionData::fn_data_query)]
|
||||||
fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
|
fn function_data(&self, func: FunctionId) -> Arc<FunctionData>;
|
||||||
|
|
||||||
|
#[salsa::invoke(ConstData::const_data_query)]
|
||||||
|
fn const_data(&self, konst: ConstId) -> Arc<ConstData>;
|
||||||
|
|
||||||
|
#[salsa::invoke(ConstData::static_data_query)]
|
||||||
|
fn static_data(&self, konst: StaticId) -> Arc<ConstData>;
|
||||||
|
|
||||||
#[salsa::invoke(Body::body_with_source_map_query)]
|
#[salsa::invoke(Body::body_with_source_map_query)]
|
||||||
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
|
fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue