diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-09 12:37:49 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-09 12:37:49 +0000 |
commit | 9d786ea221b27fbdf7c7f7beea0290db448e0611 (patch) | |
tree | 312ae071afe742011c1e396d63123729e31f9815 /crates/ra_hir_def | |
parent | defc7ad772123a449f7cc384dd46d88c3a45fb53 (diff) | |
parent | 6294fd5ec9c6946bdd91f1274956c573f9f2a136 (diff) |
Merge #2198
2198: Unfork struct and union ids r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 11 |
4 files changed, 33 insertions, 34 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 8f41e55d2..a29c4d41e 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -8,7 +8,7 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | db::DefDatabase2, type_ref::TypeRef, AstItemDef, EnumId, LocalEnumVariantId, | 10 | db::DefDatabase2, type_ref::TypeRef, AstItemDef, EnumId, LocalEnumVariantId, |
11 | LocalStructFieldId, StructId, UnionId, | 11 | LocalStructFieldId, StructOrUnionId, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | /// Note that we use `StructData` for unions as well! | 14 | /// Note that we use `StructData` for unions as well! |
@@ -49,15 +49,11 @@ pub struct StructFieldData { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | impl StructData { | 51 | impl StructData { |
52 | pub(crate) fn struct_data_query(db: &impl DefDatabase2, struct_: StructId) -> Arc<StructData> { | 52 | pub(crate) fn struct_data_query( |
53 | let src = struct_.source(db); | 53 | db: &impl DefDatabase2, |
54 | let name = src.ast.name().map(|n| n.as_name()); | 54 | id: StructOrUnionId, |
55 | let variant_data = VariantData::new(src.ast.kind()); | 55 | ) -> Arc<StructData> { |
56 | let variant_data = Arc::new(variant_data); | 56 | let src = id.source(db); |
57 | Arc::new(StructData { name, variant_data }) | ||
58 | } | ||
59 | pub(crate) fn union_data_query(db: &impl DefDatabase2, struct_: UnionId) -> Arc<StructData> { | ||
60 | let src = struct_.source(db); | ||
61 | let name = src.ast.name().map(|n| n.as_name()); | 57 | let name = src.ast.name().map(|n| n.as_name()); |
62 | let variant_data = VariantData::new(src.ast.kind()); | 58 | let variant_data = VariantData::new(src.ast.kind()); |
63 | let variant_data = Arc::new(variant_data); | 59 | let variant_data = Arc::new(variant_data); |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index a42348101..29cf71a59 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -11,7 +11,7 @@ use crate::{ | |||
11 | raw::{ImportSourceMap, RawItems}, | 11 | raw::{ImportSourceMap, RawItems}, |
12 | CrateDefMap, | 12 | CrateDefMap, |
13 | }, | 13 | }, |
14 | EnumId, StructId, UnionId, | 14 | EnumId, StructOrUnionId, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | #[salsa::query_group(InternDatabaseStorage)] | 17 | #[salsa::query_group(InternDatabaseStorage)] |
@@ -19,9 +19,8 @@ pub trait InternDatabase: SourceDatabase { | |||
19 | #[salsa::interned] | 19 | #[salsa::interned] |
20 | fn intern_function(&self, loc: crate::ItemLoc<ast::FnDef>) -> crate::FunctionId; | 20 | fn intern_function(&self, loc: crate::ItemLoc<ast::FnDef>) -> crate::FunctionId; |
21 | #[salsa::interned] | 21 | #[salsa::interned] |
22 | fn intern_struct(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::StructId; | 22 | fn intern_struct_or_union(&self, loc: crate::ItemLoc<ast::StructDef>) |
23 | #[salsa::interned] | 23 | -> crate::StructOrUnionId; |
24 | fn intern_union(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::UnionId; | ||
25 | #[salsa::interned] | 24 | #[salsa::interned] |
26 | fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId; | 25 | fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId; |
27 | #[salsa::interned] | 26 | #[salsa::interned] |
@@ -49,10 +48,7 @@ pub trait DefDatabase2: InternDatabase + AstDatabase { | |||
49 | fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>; | 48 | fn crate_def_map(&self, krate: CrateId) -> Arc<CrateDefMap>; |
50 | 49 | ||
51 | #[salsa::invoke(StructData::struct_data_query)] | 50 | #[salsa::invoke(StructData::struct_data_query)] |
52 | fn struct_data(&self, s: StructId) -> Arc<StructData>; | 51 | fn struct_data(&self, id: StructOrUnionId) -> Arc<StructData>; |
53 | |||
54 | #[salsa::invoke(StructData::union_data_query)] | ||
55 | fn union_data(&self, s: UnionId) -> Arc<StructData>; | ||
56 | 52 | ||
57 | #[salsa::invoke(EnumData::enum_data_query)] | 53 | #[salsa::invoke(EnumData::enum_data_query)] |
58 | fn enum_data(&self, e: EnumId) -> Arc<EnumData>; | 54 | fn enum_data(&self, e: EnumId) -> Arc<EnumData>; |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 63ed2a098..239317efe 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -205,26 +205,30 @@ impl AstItemDef<ast::FnDef> for FunctionId { | |||
205 | } | 205 | } |
206 | 206 | ||
207 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 207 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
208 | pub struct StructId(salsa::InternId); | 208 | pub struct StructOrUnionId(salsa::InternId); |
209 | impl_intern_key!(StructId); | 209 | impl_intern_key!(StructOrUnionId); |
210 | impl AstItemDef<ast::StructDef> for StructId { | 210 | impl AstItemDef<ast::StructDef> for StructOrUnionId { |
211 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self { | 211 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self { |
212 | db.intern_struct(loc) | 212 | db.intern_struct_or_union(loc) |
213 | } | 213 | } |
214 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> { | 214 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> { |
215 | db.lookup_intern_struct(self) | 215 | db.lookup_intern_struct_or_union(self) |
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 219 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
220 | pub struct UnionId(salsa::InternId); | 220 | pub struct StructId(pub StructOrUnionId); |
221 | impl_intern_key!(UnionId); | 221 | impl From<StructId> for StructOrUnionId { |
222 | impl AstItemDef<ast::StructDef> for UnionId { | 222 | fn from(id: StructId) -> StructOrUnionId { |
223 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self { | 223 | id.0 |
224 | db.intern_union(loc) | ||
225 | } | 224 | } |
226 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> { | 225 | } |
227 | db.lookup_intern_union(self) | 226 | |
227 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
228 | pub struct UnionId(pub StructOrUnionId); | ||
229 | impl From<UnionId> for StructOrUnionId { | ||
230 | fn from(id: UnionId) -> StructOrUnionId { | ||
231 | id.0 | ||
228 | } | 232 | } |
229 | } | 233 | } |
230 | 234 | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index aacd50df8..7e6083961 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -19,7 +19,8 @@ use crate::{ | |||
19 | }, | 19 | }, |
20 | path::{Path, PathKind}, | 20 | path::{Path, PathKind}, |
21 | AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionId, | 21 | AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionId, |
22 | LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, UnionId, | 22 | LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, StructOrUnionId, TraitId, TypeAliasId, |
23 | UnionId, | ||
23 | }; | 24 | }; |
24 | 25 | ||
25 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { | 26 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -664,12 +665,14 @@ where | |||
664 | PerNs::values(FunctionId::from_ast_id(ctx, ast_id).into()) | 665 | PerNs::values(FunctionId::from_ast_id(ctx, ast_id).into()) |
665 | } | 666 | } |
666 | raw::DefKind::Struct(ast_id) => { | 667 | raw::DefKind::Struct(ast_id) => { |
667 | let s = StructId::from_ast_id(ctx, ast_id).into(); | 668 | let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); |
669 | let s = StructId(id).into(); | ||
668 | PerNs::both(s, s) | 670 | PerNs::both(s, s) |
669 | } | 671 | } |
670 | raw::DefKind::Union(ast_id) => { | 672 | raw::DefKind::Union(ast_id) => { |
671 | let s = UnionId::from_ast_id(ctx, ast_id).into(); | 673 | let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); |
672 | PerNs::both(s, s) | 674 | let u = UnionId(id).into(); |
675 | PerNs::both(u, u) | ||
673 | } | 676 | } |
674 | raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), | 677 | raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), |
675 | raw::DefKind::Const(ast_id) => PerNs::values(ConstId::from_ast_id(ctx, ast_id).into()), | 678 | raw::DefKind::Const(ast_id) => PerNs::values(ConstId::from_ast_id(ctx, ast_id).into()), |