diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/child_by_source.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/docs.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/keys.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/src.rs | 13 |
10 files changed, 58 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index db3e63ef8..ef2b20f1e 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -11,8 +11,9 @@ use ra_arena::{map::ArenaMap, Arena}; | |||
11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db::DefDatabase, src::HasChildSource, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, | 14 | db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, |
15 | LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId, | 15 | AstItemDef, EnumId, LocalEnumVariantId, LocalStructFieldId, Lookup, StructId, UnionId, |
16 | VariantId, | ||
16 | }; | 17 | }; |
17 | 18 | ||
18 | /// Note that we use `StructData` for unions as well! | 19 | /// Note that we use `StructData` for unions as well! |
@@ -50,7 +51,7 @@ pub struct StructFieldData { | |||
50 | 51 | ||
51 | impl StructData { | 52 | impl StructData { |
52 | pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> { | 53 | pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> { |
53 | let src = id.source(db); | 54 | let src = id.lookup(db).source(db); |
54 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 55 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
55 | let variant_data = VariantData::new(src.value.kind()); | 56 | let variant_data = VariantData::new(src.value.kind()); |
56 | let variant_data = Arc::new(variant_data); | 57 | let variant_data = Arc::new(variant_data); |
@@ -153,7 +154,7 @@ impl HasChildSource for VariantId { | |||
153 | let src = it.parent.child_source(db); | 154 | let src = it.parent.child_source(db); |
154 | src.map(|map| map[it.local_id].kind()) | 155 | src.map(|map| map[it.local_id].kind()) |
155 | } | 156 | } |
156 | VariantId::StructId(it) => it.source(db).map(|it| it.kind()), | 157 | VariantId::StructId(it) => it.lookup(db).source(db).map(|it| it.kind()), |
157 | VariantId::UnionId(it) => it.source(db).map(|it| { | 158 | VariantId::UnionId(it) => it.source(db).map(|it| { |
158 | it.record_field_def_list() | 159 | it.record_field_def_list() |
159 | .map(ast::StructKind::Record) | 160 | .map(ast::StructKind::Record) |
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 3347d819c..d2aa5ce8f 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -56,7 +56,7 @@ impl Attrs { | |||
56 | Attrs::from_attrs_owner(db, src.map(|it| it as &dyn AttrsOwner)) | 56 | Attrs::from_attrs_owner(db, src.map(|it| it as &dyn AttrsOwner)) |
57 | } | 57 | } |
58 | AttrDefId::AdtId(it) => match it { | 58 | AttrDefId::AdtId(it) => match it { |
59 | AdtId::StructId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 59 | AdtId::StructId(it) => attrs_from_loc(it.lookup(db), db), |
60 | AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 60 | AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), |
61 | AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 61 | AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), |
62 | }, | 62 | }, |
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs index 88c2d3f24..eba361578 100644 --- a/crates/ra_hir_def/src/child_by_source.rs +++ b/crates/ra_hir_def/src/child_by_source.rs | |||
@@ -11,8 +11,8 @@ use crate::{ | |||
11 | dyn_map::DynMap, | 11 | dyn_map::DynMap, |
12 | keys, | 12 | keys, |
13 | src::{HasChildSource, HasSource}, | 13 | src::{HasChildSource, HasSource}, |
14 | AssocItemId, EnumId, EnumVariantId, ImplId, Lookup, ModuleDefId, ModuleId, StructFieldId, | 14 | AdtId, AssocItemId, EnumId, EnumVariantId, ImplId, Lookup, ModuleDefId, ModuleId, |
15 | TraitId, VariantId, | 15 | StructFieldId, TraitId, VariantId, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | pub trait ChildBySource { | 18 | pub trait ChildBySource { |
@@ -98,6 +98,14 @@ impl ChildBySource for ModuleId { | |||
98 | let src = trait_.lookup(db).source(db); | 98 | let src = trait_.lookup(db).source(db); |
99 | res[keys::TRAIT].insert(src, trait_) | 99 | res[keys::TRAIT].insert(src, trait_) |
100 | } | 100 | } |
101 | ModuleDefId::AdtId(adt) => match adt { | ||
102 | AdtId::StructId(strukt) => { | ||
103 | let src = strukt.lookup(db).source(db); | ||
104 | res[keys::STRUCT].insert(src, strukt) | ||
105 | } | ||
106 | AdtId::UnionId(_) => (), | ||
107 | AdtId::EnumId(_) => (), | ||
108 | }, | ||
101 | _ => (), | 109 | _ => (), |
102 | } | 110 | } |
103 | } | 111 | } |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index f0c2ae559..e120c7768 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -18,8 +18,8 @@ use crate::{ | |||
18 | CrateDefMap, | 18 | CrateDefMap, |
19 | }, | 19 | }, |
20 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId, | 20 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId, |
21 | ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, TraitId, TraitLoc, | 21 | ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, |
22 | TypeAliasId, TypeAliasLoc, UnionId, | 22 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[salsa::query_group(InternDatabaseStorage)] | 25 | #[salsa::query_group(InternDatabaseStorage)] |
@@ -27,7 +27,7 @@ pub trait InternDatabase: SourceDatabase { | |||
27 | #[salsa::interned] | 27 | #[salsa::interned] |
28 | fn intern_function(&self, loc: FunctionLoc) -> FunctionId; | 28 | fn intern_function(&self, loc: FunctionLoc) -> FunctionId; |
29 | #[salsa::interned] | 29 | #[salsa::interned] |
30 | fn intern_struct(&self, loc: ItemLoc<ast::StructDef>) -> StructId; | 30 | fn intern_struct(&self, loc: StructLoc) -> StructId; |
31 | #[salsa::interned] | 31 | #[salsa::interned] |
32 | fn intern_union(&self, loc: ItemLoc<ast::UnionDef>) -> UnionId; | 32 | fn intern_union(&self, loc: ItemLoc<ast::UnionDef>) -> UnionId; |
33 | #[salsa::interned] | 33 | #[salsa::interned] |
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs index 1921681fb..58143b894 100644 --- a/crates/ra_hir_def/src/docs.rs +++ b/crates/ra_hir_def/src/docs.rs | |||
@@ -51,7 +51,7 @@ impl Documentation { | |||
51 | } | 51 | } |
52 | } | 52 | } |
53 | AttrDefId::AdtId(it) => match it { | 53 | AttrDefId::AdtId(it) => match it { |
54 | AdtId::StructId(it) => docs_from_ast(&it.source(db).value), | 54 | AdtId::StructId(it) => docs_from_ast(&it.lookup(db).source(db).value), |
55 | AdtId::EnumId(it) => docs_from_ast(&it.source(db).value), | 55 | AdtId::EnumId(it) => docs_from_ast(&it.source(db).value), |
56 | AdtId::UnionId(it) => docs_from_ast(&it.source(db).value), | 56 | AdtId::UnionId(it) => docs_from_ast(&it.source(db).value), |
57 | }, | 57 | }, |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index cbfc3ff04..f1ce8d59a 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -71,7 +71,7 @@ impl GenericParams { | |||
71 | src.file_id | 71 | src.file_id |
72 | } | 72 | } |
73 | GenericDefId::AdtId(AdtId::StructId(it)) => { | 73 | GenericDefId::AdtId(AdtId::StructId(it)) => { |
74 | let src = it.source(db); | 74 | let src = it.lookup(db).source(db); |
75 | generics.fill(&mut sm, &src.value); | 75 | generics.fill(&mut sm, &src.value); |
76 | src.file_id | 76 | src.file_id |
77 | } | 77 | } |
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index 6ec58f5f9..758cf8097 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs | |||
@@ -8,8 +8,8 @@ use rustc_hash::FxHashMap; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | dyn_map::{DynMap, Policy}, | 10 | dyn_map::{DynMap, Policy}, |
11 | ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, TraitId, TypeAliasId, | 11 | ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId, |
12 | TypeParamId, | 12 | TypeAliasId, TypeParamId, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; | 15 | type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; |
@@ -20,6 +20,7 @@ pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new(); | |||
20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); | 20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); |
21 | pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new(); | 21 | pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new(); |
22 | pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new(); | 22 | pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new(); |
23 | pub const STRUCT: Key<ast::StructDef, StructId> = Key::new(); | ||
23 | 24 | ||
24 | pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); | 25 | pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); |
25 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); | 26 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 0fcc2cde4..1a599706a 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -149,12 +149,24 @@ impl Lookup for FunctionId { | |||
149 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 149 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
150 | pub struct StructId(salsa::InternId); | 150 | pub struct StructId(salsa::InternId); |
151 | impl_intern_key!(StructId); | 151 | impl_intern_key!(StructId); |
152 | impl AstItemDef<ast::StructDef> for StructId { | 152 | |
153 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self { | 153 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
154 | db.intern_struct(loc) | 154 | pub struct StructLoc { |
155 | pub container: ModuleId, | ||
156 | pub ast_id: AstId<ast::StructDef>, | ||
157 | } | ||
158 | |||
159 | impl Intern for StructLoc { | ||
160 | type ID = StructId; | ||
161 | fn intern(self, db: &impl db::DefDatabase) -> StructId { | ||
162 | db.intern_struct(self) | ||
155 | } | 163 | } |
156 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> { | 164 | } |
157 | db.lookup_intern_struct(self) | 165 | |
166 | impl Lookup for StructId { | ||
167 | type Data = StructLoc; | ||
168 | fn lookup(&self, db: &impl db::DefDatabase) -> StructLoc { | ||
169 | db.lookup_intern_struct(*self) | ||
158 | } | 170 | } |
159 | } | 171 | } |
160 | 172 | ||
@@ -532,7 +544,7 @@ impl HasModule for ConstLoc { | |||
532 | impl HasModule for AdtId { | 544 | impl HasModule for AdtId { |
533 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 545 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
534 | match self { | 546 | match self { |
535 | AdtId::StructId(it) => it.module(db), | 547 | AdtId::StructId(it) => it.lookup(db).container, |
536 | AdtId::UnionId(it) => it.module(db), | 548 | AdtId::UnionId(it) => it.module(db), |
537 | AdtId::EnumId(it) => it.module(db), | 549 | AdtId::EnumId(it) => it.module(db), |
538 | } | 550 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index a7bdd620b..602ec0911 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -25,7 +25,7 @@ use crate::{ | |||
25 | path::{Path, PathKind}, | 25 | path::{Path, PathKind}, |
26 | per_ns::PerNs, | 26 | per_ns::PerNs, |
27 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplLoc, | 27 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplLoc, |
28 | Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, | 28 | Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructLoc, |
29 | TraitLoc, TypeAliasLoc, UnionId, | 29 | TraitLoc, TypeAliasLoc, UnionId, |
30 | }; | 30 | }; |
31 | 31 | ||
@@ -773,8 +773,9 @@ where | |||
773 | PerNs::values(def.into()) | 773 | PerNs::values(def.into()) |
774 | } | 774 | } |
775 | raw::DefKind::Struct(ast_id) => { | 775 | raw::DefKind::Struct(ast_id) => { |
776 | let id = StructId::from_ast_id(ctx, ast_id).into(); | 776 | let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } |
777 | PerNs::both(id, id) | 777 | .intern(self.def_collector.db); |
778 | PerNs::both(def.into(), def.into()) | ||
778 | } | 779 | } |
779 | raw::DefKind::Union(ast_id) => { | 780 | raw::DefKind::Union(ast_id) => { |
780 | let id = UnionId::from_ast_id(ctx, ast_id).into(); | 781 | let id = UnionId::from_ast_id(ctx, ast_id).into(); |
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs index 858e4861e..7e212adb1 100644 --- a/crates/ra_hir_def/src/src.rs +++ b/crates/ra_hir_def/src/src.rs | |||
@@ -4,7 +4,9 @@ use hir_expand::InFile; | |||
4 | use ra_arena::map::ArenaMap; | 4 | use ra_arena::map::ArenaMap; |
5 | use ra_syntax::ast; | 5 | use ra_syntax::ast; |
6 | 6 | ||
7 | use crate::{db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, TraitLoc, TypeAliasLoc}; | 7 | use crate::{ |
8 | db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, | ||
9 | }; | ||
8 | 10 | ||
9 | pub trait HasSource { | 11 | pub trait HasSource { |
10 | type Value; | 12 | type Value; |
@@ -65,6 +67,15 @@ impl HasSource for TraitLoc { | |||
65 | } | 67 | } |
66 | } | 68 | } |
67 | 69 | ||
70 | impl HasSource for StructLoc { | ||
71 | type Value = ast::StructDef; | ||
72 | |||
73 | fn source(&self, db: &impl DefDatabase) -> InFile<ast::StructDef> { | ||
74 | let node = self.ast_id.to_node(db); | ||
75 | InFile::new(self.ast_id.file_id, node) | ||
76 | } | ||
77 | } | ||
78 | |||
68 | pub trait HasChildSource { | 79 | pub trait HasChildSource { |
69 | type ChildId; | 80 | type ChildId; |
70 | type Value; | 81 | type Value; |