aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs53
-rw-r--r--crates/ra_hir/src/db.rs18
-rw-r--r--crates/ra_hir/src/lib.rs8
-rw-r--r--crates/ra_hir/src/ty/infer.rs16
-rw-r--r--crates/ra_hir/src/ty/lower.rs8
5 files changed, 25 insertions, 78 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 3daf7488e..af07b2c4d 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -22,10 +22,10 @@ use hir_expand::{
22 name::{self, AsName}, 22 name::{self, AsName},
23}; 23};
24use ra_db::{CrateId, Edition}; 24use ra_db::{CrateId, Edition};
25use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 25use ra_syntax::ast;
26 26
27use crate::{ 27use 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,
@@ -644,12 +644,8 @@ impl Const {
644 Some(self.module(db).krate()) 644 Some(self.module(db).krate())
645 } 645 }
646 646
647 pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
648 db.const_data(self)
649 }
650
651 pub fn name(self, db: &impl HirDatabase) -> Option<Name> { 647 pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
652 self.data(db).name().cloned() 648 db.const_data(self.id).name.clone()
653 } 649 }
654 650
655 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { 651 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
@@ -681,45 +677,6 @@ impl Const {
681 } 677 }
682} 678}
683 679
684#[derive(Debug, Clone, PartialEq, Eq)]
685pub struct ConstData {
686 pub(crate) name: Option<Name>,
687 pub(crate) type_ref: TypeRef,
688}
689
690impl 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
716fn 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)] 680#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
724pub struct Static { 681pub struct Static {
725 pub(crate) id: StaticId, 682 pub(crate) id: StaticId,
@@ -734,10 +691,6 @@ impl Static {
734 Some(self.module(db).krate()) 691 Some(self.module(db).krate())
735 } 692 }
736 693
737 pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> {
738 db.static_data(self)
739 }
740
741 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { 694 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
742 db.infer(self.into()) 695 db.infer(self.into())
743 } 696 }
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
23pub use hir_def::db::{ 22pub 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};
29pub use hir_expand::db::{ 29pub 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)]
37pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { 37pub 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..471bdc387 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};
22use rustc_hash::FxHashMap; 22use rustc_hash::FxHashMap;
23 23
24use hir_def::{ 24use 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
51macro_rules! ty_app { 51macro_rules! ty_app {
@@ -69,10 +69,10 @@ pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResu
69 let resolver = DefWithBodyId::from(def).resolver(db); 69 let resolver = DefWithBodyId::from(def).resolver(db);
70 let mut ctx = InferenceContext::new(db, def, resolver); 70 let mut ctx = InferenceContext::new(db, def, resolver);
71 71
72 match def { 72 match &def {
73 DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)), 73 DefWithBody::Const(c) => ctx.collect_const(&db.const_data(c.id)),
74 DefWithBody::Function(ref f) => ctx.collect_fn(&db.function_data(f.id)), 74 DefWithBody::Function(f) => ctx.collect_fn(&db.function_data(f.id)),
75 DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)), 75 DefWithBody::Static(s) => ctx.collect_const(&db.static_data(s.id)),
76 } 76 }
77 77
78 ctx.infer_body(); 78 ctx.infer_body();
@@ -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..2272510e8 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -639,18 +639,18 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty {
639 639
640/// Build the declared type of a const. 640/// Build the declared type of a const.
641fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty { 641fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty {
642 let data = def.data(db); 642 let data = db.const_data(def.id);
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.
649fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty { 649fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty {
650 let data = def.data(db); 650 let data = db.static_data(def.id);
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.