public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] privacy: reachability: Cleanup Struct definition visitor Date: Wed, 8 Jun 2022 12:31:11 +0000 (GMT) [thread overview] Message-ID: <20220608123111.8D9573888789@sourceware.org> (raw) 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);
reply other threads:[~2022-06-08 12:31 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608123111.8D9573888789@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).