]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Load modules during CfgStrip phase
authorOwen Avery <powerboat9.gamer@gmail.com>
Thu, 3 Jul 2025 01:38:56 +0000 (21:38 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:57 +0000 (16:36 +0200)
TopLevel would ignore just-loaded modules but Early and ExpandVisitor
wouldn't. The latter would produce errors when it hit attributes which
should have been indirectly CfgStrip'd away.

gcc/rust/ChangeLog:

* expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded
modules.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Assume modules have been loaded by CfgStrip.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/expand/rust-cfg-strip.cc
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc

index 774e2b46b947a86344baead47966b99f1f6be517..ac795f7259d76afde2eb2cd5c234fb292ccb40f0 100644 (file)
@@ -1765,16 +1765,17 @@ CfgStrip::visit (AST::Module &module)
       return;
     }
 
-  // A loaded module might have inner attributes
-  if (module.get_kind () == AST::Module::ModuleKind::LOADED)
+  if (module.get_kind () == AST::Module::UNLOADED)
     {
-      // strip test based on inner attrs
-      expand_cfg_attrs (module.get_inner_attrs ());
-      if (fails_cfg_with_expand (module.get_inner_attrs ()))
-       {
-         module.mark_for_strip ();
-         return;
-       }
+      module.load_items ();
+    }
+
+  // strip test based on inner attrs
+  expand_cfg_attrs (module.get_inner_attrs ());
+  if (fails_cfg_with_expand (module.get_inner_attrs ()))
+    {
+      module.mark_for_strip ();
+      return;
     }
 
   // strip items if required
index a7b442d5b440666d9abe38d340b6fc13e4060b8a..713dce6b95a9d46a77405e3f766026e2909b46ae 100644 (file)
@@ -101,27 +101,6 @@ TopLevel::go (AST::Crate &crate)
 void
 TopLevel::visit (AST::Module &module)
 {
-  // Parse the module's items if they haven't been expanded and the file
-  // should be parsed (i.e isn't hidden behind an untrue or impossible cfg
-  // directive
-  // TODO: make sure this is right
-  // TODO: avoid loading items if cfg attributes are present?
-  //       might not be needed if this runs after early resolution?
-  // This was copied from the old early resolver method
-  // 'accumulate_escaped_macros'
-  if (module.get_kind () == AST::Module::UNLOADED)
-    {
-      module.load_items ();
-
-      // If the module was previously unloaded, then we don't want to visit it
-      // this time around as the CfgStrip hasn't run on its inner items yet.
-      // Skip it for now, mark the visitor as dirty and try again
-
-      dirty = true;
-
-      return;
-    }
-
   DefaultResolver::visit (module);
 
   if (Analysis::Mappings::get ().lookup_ast_module (module.get_node_id ())