From d4f4ae0dd88f0baf0065d612f41fea3d54af79fd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 18:46:39 +0300 Subject: Move const&static date to hir_def --- crates/ra_hir/src/code_model.rs | 51 +++++------------------------------------ crates/ra_hir/src/db.rs | 18 +++++---------- crates/ra_hir/src/lib.rs | 8 +++---- crates/ra_hir/src/ty/infer.rs | 8 +++---- crates/ra_hir/src/ty/lower.rs | 4 ++-- 5 files changed, 22 insertions(+), 67 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3daf7488e..1b65eefe5 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -10,7 +10,7 @@ use hir_def::{ adt::VariantData, body::scope::ExprScopes, builtin_type::BuiltinType, - data::TraitData, + data::{ConstData, TraitData}, nameres::per_ns::PerNs, resolver::{HasResolver, TypeNs}, type_ref::TypeRef, @@ -22,10 +22,10 @@ use hir_expand::{ name::{self, AsName}, }; use ra_db::{CrateId, Edition}; -use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; +use ra_syntax::ast; use crate::{ - db::{AstDatabase, DefDatabase, HirDatabase}, + db::{DefDatabase, HirDatabase}, expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, ids::{ AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, @@ -645,11 +645,11 @@ impl Const { } pub fn data(self, db: &impl HirDatabase) -> Arc { - db.const_data(self) + db.const_data(self.id) } pub fn name(self, db: &impl HirDatabase) -> Option { - self.data(db).name().cloned() + self.data(db).name.clone() } pub fn infer(self, db: &impl HirDatabase) -> Arc { @@ -681,45 +681,6 @@ impl Const { } } -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct ConstData { - pub(crate) name: Option, - 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 { - let node = konst.source(db).value; - const_data_for(&node) - } - - pub(crate) fn static_data_query( - db: &(impl DefDatabase + AstDatabase), - konst: Static, - ) -> Arc { - let node = konst.source(db).value; - const_data_for(&node) - } -} - -fn const_data_for(node: &N) -> Arc { - 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)] pub struct Static { pub(crate) id: StaticId, @@ -735,7 +696,7 @@ impl Static { } pub fn data(self, db: &impl HirDatabase) -> Arc { - db.static_data(self) + db.static_data(self.id) } pub fn infer(self, db: &impl HirDatabase) -> Arc { diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 8b9af0565..85d46b485 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -16,15 +16,15 @@ use crate::{ CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, TypeCtor, }, - Const, ConstData, Crate, DefWithBody, GenericDef, ImplBlock, Module, Static, StructField, - Trait, + Crate, DefWithBody, GenericDef, ImplBlock, Module, StructField, Trait, }; pub use hir_def::db::{ - BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, - EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, - InternDatabase, InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, - StructDataQuery, TraitDataQuery, TypeAliasDataQuery, + BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, DefDatabase2, + DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, + ImplDataQuery, InternDatabase, InternDatabaseStorage, RawItemsQuery, + RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, + TypeAliasDataQuery, }; pub use hir_expand::db::{ AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, @@ -35,12 +35,6 @@ pub use hir_expand::db::{ #[salsa::query_group(DefDatabaseStorage)] #[salsa::requires(AstDatabase)] pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { - #[salsa::invoke(ConstData::const_data_query)] - fn const_data(&self, konst: Const) -> Arc; - - #[salsa::invoke(ConstData::static_data_query)] - fn static_data(&self, konst: Static) -> Arc; - #[salsa::invoke(LangItems::module_lang_items_query)] fn module_lang_items(&self, module: Module) -> Option>; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index d29cc9258..e164c9b32 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -54,10 +54,10 @@ pub use crate::{ attrs::{AttrDef, HasAttrs}, docs::{DocDef, Docs, Documentation}, src::{HasBodySource, HasSource}, - Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, - EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local, - MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, - TypeAlias, Union, VariantDef, + Adt, AssocItem, Const, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, + FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local, MacroDef, + Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, TypeAlias, + Union, VariantDef, }, expr::ExprScopes, from_source::FromSource, diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 6e07ab86e..39976a359 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -22,7 +22,7 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; use hir_def::{ - data::FunctionData, + data::{ConstData, FunctionData}, path::known, resolver::{HasResolver, Resolver, TypeNs}, type_ref::{Mutability, TypeRef}, @@ -44,8 +44,8 @@ use crate::{ db::HirDatabase, expr::{BindingAnnotation, Body, ExprId, PatId}, ty::infer::diagnostics::InferenceDiagnostic, - Adt, AssocItem, ConstData, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField, - Trait, VariantDef, + Adt, AssocItem, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField, Trait, + VariantDef, }; macro_rules! ty_app { @@ -560,7 +560,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } 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) { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 42daa9cb9..ac7f3f775 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -642,7 +642,7 @@ fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty { let data = def.data(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. @@ -650,7 +650,7 @@ fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty { let data = def.data(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. -- cgit v1.2.3