diff options
author | cynecx <[email protected]> | 2021-03-20 17:29:30 +0000 |
---|---|---|
committer | cynecx <[email protected]> | 2021-03-20 17:29:30 +0000 |
commit | 30980396afa713a7b877c7962c5b45329230cdc5 (patch) | |
tree | 212d7454063dad760f4fefa629c9376a5b4c0836 /crates/hir_ty/src | |
parent | edfd741c5bdd9bbc044e3e362f5b446db7d817ef (diff) |
hir_ty: add field_visibilities and fn_visibility queries
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/db.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 27 |
2 files changed, 33 insertions, 4 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index 91a2e0b5b..b1d22a9f9 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs | |||
@@ -4,8 +4,8 @@ use std::sync::Arc; | |||
4 | 4 | ||
5 | use base_db::{impl_intern_key, salsa, CrateId, Upcast}; | 5 | use base_db::{impl_intern_key, salsa, CrateId, Upcast}; |
6 | use hir_def::{ | 6 | use hir_def::{ |
7 | db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId, | 7 | db::DefDatabase, expr::ExprId, visibility::Visibility, ConstParamId, DefWithBodyId, FunctionId, |
8 | LocalFieldId, TypeParamId, VariantId, | 8 | GenericDefId, ImplId, LocalFieldId, TypeParamId, VariantId, |
9 | }; | 9 | }; |
10 | use la_arena::ArenaMap; | 10 | use la_arena::ArenaMap; |
11 | 11 | ||
@@ -128,6 +128,12 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { | |||
128 | krate: CrateId, | 128 | krate: CrateId, |
129 | env: chalk_ir::Environment<chalk::Interner>, | 129 | env: chalk_ir::Environment<chalk::Interner>, |
130 | ) -> chalk_ir::ProgramClauses<chalk::Interner>; | 130 | ) -> chalk_ir::ProgramClauses<chalk::Interner>; |
131 | |||
132 | #[salsa::invoke(crate::lower::field_visibilities_query)] | ||
133 | fn field_visibilities(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Visibility>>; | ||
134 | |||
135 | #[salsa::invoke(crate::lower::fn_visibility_query)] | ||
136 | fn fn_visibility(&self, def: FunctionId) -> Visibility; | ||
131 | } | 137 | } |
132 | 138 | ||
133 | fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { | 139 | fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { |
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index cbbb535e5..c4062a41d 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -16,9 +16,10 @@ use hir_def::{ | |||
16 | path::{GenericArg, Path, PathSegment, PathSegments}, | 16 | path::{GenericArg, Path, PathSegment, PathSegments}, |
17 | resolver::{HasResolver, Resolver, TypeNs}, | 17 | resolver::{HasResolver, Resolver, TypeNs}, |
18 | type_ref::{TypeBound, TypeRef}, | 18 | type_ref::{TypeBound, TypeRef}, |
19 | visibility::Visibility, | ||
19 | AdtId, AssocContainerId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId, | 20 | AdtId, AssocContainerId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId, |
20 | GenericDefId, HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, | 21 | GenericDefId, HasModule, ImplId, LocalFieldId, Lookup, ModuleDefId, StaticId, StructId, |
21 | TypeAliasId, TypeParamId, UnionId, VariantId, | 22 | TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, |
22 | }; | 23 | }; |
23 | use hir_expand::name::Name; | 24 | use hir_expand::name::Name; |
24 | use la_arena::ArenaMap; | 25 | use la_arena::ArenaMap; |
@@ -867,6 +868,28 @@ pub(crate) fn field_types_query( | |||
867 | Arc::new(res) | 868 | Arc::new(res) |
868 | } | 869 | } |
869 | 870 | ||
871 | /// Resolve visibility of all specific fields of a struct or union variant. | ||
872 | pub(crate) fn field_visibilities_query( | ||
873 | db: &dyn HirDatabase, | ||
874 | variant_id: VariantId, | ||
875 | ) -> Arc<ArenaMap<LocalFieldId, Visibility>> { | ||
876 | let def_db = db.upcast(); | ||
877 | let var_data = variant_data(def_db, variant_id); | ||
878 | let resolver = variant_id.module(def_db).resolver(def_db); | ||
879 | let mut res = ArenaMap::default(); | ||
880 | for (field_id, field_data) in var_data.fields().iter() { | ||
881 | res.insert(field_id, field_data.visibility.resolve(def_db, &resolver)) | ||
882 | } | ||
883 | Arc::new(res) | ||
884 | } | ||
885 | |||
886 | /// Resolve visibility of a function. | ||
887 | pub(crate) fn fn_visibility_query(db: &dyn HirDatabase, def: FunctionId) -> Visibility { | ||
888 | let def_db = db.upcast(); | ||
889 | let resolver = ModuleDefId::from(def).module(def_db).unwrap().resolver(def_db); | ||
890 | db.function_data(def).visibility.resolve(def_db, &resolver) | ||
891 | } | ||
892 | |||
870 | /// This query exists only to be used when resolving short-hand associated types | 893 | /// This query exists only to be used when resolving short-hand associated types |
871 | /// like `T::Item`. | 894 | /// like `T::Item`. |
872 | /// | 895 | /// |