diff options
author | Aleksey Kladov <[email protected]> | 2019-11-22 15:46:39 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-22 15:46:39 +0000 |
commit | d4f4ae0dd88f0baf0065d612f41fea3d54af79fd (patch) | |
tree | a08c33528a8a1579c9017e43ad3b28042e77f8fe /crates/ra_hir/src | |
parent | b841c53a0c93cdca3f08b1c917c9fa8a63d31604 (diff) |
Move const&static date to hir_def
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 51 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 4 |
5 files changed, 22 insertions, 67 deletions
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::{ | |||
10 | adt::VariantData, | 10 | adt::VariantData, |
11 | body::scope::ExprScopes, | 11 | body::scope::ExprScopes, |
12 | builtin_type::BuiltinType, | 12 | builtin_type::BuiltinType, |
13 | data::TraitData, | 13 | data::{ConstData, TraitData}, |
14 | nameres::per_ns::PerNs, | 14 | nameres::per_ns::PerNs, |
15 | resolver::{HasResolver, TypeNs}, | 15 | resolver::{HasResolver, TypeNs}, |
16 | type_ref::TypeRef, | 16 | type_ref::TypeRef, |
@@ -22,10 +22,10 @@ use hir_expand::{ | |||
22 | name::{self, AsName}, | 22 | name::{self, AsName}, |
23 | }; | 23 | }; |
24 | use ra_db::{CrateId, Edition}; | 24 | use ra_db::{CrateId, Edition}; |
25 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 25 | use ra_syntax::ast; |
26 | 26 | ||
27 | use crate::{ | 27 | use crate::{ |
28 | db::{AstDatabase, DefDatabase, HirDatabase}, | 28 | db::{DefDatabase, HirDatabase}, |
29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, | 29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, |
30 | ids::{ | 30 | ids::{ |
31 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, | 31 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, |
@@ -645,11 +645,11 @@ impl Const { | |||
645 | } | 645 | } |
646 | 646 | ||
647 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | 647 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
648 | db.const_data(self) | 648 | db.const_data(self.id) |
649 | } | 649 | } |
650 | 650 | ||
651 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | 651 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { |
652 | self.data(db).name().cloned() | 652 | self.data(db).name.clone() |
653 | } | 653 | } |
654 | 654 | ||
655 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 655 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
@@ -681,45 +681,6 @@ impl Const { | |||
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
685 | pub struct ConstData { | ||
686 | pub(crate) name: Option<Name>, | ||
687 | pub(crate) type_ref: TypeRef, | ||
688 | } | ||
689 | |||
690 | impl ConstData { | ||
691 | pub fn name(&self) -> Option<&Name> { | ||
692 | self.name.as_ref() | ||
693 | } | ||
694 | |||
695 | pub fn type_ref(&self) -> &TypeRef { | ||
696 | &self.type_ref | ||
697 | } | ||
698 | |||
699 | pub(crate) fn const_data_query( | ||
700 | db: &(impl DefDatabase + AstDatabase), | ||
701 | konst: Const, | ||
702 | ) -> Arc<ConstData> { | ||
703 | let node = konst.source(db).value; | ||
704 | const_data_for(&node) | ||
705 | } | ||
706 | |||
707 | pub(crate) fn static_data_query( | ||
708 | db: &(impl DefDatabase + AstDatabase), | ||
709 | konst: Static, | ||
710 | ) -> Arc<ConstData> { | ||
711 | let node = konst.source(db).value; | ||
712 | const_data_for(&node) | ||
713 | } | ||
714 | } | ||
715 | |||
716 | fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { | ||
717 | let name = node.name().map(|n| n.as_name()); | ||
718 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); | ||
719 | let sig = ConstData { name, type_ref }; | ||
720 | Arc::new(sig) | ||
721 | } | ||
722 | |||
723 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 684 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
724 | pub struct Static { | 685 | pub struct Static { |
725 | pub(crate) id: StaticId, | 686 | pub(crate) id: StaticId, |
@@ -735,7 +696,7 @@ impl Static { | |||
735 | } | 696 | } |
736 | 697 | ||
737 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | 698 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
738 | db.static_data(self) | 699 | db.static_data(self.id) |
739 | } | 700 | } |
740 | 701 | ||
741 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 702 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
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::{ | |||
16 | CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, | 16 | CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, |
17 | TypeCtor, | 17 | TypeCtor, |
18 | }, | 18 | }, |
19 | Const, ConstData, Crate, DefWithBody, GenericDef, ImplBlock, Module, Static, StructField, | 19 | Crate, DefWithBody, GenericDef, ImplBlock, Module, StructField, Trait, |
20 | Trait, | ||
21 | }; | 20 | }; |
22 | 21 | ||
23 | pub use hir_def::db::{ | 22 | pub use hir_def::db::{ |
24 | BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, | 23 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, DefDatabase2, |
25 | EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, | 24 | DefDatabase2Storage, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, |
26 | InternDatabase, InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, | 25 | ImplDataQuery, InternDatabase, InternDatabaseStorage, RawItemsQuery, |
27 | StructDataQuery, TraitDataQuery, TypeAliasDataQuery, | 26 | RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, |
27 | TypeAliasDataQuery, | ||
28 | }; | 28 | }; |
29 | pub use hir_expand::db::{ | 29 | pub use hir_expand::db::{ |
30 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 30 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
@@ -35,12 +35,6 @@ pub use hir_expand::db::{ | |||
35 | #[salsa::query_group(DefDatabaseStorage)] | 35 | #[salsa::query_group(DefDatabaseStorage)] |
36 | #[salsa::requires(AstDatabase)] | 36 | #[salsa::requires(AstDatabase)] |
37 | pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { | 37 | pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { |
38 | #[salsa::invoke(ConstData::const_data_query)] | ||
39 | fn const_data(&self, konst: Const) -> Arc<ConstData>; | ||
40 | |||
41 | #[salsa::invoke(ConstData::static_data_query)] | ||
42 | fn static_data(&self, konst: Static) -> Arc<ConstData>; | ||
43 | |||
44 | #[salsa::invoke(LangItems::module_lang_items_query)] | 38 | #[salsa::invoke(LangItems::module_lang_items_query)] |
45 | fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>; | 39 | fn module_lang_items(&self, module: Module) -> Option<Arc<LangItems>>; |
46 | 40 | ||
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::{ | |||
54 | attrs::{AttrDef, HasAttrs}, | 54 | attrs::{AttrDef, HasAttrs}, |
55 | docs::{DocDef, Docs, Documentation}, | 55 | docs::{DocDef, Docs, Documentation}, |
56 | src::{HasBodySource, HasSource}, | 56 | src::{HasBodySource, HasSource}, |
57 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 57 | Adt, AssocItem, Const, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, |
58 | EnumVariant, FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local, | 58 | FieldSource, Function, GenericDef, GenericParam, HasBody, ImplBlock, Local, MacroDef, |
59 | MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, | 59 | Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, TypeAlias, |
60 | TypeAlias, Union, VariantDef, | 60 | Union, VariantDef, |
61 | }, | 61 | }, |
62 | expr::ExprScopes, | 62 | expr::ExprScopes, |
63 | from_source::FromSource, | 63 | 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}; | |||
22 | use rustc_hash::FxHashMap; | 22 | use rustc_hash::FxHashMap; |
23 | 23 | ||
24 | use hir_def::{ | 24 | use hir_def::{ |
25 | data::FunctionData, | 25 | data::{ConstData, FunctionData}, |
26 | path::known, | 26 | path::known, |
27 | resolver::{HasResolver, Resolver, TypeNs}, | 27 | resolver::{HasResolver, Resolver, TypeNs}, |
28 | type_ref::{Mutability, TypeRef}, | 28 | type_ref::{Mutability, TypeRef}, |
@@ -44,8 +44,8 @@ use crate::{ | |||
44 | db::HirDatabase, | 44 | db::HirDatabase, |
45 | expr::{BindingAnnotation, Body, ExprId, PatId}, | 45 | expr::{BindingAnnotation, Body, ExprId, PatId}, |
46 | ty::infer::diagnostics::InferenceDiagnostic, | 46 | ty::infer::diagnostics::InferenceDiagnostic, |
47 | Adt, AssocItem, ConstData, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField, | 47 | Adt, AssocItem, DefWithBody, FloatTy, Function, HasBody, IntTy, Path, StructField, Trait, |
48 | Trait, VariantDef, | 48 | VariantDef, |
49 | }; | 49 | }; |
50 | 50 | ||
51 | macro_rules! ty_app { | 51 | macro_rules! ty_app { |
@@ -560,7 +560,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
560 | } | 560 | } |
561 | 561 | ||
562 | fn collect_const(&mut self, data: &ConstData) { | 562 | fn collect_const(&mut self, data: &ConstData) { |
563 | self.return_ty = self.make_ty(data.type_ref()); | 563 | self.return_ty = self.make_ty(&data.type_ref); |
564 | } | 564 | } |
565 | 565 | ||
566 | fn collect_fn(&mut self, data: &FunctionData) { | 566 | 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 { | |||
642 | let data = def.data(db); | 642 | let data = def.data(db); |
643 | let resolver = def.id.resolver(db); | 643 | let resolver = def.id.resolver(db); |
644 | 644 | ||
645 | Ty::from_hir(db, &resolver, data.type_ref()) | 645 | Ty::from_hir(db, &resolver, &data.type_ref) |
646 | } | 646 | } |
647 | 647 | ||
648 | /// Build the declared type of a static. | 648 | /// Build the declared type of a static. |
@@ -650,7 +650,7 @@ fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty { | |||
650 | let data = def.data(db); | 650 | let data = def.data(db); |
651 | let resolver = def.id.resolver(db); | 651 | let resolver = def.id.resolver(db); |
652 | 652 | ||
653 | Ty::from_hir(db, &resolver, data.type_ref()) | 653 | Ty::from_hir(db, &resolver, &data.type_ref) |
654 | } | 654 | } |
655 | 655 | ||
656 | /// Build the declared type of a static. | 656 | /// Build the declared type of a static. |