public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] privacy: reachability: Cleanup Struct definition visitor
@ 2022-06-08 12:31 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:cdfb5b34ac243c9c3c7c5b24f9a7409e0ebd459f
commit cdfb5b34ac243c9c3c7c5b24f9a7409e0ebd459f
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Tue Apr 12 16:33:29 2022 +0200
privacy: reachability: Cleanup Struct definition visitor
Diff:
---
gcc/rust/privacy/rust-reachability.cc | 67 ++++++++++++++++++-----------------
gcc/rust/privacy/rust-reachability.h | 8 +++++
2 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/gcc/rust/privacy/rust-reachability.cc b/gcc/rust/privacy/rust-reachability.cc
index 82a48271177..ea7ca247e2f 100644
--- a/gcc/rust/privacy/rust-reachability.cc
+++ b/gcc/rust/privacy/rust-reachability.cc
@@ -31,6 +31,38 @@ maybe_get_vis_item (std::unique_ptr<HIR::Item> &item)
return static_cast<HIR::VisItem *> (item.get ());
}
+void
+ReachabilityVisitor::visit_generic_predicates (
+ const std::vector<std::unique_ptr<HIR::GenericParam>> &generics,
+ ReachLevel item_reach)
+{
+ if (item_reach == ReachLevel::Unreachable)
+ return;
+
+ for (auto &generic : generics)
+ {
+ if (generic->get_kind () == HIR::GenericParam::TYPE)
+ {
+ TyTy::BaseType *generic_ty = nullptr;
+ rust_assert (
+ ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
+ &generic_ty));
+
+ // FIXME: Can we really get anything else than a TyTy::PARAM here?
+ // Should we change this to an assertion instead?
+ if (generic_ty->get_kind () == TyTy::PARAM)
+ {
+ auto generic_param = static_cast<TyTy::ParamType *> (generic_ty);
+ for (const auto &bound : generic_param->get_specified_bounds ())
+ {
+ const auto trait = bound.get ()->get_hir_trait_ref ();
+ ctx.update_reachability (trait->get_mappings (), item_reach);
+ }
+ }
+ }
+ }
+}
+
void
ReachabilityVisitor::visit (HIR::Module &mod)
{
@@ -75,41 +107,10 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item)
auto old_level = current_level;
current_level = struct_reach;
+ visit_generic_predicates (struct_item.get_generic_params (), struct_reach);
+
if (struct_reach != ReachLevel::Unreachable)
{
- for (auto &field : struct_item.get_fields ())
- if (field.get_visibility ().is_public ())
- ctx.update_reachability (field.get_mappings (), struct_reach);
-
- for (auto &generic : struct_item.get_generic_params ())
- {
- switch (generic->get_kind ())
- {
- case HIR::GenericParam::LIFETIME:
- break;
- case HIR::GenericParam::TYPE:
- TyTy::BaseType *generic_ty = nullptr;
- rust_assert (
- ty_ctx.lookup_type (generic->get_mappings ().get_hirid (),
- &generic_ty));
-
- if (generic_ty->get_kind () == TyTy::PARAM)
- {
- auto generic_param
- = static_cast<TyTy::ParamType *> (generic_ty);
- for (const auto &bound :
- generic_param->get_specified_bounds ())
- {
- const auto trait = bound.get ()->get_hir_trait_ref ();
- ctx.update_reachability (trait->get_mappings (),
- struct_reach);
- }
- }
-
- break;
- }
- }
-
for (auto &field : struct_item.get_fields ())
if (field.get_visibility ().is_public ())
ctx.update_reachability (field.get_field_type ()->get_mappings (),
diff --git a/gcc/rust/privacy/rust-reachability.h b/gcc/rust/privacy/rust-reachability.h
index 75ed2699df6..8d740c8f062 100644
--- a/gcc/rust/privacy/rust-reachability.h
+++ b/gcc/rust/privacy/rust-reachability.h
@@ -46,6 +46,14 @@ public:
: current_level (ReachLevel::Reachable), ctx (ctx), ty_ctx (ty_ctx)
{}
+ /**
+ * Visit all the predicates of all the generic types of a given item, marking
+ * them as reachable or not.
+ */
+ void visit_generic_predicates (
+ const std::vector<std::unique_ptr<HIR::GenericParam>> &generics,
+ ReachLevel item_reach);
+
virtual void visit (HIR::Module &mod);
virtual void visit (HIR::ExternCrate &crate);
virtual void visit (HIR::UseDeclaration &use_decl);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:31 [gcc/devel/rust/master] privacy: reachability: Cleanup Struct definition visitor Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).