]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr1.0: Remove support in privacy checker
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 23 Aug 2025 17:29:54 +0000 (13:29 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:44 +0000 (20:58 +0100)
gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-check.cc: Adjust includes.
(Resolver::resolve): Pass 2.0 name resolution context to
VisibilityResolver and PrivacyReporter.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::PrivacyReporter): Change type of resolver
parameter.
(is_child_module): Remove static function.
(PrivacyReporter::check_for_privacy_violation): Assume nr2.0 is
enabled and handle removal of is_child_module.
* checks/errors/privacy/rust-privacy-reporter.h: Adjust
includes.
(PrivacyReporter::PrivacyReporter): Change type of resolver
parameter.
(PrivacyReporter::resolver): Change member variable type.
* checks/errors/privacy/rust-visibility-resolver.cc: Adjust
includes.
(VisibilityResolver::VisibilityResolver): Change type of
resolver parameter.
(VisibilityResolver::resolve_module_path): Assume nr2.0 is
enabled.
* checks/errors/privacy/rust-visibility-resolver.h: Adjust
includes.
(VisibilityResolver::VisibilityResolver): Change type of
resolver parameter.
(VisibilityResolver::resolver): Change member variable type.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/checks/errors/privacy/rust-privacy-check.cc
gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
gcc/rust/checks/errors/privacy/rust-visibility-resolver.h

index 5291276a7a378cf9606ff298c311e1925524158d..90248d31b8d3ef14dfb119034d5b57a4aa72c048 100644 (file)
@@ -20,7 +20,7 @@
 #include "rust-reachability.h"
 #include "rust-hir-type-check.h"
 #include "rust-hir-map.h"
-#include "rust-name-resolver.h"
+#include "rust-immutable-name-resolution-context.h"
 #include "rust-visibility-resolver.h"
 #include "rust-pub-restricted-visitor.h"
 #include "rust-privacy-reporter.h"
@@ -35,12 +35,13 @@ Resolver::resolve (HIR::Crate &crate)
 {
   PrivacyContext ctx;
   auto &mappings = Analysis::Mappings::get ();
-  auto resolver = Rust::Resolver::Resolver::get ();
+  auto &resolver
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
   auto ty_ctx = ::Rust::Resolver::TypeCheckContext::get ();
 
-  VisibilityResolver (mappings, *resolver).go (crate);
+  VisibilityResolver (mappings, resolver).go (crate);
   PubRestrictedVisitor (mappings).go (crate);
-  PrivacyReporter (mappings, *resolver, *ty_ctx).go (crate);
+  PrivacyReporter (mappings, resolver, *ty_ctx).go (crate);
 
   auto visitor = ReachabilityVisitor (ctx, *ty_ctx);
 
index 4af9639c38ff25bb7a178978de9744fb1608e8b4..c1a3d4501636df8ee62c66b73a0e830eaa4c1bd8 100644 (file)
@@ -28,7 +28,8 @@ namespace Rust {
 namespace Privacy {
 
 PrivacyReporter::PrivacyReporter (
-  Analysis::Mappings &mappings, Resolver::Resolver &resolver,
+  Analysis::Mappings &mappings,
+  const Resolver2_0::NameResolutionContext &resolver,
   const Rust::Resolver::TypeCheckContext &ty_ctx)
   : mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
     current_module (tl::nullopt)
@@ -90,59 +91,18 @@ PrivacyReporter::go (HIR::Crate &crate)
     }
 }
 
-static bool
-is_child_module (Analysis::Mappings &mappings, NodeId parent,
-                NodeId possible_child)
-{
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      return nr_ctx.values.is_module_descendant (parent, possible_child);
-    }
-
-  auto children = mappings.lookup_module_children (parent);
-
-  if (!children)
-    return false;
-
-  // Visit all toplevel children
-  for (auto &child : *children)
-    if (child == possible_child)
-      return true;
-
-  // Now descend recursively in the child module tree
-  for (auto &child : *children)
-    if (is_child_module (mappings, child, possible_child))
-      return true;
-
-  return false;
-}
-
 // FIXME: This function needs a lot of refactoring
 void
 PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
                                              const location_t locus)
 {
-  NodeId ref_node_id = UNKNOWN_NODEID;
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      if (auto id = nr_ctx.lookup (use_id))
-       ref_node_id = *id;
-    }
-  // FIXME: Don't assert here - we might be dealing with a type
-  else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
-    resolver.lookup_resolved_type (use_id, &ref_node_id);
+  NodeId ref_node_id;
 
   // FIXME: Assert here. For now, we return since this causes issues when
   // checking inferred types (#1260)
-  // rust_assert (ref_node_id != UNKNOWN_NODEID);
-  if (ref_node_id == UNKNOWN_NODEID)
+  if (auto id = resolver.lookup (use_id))
+    ref_node_id = *id;
+  else
     return;
 
   auto vis = mappings.lookup_visibility (ref_node_id);
@@ -175,7 +135,9 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
 
        // FIXME: This needs a LOT of TLC: hinting about the definition, a
        // string to say if it's a module, function, type, etc...
-       if (!is_child_module (mappings, mod_node_id, current_module.value ()))
+
+       if (!resolver.values.is_module_descendant (mod_node_id,
+                                                  current_module.value ()))
          valid = false;
       }
       break;
index 72716a6aa8a335dc56f102e8f41a67060aa7bbaa..d64b7a74df91e43df400db3b64ca7334fe671775 100644 (file)
@@ -22,8 +22,9 @@
 #include "rust-hir-expr.h"
 #include "rust-hir-map.h"
 #include "rust-hir-visitor.h"
+#include "rust-hir-type-check.h"
 #include "rust-mapping-common.h"
-#include "rust-name-resolver.h"
+#include "rust-name-resolution-context.h"
 
 namespace Rust {
 namespace Privacy {
@@ -38,7 +39,7 @@ class PrivacyReporter : public HIR::HIRExpressionVisitor,
 {
 public:
   PrivacyReporter (Analysis::Mappings &mappings,
-                  Rust::Resolver::Resolver &resolver,
+                  const Resolver2_0::NameResolutionContext &resolver,
                   const Rust::Resolver::TypeCheckContext &ty_ctx);
 
   /**
@@ -157,7 +158,7 @@ types
   virtual void visit (HIR::ExprStmt &stmt);
 
   Analysis::Mappings &mappings;
-  Rust::Resolver::Resolver &resolver;
+  const Resolver2_0::NameResolutionContext &resolver;
   const Rust::Resolver::TypeCheckContext &ty_ctx;
 
   // `None` means we're in the root module - the crate
index c59763d73782bdfa5609376b3c16103a3e423436..4240673d40504cc2a9bd5ae3c46579208507de52 100644 (file)
 #include "rust-ast.h"
 #include "rust-hir.h"
 #include "rust-hir-item.h"
-#include "rust-immutable-name-resolution-context.h"
-
-// for flag_name_resolution_2_0
-#include "options.h"
+#include "rust-name-resolution-context.h"
 
 namespace Rust {
 namespace Privacy {
 
-VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings,
-                                       Resolver::Resolver &resolver)
+VisibilityResolver::VisibilityResolver (
+  Analysis::Mappings &mappings,
+  const Resolver2_0::NameResolutionContext &resolver)
   : mappings (mappings), resolver (resolver)
 {}
 
@@ -64,23 +62,12 @@ VisibilityResolver::resolve_module_path (const HIR::SimplePath &restriction,
     = Error (restriction.get_locus (),
             "cannot use non-module path as privacy restrictor");
 
-  NodeId ref_node_id = UNKNOWN_NODEID;
-  if (flag_name_resolution_2_0)
+  NodeId ref_node_id;
+  if (auto id = resolver.lookup (ast_node_id))
     {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      if (auto id = nr_ctx.lookup (ast_node_id))
-       {
-         ref_node_id = *id;
-       }
-      else
-       {
-         invalid_path.emit ();
-         return false;
-       }
+      ref_node_id = *id;
     }
-  else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+  else
     {
       invalid_path.emit ();
       return false;
index 4dfba4cb86b4bdbeb962d00003c274a4046e7517..ddd70a8e467f09a2d3561619f598ff09e9855225 100644 (file)
@@ -24,7 +24,7 @@
 #include "rust-hir-stmt.h"
 #include "rust-hir-item.h"
 #include "rust-hir-map.h"
-#include "rust-name-resolver.h"
+#include "rust-name-resolution-context.h"
 #include "rust-hir-visitor.h"
 
 namespace Rust {
@@ -34,7 +34,7 @@ class VisibilityResolver : public HIR::HIRVisItemVisitor
 {
 public:
   VisibilityResolver (Analysis::Mappings &mappings,
-                     Rust::Resolver::Resolver &resolver);
+                     const Resolver2_0::NameResolutionContext &resolver);
 
   /**
    * Perform visibility resolving on an entire crate
@@ -93,7 +93,7 @@ public:
 
 private:
   Analysis::Mappings &mappings;
-  Rust::Resolver::Resolver &resolver;
+  const Resolver2_0::NameResolutionContext &resolver;
   DefId current_module;
 };