From 6294fd5ec9c6946bdd91f1274956c573f9f2a136 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Nov 2019 15:34:00 +0300 Subject: Unfork struct and union ids --- crates/ra_hir_def/src/adt.rs | 16 ++++++---------- crates/ra_hir_def/src/db.rs | 12 ++++-------- crates/ra_hir_def/src/lib.rs | 28 ++++++++++++++++------------ crates/ra_hir_def/src/nameres/collector.rs | 11 +++++++---- 4 files changed, 33 insertions(+), 34 deletions(-) (limited to 'crates/ra_hir_def') 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}; use crate::{ db::DefDatabase2, type_ref::TypeRef, AstItemDef, EnumId, LocalEnumVariantId, - LocalStructFieldId, StructId, UnionId, + LocalStructFieldId, StructOrUnionId, }; /// Note that we use `StructData` for unions as well! @@ -49,15 +49,11 @@ pub struct StructFieldData { } impl StructData { - pub(crate) fn struct_data_query(db: &impl DefDatabase2, struct_: StructId) -> Arc { - let src = struct_.source(db); - let name = src.ast.name().map(|n| n.as_name()); - let variant_data = VariantData::new(src.ast.kind()); - let variant_data = Arc::new(variant_data); - Arc::new(StructData { name, variant_data }) - } - pub(crate) fn union_data_query(db: &impl DefDatabase2, struct_: UnionId) -> Arc { - let src = struct_.source(db); + pub(crate) fn struct_data_query( + db: &impl DefDatabase2, + id: StructOrUnionId, + ) -> Arc { + let src = id.source(db); let name = src.ast.name().map(|n| n.as_name()); let variant_data = VariantData::new(src.ast.kind()); 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::{ raw::{ImportSourceMap, RawItems}, CrateDefMap, }, - EnumId, StructId, UnionId, + EnumId, StructOrUnionId, }; #[salsa::query_group(InternDatabaseStorage)] @@ -19,9 +19,8 @@ pub trait InternDatabase: SourceDatabase { #[salsa::interned] fn intern_function(&self, loc: crate::ItemLoc) -> crate::FunctionId; #[salsa::interned] - fn intern_struct(&self, loc: crate::ItemLoc) -> crate::StructId; - #[salsa::interned] - fn intern_union(&self, loc: crate::ItemLoc) -> crate::UnionId; + fn intern_struct_or_union(&self, loc: crate::ItemLoc) + -> crate::StructOrUnionId; #[salsa::interned] fn intern_enum(&self, loc: crate::ItemLoc) -> crate::EnumId; #[salsa::interned] @@ -49,10 +48,7 @@ pub trait DefDatabase2: InternDatabase + AstDatabase { fn crate_def_map(&self, krate: CrateId) -> Arc; #[salsa::invoke(StructData::struct_data_query)] - fn struct_data(&self, s: StructId) -> Arc; - - #[salsa::invoke(StructData::union_data_query)] - fn union_data(&self, s: UnionId) -> Arc; + fn struct_data(&self, id: StructOrUnionId) -> Arc; #[salsa::invoke(EnumData::enum_data_query)] fn enum_data(&self, e: EnumId) -> Arc; 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 for FunctionId { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct StructId(salsa::InternId); -impl_intern_key!(StructId); -impl AstItemDef for StructId { +pub struct StructOrUnionId(salsa::InternId); +impl_intern_key!(StructOrUnionId); +impl AstItemDef for StructOrUnionId { fn intern(db: &impl InternDatabase, loc: ItemLoc) -> Self { - db.intern_struct(loc) + db.intern_struct_or_union(loc) } fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc { - db.lookup_intern_struct(self) + db.lookup_intern_struct_or_union(self) } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct UnionId(salsa::InternId); -impl_intern_key!(UnionId); -impl AstItemDef for UnionId { - fn intern(db: &impl InternDatabase, loc: ItemLoc) -> Self { - db.intern_union(loc) +pub struct StructId(pub StructOrUnionId); +impl From for StructOrUnionId { + fn from(id: StructId) -> StructOrUnionId { + id.0 } - fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc { - db.lookup_intern_union(self) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct UnionId(pub StructOrUnionId); +impl From for StructOrUnionId { + fn from(id: UnionId) -> StructOrUnionId { + id.0 } } 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::{ }, path::{Path, PathKind}, AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionId, - LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, UnionId, + LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, StructOrUnionId, TraitId, TypeAliasId, + UnionId, }; pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { @@ -664,12 +665,14 @@ where PerNs::values(FunctionId::from_ast_id(ctx, ast_id).into()) } raw::DefKind::Struct(ast_id) => { - let s = StructId::from_ast_id(ctx, ast_id).into(); + let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); + let s = StructId(id).into(); PerNs::both(s, s) } raw::DefKind::Union(ast_id) => { - let s = UnionId::from_ast_id(ctx, ast_id).into(); - PerNs::both(s, s) + let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); + let u = UnionId(id).into(); + PerNs::both(u, u) } raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), raw::DefKind::Const(ast_id) => PerNs::values(ConstId::from_ast_id(ctx, ast_id).into()), -- cgit v1.2.3